Repository navigation
Conversation
There was a problem hiding this comment.
💡 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".
| result = await withTimeout( | ||
| async (signal) => | ||
| await dispatcher.dispatch({ | ||
| method: methodRaw, | ||
| path, |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
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 SummaryThis PR completes the local browser timeout/abort plumbing that was left unfinished after the Key observations:
Confidence Score: 4/5
Last reviewed commit: bb5a5bf |
| 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); | ||
| } | ||
| } | ||
| } |
There was a problem hiding this 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
reasonstring passed toforceDisconnectPlaywrightForTarget("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!
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
💡 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".
| if (path === "/navigate" || path === "/pdf") { | ||
| return true; |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
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.
|
Rebased this branch onto the current Re-ran the targeted browser regression coverage after the rebase:
|
4570ce1 to
a7a4cd2
Compare
|
Rebased this branch onto the current This round kept both behaviors in
Re-ran the focused validation after rebasing:
|
a7a4cd2 to
c95a560
Compare
|
Rebased this branch onto the current This round keeps both behaviors in
Re-ran the focused browser validation after rebasing:
|
534ee30 to
5f40e76
Compare
|
Rebased onto the latest What I kept in the rebased branch:
I also updated one existing test assertion to match upstream's new Local verification after the rebase:
Both test runs passed locally (14 + 23 tests).
|
There was a problem hiding this comment.
💡 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".
| if (path === "/navigate" || path === "/pdf") { | ||
| return true; | ||
| } | ||
| if (path !== "/act" || !params.body || typeof params.body !== "object") { | ||
| return false; |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
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.
|
Rebased onto current 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 Validated again after the rebase:
|
390b731 to
74c6650
Compare
There was a problem hiding this comment.
💡 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".
| try { | ||
| response = await navigate(); |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
💡 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".
| if (signal.aborted) { | ||
| disconnect(); | ||
| throw abortReason(); |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
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.
|
Rebased onto the current This was a clean rebase with no semantic changes to the PR. I re-checked that Re-ran the focused regression set after rebasing:
That run passed locally (14 tests). |
f3b85aa to
166d4f0
Compare
There was a problem hiding this comment.
💡 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".
| const profile = params.cfg.browser?.profiles?.[profileName]; | ||
| return typeof profile?.driver === "string" ? profile.driver : undefined; |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
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.
b739d4c to
ae52c8e
Compare
|
Rebased onto current This PR is still carrying behavior that is not on Re-ran the targeted regression suite after the rebase:
|
|
Superseded by #55925. The Mar 26 browser plugin refactor moved this fix from the old |
AI-assisted: yes (Codex).
Testing: focused regression tests +
pnpm build.Summary
v2026.3.7landed the overlappingpw-sessionrefactor ina075baba8(refactor(browser): scope CDP sessions and harden stale target recovery), the old branch now conflicts heavily withmain.browser.requeststill timed out at the caller while in-process Playwright work could continue, and most non-evaluatebrowser actions/snapshots still did not honor request aborts.browser.requesttimeouts 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.pw-sessionstructure fromv2026.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)
Scope (select all touched areas)
Linked Issue/PR
User-visible / Behavior Changes
Security Impact (required)
Yes/No) NoYes/No) NoYes/No) NoYes/No) NoYes/No) NoYes, explain risk + mitigation:Repro + Verification
Environment
pnpmattachOnly: true), persistent browser profile, local CDP endpoint, local gateway websocketSteps
browser status,browser tabs, andbrowser snapshotsucceed.browser act kind=type ... --submitorbrowser act kind=click ....Expected
Actual
Evidence
Human Verification (required)
snapshot+type --submit, plusexample.comclick flows), and this re-based source version was validated with focused regression tests pluspnpm build.v2026.3.7on Raspberry Pi after re-basing; verification here is source-level plus the already reproduced runtime behavior.Compatibility / Migration
Yes/No) YesYes/No) NoYes/No) NoFailure Recovery (if this breaks)
Risks and Mitigations
v2026.3.7; anything else can follow up separately without re-opening the oldpw-sessionconflict set.