Skip to content

fix(browser): stop cancelled downloads from capturing later files - #124382

Merged
steipete merged 2 commits into
mainfrom
fix/autoqa-refill-browser-downloads-v2
Aug 16, 2026
Merged

steipete merged 2 commits into
mainfrom
fix/autoqa-refill-browser-downloads-v2

Conversation

@steipete

Copy link
Copy Markdown
Contributor

Related: #124064

What Problem This Solves

Fixes an issue where cancelling a browser download request could leave its download listener and click running, allowing that abandoned request to capture or write a later download intended for a successor request.

Why This Change Was Made

The request's AbortSignal now follows the existing ownership chain from the browser tool HTTP call through the route lease into both the explicit capture owner and Playwright's click operation. Cancellation rejects with the caller's reason, releases the listener/timer/depth owner immediately, observes the capture rejection while the click is still pending, and prevents the cancelled operation from consuming a successor download.

Playwright 1.62.1 source and types were checked directly: locator clicks accept AbortSignal; its client sends protocol cancellation, preserves the caller cause on the resulting abort error, and removes the signal listener when the command settles. The separately landed #124064 closed-tab retirement path remains unchanged and composes with this request-owned cancellation path.

Production LOC: +43/-15 (net +28) | Tests: +342/-0 (net +342)

The production growth carries one existing request signal across the tool/client/route boundary and adds cleanup at the capture owner. It adds no parallel resolver, compatibility path, test-only production seam, schema, dependency, public API, path-policy, or security-policy surface.

User Impact

Cancelled waitfordownload and click-to-download requests now stop promptly and cannot steal or overwrite later downloads. Successor requests, repeated same-name downloads, and downloads after a managed-profile restart continue to succeed with unique managed paths and no temporary-file residue.

Evidence

Candidate head: c1b92eb44e964863cc0262956459607eeec993a5

Rebased local-main baseline: 4b8ca98a940a76ebb2263b1448d539f7b7377dd0; later local-main drift touched no browser files.

  • Real Chromium cancellation/successor/same-name/profile-restart/cleanup scenario: 1 passed.
  • Focused capture and HTTP route suites: 55 passed.
  • Browser tool, Playwright session, request transport, and route-owner siblings: 210 passed.
  • Source-blind behavior contract: 11/11 observable clauses passed, including prompt rejection, caller reason, successor ownership, unique same-name paths, restart behavior, no unhandled rejection, and physical cleanup.
  • Full build, changed gate, explicit extension production/test types, extension lint, formatting, runtime and Madge cycle checks, dead-export/plugin/database/sidecar/temp guards: passed on Blacksmith Testbox tbx_01m0490v6q9dy4kcv3r9f059wh (run 31923780499).
  • git diff --check: passed.
  • Fresh structured autoreview: no accepted/actionable findings.

No changelog edit: release generation owns CHANGELOG.md.

@clawsweeper

clawsweeper Bot commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@steipete steipete self-assigned this Aug 16, 2026
@steipete
steipete marked this pull request as ready for review August 16, 2026 03:31
@steipete

Copy link
Copy Markdown
Contributor Author

Land-ready proof for exact head c1b92eb44e964863cc0262956459607eeec993a5:

  • Real Chromium cancellation/successor/same-name/profile-restart/cleanup scenario: OPENCLAW_BROWSER_DOWNLOAD_E2E=1 node scripts/run-vitest.mjs extensions/browser/src/browser/pw-download-cancel.chromium.test.ts — 1 passed.
  • Focused owner/route proof: node scripts/run-vitest.mjs extensions/browser/src/browser/pw-tools-core.waits-next-download-saves-it.test.ts extensions/browser/src/browser/server.agent-contract-form-layout-act-commands.test.ts — 55 passed.
  • Sibling tool/session/transport/route proof: node scripts/run-vitest.mjs extensions/browser/src/browser-tool.test.ts extensions/browser/src/browser/pw-session.test.ts extensions/browser/src/browser/routes/agent.shared.test.ts extensions/browser/src/browser/routes/dispatcher.abort.test.ts extensions/browser/src/browser/client-actions-core.downloads.test.ts extensions/browser/src/browser/client-fetch.timeout.test.ts — 210 passed.
  • Source-blind behavior contract: 11/11 clauses passed, including prompt cancellation, preserved caller reason, released capture ownership, no successor capture/write, unique same-name downloads across profile restart, no unhandled rejection, and no residue.
  • Blacksmith Testbox tbx_01m0490v6q9dy4kcv3r9f059wh: full build, check:changed, extension production/test types, extension lint, changed-file format, runtime and Madge cycles, and requested guards passed in run 31923780499.
  • Exact-head CI run 31924442148 completed successfully; required openclaw/ci-gate is green.
  • Native review artifacts validate as READY FOR /prepare-pr with zero findings. Fresh structured autoreview reported no accepted/actionable findings.

Production LOC is +43/-15, net +28; tests are +342/-0. No schema, dependency, public API, path/security policy, changelog, or test-only production seam changed. Known proof gaps: none.

@clawsweeper

clawsweeper Bot commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 15, 2026, 11:37 PM ET / August 16, 2026, 03:37 UTC.

ClawSweeper review

What this changes

This PR propagates request cancellation through browser download operations so an aborted request releases its download capture before a later request starts.

Regression provenance

Possible regression — suspected (reviewed change). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

Keep open for active maintainer review. Current main still leaves cancelled download captures armed; the branch binds cancellation to the capture owner and covers the race without a concrete patch defect found.

