Repository navigation
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8d86ac2da7
ℹ️ 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".
| await forceDisconnectPlaywrightForTarget({ | ||
| cdpUrl: opts.cdpUrl, | ||
| targetId: opts.targetId, | ||
| reason: "abort browser action", |
There was a problem hiding this comment.
Scope abort disconnects to the current target
This abort path now runs for most act/snapshot operations, but forceDisconnectPlaywrightForTarget tears down the shared Playwright connection for the entire cdpUrl (it clears global cached state in src/browser/pw-session.ts), not just the provided targetId. In concurrent usage (multiple tabs/channels on one profile), a timeout in one request can now drop unrelated in-flight requests, which is a new cross-request regression introduced by this wrapper.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Good catch. I tightened this so forceDisconnectPlaywrightForTarget() first does the target-local Runtime.terminateExecution, and it only tears down the shared cached Playwright/CDP connection when that connection is effectively single-page. In multi-page shared sessions it now returns after the target-local terminate, so an abort on one tab no longer drops unrelated tabs/requests on the same cdpUrl.
| normalizeTimeoutMs(params?.explicitMs) ?? | ||
| parseParentTimeoutMs(opts) ?? | ||
| normalizeTimeoutMs(params?.fallbackMs) |
There was a problem hiding this comment.
Preserve fallback timeouts when parent timeout is defaulted
resolveBrowserRequestTimeoutMs prefers opts.timeout before fallbackMs, but the browser CLI always defines --timeout with a default of 30000 (src/cli/gateway-rpc.ts), so these new fallback values are effectively never used in normal CLI runs. That silently changes default behavior for commands that previously had shorter fail-fast timeouts (for example status/tabs), causing them to wait the global 30s unless users explicitly override timeout.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Good catch. I now carry the top-level --timeout source into BrowserParentOpts and ignore it when it is still Commander's implicit default. That preserves command-specific fallbacks (status, tabs, etc.) while still letting an explicit parent browser --timeout override them. I also added regression coverage in src/cli/browser-cli-shared.test.ts and src/cli/browser-cli-manage.timeout-option.test.ts.
Greptile SummaryThis PR fixes two related problems: (1) local browser actions/snapshots that timed out only stopped the caller while the underlying Playwright/CDP work kept running, and (2) browser CLI subcommands used hardcoded timeout defaults instead of respecting the parent Key observations:
Confidence Score: 5/5
Last reviewed commit: 8d86ac2 |
| 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 = async () => { | ||
| await forceDisconnectPlaywrightForTarget({ | ||
| cdpUrl: opts.cdpUrl, | ||
| targetId: opts.targetId, | ||
| reason: "abort browser action", | ||
| }).catch(() => {}); | ||
| }; | ||
|
|
||
| if (signal.aborted) { | ||
| await 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; | ||
| void disconnect().finally(() => 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.
runAbortablePlaywrightAction here and runAbortableSnapshotWork in pw-tools-core.snapshot.ts (lines 29-87) are functionally identical—the only difference is the reason string passed to forceDisconnectPlaywrightForTarget. Any future fix or enhancement to the abort logic (such as adding guards or refining the disconnect timing) would need to be applied in both places, creating a maintenance burden.
Consider extracting this into a shared runAbortableTargetWork<T>(opts, work, reason) helper—perhaps in pw-session.ts or a new pw-tools-core.abort.ts—and re-using it from both modules.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/browser/pw-tools-core.interactions.ts
Line: 25-83
Comment:
`runAbortablePlaywrightAction` here and `runAbortableSnapshotWork` in `pw-tools-core.snapshot.ts` (lines 29-87) are functionally identical—the only difference is the `reason` string passed to `forceDisconnectPlaywrightForTarget`. Any future fix or enhancement to the abort logic (such as adding guards or refining the disconnect timing) would need to be applied in both places, creating a maintenance burden.
Consider extracting this into a shared `runAbortableTargetWork<T>(opts, work, reason)` helper—perhaps in `pw-session.ts` or a new `pw-tools-core.abort.ts`—and re-using it from both modules.
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.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ce0c5f2fe4
ℹ️ 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 (!isRetryableNavigateError(err)) { | ||
| throw err; | ||
| } | ||
| // Extension relays can briefly drop CDP during renderer swaps/navigation. | ||
| // Force a clean reconnect, then retry once on the refreshed page handle. |
There was a problem hiding this comment.
Stop retrying navigation after request abort
When the request signal aborts during page.goto, runAbortableSnapshotWork disconnects Playwright, which makes goto fail with a retryable "browser/page closed" error. This catch block then unconditionally runs the reconnect+retry path, so a timed-out /navigate request can still complete a background navigation after the caller has already received a timeout. Add an opts.signal?.aborted guard before retrying so aborted requests do not mutate tab state after timeout.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Agreed. I added an abort guard before the retry path (and again after the reconnect helper) so a timed-out /navigate request now exits instead of doing a background reconnect+goto. I also added a regression test in src/browser/pw-tools-core.snapshot.navigate-guard.test.ts that aborts during the first goto and verifies we do not issue the retry navigation.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4a9ec65793
ℹ️ 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".
| return; | ||
| } | ||
| abortTriggered = true; | ||
| void disconnect().finally(() => reject(abortReason())); |
There was a problem hiding this comment.
Reject abort race before waiting on disconnect
This abort branch waits for disconnect() to finish before rejecting, so cancellation is delayed by CDP cleanup latency. Because Promise.race([workPromise, abortPromise]) is still running during that delay, a near-complete action can resolve first and the timed-out request still executes in the background (e.g., click/type/navigate mutating tab state after the caller already received a timeout). Reject immediately when the signal aborts and run disconnect in parallel/fire-and-forget so abort reliably wins once raised.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Agreed. I changed both abort helpers so abort now rejects immediately and runs the disconnect cleanup in the background instead of awaiting cleanup before rejecting. That makes the abort side win the race once the signal is raised, even if CDP cleanup is slow. I also added regression coverage in src/browser/pw-tools-core.interactions.abort.test.ts and src/browser/pw-tools-core.snapshot.abort.test.ts that holds disconnect cleanup open and verifies the action/snapshot still rejects instead of resolving.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 013f82842d
ℹ️ 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".
| await tryTerminateExecutionViaCdp({ cdpUrl: normalized, targetId }).catch(() => {}); | ||
| const pages = await getAllPages(cur.browser).catch(() => []); | ||
| if (pages.length > 1) { | ||
| return; |
There was a problem hiding this comment.
Fall back to disconnect when target termination fails
This early return skips shared Playwright disconnect for any multi-page session even if the target-local termination just failed (the error is swallowed on the previous line), so aborted requests can keep running in the background and still mutate page state. That is especially likely on relays where target attach/terminate is unsupported, and it defeats the new abort cleanup path for those environments.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 8b7a5ee. tryTerminateExecutionViaCdp() now reports whether target-local termination actually succeeded, and multi-page sessions only skip the shared Playwright disconnect on success. If attach/terminate is unsupported or fails, we now fall back to the disconnect path instead of silently doing nothing. Added regression coverage in src/browser/pw-session.abort-fallback.test.ts.
| if (opts.timeoutSource === "default") { | ||
| return undefined; |
There was a problem hiding this comment.
Keep implicit 30s timeout for no-fallback browser requests
Dropping opts.timeout whenever the option source is default makes resolveBrowserRequestTimeoutMs return undefined for callers that do not provide a fallback timeout (for example browser start/stop paths), so browser.request no longer carries timeoutMs. In those cases the gateway-side dispatch timeout is disabled and node-side invoke timeout is not enforced, allowing work to continue after the CLI transport timeout expires.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 8b7a5ee. callBrowserRequest() now falls back to the parsed parent CLI timeout when there is no browser-specific explicit or fallback timeout, so browser.request.timeoutMs still carries the implicit 30s on paths like browser start/stop. Added regression coverage in src/cli/browser-cli-shared.call.test.ts.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8b7a5ee953
ℹ️ 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".
| } | ||
| // Also clear `connecting` so the next call does a fresh connectOverCDP | ||
| // rather than awaiting a stale promise. | ||
| connecting = null; |
There was a problem hiding this comment.
Avoid clearing active connect promise after async checks
forceDisconnectPlaywrightForTarget now awaits target-termination/page-count work before resetting globals, but connecting = null still runs unconditionally afterward. In the abort/retry path, another request can begin a fresh connectBrowser() during those awaits and set a new in-flight connecting promise; this line then wipes that live promise even when cached has already moved off cur, allowing concurrent callers to start duplicate CDP connects instead of coalescing on the same reconnect.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
I agree this is a narrower reconnect-coalescing race, but I am leaving it out of this PR to keep the change scoped to timeout/abort correctness. The current behavior could allow duplicate reconnect attempts in that window, but it does not reopen the user-visible regression this PR fixes (requests continuing to mutate tab state after timeout/abort). I would rather handle any cached/connecting reshaping as a separate follow-up.
|
Superseded by #40305.
|
AI-assisted: yes (Codex).
Testing: focused regression tests +
pnpm build;pnpm checkis still blocked by unrelated pre-existing repo failures.Summary
Describe the problem and fix in 2–5 bullets:
browser.requesttimeouts only stopped the caller; the in-process Playwright work kept running, and several browser CLI subcommands also overrode the parentbrowser --timeoutwith hardcoded defaults.type/click/snapshotpath timed out, later interactive browser requests could degrade into more timeouts against the same attached session, and users could not reliably tune CLI timeout behavior.req.signalthrough browser route handlers and Playwright helpers, force-disconnect the target CDP session when an action/snapshot is aborted, and make browser CLI timeout resolution consistent (--timeout-ms> parentbrowser --timeout> fallback default).Change Type (select all)
Scope (select all touched areas)
Linked Issue/PR
User-visible / Behavior Changes
browser --timeoutnow applies consistently across browser CLI subcommands unless a more specific--timeout-msflag is provided.Security Impact (required)
Yes/No) NoYes/No) NoYes/No) NoYes/No) NoYes/No) NoYes, explain risk + mitigation:Repro + Verification
Environment
pnpmattachOnly: true), persistentopenclawprofile, local CDP endpoint, local gateway websocketSteps
browser status,browser tabs, andbrowser snapshotsucceed.browser act kind=type ... --submiton Gemini orbrowser act kind=click ...onhttp://example.com/.Expected
Actual
browser --timeoutwas set.Evidence
Attach at least one:
Human Verification (required)
What you personally verified (not just CI), and how:
snapshot+type --submit, plusexample.comclick flows), and the source changes were covered by focused regression tests pluspnpm build.browser --timeoutprecedence, and explicit subcommand--timeout-msoverride behavior.pnpm checkis still blocked by unrelated pre-existingtsgoerrors in other packages/extensions, and I did not do a new cross-platform browser matrix beyond the reproduced Linux arm64 attach-only flow.Compatibility / Migration
Yes/No) YesYes/No) NoYes/No) NoFailure Recovery (if this breaks)
Risks and Mitigations
List only real risks for this PR. Add/remove entries as needed. If none, write
None.browser --timeoutnow taking effect.--timeout-msstill wins, and the new precedence matches the documented/top-level CLI behavior.