Skip to content

fix(gateway): abort timed-out local browser requests - #40305

Closed
lampten wants to merge 8 commits into
openclaw:mainfrom
lampten:fix/browser-local-timeout-aborts
Closed

lampten wants to merge 8 commits into
openclaw:mainfrom
lampten:fix/browser-local-timeout-aborts

Conversation

@lampten

@lampten lampten commented Mar 8, 2026

Copy link
Copy Markdown

AI-assisted: yes (Codex).
Testing: focused regression tests + pnpm build.

Summary

  • This supersedes Fix browser timeout propagation for local actions and CLI commands #39277. After v2026.3.7 landed the overlapping pw-session refactor in a075baba8 (refactor(browser): scope CDP sessions and harden stale target recovery), the old branch now conflicts heavily with main.
  • The upstream refactor improved session scoping, but it did not finish the local timeout/abort path that triggered the original bug: local browser.request still timed out at the caller while in-process Playwright work could continue, and most non-evaluate browser actions/snapshots still did not honor request aborts.
  • This PR re-submits only the remaining bugfix: wire local browser.request timeouts into in-process dispatch, pass route abort signals into action/snapshot Playwright helpers, make those helpers reject immediately on abort while disconnecting in the background, and avoid retrying navigation after the request is already aborted.
  • Scope boundary: this intentionally does not re-touch the new pw-session structure from v2026.3.7, and it does not include the broader CLI timeout cleanups from Fix browser timeout propagation for local actions and CLI commands #39277.

Change Type (select all)

  • Bug fix
  • Feature
  • Refactor
  • Docs
  • Security hardening
  • Chore/infra

Scope (select all touched areas)

  • Gateway / orchestration
  • Skills / tool execution
  • Auth / tokens
  • Memory / storage
  • Integrations
  • API / contracts
  • UI / DX
  • CI/CD / infra

Linked Issue/PR

User-visible / Behavior Changes

  • Timed-out local browser actions and snapshots now abort cleanly instead of leaving the attached Playwright/CDP target running in the background.
  • Follow-up interactive requests against the same attached session are less likely to degrade into repeated timeouts after one aborted action.

Security Impact (required)

  • New permissions/capabilities? (Yes/No) No
  • Secrets/tokens handling changed? (Yes/No) No
  • New/changed network calls? (Yes/No) No
  • Command/tool execution surface changed? (Yes/No) No
  • Data access scope changed? (Yes/No) No
  • If any Yes, explain risk + mitigation:

Repro + Verification

Environment

  • OS: Linux arm64 (original Raspberry Pi repro) and local Linux dev environment for source validation
  • Runtime/container: Node.js workspace via pnpm
  • Relevant config (redacted): attached Chromium session (attachOnly: true), persistent browser profile, local CDP endpoint, local gateway websocket

Steps

  1. Attach OpenClaw to a persistent Chromium/CDP session and confirm browser status, browser tabs, and browser snapshot succeed.
  2. Run an interactive browser action such as browser act kind=type ... --submit or browser act kind=click ....
  3. Observe timeout/abort behavior and then retry follow-up browser actions against the same tab/session.

Expected

  • Timed-out browser work should abort cleanly, and follow-up actions should still be able to reuse the session.

Actual

  • Before this change, local request timeout could fire first while in-process Playwright work kept running, which left later interactive requests prone to more timeouts.

Evidence

  • Failing test/log before + passing after
  • Trace/log snippets
  • Screenshot/recording
  • Perf numbers (if relevant)

Human Verification (required)

  • Verified scenarios: the original runtime hotfix was exercised end-to-end against a live attached Chromium session on Raspberry Pi (Gemini snapshot + type --submit, plus example.com click flows), and this re-based source version was validated with focused regression tests plus pnpm build.
  • Edge cases checked: local gateway timeout forwarding, route-level signal propagation for actions and snapshots, abort-triggered helper rejection, and navigation retry suppression after abort.
  • What I did not verify: a fresh end-to-end attach-only browser run against v2026.3.7 on Raspberry Pi after re-basing; verification here is source-level plus the already reproduced runtime behavior.

Compatibility / Migration

  • Backward compatible? (Yes/No) Yes
  • Config/env changes? (Yes/No) No
  • Migration needed? (Yes/No) No
  • If yes, exact upgrade steps:

