From e8315c3fd27759a77927ed50e9cd0f2c95c46a0e Mon Sep 17 00:00:00 2001 From: iceteaSA <171169159+iceteaSA@users.noreply.github.com> Date: Sun, 17 May 2026 11:36:08 +0200 Subject: [PATCH] perf: pass storage to tryFallbackAccounts to skip redundant disk read The fetch handler already loads storage at the start of every request. tryFallbackAccounts was reloading it from disk unnecessarily. Now accepts an optional existingStorage parameter to reuse the caller's copy. --- packages/opencode/src/index.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/opencode/src/index.ts b/packages/opencode/src/index.ts index 38f51a5..e02bcf3 100644 --- a/packages/opencode/src/index.ts +++ b/packages/opencode/src/index.ts @@ -873,13 +873,15 @@ export const AnthropicAuthPlugin: Plugin = async (ctx) => { ReturnType >, trace?: PerfTrace, + existingStorage?: Awaited>, ) { if (!isReplayableRequest(input, init?.body)) return mainResponse const loadStart = nowMs() - const storage = await loadAccounts() + const storage = existingStorage ?? (await loadAccounts()) trace?.mark('fallback_load_storage', { ms: roundMs(nowMs() - loadStart), + cached: !!existingStorage, }) let currentResponse = mainResponse let shouldFallback = shouldFallbackStatus( @@ -1022,6 +1024,7 @@ export const AnthropicAuthPlugin: Plugin = async (ctx) => { mainResponse, preselectedFallbackAccounts, trace, + storage, ) trace.done('return_response', { status: response.status })