From 376084c19a9b27aa126e37d3835119abb45a8be5 Mon Sep 17 00:00:00 2001 From: can1357 Date: Sat, 11 Jul 2026 06:45:12 +0200 Subject: [PATCH] feat(coding-agent/web): ensured proper cleanup of authentication storage - Added a mandatory check to ensure authentication storage is successfully initialized before executing searches. - Implemented a finally block to close the discovered authentication storage after the search execution completes. --- packages/coding-agent/src/web/search/index.ts | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/packages/coding-agent/src/web/search/index.ts b/packages/coding-agent/src/web/search/index.ts index 8e025f369..b81eedacf 100644 --- a/packages/coding-agent/src/web/search/index.ts +++ b/packages/coding-agent/src/web/search/index.ts @@ -231,12 +231,20 @@ export async function runSearchQuery( params: SearchQueryParams, options: { authStorage?: AuthStorage; sessionId?: string; signal?: AbortSignal } = {}, ): Promise<{ content: Array<{ type: "text"; text: string }>; details: SearchRenderDetails }> { - const authStorage = options.authStorage ?? (await discoverAuthStorage()); - return executeSearch("cli-web-search", params, { - authStorage, - sessionId: options.sessionId, - signal: options.signal, - }); + const createdAuthStorage = options.authStorage ? undefined : await discoverAuthStorage(); + const authStorage = options.authStorage ?? createdAuthStorage; + if (!authStorage) { + throw new Error("Failed to initialize authentication storage"); + } + try { + return await executeSearch("cli-web-search", params, { + authStorage, + sessionId: options.sessionId, + signal: options.signal, + }); + } finally { + createdAuthStorage?.close(); + } } /**