From 9dddc5e517b3a1db2a6610b808c3e6843cc1454f Mon Sep 17 00:00:00 2001 From: zeroaltitude Date: Tue, 3 Mar 2026 20:17:30 -0700 Subject: [PATCH] fix(browser): restore res.json before error handling in withRouteTabContext The intercepted res.json was not restored on exceptions from run(), causing handleRouteError -> jsonError to hit the buffer interceptor instead of actually sending the error response. This could leave HTTP requests hanging on any Playwright failure in tab-targeting routes. Addresses codex-connector P1 on PR #30323. --- src/browser/routes/agent.shared.ts | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/browser/routes/agent.shared.ts b/src/browser/routes/agent.shared.ts index 37b30e00a50..5be92f9c0c2 100644 --- a/src/browser/routes/agent.shared.ts +++ b/src/browser/routes/agent.shared.ts @@ -133,11 +133,18 @@ export async function withRouteTabContext( return params.res; }; - const result = await params.run({ - profileCtx, - tab, - cdpUrl: profileCtx.profile.cdpUrl, - }); + let result: T | undefined; + try { + result = await params.run({ + profileCtx, + tab, + cdpUrl: profileCtx.profile.cdpUrl, + }); + } catch (runErr) { + // Restore original res.json so error handling can actually send. + params.res.json = originalJson; + throw runErr; + } // Now enrich and flush the intercepted response body. if (jsonCalled) {