{"record":{"id":"99b15f739cee0708","repo":"can1357/oh-my-pi","slug":"failed-to-initialize-authentication-storage","errorCode":null,"errorMessage":"Failed to initialize authentication storage","messagePattern":"Failed to initialize authentication storage","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/web/search/index.ts","lineNumber":298,"sourceCode":"\t\t},\n\t};\n}\n\n/**\n * Execute a web search query for CLI/testing workflows.\n *\n * `authStorage` may be omitted; in that case we discover one via the standard\n * factory (`discoverAuthStorage`), which honours `OMP_AUTH_BROKER_URL` and\n * otherwise opens the local SQLite credential store.\n */\nexport async function runSearchQuery(\n\tparams: SearchQueryParams,\n\toptions: { authStorage?: AuthStorage; modelRegistry?: ModelRegistry; sessionId?: string; signal?: AbortSignal } = {},\n): Promise<{ content: Array<{ type: \"text\"; text: string }>; details: SearchRenderDetails }> {\n\tconst createdAuthStorage = options.authStorage || options.modelRegistry ? undefined : await discoverAuthStorage();\n\tconst authStorage = options.authStorage ?? options.modelRegistry?.authStorage ?? createdAuthStorage;\n\tif (!authStorage) {\n\t\tthrow new Error(\"Failed to initialize authentication storage\");\n\t}\n\tconst modelRegistry = options.modelRegistry ?? (createdAuthStorage ? new ModelRegistry(authStorage) : undefined);\n\ttry {\n\t\treturn await executeSearch(\"cli-web-search\", params, {\n\t\t\tauthStorage,\n\t\t\tmodelRegistry,\n\t\t\tsessionId: options.sessionId,\n\t\t\tsignal: options.signal,\n\t\t});\n\t} finally {\n\t\tcreatedAuthStorage?.close();\n\t}\n}\n\n/**\n * Web search tool implementation.\n *\n * Supports the configured web-search provider chain with automatic fallback.","sourceCodeStart":280,"sourceCodeEnd":316,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/web/search/index.ts#L280-L316","documentation":"runSearchQuery needs an AuthStorage instance to access provider credentials and a ModelRegistry. If the caller supplies neither authStorage nor modelRegistry and discoverAuthStorage() cannot locate/create one (no stored auth on disk), it throws 'Failed to initialize authentication storage'. It is an environment/setup failure, not a search failure.","triggerScenarios":"Calling runSearchQuery with no options.authStorage and no options.modelRegistry while the machine has no discoverable auth storage (fresh environment, HOME not set, credentials never initialized).","commonSituations":"Running the web-search tool in CI or a container without prior login; running under a different user/HOME than where credentials were created; SDK/embedding usage without passing an explicit authStorage.","solutions":["Run the app's auth/login flow once to create the auth storage on this machine/user.","Pass an explicit AuthStorage (or a ModelRegistry with authStorage) via options instead of relying on discovery.","Check HOME/USERPROFILE and app config directory resolution — discovery may look in the wrong place in daemons/CI.","Reuse a single shared authStorage instance you create at startup and thread it through all tool calls."],"exampleFix":"// before\nawait runSearchQuery(params); // relies on discoverAuthStorage()\n// after\nimport { discoverAuthStorage } from \"...\";\nconst authStorage = await discoverAuthStorage();\nif (!authStorage) throw new Error(\"Run `omp auth` to initialize credentials\");\nawait runSearchQuery(params, { authStorage });","handlingStrategy":"validation","validationCode":"const authStorage = options.authStorage ?? options.modelRegistry?.authStorage ?? (await discoverAuthStorage());\nif (!authStorage) {\n  throw new Error(\"No auth storage — run the app's auth/login flow or pass authStorage explicitly\");\n}","typeGuard":"null","tryCatchPattern":"try { return await runSearchQuery(params, opts); }\ncatch (e) {\n  if (e instanceof Error && e.message === \"Failed to initialize authentication storage\") {\n    // prompt user to authenticate or re-run with explicit authStorage\n    return { content: [{ type: \"text\", text: \"Authentication not initialized. Run `omp auth`.\" }] };\n  }\n  throw e;\n}","preventionTips":["Create auth storage at application startup and pass it explicitly to tool calls.","In CI/containers, provision or mount the auth storage directory before running.","Don't rely on discoverAuthStorage() under nonstandard HOME or daemon contexts.","Initialize ModelRegistry from the same authStorage you pass to searches."],"tags":["configuration","auth","initialization"],"backgroundTag":"missing-env-var","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}