Priority: P1
Reviewed head: c1b92eb44e964863cc0262956459607eeec993a5

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) The patch repairs the owning boundary and backs it with route, capture-owner, and real Chromium coverage.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored PR includes a described real Chromium after-fix scenario; the external-contributor proof gate does not apply.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored PR includes a described real Chromium after-fix scenario; the external-contributor proof gate does not apply.
Evidence reviewed 7 items Current-main failure mechanism: Current main arms the explicit capture but has no cancellation signal or listener, so only a download event, timeout, or click error releases its handler and ownership depth.
Capture-owner repair: The branch registers the request signal at the capture owner and abort cleanup removes the listener, timer, and ownership depth before rejecting with the caller reason.
End-to-end owner chain: The browser tool forwards its execution signal to local download clients, and the route forwards its leased request signal to both wait and click implementations.
Findings None None.
Security None None.

How this fits together

The browser plugin sends agent download actions through an HTTP route to a Playwright-backed managed browser session. The route owns request cancellation, while the download capture owns its listener, timer, output file, and completion result.

flowchart LR
  A[Agent browser action] --> B[Browser tool client]
  B --> C[Download HTTP route]
  C --> D[Route cancellation lease]
  D --> E[Playwright click or wait]
  E --> F[Download capture owner]
  F --> G[Managed download file]
Loading

Before merge

  • Resolve merge risk (P2) - The bug fix adds 28 production lines; its signal propagation and owner cleanup should remain the single cancellation path rather than growing compatibility or fallback logic.
  • Resolve merge risk (P1) - Direct Playwright 1.62.1 source/types could not be fetched in this environment; exact-head typecheck and the described real Chromium run mitigate, but do not replace direct upstream inspection when available.
  • Complete next step (P2) - This active maintainer-authored protected-label PR needs normal exact-head CI completion, not a repair-lane dispatch.
Agent review details

Security

None.

PR surface

Source +28, Tests +342. Total +370 across 9 files.

View PR surface stats
Area Files Added Removed Net
Source 6 43 15 +28
Tests 3 342 0 +342
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 9 385 15 +370

Review metrics

Metric Value Why it matters
Production and regression coverage production +28, tests +342 Production growth carries one existing request signal through existing boundaries and adds capture-owner cleanup; tests cover route, owner, and real-Chromium behavior.

Stored data model

Persistent data-model change detected: serialized state: extensions/browser/src/browser/pw-tools-core.waits-next-download-saves-it.test.ts, serialized state: extensions/browser/src/browser/server.agent-contract-form-layout-act-commands.test.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Retain the single route-lease-to-capture cancellation flow, then merge after exact-head CI completes without adding downstream listener guards or parallel cancellation paths.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Retain the single route-lease-to-capture cancellation flow, then merge after exact-head CI completes without adding downstream listener guards or parallel cancellation paths.

Do we have a high-confidence way to reproduce the issue?

Yes, at source level: current main leaves the explicit capture armed after outer-request cancellation, and the added Chromium scenario exercises cancellation followed by a successor download.

Is this the best way to solve the issue?

Yes. Passing the existing request lease into the capture owner removes stale state at its producer rather than filtering a later download downstream.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against a0498f7a9c8a.

Labels

Label changes:

  • add P1: A cancellation race in browser download handling can misdirect a later file into an abandoned request.
  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🌊 off-meta tidepool and patch quality is 🦞 diamond lobster.

Label justifications:

  • P1: A cancellation race in browser download handling can misdirect a later file into an abandoned request.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🌊 off-meta tidepool and patch quality is 🦞 diamond lobster.

Evidence

What I checked:

Likely related people:

  • Vyctor H. Brzezowski: Available history shows this person introduced the current capture, download-operation, and route modules together. (role: current feature introducer; confidence: high; commits: 8a3fff21a890; files: extensions/browser/src/browser/pw-download-capture.ts, extensions/browser/src/browser/pw-tools-core.downloads.ts, extensions/browser/src/browser/routes/agent.act.download.ts)
  • steipete: The related merged browser lifecycle repair covers the neighboring browser ownership boundary. (role: recent adjacent contributor; confidence: medium; commits: 056184bccc38; files: extensions/browser/src/browser-tool.actions.ts, extensions/browser/src/browser-tool.ts)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@steipete

Copy link
Copy Markdown
Contributor Author

ClawSweeper pre-merge notes resolved on reviewed head c1b92eb44e964863cc0262956459607eeec993a5:

  • The +28 production LOC is the single request-lease-to-capture/click cancellation path. No compatibility, fallback, downstream guard, or second cancellation owner was added.
  • Playwright 1.62.1 was inspected directly from the pinned installed package: types/types.d.ts confirms locator click and page event waits accept AbortSignal; lib/coreBundle.js shows the click signal is sent as protocol __abort__, the caller reason is restored as the abort cause, and the listener is removed in finally.
  • Exact-head CI 31924442148 is complete and green, including required openclaw/ci-gate.
  • The reported stored-data-model entries are false positives: both named files are *.test.ts; this PR changes no serialized runtime state, persistence schema, migration, or upgrade contract.

No ClawSweeper finding or rank-up code change remains. The current review is fresh and covers this exact head, so no re-review request is needed.

@steipete
steipete merged commit 4823b23 into main Aug 16, 2026
162 of 163 checks passed
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

@steipete
steipete deleted the fix/autoqa-refill-browser-downloads-v2 branch August 16, 2026 03:44
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 16, 2026
…enclaw#124382)

* fix(browser): cancel abandoned download waits

* fix(browser): cancel in-flight download clicks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant