A desktop coding agent with free access to frontier models.
TypeScript
fix: claude access reads an account with many devices
ogsamrat1b21199a8a91
diff --git a/apps/server/src/claude-code/access.test.ts b/apps/server/src/claude-code/access.test.tsindex 713e7df9..a1b17927 100644--- a/apps/server/src/claude-code/access.test.ts+++ b/apps/server/src/claude-code/access.test.ts@@ -47,3 +47,17 @@ test("a 403 from the token mint forgets the cached access", async () => {expect((await access.access()).models).toEqual([]);expect(state.calls.filter((call) => call === "collect/capabilities").length).toBe(before + 1);});++test("an account with many devices (a large device/me answer) still gets its Claude access", async () => {+ const devices = Array.from({ length: 2000 }, (_, i) => ({ id: `dev-${i}`, name: `device ${i}`, revoked_at: "2026-10-27T00:00:00Z" }));+ const request = async (route: string) => {+ if (route === "device/me") return Response.json({ id: "acct", devices });+ if (route === "collect/capabilities") return Response.json({ claude_code: { enabled: true, models: ["claude-opus-5-5"], catalog: [{ id: "claude-opus-5-5", display_name: "Claude Opus 5.5" }] } });+ throw new Error(route);+ };+ const body = JSON.stringify({ id: "acct", devices });+ expect(body.length).toBeGreaterThan(64 * 1024);+ const answer = await new ClaudeDeviceAccess(request, "desktop/test").access();+ expect(answer.owner).toBe("acct");+ expect(answer.models).toEqual(["claude-opus-5-5"]);+});diff --git a/apps/server/src/claude-code/access.ts b/apps/server/src/claude-code/access.tsindex e11631e2..03f31fe8 100644--- a/apps/server/src/claude-code/access.ts+++ b/apps/server/src/claude-code/access.ts@@ -62,7 +62,12 @@ function budgetSnapshot(value: unknown, context: ClaudeAuthorization): ClaudeBud};}-async function read(response: Response): Promise<unknown> {+/** The cap for token answers (they hold credentials and are small). */+const TOKEN_ANSWER_BYTES = 64 * 1024;+/** device/me and capabilities list every device row of the account: thousands on a long-used test or farm account. */+const ACCOUNT_ANSWER_BYTES = 16 * 1024 * 1024;++async function read(response: Response, limit = TOKEN_ANSWER_BYTES): Promise<unknown> {// Device responses contain credentials. Never include their bodies in errors.if (!response.ok) {const reason = response.status === 409 ? "The session's model or capture contract conflicts with its backend binding"@@ -81,7 +86,7 @@ async function read(response: Response): Promise<unknown> {while (true) {const next = await reader.read(); if (next.done) break;bytes += next.value.byteLength;- if (bytes > 64 * 1024) throw new Error("Invalid Claude authorization response");+ if (bytes > limit) throw new Error("Invalid Claude authorization response");chunks.push(next.value);}try { return JSON.parse(Buffer.concat(chunks).toString("utf8")); }@@ -98,12 +103,12 @@ export class ClaudeDeviceAccess {/** `fresh`: ask the server again now (a turn's start), not the answer of the last 30 s. */async access(options: { fresh?: boolean } = {}): Promise<ClaudeAccess> {- const account = await read(await this.request("device/me"));+ const account = await read(await this.request("device/me"), ACCOUNT_ANSWER_BYTES);if (!record(account) || typeof account.id !== "string" || !account.id) throw new Error("Sign in to OmniRush to use Claude Code");if (options.fresh || !this.capability || this.capability.owner !== account.id || Date.now() >= this.capability.expiresAt) {let models: string[] = [], catalog: ClaudeCatalogEntry[] = [], reason: string | null = "unavailable";try {- const value = await read(await this.request("collect/capabilities"));+ const value = await read(await this.request("collect/capabilities"), ACCOUNT_ANSWER_BYTES);const code = record(value) ? value.claude_code : null;if (record(code)) {// The catalog is shown to every account; `models` (what may run) only to allowed ones.diff --git a/apps/server/src/claude-code/chat.ts b/apps/server/src/claude-code/chat.tsindex 0282d3d1..f3ff61fa 100644--- a/apps/server/src/claude-code/chat.ts+++ b/apps/server/src/claude-code/chat.ts@@ -25,6 +25,9 @@ export function claudeNotAllowedMessage(name: string): string {export type ClaudeChatInput = { op?: unknown; sessionID?: unknown; model?: unknown; resume?: unknown; earlier?: unknown; uuid?: unknown; ok?: unknown; directory?: unknown };export type ClaudeChatAnswer = { ok: true; token?: string; baseUrl?: string; client?: string } | { ok: false; message: string };+/** What the person sees when the server could not say whether Claude is available (the detail goes to the log). */+export const CLAUDE_ACCESS_CHECK_FAILED = "Couldn't check your Claude access. Try again.";+export function claudeChatRoute(deps: {access: () => Promise<ClaudeAccess>;authorize: (context: ClaudeAuthorization) => Promise<ClaudeGrant>;@@ -49,7 +52,10 @@ export function claudeChatRoute(deps: {if (input.op !== "grant") return refuse("Unknown Claude request.");const model = typeof input.model === "string" ? input.model : "";let account: ClaudeAccess;- try { account = await deps.access(); } catch (error) { return refuse(error instanceof Error ? error.message : "Claude could not start."); }+ try { account = await deps.access(); } catch (error) {+ deps.log?.("warn", "claude: no access answer", { error: error instanceof Error ? error.message : String(error) });+ return refuse(CLAUDE_ACCESS_CHECK_FAILED);+ }const entry = account.catalog?.find((e) => e.id === model);if (!entry) return refuse(`${model || "This model"} isn't offered here.`);const pinned = deps.pin(sessionID);diff --git a/apps/server/src/omnirush-gateway-broker.ts b/apps/server/src/omnirush-gateway-broker.tsindex 1fee74da..706577e6 100644--- a/apps/server/src/omnirush-gateway-broker.ts+++ b/apps/server/src/omnirush-gateway-broker.ts@@ -1892,7 +1892,8 @@ export class OmniRushGatewayBroker {await response.body?.cancel().catch(() => undefined);return null;}- const text = await boundedText(response, 256 * 1024);+ // device/me lists every device row of the account: thousands on a long-used test or farm account.+ const text = await boundedText(response, 16 * 1024 * 1024);const payload: unknown = text === null ? null : JSON.parse(text);const id = isRecord(payload) && typeof payload.id === "string" ? payload.id.trim() : "";if (id) this.knownAccountId = id;