Repository navigation
Conversation
Greptile SummaryThis PR propagates HTTP request Confidence Score: 5/5Safe to merge — changes are narrowly scoped to abort/timeout propagation with no behavioral changes to non-local or existing-session paths. All findings are P2 (code quality/duplication). The abort-race logic is correctly implemented with proper double-check for already-aborted signals, { once: true } listener registration, completed/abortTriggered guards, and event-listener cleanup in finally. The navigate retry guard is correct. Tests cover the key concurrency scenarios. No correctness, data-integrity, or security issues were found. No files require special attention for merging, but pw-tools-core.snapshot.ts and pw-tools-core.interactions.ts carry duplicated abort helper logic worth consolidating in a follow-up.
|
| Filename | Overview |
|---|---|
| extensions/browser/src/gateway/browser-request.ts | Adds shouldWrapLocalBrowserRequestWithTimeout + ABORT_AWARE_LOCAL_ACT_KINDS to gate withTimeout wrapping on supported act/navigate/pdf routes; existing-session profiles skip the wrapper. Error handling now catches dispatch rejections and responds with UNAVAILABLE. |
| extensions/browser/src/browser/pw-tools-core.interactions.ts | Adds runAbortablePlaywrightAction wrapper and threads signal through all interaction helpers (click, hover, drag, select, fill, type, press, scroll, wait, screenshot, fillForm). |
| extensions/browser/src/browser/pw-tools-core.snapshot.ts | Adds runAbortableSnapshotWork (duplicate of runAbortablePlaywrightAction) and wraps all snapshot helpers; navigateViaPlaywright gains throwIfAborted guards before each navigate attempt to prevent retries after abort. |
| extensions/browser/src/browser/routes/agent.act.ts | Threads req.signal into all Playwright helper calls for act routes. |
| extensions/browser/src/browser/routes/agent.snapshot.ts | Threads req.signal into all Playwright helper calls for snapshot routes. |
Prompt To Fix All With AI
This is a comment left during a code review.
Path: extensions/browser/src/browser/pw-tools-core.snapshot.ts
Line: 40-107
Comment:
**Duplicated abort-race helper**
`runAbortableSnapshotWork` (here) and `runAbortablePlaywrightAction` in `pw-tools-core.interactions.ts` are byte-for-byte identical except for the default `disconnectReason` string. Both carry the same subtle double-check pattern, the `completed`/`abortTriggered` guards, and the `finally`-cleanup for the event listener.
`evaluateViaPlaywright` also has its own bespoke inline variant of the same pattern (with an extra `Promise.race` for the browser-side evaluate timeout).
Having three copies of this logic means any future fix to the race-condition guard has to be applied in three places. Consider extracting the core race to a shared utility, e.g.:
```ts
// shared e.g. pw-tools-core.abort.ts
export async function runAbortablePlaywrightWork<T>(
opts: { cdpUrl: string; targetId?: string; signal?: AbortSignal; disconnectReason?: string },
work: () => Promise<T>,
): Promise<T> { /* single implementation */ }
```
Then `runAbortableSnapshotWork` and `runAbortablePlaywrightAction` become thin wrappers (or are removed entirely).
How can I resolve this? If you propose a fix, please make it concise.Reviews (1): Last reviewed commit: "fix(browser): propagate local browser re..." | Re-trigger Greptile
| 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: opts.disconnectReason ?? "abort browser snapshot", | ||
| }).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); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| export async function snapshotAriaViaPlaywright(opts: { | ||
| cdpUrl: string; | ||
| targetId?: string; | ||
| limit?: number; | ||
| signal?: AbortSignal; | ||
| }): Promise<{ nodes: AriaSnapshotNode[] }> { | ||
| const limit = Math.max(1, Math.min(2000, Math.floor(opts.limit ?? 500))); | ||
| const page = await getPageForTargetId({ | ||
| cdpUrl: opts.cdpUrl, | ||
| targetId: opts.targetId, | ||
| return await runAbortableSnapshotWork(opts, async () => { | ||
| const limit = Math.max(1, Math.min(2000, Math.floor(opts.limit ?? 500))); | ||
| const page = await getPageForTargetId({ |
There was a problem hiding this comment.
runAbortableSnapshotWork (here) and runAbortablePlaywrightAction in pw-tools-core.interactions.ts are byte-for-byte identical except for the default disconnectReason string. Both carry the same subtle double-check pattern, the completed/abortTriggered guards, and the finally-cleanup for the event listener.
evaluateViaPlaywright also has its own bespoke inline variant of the same pattern (with an extra Promise.race for the browser-side evaluate timeout).
Having three copies of this logic means any future fix to the race-condition guard has to be applied in three places. Consider extracting the core race to a shared utility, e.g.:
// shared e.g. pw-tools-core.abort.ts
export async function runAbortablePlaywrightWork<T>(
opts: { cdpUrl: string; targetId?: string; signal?: AbortSignal; disconnectReason?: string },
work: () => Promise<T>,
): Promise<T> { /* single implementation */ }Then runAbortableSnapshotWork and runAbortablePlaywrightAction become thin wrappers (or are removed entirely).
Prompt To Fix With AI
This is a comment left during a code review.
Path: extensions/browser/src/browser/pw-tools-core.snapshot.ts
Line: 40-107
Comment:
**Duplicated abort-race helper**
`runAbortableSnapshotWork` (here) and `runAbortablePlaywrightAction` in `pw-tools-core.interactions.ts` are byte-for-byte identical except for the default `disconnectReason` string. Both carry the same subtle double-check pattern, the `completed`/`abortTriggered` guards, and the `finally`-cleanup for the event listener.
`evaluateViaPlaywright` also has its own bespoke inline variant of the same pattern (with an extra `Promise.race` for the browser-side evaluate timeout).
Having three copies of this logic means any future fix to the race-condition guard has to be applied in three places. Consider extracting the core race to a shared utility, e.g.:
```ts
// shared e.g. pw-tools-core.abort.ts
export async function runAbortablePlaywrightWork<T>(
opts: { cdpUrl: string; targetId?: string; signal?: AbortSignal; disconnectReason?: string },
work: () => Promise<T>,
): Promise<T> { /* single implementation */ }
```
Then `runAbortableSnapshotWork` and `runAbortablePlaywrightAction` become thin wrappers (or are removed entirely).
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.
I agree the duplication is real, but I am intentionally not folding that cleanup into this PR.
This change is narrowly scoped to the remaining local timeout/abort bug after the browser plugin migration. The follow-up commit here fixes one concrete behavior gap in navigateViaPlaywright(); extracting the shared abort helper would expand the patch into a refactor across interactions, snapshots, and evaluate without changing user-visible behavior. I’d rather leave that as a separate cleanup once this bugfix lands.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5746317db7
ℹ️ 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.
Don’t timeout-wrap /navigate until abort is enforced
/navigate is now included in the timeout-wrapped local browser.request path, but the navigation helper still does not cancel an in-flight page.goto when the signal aborts. It only checks signal.aborted before navigation/retry and in the catch path, so a timeout can return UNAVAILABLE while the original navigation keeps running and still changes the tab URL/state afterward. That makes timeout responses unreliable and can corrupt subsequent step sequencing.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 4e62c9ac2b.
Root cause was exactly that navigateViaPlaywright() only checked signal.aborted before the first goto() / retry path, so the local gateway timeout could return while the in-flight navigation was still running. I kept the fix narrow: navigateViaPlaywright() now runs inside the same abort race used by the other Playwright snapshot paths, with a dedicated abort browser navigate disconnect reason, and I added a regression test that aborts after goto() has started to verify we reject immediately and disconnect the target instead of letting the navigation continue in the background.
4e62c9a to
36e3170
Compare
|
Rebased this PR onto current The only real overlap was
Local result: |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 36e317081e
ℹ️ 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") { |
There was a problem hiding this comment.
Wrap snapshot routes in local timeout handling
browser.request now only applies withTimeout(...) to /navigate, /pdf, and selected /act kinds, so local /snapshot and /screenshot requests still dispatch without a signal even when timeoutMs is provided. That means the new abort propagation in snapshot handlers is never triggered for these local calls, and long snapshot/screenshot operations can still run indefinitely despite a caller-supplied timeout.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
I agree there is still a remaining gap for local /snapshot and /screenshot, but I am intentionally not broadening the gateway wrapper in this PR.
Those routes still multiplex abort-aware Playwright branches with non-abort-aware Chrome MCP / direct CDP branches in the same handler. Wrapping them wholesale here would reintroduce the original mismatch for the non-Playwright paths: the local request could time out while the underlying snapshot/screenshot work continues anyway.
This change keeps the gateway timeout wrapper limited to routes and act kinds that are abort-aware end to end today. Expanding /snapshot / /screenshot safely should happen as a follow-up once those handlers are split or uniformly abort-aware.
36e3170 to
e8c026e
Compare
|
Rebased onto current
Focused validation after the rebase:
That focused set is green locally ( |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e8c026e0d0
ℹ️ 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.
Keep timeoutMs effective for non-act local requests
This gate now returns false for every local path except /navigate, /pdf, and /act, so requests like /tabs/open skip withTimeout(...) even when callers provide timeoutMs. In local mode (no browser node), a stalled route can now run indefinitely instead of returning UNAVAILABLE, which regresses the existing browser.request timeout behavior that browser-request.timeout.test.ts already asserts for /tabs/open.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 7e5ef9fa6a.
Root cause was that my earlier scope reduction replaced the old generic local timeout behavior with an overly narrow positive allowlist, which accidentally dropped withTimeout(...) for non-/act local routes like /tabs/open. I changed the gate back to the safer shape for today’s code: local requests are timeout-wrapped by default, but we explicitly exclude the known mixed / non-abort-aware paths (/snapshot, /screenshot, /highlight, download hooks, etc.) and keep the narrower act-kind allowlist only for /act. I also added a regression test that exercises local /tabs/open with timeoutMs and asserts the dispatch still receives an abort signal.
| query?: Record<string, unknown>; | ||
| body?: unknown; | ||
| }): string | undefined { | ||
| const resolvedBrowser = resolveBrowserConfig(params.cfg.browser, params.cfg); |
There was a problem hiding this comment.
Handle config parse failures in timeout gating
resolveRequestedProfileDriver now calls resolveBrowserConfig(...), which can throw on invalid browser URL/port values, but this evaluation happens before the request dispatch try/catch. If config becomes malformed while the browser service is already running, browser.request can fail with an unhandled exception path instead of a shaped gateway error response.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 7e5ef9fa6a.
resolveRequestedProfileDriver(...) now treats browser-config resolution as best-effort inside the timeout gate. If resolveBrowserConfig(...) throws, we fall back to the generic local timeout behavior instead of failing before the request dispatch error handling. That keeps malformed browser config from escaping through an unshaped exception path, and I added a regression test that forces resolveBrowserConfig to throw while asserting the local request still goes through the normal timeout-wrapped dispatch path.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7e5ef9fa6a
ℹ️ 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".
| "resize", | ||
| "wait", | ||
| "evaluate", | ||
| "close", |
There was a problem hiding this comment.
Drop non-abortable act kinds from timeout-safe allowlist
browser.request now treats /act kinds resize and close as abort-aware, so those requests are wrapped in withTimeout(...) and expected to cancel cleanly. However, the act executor still does not pass signal into resizeViewportViaPlaywright or closePageViaPlaywright (extensions/browser/src/browser/pw-tools-core.interactions.ts), so a timed-out local /act call can still keep running and mutate tab state after the gateway already returned UNAVAILABLE. This reintroduces the same stale-state hazard the new allowlist is trying to prevent for timed requests.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 005d79debe.
You were right about the immediate resize / close gap, but the root cause was broader: the gateway allowlist was treating a whole set of Playwright /act kinds as abort-aware while executeSingleAction(...) was only threading signal through a subset of them. I fixed this as one audit instead of another one-off patch:
executeSingleAction(...)now passessignalto every allowlisted Playwright act helper- the interaction helpers (
click,type,press,hover,scrollIntoView,drag,select,fill) now all run under the same abort/disconnect wrapper resize/closestill pass theirsignalinto the snapshot-side helpers- added a click abort regression test and tightened the batch test to assert
signalpropagation forresize/close
That keeps the local /act timeout allowlist aligned with the actual end-to-end abort behavior instead of fixing only one or two members.
AI-assisted: yes (Codex).
Testing: focused regression tests; broader contract/build checks still hit unrelated main-branch failures noted below.
Summary
src/browser/...andsrc/gateway/...intoextensions/browser/....main: localbrowser.requesttimeouts can still outpace in-process Playwright work, and the Playwright action/snapshot paths still do not consistently honor request aborts.What Changed
browser.requestroutes withwithTimeout(...)and forward the resultingAbortSignalinto local dispatchexisting-sessionprofiles, including the built-inuserprofilereq.signalthrough browser action and snapshot routes into Playwright helpersnavigateViaPlaywright(...)from retrying once the request has already been abortedWhy A New PR
extensions/browser/...is cleaner for human reviewers than asking them to reconstruct intent across stale bot threads and deleted paths.Linked PRs / Issues
Verification
Passed locally:
pnpm exec vitest run extensions/browser/src/gateway/browser-request.local-timeout.test.ts extensions/browser/src/browser/pw-tools-core.interactions.abort.test.ts extensions/browser/src/browser/pw-tools-core.snapshot.abort.test.ts extensions/browser/src/browser/pw-tools-core.snapshot.navigate-guard.test.ts extensions/browser/src/browser/routes/agent.snapshot.test.tsAlso checked:
pnpm exec oxfmt --checkon all touched filesgit diff --checkStill failing on current
main, outside this diff:pnpm buildfails in unrelated agent/skills files (src/agents/compaction.ts,src/agents/pi-extensions/compaction-safeguard.ts,src/agents/skills/source.ts)extensions/browser/src/browser/server.agent-contract-snapshot-endpoints.test.tsandextensions/browser/src/browser/server.agent-contract-form-layout-act-commands.test.tscurrently fail before reaching this logic becauseextensions/browser/src/browser/paths.tsimports a missingresolvePreferredOpenClawTmpDirfunction under the test harnessRisk / Scope