can1357/oh-my-pi · error
Failed to initialize authentication storage
Error message
Failed to initialize authentication storage
What it means
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.
Source
Thrown at packages/coding-agent/src/web/search/index.ts:298
},
};
}
/**
* Execute a web search query for CLI/testing workflows.
*
* `authStorage` may be omitted; in that case we discover one via the standard
* factory (`discoverAuthStorage`), which honours `OMP_AUTH_BROKER_URL` and
* otherwise opens the local SQLite credential store.
*/
export async function runSearchQuery(
params: SearchQueryParams,
options: { authStorage?: AuthStorage; modelRegistry?: ModelRegistry; sessionId?: string; signal?: AbortSignal } = {},
): Promise<{ content: Array<{ type: "text"; text: string }>; details: SearchRenderDetails }> {
const createdAuthStorage = options.authStorage || options.modelRegistry ? undefined : await discoverAuthStorage();
const authStorage = options.authStorage ?? options.modelRegistry?.authStorage ?? createdAuthStorage;
if (!authStorage) {
throw new Error("Failed to initialize authentication storage");
}
const modelRegistry = options.modelRegistry ?? (createdAuthStorage ? new ModelRegistry(authStorage) : undefined);
try {
return await executeSearch("cli-web-search", params, {
authStorage,
modelRegistry,
sessionId: options.sessionId,
signal: options.signal,
});
} finally {
createdAuthStorage?.close();
}
}
/**
* Web search tool implementation.
*
* Supports the configured web-search provider chain with automatic fallback.View on GitHub (pinned to 9690622007)
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.
Example fix
// before
await runSearchQuery(params); // relies on discoverAuthStorage()
// after
import { discoverAuthStorage } from "...";
const authStorage = await discoverAuthStorage();
if (!authStorage) throw new Error("Run `omp auth` to initialize credentials");
await runSearchQuery(params, { authStorage }); Defensive patterns
Strategy: validation
Validate before calling
const authStorage = options.authStorage ?? options.modelRegistry?.authStorage ?? (await discoverAuthStorage());
if (!authStorage) {
throw new Error("No auth storage — run the app's auth/login flow or pass authStorage explicitly");
} Type guard
null
Try / catch
try { return await runSearchQuery(params, opts); }
catch (e) {
if (e instanceof Error && e.message === "Failed to initialize authentication storage") {
// prompt user to authenticate or re-run with explicit authStorage
return { content: [{ type: "text", text: "Authentication not initialized. Run `omp auth`." }] };
}
throw e;
} Prevention
- 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.
When it happens
Trigger: 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).
Common situations: 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.
Understand the failure class
Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.
- Authentication and authorization failures — expired tokens, bad credentials, and missing scopes.
Related errors
- No model configured
- gitlab-duo-agent
- No session - local:// unavailable
- No API key for ${resolved.model.provider}/${resolved.model.i
- No available model to generate agent specification.
AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31).
Data as JSON: /api/errors/99b15f739cee0708.
Report an issue: GitHub.