Failure Recovery (if this breaks)

  • How to disable/revert this change quickly: revert this PR/commit; the behavior is isolated to local browser timeout/abort propagation.
  • Files/config to restore: the touched browser gateway, route, and Playwright helper files.
  • Known bad symptoms reviewers should watch for: aborted browser actions unexpectedly disconnecting healthy sessions too aggressively, or timed-out local browser requests continuing to mutate tab state afterward.

Risks and Mitigations

  • Risk: abort-triggered Playwright disconnect/recovery could still interrupt the current target's in-flight work.
    • Mitigation: this only happens on timeout/abort paths and is preferable to leaving the local session wedged for follow-up requests.
  • Risk: this does not address every browser timeout behavior from Fix browser timeout propagation for local actions and CLI commands #39277.
    • Mitigation: the PR is intentionally narrowed to the remaining user-visible bug after v2026.3.7; anything else can follow up separately without re-opening the old pw-session conflict set.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bb5a5bf9cb

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/gateway/server-methods/browser.ts Outdated
Comment on lines +250 to +254
result = await withTimeout(
async (signal) =>
await dispatcher.dispatch({
method: methodRaw,
path,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Limit local timeout wrapper to abort-aware browser routes

Applying withTimeout to every local dispatcher.dispatch call means browser.request can now time out while some routes still ignore req.signal (for example, /highlight still calls highlightViaPlaywright without a signal path), so the caller gets a timeout response but the in-process Playwright work can keep running until its own timeout and interfere with immediate retries on the same target. This reintroduces the "timed out caller, still-running local browser work" failure mode for non-migrated routes; either gate the wrapper to signal-aware endpoints or propagate abort signals through the remaining handlers/helpers.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Scoped the local timeout wrapper to routes that already consume abort signals, and wired act:resize / act:close into the same abort path in 4570ce1d5. That keeps /highlight and the other non-migrated routes on direct dispatch for now, so this PR no longer reports a timeout while leaving unabortable local work behind it.

@greptile-apps

greptile-apps Bot commented Mar 8, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR completes the local browser timeout/abort plumbing that was left unfinished after the v2026.3.7 pw-session refactor. It wires three layers together: the gateway browser.request handler now passes a withTimeout-derived abort signal down to the local dispatcher; the dispatcher's route handlers thread req.signal into every Playwright action and snapshot helper; and those helpers are wrapped in a new runAbortablePlaywrightAction / runAbortableSnapshotWork pattern that races in-flight Playwright work against an abort promise, triggers forceDisconnectPlaywrightForTarget on abort, and guards the navigateViaPlaywright retry path from executing after a signal fires.

Key observations:

  • The abort-wrapper logic is identically copy-pasted into two files (pw-tools-core.interactions.ts and pw-tools-core.snapshot.ts) with only the function name and disconnect reason string differing. Extracting a shared helper would reduce future maintenance risk.
  • Test coverage is thorough: focused unit tests for the abort behavior of clickViaPlaywright, snapshotAiViaPlaywright, all four navigateViaPlaywright scenarios, and the gateway-level timeout forwarding.

Confidence Score: 4/5

  • Safe to merge; the abort paths are well-tested and changes are strictly additive to existing timeout/signal handling.
  • The core abort-wrapper logic is sound and all three layers of timeout propagation (gateway → dispatcher → Playwright helpers) are correctly wired. Test coverage is thorough. No functional regressions are expected. The flagged code duplication between the two wrapper implementations is a maintainability concern, not a functional issue.
  • The abort-wrapper implementations in src/browser/pw-tools-core.interactions.ts and src/browser/pw-tools-core.snapshot.ts could benefit from refactoring to share common logic, but this is low priority and can be addressed separately.

Last reviewed commit: bb5a5bf

Comment on lines +25 to +84
async function runAbortablePlaywrightAction<T>(
opts: TargetOpts & { signal?: AbortSignal },
work: () => Promise<T>,
): Promise<T> {
const signal = opts.signal;
if (!signal) {
return await work();
}

const abortReason = () => signal.reason ?? new Error("aborted");
const disconnect = () => {
void forceDisconnectPlaywrightForTarget({
cdpUrl: opts.cdpUrl,
targetId: opts.targetId,
reason: "abort browser action",
}).catch(() => {});
};

if (signal.aborted) {
disconnect();
throw abortReason();
}

let completed = false;
let abortTriggered = false;
let abortListener: (() => void) | undefined;
const abortPromise: Promise<never> = new Promise((_, reject) => {
abortListener = () => {
if (completed || abortTriggered) {
return;
}
abortTriggered = true;
disconnect();
reject(abortReason());
};
signal.addEventListener("abort", abortListener, { once: true });
});

if (signal.aborted) {
abortListener?.();
}
if (abortTriggered) {
return await abortPromise;
}

const workPromise = work().finally(() => {
completed = true;
});

try {
return await Promise.race([workPromise, abortPromise]);
} catch (err) {
void workPromise.catch(() => {});
throw err;
} finally {
if (abortListener) {
signal.removeEventListener("abort", abortListener);
}
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code duplication between abort-wrapper implementations

runAbortablePlaywrightAction here and runAbortableSnapshotWork in pw-tools-core.snapshot.ts are identical except for:

  • the function/type name
  • the reason string passed to forceDisconnectPlaywrightForTarget ("abort browser action" vs "abort browser snapshot")

If this pattern needs to change in the future (e.g., for optimizations or new abort behaviors), both copies must be manually kept in sync. Consider extracting a shared generic helper — for example, makeAbortableRunner(disconnectReason: string) — in a shared utility module. This reduces future maintenance risk and ensures both abort paths evolve together.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/browser/pw-tools-core.interactions.ts
Line: 25-84

Comment:
**Code duplication between abort-wrapper implementations**

`runAbortablePlaywrightAction` here and `runAbortableSnapshotWork` in `pw-tools-core.snapshot.ts` are identical except for:
- the function/type name
- the `reason` string passed to `forceDisconnectPlaywrightForTarget` (`"abort browser action"` vs `"abort browser snapshot"`)

If this pattern needs to change in the future (e.g., for optimizations or new abort behaviors), both copies must be manually kept in sync. Consider extracting a shared generic helper — for example, `makeAbortableRunner(disconnectReason: string)` — in a shared utility module. This reduces future maintenance risk and ensures both abort paths evolve together.

How can I resolve this? If you propose a fix, please make it concise.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keeping the helper extraction out of this PR so the diff stays focused on the timeout/abort regression. If we extend abort support across the remaining browser routes, I agree it would make sense to consolidate the runners in a follow-up.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4570ce1d5c

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +45 to +46
if (path === "/navigate" || path === "/pdf") {
return true;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Wrap local snapshot routes with timeout forwarding

This timeout gate only enables withTimeout for /navigate, /pdf, and selected /act requests, so local browser.request calls to /snapshot and /screenshot still skip timeout/abort propagation even though this commit now passes req.signal into those Playwright snapshot/screenshot paths. In local mode (no browser node) with timeoutMs set, long Playwright-backed snapshot/screenshot work can still outlive the caller timeout and continue running against the same CDP session, recreating the timed-out-caller/still-running-work behavior for inspect flows.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Intentionally leaving /snapshot and /screenshot out of the gateway-side timeout gate in this PR. Both routes still have mixed implementations today: some branches are Playwright-backed and consume req.signal, while others still fall back to CDP-only helpers (snapshotAria, captureScreenshot) that do not. Broadening the gate here would reintroduce the same timeout-vs-still-running-work mismatch on those non-abortable branches, so I kept this change scoped to routes that are fully abort-aware end to end. If we want timeout forwarding for inspect flows too, I think that needs to happen in a follow-up once those mixed paths are split or made consistently abortable.

@lampten

lampten commented Mar 9, 2026

Copy link
Copy Markdown
Author

Rebased this branch onto the current main (f6243916b) to resolve the new conflicts from the recent browser relay/profile refactors.

Re-ran the targeted browser regression coverage after the rebase:

  • pnpm exec vitest run src/browser/pw-tools-core.interactions.abort.test.ts src/browser/pw-tools-core.snapshot.abort.test.ts src/browser/pw-tools-core.snapshot.navigate-guard.test.ts src/browser/pw-tools-core.interactions.evaluate.abort.test.ts src/gateway/server-methods/browser.local-timeout.test.ts
  • pnpm exec vitest run src/browser/pw-tools-core.clamps-timeoutms-scrollintoview.test.ts src/browser/pw-tools-core.screenshots-element-selector.test.ts src/browser/pw-tools-core.waits-next-download-saves-it.test.ts src/browser/pw-tools-core.last-file-chooser-arm-wins.test.ts
  • pnpm build

@lampten
lampten force-pushed the fix/browser-local-timeout-aborts branch from 4570ce1 to a7a4cd2 Compare March 9, 2026 01:51
@lampten

lampten commented Mar 9, 2026

Copy link
Copy Markdown
Author

Rebased this branch onto the current main (f6d0712f5) to resolve the new conflicts from the 2026.3.9 browser snapshot/navigate changes.

This round kept both behaviors in navigateViaPlaywright:

  • the new redirect-hop SSRF enforcement from main
  • this PR's abort/timeout forwarding so aborted navigations still fail fast and do not retry in the background

Re-ran the focused validation after rebasing:

  • pnpm exec vitest run src/browser/pw-tools-core.interactions.abort.test.ts src/browser/pw-tools-core.snapshot.abort.test.ts src/browser/pw-tools-core.snapshot.navigate-guard.test.ts src/browser/pw-tools-core.interactions.evaluate.abort.test.ts src/gateway/server-methods/browser.local-timeout.test.ts
  • pnpm exec vitest run src/browser/pw-tools-core.clamps-timeoutms-scrollintoview.test.ts src/browser/pw-tools-core.screenshots-element-selector.test.ts src/browser/pw-tools-core.waits-next-download-saves-it.test.ts src/browser/pw-tools-core.last-file-chooser-arm-wins.test.ts
  • pnpm build

@lampten
lampten force-pushed the fix/browser-local-timeout-aborts branch from a7a4cd2 to c95a560 Compare March 9, 2026 11:54
@lampten

lampten commented Mar 12, 2026

Copy link
Copy Markdown
Author

Rebased this branch onto the current main (4f620bebe) and resolved the new conflict in src/gateway/server-methods/browser.ts.

This round keeps both behaviors in browser.request:

  • the new main-branch guard that blocks persistent profile create/delete mutations through browser.request
  • this PR's local timeout/abort forwarding for the already abort-aware browser routes

Re-ran the focused browser validation after rebasing:

  • pnpm exec vitest run src/browser/pw-tools-core.interactions.abort.test.ts src/browser/pw-tools-core.snapshot.abort.test.ts src/browser/pw-tools-core.snapshot.navigate-guard.test.ts src/browser/pw-tools-core.interactions.evaluate.abort.test.ts src/gateway/server-methods/browser.local-timeout.test.ts
  • pnpm exec vitest run src/browser/pw-tools-core.clamps-timeoutms-scrollintoview.test.ts src/browser/pw-tools-core.screenshots-element-selector.test.ts src/browser/pw-tools-core.waits-next-download-saves-it.test.ts src/browser/pw-tools-core.last-file-chooser-arm-wins.test.ts
  • pnpm build

@lampten
lampten force-pushed the fix/browser-local-timeout-aborts branch 2 times, most recently from 534ee30 to 5f40e76 Compare March 13, 2026 22:39
@lampten

lampten commented Mar 13, 2026

Copy link
Copy Markdown
Author

Rebased onto the latest main to resolve the new conflicts from fix(browser): normalize batch act dispatch for selector and batch support.

What I kept in the rebased branch:

  • the local browser.request timeout/abort forwarding in src/gateway/server-methods/browser.ts
  • the req.signal forwarding for abort-aware /act routes
  • the Playwright abort wrappers in src/browser/pw-tools-core.interactions.ts / src/browser/pw-tools-core.snapshot.ts
  • the abort-after-timeout navigate guard

I also updated one existing test assertion to match upstream's new scrollIntoView selector support.

Local verification after the rebase:

  • pnpm exec vitest run src/browser/pw-tools-core.interactions.abort.test.ts src/browser/pw-tools-core.snapshot.abort.test.ts src/browser/pw-tools-core.snapshot.navigate-guard.test.ts src/browser/pw-tools-core.interactions.evaluate.abort.test.ts src/gateway/server-methods/browser.local-timeout.test.ts
  • pnpm exec vitest run src/browser/pw-tools-core.clamps-timeoutms-scrollintoview.test.ts src/browser/pw-tools-core.screenshots-element-selector.test.ts src/browser/pw-tools-core.waits-next-download-saves-it.test.ts src/browser/pw-tools-core.last-file-chooser-arm-wins.test.ts

Both test runs passed locally (14 + 23 tests).

pnpm build currently fails locally in scripts/write-cli-compat.ts with No daemon-cli bundle found in dist; cannot write legacy CLI shim. That appears unrelated to this browser diff and started after updating to the current mainline.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5f40e76009

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +61 to +65
if (path === "/navigate" || path === "/pdf") {
return true;
}
if (path !== "/act" || !params.body || typeof params.body !== "object") {
return false;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Make local timeout gate profile-aware

Fresh evidence in this commit: shouldWrapLocalBrowserRequestWithTimeout decides purely from path/kind, so local browser.request calls are timeout-wrapped even when they resolve to driver === "existing-session" handlers that do not consume req.signal (for example /navigate and existing-session /act branches call Chrome MCP helpers without abort wiring). With timeoutMs set, the caller can now receive a timeout while the underlying existing-session action keeps running, recreating the timed-out-caller/still-running-work failure mode this change is intended to eliminate.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 459ddd6a1. The local timeout gate now checks the requested profile driver first and skips withTimeout for existing-session profiles, so Chrome MCP-backed /navigate and /act requests stay on the direct dispatch path. Added a regression test in src/gateway/server-methods/browser.local-timeout.test.ts covering an existing-session /navigate request with timeoutMs.

@lampten

lampten commented Mar 14, 2026

Copy link
Copy Markdown
Author

Rebased onto current main after v2026.3.13.

I re-checked the new Chrome DevTools MCP existing-session work before updating this branch. That release adds direct live-Chrome attach flows and hardens existing-session lifecycle handling, but origin/main still does not carry the local browser.request timeout/abort wrapper in src/gateway/server-methods/browser.ts, and the Playwright navigate/action paths here still need the abort-aware forwarding covered by this PR.

Validated again after the rebase:

  • pnpm exec vitest run src/gateway/server-methods/browser.local-timeout.test.ts src/browser/pw-tools-core.interactions.abort.test.ts src/browser/pw-tools-core.snapshot.abort.test.ts src/browser/pw-tools-core.snapshot.navigate-guard.test.ts
  • pnpm exec vitest run src/browser/pw-tools-core.waits-next-download-saves-it.test.ts src/browser/routes/agent.act.test.ts src/browser/routes/agent.snapshot.test.ts
  • pnpm build

@lampten
lampten force-pushed the fix/browser-local-timeout-aborts branch from 390b731 to 74c6650 Compare March 14, 2026 11:47

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 74c6650950

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +280 to +281
try {
response = await navigate();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Guard first navigate attempt when request is already aborted

If timeoutMs expires while assertBrowserNavigationAllowed(...) or tab lookup is running, runAbortableSnapshotWork has already rejected the caller, but this function still proceeds to the initial page.goto(...) because the abort check is only in the retry path. Since disconnect is fire-and-forget, there is a real window where timed-out /navigate requests can still navigate the page after the client received a timeout, recreating the timed-out-caller/still-running-work behavior for this route.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in the latest push.

navigateViaPlaywright now checks signal.aborted before the initial page.goto(...) as well as around the retry path, so a request that times out during URL validation or page lookup no longer starts a late first navigation after the caller already saw the timeout. I also added a regression test covering the aborted-before-first-goto window.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f3b85aa7ff

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +56 to +58
if (signal.aborted) {
disconnect();
throw abortReason();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Avoid disconnecting pre-aborted snapshot requests

This pre-abort branch disconnects Playwright even when the signal is already aborted before any snapshot work has started, which now happens when the new local browser.request timeout expires during route prework (for example tab/profile resolution) before navigateViaPlaywright/pdfViaPlaywright begin. Because forceDisconnectPlaywrightForTarget tears down the cached CDP connection for the profile, these harmless early timeouts can drop otherwise healthy sessions and make immediate retries pay a full reconnect penalty; the disconnect should be deferred until an in-flight Playwright operation actually starts.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree this is a narrower tradeoff, but I do not want to widen this PR further for it. The current behavior is intentionally conservative: once the request signal is already aborted before entering the helper, we fail closed and drop the cached Playwright session rather than trying to distinguish whether any helper-local work has started. That avoids reopening the original timeout-vs-still-running-work class of bugs, at the cost of an occasional reconnect on pre-aborted requests. If we want to optimize that path away, I think it should happen in a follow-up that updates both abort runners together rather than only changing the snapshot side here.

@lampten

lampten commented Mar 14, 2026

Copy link
Copy Markdown
Author

Rebased onto the current main (3704293e6) after the latest browser existing-session simplification landed.

This was a clean rebase with no semantic changes to the PR. I re-checked that origin/main still does not carry the local browser.request timeout/abort wrapper or the Playwright abort plumbing covered here, so this PR remains additive.

Re-ran the focused regression set after rebasing:

  • pnpm exec vitest run src/gateway/server-methods/browser.local-timeout.test.ts src/browser/pw-tools-core.interactions.abort.test.ts src/browser/pw-tools-core.snapshot.abort.test.ts src/browser/pw-tools-core.snapshot.navigate-guard.test.ts

That run passed locally (14 tests).

@lampten
lampten force-pushed the fix/browser-local-timeout-aborts branch from f3b85aa to 166d4f0 Compare March 14, 2026 22:57

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 166d4f0e31

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/gateway/server-methods/browser.ts Outdated
Comment on lines +70 to +71
const profile = params.cfg.browser?.profiles?.[profileName];
return typeof profile?.driver === "string" ? profile.driver : undefined;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Resolve profile driver from effective browser config

resolveRequestedProfileDriver only looks at loadConfig().browser.profiles, but local browser routing resolves profiles from resolveBrowserConfig, which auto-injects the built-in user profile as driver: "existing-session" even when it is absent from raw config. In that common case (profile=user or defaultProfile=user), this function returns undefined, so shouldWrapLocalBrowserRequestWithTimeout still applies withTimeout to /navigate and abort-aware /act kinds; those existing-session handlers do not consume req.signal, so the caller can time out while Chrome MCP work keeps running in-process, reintroducing the timed-out-caller/still-running-work failure mode this change is trying to prevent.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in the latest push. resolveRequestedProfileDriver now derives the driver from resolveBrowserConfig(...) instead of only reading raw loadConfig().browser.profiles, so the gateway timeout gate sees the same effective browser config as the local browser server, including the built-in user existing-session profile. I also added a regression test covering defaultProfile=user / profile=user with timeoutMs to make sure those requests stay on the direct dispatch path.

@lampten
lampten force-pushed the fix/browser-local-timeout-aborts branch from b739d4c to ae52c8e Compare March 23, 2026 13:38
@lampten

lampten commented Mar 23, 2026

Copy link
Copy Markdown
Author

Rebased onto current main after the latest gateway/browser changes.

This PR is still carrying behavior that is not on main yet rather than reviving an obsolete diff: the local browser.request timeout/abort wrapper and the Playwright abort plumbing are still missing upstream.

Re-ran the targeted regression suite after the rebase:

  • pnpm exec vitest run src/gateway/server-methods/browser.local-timeout.test.ts src/browser/pw-tools-core.interactions.abort.test.ts src/browser/pw-tools-core.snapshot.abort.test.ts src/browser/pw-tools-core.snapshot.navigate-guard.test.ts src/browser/routes/agent.act.test.ts src/browser/routes/agent.snapshot.test.ts
  • 23 passed

@lampten

lampten commented Mar 27, 2026

Copy link
Copy Markdown
Author

Superseded by #55925.

The Mar 26 browser plugin refactor moved this fix from the old src/browser/... / src/gateway/... paths into extensions/browser/..., so I reopened the remaining bugfix as a clean follow-up PR instead of asking reviewers to work through stale bot threads and deleted files here.

@lampten lampten closed this Mar 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime size: XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant