Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(plan-usage): never read the Claude Code login for the usage meter (#5300)
milind-sonib9c7f1217122
diff --git a/server/engine-limits.e2e.test.ts b/server/engine-limits.e2e.test.tsindex 6f007401c2..ee67b4a2ea 100644--- a/server/engine-limits.e2e.test.ts+++ b/server/engine-limits.e2e.test.ts@@ -26,7 +26,8 @@ it("a bot's turn reads its accounts' usage limits through its own capability, anconst { text } = await answer.json() as { text: string };const accounts = JSON.parse(text).accounts as Array<{ engine: string; status: string; windows: unknown[]; why?: string }>;const claude = accounts.find((account) => account.engine === "claudeAgent");- expect(claude, text).toMatchObject({ status: "unknown", windows: [] });+ // The Claude Code login is never read for usage, so Claude reports no limits; a refused turn still fails over.+ expect(claude, text).toMatchObject({ status: "unsupported", windows: [] });expect(claude!.why, text).toBeTruthy();writeFileSync(gate, "finish");} finally {diff --git a/server/limit-resets.test.ts b/server/limit-resets.test.tsindex 73b22f5ff8..a87aacb514 100644--- a/server/limit-resets.test.ts+++ b/server/limit-resets.test.ts@@ -34,8 +34,8 @@ const codex = (primary: [number, number], secondary: [number, number]) => row("c}));const report = (...providers: PlanProviderRow[]): PlanUsageReport => ({ fetchedAt: iso(NOW), providers });-describe("a Claude account whose usage meter is turned off", () => {- it("stops a full reading from holding it, even one fetched before the switch, and keeps a refusal's hold", () => {+describe("a Claude account whose usage is not read", () => {+ it("stops a full reading from holding it, even one saved before an update stopped reading it, and keeps a refusal's hold", () => {const account = { id: "claude", name: "Claude", driver: "claude" as const, environment: {} };let accounts: Array<typeof account & { noUsage?: true }> = [account];const instance = new LimitResetClock({ accounts: () => accounts, now: () => NOW });diff --git a/server/plan-usage.test.ts b/server/plan-usage.test.tsindex 2b92396473..e19dc62dd1 100644--- a/server/plan-usage.test.ts+++ b/server/plan-usage.test.ts@@ -489,13 +489,13 @@ describe("plan usage fetcher", () => {it("lists configured Claude, Codex, and Grok accounts and skips other engines", () => {expect(planAccountsFromInstances({- claude: { driver: "claudeAgent", displayName: " Personal Claude ", config: { configDir: "/tmp/claude", usageMeter: true } },+ claude: { driver: "claudeAgent", displayName: " Personal Claude ", config: { configDir: "/tmp/claude" } },codex: { driver: "codex" },grok: { driver: "grokAgent", environment: { GROK_HOME: "/tmp/grok" } },cursor: { driver: "cursorAgent", displayName: "Cursor" },api: { driver: "grok", displayName: "Grok API" },})).toEqual([- { id: "claude", name: "Personal Claude", driver: "claude", environment: {}, configDir: "/tmp/claude" },+ { id: "claude", name: "Personal Claude", driver: "claude", environment: {}, configDir: "/tmp/claude", noUsage: true },{ id: "codex", name: "Codex", driver: "codex", environment: {} },{ id: "grok", name: "Grok", driver: "grok", environment: { GROK_HOME: "/tmp/grok" } },]);@@ -615,31 +615,22 @@ describe("plan usage fetcher", () => {expect(report.providers.map((row) => row.id)).toEqual(["codex"]);});- it("reads no Claude login unless the instance turns its usage meter on", async () => {+ it("never reads a Claude Code login, on any Claude instance, and still reads the other engines", async () => {const accounts = planAccountsFromInstances({claude: { driver: "claudeAgent" },- metered: { driver: "claudeAgent", displayName: "Metered", config: { usageMeter: true } },+ work: { driver: "claudeAgent", displayName: "Work", config: { configDir: "/tmp/claude-work" } },+ codex: { driver: "codex" },});+ // Still listed, so a refused turn's hold names the account and fails over.expect(accounts).toEqual([{ id: "claude", name: "Claude", driver: "claude", environment: {}, noUsage: true },- { id: "metered", name: "Metered", driver: "claude", environment: {} },+ { id: "work", name: "Work", driver: "claude", environment: {}, configDir: "/tmp/claude-work", noUsage: true },+ { id: "codex", name: "Codex", driver: "codex", environment: {} },]);const read = vi.fn((_account: PlanAccount) => ({ token: SECRET, accountId: null, expired: false }));- const fetchImpl = vi.fn<PlanFetch>(async () => jsonResponse({}));+ const fetchImpl = vi.fn<PlanFetch>(async () => jsonResponse({ rate_limit: { primary_window: { used_percent: 10 } } }));const report = await fetchPlanUsage(accounts, { fetch: fetchImpl, now: () => NOW, credentials: { read } });- expect(read.mock.calls.map(([account]) => account.id)).toEqual(["metered"]);- expect(report.providers.map((row) => row.id)).toEqual(["metered"]);- });-- it("never serves a cached report across a usage-meter switch", async () => {- const read = vi.fn((_account: PlanAccount) => ({ token: SECRET, accountId: null, expired: false }));- const fetchImpl = vi.fn<PlanFetch>(async () => jsonResponse({}));- const load = (usageMeter: boolean) => loadPlanUsage({- accounts: planAccountsFromInstances({ claude: { driver: "claudeAgent", config: { usageMeter } } }),- fetch: fetchImpl, now: NOW, credentials: { read },- });- expect((await load(true)).providers.map((row) => row.id)).toEqual(["claude"]);- expect((await load(false)).providers).toEqual([]);- expect((await load(true)).providers.map((row) => row.id)).toEqual(["claude"]);+ expect(read.mock.calls.map(([account]) => account.id)).toEqual(["codex"]);+ expect(report.providers.map((row) => row.id)).toEqual(["codex"]);});});diff --git a/server/plan-usage.ts b/server/plan-usage.tsindex 4f666b92a5..41293d59d7 100644--- a/server/plan-usage.ts+++ b/server/plan-usage.ts@@ -72,7 +72,7 @@ export interface PlanAccount {driver: PlanDriver;environment: Record<string, string | undefined>;configDir?: string;- /** No usage reading: a ChatGPT plan signed in through OpenMausBot has no CLI login on disk, and a Claude login is read only when its instance sets `usageMeter: true`, since Anthropic's credential policy covers that token for Claude Code alone (a refused turn still fails over). */+ /** No usage reading: a ChatGPT plan signed in through OpenMausBot has no CLI login on disk, and a Claude Code login is never read, since Anthropic's credential policy covers that token for Claude Code alone (a refused turn still fails over). */noUsage?: true;}@@ -164,7 +164,7 @@ export function planAccountsFromInstances(instances: InstanceConfigMap): PlanAccenvironment: { ...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" || (driver === "claude" && config?.usageMeter !== true) ? { noUsage: true as const } : {}),+ ...(config?.authMode === "chatgpt-plan" || driver === "claude" ? { noUsage: true as const } : {}),});}return accounts;