Claude Code. Any Model. The most powerful AI coding agent now speaks every language.
fix(adapters): bill an openai-codex hop by the arm that signed it
Jack Rudenkoda614153f3cb
diff --git a/ai-docs/architecture/advisor.md b/ai-docs/architecture/advisor.mdindex c13eaa2c..6654ba06 100644--- a/ai-docs/architecture/advisor.md+++ b/ai-docs/architecture/advisor.md@@ -502,8 +502,11 @@ value:### Billing and stats`billing` is decided by the arm that signed, never by the provider name: routed calls read it-from the hop log after signing (`HopAttempt.billing` = `isSubscriptionProvider` once the-credential arm is known, so `openai-codex` bills by the credential that signed); Claude calls+from the hop log after signing (`HopAttempt.billing`, set by `markHopSigned`: for+`openai-codex`, the one credential-decided provider, it is that request's own+`RequestAuth.arm`, `oauth` = subscription and anything else metered, never the name check, whose+probe reads a process-wide last-signed arm; for every other provider it is its+`SUBSCRIPTION_PROVIDERS` membership); Claude callsare `subscription` iff `arm === "oauth"` (`native-anthropic` is in neither billing set). That isthe $0 evidence with stats on or off: `getModelPricing` returns zero exactly when`isSubscriptionProvider` is true.diff --git a/packages/cli/src/handlers/composed-handler.ts b/packages/cli/src/handlers/composed-handler.tsindex e54587b3..42451df9 100644--- a/packages/cli/src/handlers/composed-handler.ts+++ b/packages/cli/src/handlers/composed-handler.ts@@ -134,7 +134,10 @@ import { hasActionableLink, hasModelUnsupportedWording } from "./shared/model-unimport { filterIdentity } from "./shared/openai-compat.js";import { hasPlanLimitWording, isQuotaExhaustionError } from "./shared/quota-exhaustion.js";import { connectionFaultHeaders, recoveryHoldHeaders } from "./shared/recovery-marker.js";-import { isSubscriptionProvider } from "./shared/remote-provider-types.js";+import {+ CREDENTIAL_DECIDED_PROVIDERS,+ isSubscriptionProvider,+} from "./shared/remote-provider-types.js";import {CONTEXT_OVERFLOW_PHRASE,isContextOverflowError,@@ -597,12 +600,24 @@ export class ComposedHandler implements ModelHandler {/*** Fill a hop-log entry once the request is signed: the arm from the* binding the credential half returned (`RequestAuth.arm`, never inferred- * from a resolved object's truthiness), and the billing the provider has- * now, which for `openai-codex` reflects the arm just recorded.+ * from a resolved object's truthiness), and the billing.+ *+ * For a provider whose billing the signing credential decides+ * (`CREDENTIAL_DECIDED_PROVIDERS`, i.e. `openai-codex`) the billing is THIS+ * request's arm: `oauth` is the subscription, anything else (absent+ * included) is metered. It is never `isSubscriptionProvider(name)`, whose+ * probe reads a process-wide last-signed arm that a concurrent main request+ * can overwrite between this request's refresh and this line. Every other+ * provider's billing is its fixed category (`SUBSCRIPTION_PROVIDERS`+ * membership), whatever arm signs: a flat-rate key is still flat-rate.*/private markHopSigned(hop: HopAttempt, binding: AuthBinding | undefined): void {hop.arm = binding?.auth?.arm ?? null;- hop.billing = isSubscriptionProvider(this.provider.name) ? "subscription" : "metered";+ const name = this.provider.name.toLowerCase();+ const subscription = CREDENTIAL_DECIDED_PROVIDERS.has(name)+ ? hop.arm === "oauth"+ : isSubscriptionProvider(name);+ hop.billing = subscription ? "subscription" : "metered";}/**diff --git a/packages/cli/src/handlers/shared/call-context.ts b/packages/cli/src/handlers/shared/call-context.tsindex 43a1cf4e..5cfb9306 100644--- a/packages/cli/src/handlers/shared/call-context.ts+++ b/packages/cli/src/handlers/shared/call-context.ts@@ -359,7 +359,7 @@ export function abortedResponse(): Response {*/export const HOP_LOG_KEY = "claudishHopLog" as const;-/** How a hop bills: by the provider's subscription status right after signing. */+/** How a hop bills, decided right after signing (see `HopAttempt.billing`). */export type HopBilling = "subscription" | "metered";/**@@ -374,7 +374,12 @@ export interface HopAttempt {wireModel: string;/** The arm that signed (`RequestAuth.arm`); null until signed, or when the transport names none. */arm: CredentialArm | null;- /** `isSubscriptionProvider(provider)` right after signing; null until signed. */+ /**+ * Set right after signing; null until signed. For a credential-decided+ * provider (`openai-codex`) it is the arm that signed (`oauth` =+ * subscription); for every other provider its `SUBSCRIPTION_PROVIDERS`+ * membership (`ComposedHandler.markHopSigned`).+ */billing: HopBilling | null;/*** The planned hop's provider uid, stamped by a caller that knows which