Skip to content

Commit 300baf8

Browse files
only21milclaude
andauthored
fix(server): the Codex plan badge updates after a ChatGPT downgrade (#24978)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent a83ab55 commit 300baf8

2 files changed

Lines changed: 33 additions & 3 deletions

File tree

‎apps/server/src/provider/CodexProvider.ts‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,17 @@ function reasoningEffortLabel(reasoningEffort: string): string {
117117
return REASONING_EFFORT_LABELS[reasoningEffort] ?? reasoningEffort;
118118
}
119119

120-
function codexAccountAuthLabel(account: CodexSchema.V2GetAccountResponse["account"]) {
120+
function codexAccountAuthLabel(
121+
account: CodexSchema.V2GetAccountResponse["account"],
122+
usagePlanType: string | null | undefined,
123+
) {
121124
if (!account) return undefined;
122125
if (account.type === "apiKey") return "OpenAI API Key";
123126
if (account.type === "amazonBedrock") return "Amazon Bedrock";
124127
if (account.type !== "chatgpt") return undefined;
125-
return codexPlanLabel(account.planType);
128+
// account/read takes the plan from the cached login token; the usage read asks the backend.
129+
const usageLabel = usagePlanType === "unknown" ? undefined : codexPlanLabel(usagePlanType);
130+
return usageLabel ?? codexPlanLabel(account.planType);
126131
}
127132

128133
export function codexPlanLabel(planType: string | null | undefined): string | undefined {
@@ -698,7 +703,10 @@ function accountProbeStatus({ account, rateLimits }: CodexAppServerProviderSnaps
698703
readonly auth: ServerProvider["auth"];
699704
readonly message?: string;
700705
} {
701-
const authLabel = codexAccountAuthLabel(account.account);
706+
const authLabel = codexAccountAuthLabel(
707+
account.account,
708+
rateLimits && "snapshot" in rateLimits ? rateLimits.snapshot.planType : undefined,
709+
);
702710
const authEmail = codexAccountEmail(account.account);
703711
const workspaceId =
704712
rateLimits && "accountId" in rateLimits ? rateLimits.accountId?.trim() : undefined;

‎apps/server/src/provider/ProviderRegistry.test.ts‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,28 @@ it.layer(
410410
}),
411411
);
412412

413+
it.effect("labels the plan the usage read reports over the cached login plan", () =>
414+
Effect.gen(function* () {
415+
const statusWithUsagePlan = (planType: string | null) =>
416+
checkCodexProviderStatus(defaultCodexSettings, () =>
417+
Effect.succeed(
418+
makeCodexProbeSnapshot({
419+
rateLimits: { snapshot: { planType }, resetCredits: null },
420+
}),
421+
),
422+
);
423+
424+
const downgraded = yield* statusWithUsagePlan("free");
425+
assert.strictEqual(downgraded.auth.label, "ChatGPT Free Subscription");
426+
427+
const unreported = yield* statusWithUsagePlan(null);
428+
assert.strictEqual(unreported.auth.label, "ChatGPT Pro 200 Subscription");
429+
430+
const unknown = yield* statusWithUsagePlan("unknown");
431+
assert.strictEqual(unknown.auth.label, "ChatGPT Pro 200 Subscription");
432+
}),
433+
);
434+
413435
it.effect("returns unauthenticated when app-server requires OpenAI auth", () =>
414436
Effect.gen(function* () {
415437
const status = yield* checkCodexProviderStatus(defaultCodexSettings, () =>

0 commit comments

Comments
 (0)