Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

Plan usage: don't show the default Codex account's limit on a ChatGPT-plan provider (#4146)

Aditya Umalebed234155cd9
diff --git a/server/plan-usage.test.ts b/server/plan-usage.test.ts
index 40124bfce7..ddd8d1e0fe 100644
--- a/server/plan-usage.test.ts
+++ b/server/plan-usage.test.ts
@@ -472,4 +472,25 @@ describe("plan usage fetcher", () => {
{ id: "grok", name: "Grok", driver: "grok", environment: { GROK_HOME: "/tmp/grok" } },
]);
});
+
+ it("reads no usage for a ChatGPT-plan provider, whose sign-in is not the shared Codex login", async () => {
+ // Reading ~/.codex/auth.json for it reported (and held) the default Codex account's limit on a different account.
+ const accounts = planAccountsFromInstances({
+ codex: { driver: "codex" },
+ chatgpt: { driver: "codex", displayName: "ChatGPT plan", config: { authMode: "chatgpt-plan" } },
+ });
+ // Still listed, so a refusal-based hold names it properly.
+ expect(accounts).toEqual([
+ { id: "codex", name: "Codex", driver: "codex", environment: {} },
+ { id: "chatgpt", name: "ChatGPT plan", driver: "codex", environment: {}, noUsage: true },
+ ]);
+ const fetchImpl = vi.fn<PlanFetch>(async () => jsonResponse({ rate_limit: { primary_window: { used_percent: 100 } } }));
+ const report = await fetchPlanUsage(accounts, {
+ fetch: fetchImpl,
+ now: () => NOW,
+ credentials: { read: () => ({ token: SECRET, accountId: null, expired: false }) },
+ });
+ expect(fetchImpl).toHaveBeenCalledTimes(1);
+ expect(report.providers.map((row) => row.id)).toEqual(["codex"]);
+ });
});
diff --git a/server/plan-usage.ts b/server/plan-usage.ts
index f1cd89b9e0..977ae18064 100644
--- a/server/plan-usage.ts
+++ b/server/plan-usage.ts
@@ -71,6 +71,8 @@ export interface PlanAccount {
driver: PlanDriver;
environment: Record<string, string | undefined>;
configDir?: string;
+ /** Signed in through OpenMausBot (ChatGPT plan), not a CLI login on disk, so it has no usage reading. */
+ noUsage?: true;
}
export interface PlanCredential {
@@ -156,6 +158,8 @@ export function planAccountsFromInstances(instances: InstanceConfigMap): PlanAcc
driver,
environment: { ...entry.environment },
...(configDir ? { configDir } : {}),
+ // Reading ~/.codex/auth.json for a ChatGPT-plan provider would report (and hold it on) another account's limit.
+ ...(config?.authMode === "chatgpt-plan" ? { noUsage: true as const } : {}),
});
}
return accounts;
@@ -263,7 +267,7 @@ export function defaultCredentialReader(env: NodeJS.ProcessEnv = process.env): C
export async function fetchPlanUsage(accounts: PlanAccount[], deps: PlanUsageDeps): Promise<PlanUsageReport> {
const now = deps.now?.() ?? Date.now();
- const providers = await Promise.all(accounts.map((account) => fetchProvider(account, deps)));
+ const providers = await Promise.all(accounts.filter((account) => !account.noUsage).map((account) => fetchProvider(account, deps)));
return { fetchedAt: new Date(now).toISOString(), providers };
}