{"record":{"id":"6efab3792463a2b2","repo":"can1357/oh-my-pi","slug":"auth-broker-returned-no-initial-snapshot-6efab3","errorCode":null,"errorMessage":"Auth broker returned no initial snapshot","messagePattern":"Auth broker returned no initial snapshot","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/cli/auth-gateway-cli.ts","lineNumber":140,"sourceCode":"\tif (existing) return existing;\n\tconst token = generateToken();\n\tif (await createTokenExclusive(token)) return token;\n\t// Another concurrent invocation won the create race; read what they wrote.\n\tconst fromRace = await readToken();\n\tif (fromRace) return fromRace;\n\t// File existed-then-disappeared between EEXIST and read; last resort, write\n\t// our generated token unconditionally so callers don't see an empty string.\n\tawait writeToken(token);\n\treturn token;\n}\n\nfunction createBrokerClient(brokerConfig: AuthBrokerClientConfig): AuthBrokerClient {\n\treturn new AuthBrokerClient({ url: brokerConfig.url, token: brokerConfig.token });\n}\n\nasync function fetchBrokerSnapshot(client: AuthBrokerClient): Promise<SnapshotResponse> {\n\tconst result = await client.fetchSnapshot();\n\tif (result.status !== 200) throw new Error(\"Auth broker returned no initial snapshot\");\n\treturn result.snapshot;\n}\n\n/**\n * How often a long-lived `serve` rebuilds its catalog from the registry so\n * models discovered after boot become routable without a restart. `refresh()`\n * reuses the `models.db` cache and only hits the network when a provider's\n * cached row is stale, so a short interval stays cheap.\n */\nconst CATALOG_REFRESH_INTERVAL_MS = 15 * 60 * 1000;\n\n/**\n * Index resolvable models by the request ids clients may send: the\n * provider-qualified `provider/id` (always) and the bare `id` (first-write-wins\n * fallback for legacy clients). Scoped to providers the gateway holds broker\n * credentials for, since only those are routable.\n */\nexport function indexModelsByRequestId(","sourceCodeStart":122,"sourceCodeEnd":158,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/cli/auth-gateway-cli.ts#L122-L158","documentation":"fetchBrokerSnapshot wraps AuthBrokerClient.fetchSnapshot() and throws when the HTTP status is not 200, since the gateway's model catalog depends on a valid broker snapshot. This is the same guard as the migrate path but for `omp auth-gateway serve` (via initialSnapshot/snapshot).","triggerScenarios":"`omp auth-gateway serve` boot or catalog refresh when the broker returns non-200 (bad token, wrong URL, broker outage).","commonSituations":"Gateway started with a stale OMP_AUTH_BROKER_TOKEN after token rotation; broker URL pointing at the gateway itself or a wrong port; broker temporarily down while gateway refreshes its catalog.","solutions":["Verify auth.broker.url / auth.broker.token (or OMP_AUTH_BROKER_URL/TOKEN env vars) are correct.","Confirm the broker is reachable: curl its snapshot endpoint with the token and inspect the status.","Restart the gateway with corrected credentials after a token rotation.","If 5xx, check broker logs/service health and retry."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"if (!process.env.OMP_AUTH_BROKER_URL && !config.auth?.broker?.url) throw new Error(\"broker not configured\");","typeGuard":"function isSnapshotOk(r: { status: number; snapshot?: Snapshot }): r is { status: 200; snapshot: Snapshot } {\n  return r.status === 200 && !!r.snapshot;\n}","tryCatchPattern":"try {\n  const snapshot = await fetchBrokerSnapshot(client);\n} catch (err) {\n  logger.warn(\"broker snapshot failed, retrying\", { err });\n  await Bun.sleep(backoffMs);\n  return fetchBrokerSnapshot(client);\n}","preventionTips":["Keep gateway and broker tokens in sync via one secret source","Monitor broker /health from the gateway host","Add retry with backoff around catalog refresh"],"tags":["auth-gateway","auth-broker","http-status","network"],"backgroundTag":"non-200-http-response","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}