Repository navigation
fix(browser): preserve tab ownership during lazy cleanup - #137671
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
@clawsweeper re-review The completed candidate is |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Codex review: blocked before merge. Reviewed September 4, 2026, 12:40 AM ET / 04:40 UTC. ClawSweeper reviewWhat this changesThe PR makes Browser tab cleanup load its runtime only for tabs it owns and preserves tab-registration ownership across overlapping cleanup operations. Regression provenancePossible regression — suspected (reviewed change). No predecessor PR is attributed. Merge readiness⛔ Blocked before merge - 4 items remain No introduced correctness or security finding was identified. This member-owned Browser cleanup PR remains open pending a successful exact-head required security audit. Priority: P1 Review scores
Verification
How this fits togetherBrowser session cleanup tracks tabs owned by an agent session, then closes them through the Browser control service or Chrome DevTools Protocol. The registry coordinates lifecycle and idle-sweep cleanup before issuing a close. flowchart LR
A[Session lifecycle or idle sweep] --> B[Tracked tab registry]
B --> C{Registration still owned?}
C -->|yes| D[Lazy runtime lookup]
C -->|no| E[Preserve replacement tab]
D --> F[Browser control or CDP close]
F --> G[Retire acquired registration]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +43, Tests +578. Total +621 across 9 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Copy recommended automerge instructionTechnical reviewBest possible solution: Keep one cleanup owner per volatile target, retain registration identity through lazy preparation, and merge after a successful exact-head security audit confirms the reviewed head. Do we have a high-confidence way to reproduce the issue? Yes—source and the added held-operation tests provide a high-confidence path for the lazy-import, replacement, and cleanup-handoff races, though this read-only review did not execute them. Is this the best way to solve the issue? Yes—the repair belongs at the tab registry that owns selection, coalescing, and retirement; downstream caller guards or a completed-failure cache would not preserve registration identity through preparation. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 5ebe54c250b3. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (8 earlier review cycles)
|
7ac6659 to
2dd7591
Compare
|
I am correcting the earlier dismissal of the cleanup-coalescing finding. Please hold this PR for the repair already in progress. A deterministic regression on the original PR source now reproduces an overlapping custom closer running while the first cleanup waits for its client import. The import at session-tab-registry.ts:623 precedes publication of the in-flight owner at line 642. A synchronous close failure can therefore release its reservation before the preparing request resumes. The whole registry file reported 22 passing tests and this one expected regression failure, with normal process closure and no timeout. The fix reserves the operation across preparation and dispatch, then keeps the reservation until completion settles. A second failure-first case against the initial local repair exposed an overlapping-waiter handoff that also needed this completion ordering. This does not require a completed-failure cache, and later independent cleanup calls must still retry failed closes. The new public head |
|
@clawsweeper re-review The body now corrects the earlier coalescing assessment. Head |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Supplementary local cleanup evidence for exact head One baseline-then-candidate diagnostic applied all nine exact PR files to the same fixture. Both arms passed the same 14 cases with unchanged calls, assertions, request deadlines and diagnostic markers. The first Browser cleanup call was 63.020 s before and 2.700 s with this PR; the three later calls were 1.026–1.048 s before and 0.133–0.139 s after. The driver's child-and-group interval was 90.853 s and 26.567 s. That interval excludes source rehashing, temporary-runtime removal and receipt publication. The replacement case passed in both arms (2.247 s and 1.333 s); one other case rose from 289 to 290 ms. All raw observations, including slower phase markers, remain retained. An independent audit matched all 162 diagnostic signatures, 14 case identities, 11 shared source hashes and nine Browser postimages. This is one instrumented local pair, not an order-balanced statistical benchmark, production Gateway timing, normalized-memory measurement or proof of the hosted Linux timeout's cause. The original pair records the Node path/version but not its binary hash or actual loaded-module origins. To check the swallowed-loader-error possibility, a separate observation-only candidate run recorded the actual worker Browser maintenance and registry module URLs, four empty tracked-tab selections, four normal zero-count returns, and no warning callbacks. All 14 cases passed. It also recorded the actual Jiti resolver and the resolved Node executable hash before and after. Its timings are excluded from the earlier pair; it does not retroactively add missing records to that pair. Positive tab closure remains covered by the separate ownership and HTTP/CDP tests already described in the PR. No source change or CI retry accompanied this evidence. Attempt 3 of the current CI run still fails the npm advisory audit, so landing remains held. This supplements the existing verification in the body without replacing it. |
0807123 to
395b1d0
Compare
395b1d0 to
128b8e3
Compare
|
Merged via squash.
|
Backport main commit 05269b5 (#137671) unchanged for the 2026.9.2 release candidate. Avoid loading Browser control, config and transport code for empty cleanup. Reserve exact tab registrations through client preparation and dispatch so replacements survive overlapping or cancelled cleanup. Release-context proof: 105 Browser/SDK tests, 14 Gateway tests, 17 Cron tests, full build and extension types. The frozen-production negative control fails on eager imports and replacement ownership. Independent review clean.
…7671) * fix(browser): preserve tab ownership during lazy cleanup * fix(browser): reserve cleanup through client preparation
Related: #137502.
Additional instructions
MUST: Keep Allow edits from maintainers enabled for this PR so maintainers can help update the branch when needed.
What Problem This Solves
Session cleanup could initialize Browser runtime even when the session owned no browser tabs. Independent reproductions also found cleanup closing or removing a replacement registration, absorbing a replacement's cleanup request, and failing to coalesce requests that overlapped lazy client preparation.
Why This Change Was Made
Browser maintenance now resolves runtime dependencies only when a selected tab needs them. The volatile cleanup owner reserves the target before preparation, revalidates registration and activity after the import, and retires only registrations acquired by that operation. Replacement requests wait and acquire their own operation. Requests covered by the same attempted close share its outcome, including failure; a later independent call can retry.
A sweep revoked before dispatch releases its claim without pretending a close occurred, allowing a waiting lifecycle cleanup to proceed. The reservation remains visible through the outer completion await so two waiting callers cannot repeat a synchronously failed close during handoff. This uses the existing in-flight owner; it adds no completed-failure history or cache.
Durable cleanup retains the existing SQLite owner and revalidates its claim after asynchronous configuration resolution. Broad target deletion, duplicate durable forwarding and a redundant type alias are removed. No schema, storage, SDK, configuration or dependency change.
User Impact
Sessions without browser tabs avoid unrelated Browser initialization during cleanup. Replacement registrations remain available to their current owner, and overlapping cleanup requests share the appropriate operation without deleting a replacement or repeating a failed close.
Evidence and Review Correction
The earlier body incorrectly dismissed a review concern about the gap before acquiring the target reservation. That assessment is withdrawn. A deterministic regression against the original PR observed the unwanted overlapping custom closer. A second regression against the first local repair reproduced duplicate failure during a revoked-sweep handoff. Both failures are retained and both pass on the final source. The fix reserves through preparation rather than retaining completed failure history.
Final source validation passed 87 cases across 13 complete sibling files, including all 26 registry cases, plus the original 14-case Gateway file: 101 distinct selected cases across 14 files. Tests preserve original deadlines and use explicit deferred gates, not sleeps. Coverage includes real loopback HTTP DELETE/CDP WebSocket closure, public SDK facade, cold loading, duplicate bundles, SQLite ownership, route/alias selection, replacement and lifecycle cleanup. Full changed checking passed all 26 normal gates, including plugin/test typechecks, three dead-code scans, lint and architectural guards. The normal build also passed.
Fresh managed Codex P0–P2 review and an independent full-owner source review found no remaining actionable findings. Intermediate failed reproductions, line-limit/type/lint failures and their fixes remain recorded; the final implementation uses ordinary promises without a compiler-lib change, polyfill or cast.
The original hosted Linux 120-second rollback timeout was not reproduced exactly. These passing cases do not establish that timeout's cause. Main's separate fixture repair #137743 joins timed-out cleanup and prepares the real mutation runtime at suite scope; it was not substituted into this original-file proof. No full desktop Browser service was launched: closure proof uses real loopback transports and SQLite with synthetic fixtures.
Production for the whole PR is +150/−107, net +43; tests +584/−6, net +578. The corrective commit alone removes three production lines. The remaining growth records the registration identity required to distinguish activity, replacement and an already-owned cleanup operation. Removed broad deletion and forwarding paths keep that ownership in one place.
Current Landing State
Current head
128b8e3e13a950bafb715eac9de4f8b80909ae26mechanically rebases the two reviewed commits onto maine5d413f7e54a85f0a365ddcf36bd1ba23afcb212, including the separately approved ordinary-CI availability policy from #137881. All nine files and both stable patch IDs are identical to the prior reviewed 395 head. All nine Browser source/test files are byte-identical to reviewed0807123; both commits have identical range-diff patches. The latest ClawSweeper review at 04:40 UTC covers395b1d0with no actionable code or security finding. Its remaining rank-up is green required CI; its reviewer could not fetch current-main Browser blobs. The maintainer inspected them locally: the entire Browser plugin and core Browser/lifecycle neighborhood are unchanged between the reviewed c86 baseline and current main e5d413f, so this repair is not superseded. All nine final files remain byte-identical after the rebase. The +43 production-line risk is addressed by the registration-identity owner and failure-first transport coverage above. Current-head required CI is complete and green.Independent verification of
0807123reproduced three intended failures with the unchanged registry tests on2dd7591(23 controls passed), then passed all 124 tests across the complete 14-file owner/transport selection. Targeted formatting, type-aware lint and patch checks passed; source and review-context hashes stayed unchanged. Independent Codex review is scoped-clean with no P0–P2 findings. The cold-import case intentionally runs first within its file; canonical file order passed, with no shuffled-order claim.A subsequent controlled Linux pair used the exact failed cache CI merge
1da0eec7d51fbd96dc6190370d64ab28fda538ea, which already includes #137743. The original 214-pattern child, unchanged config order and two workers passed all 2,959 tests in both arms. With separate dependency trees and cold Node/Vitest caches, the first rollback took 85.411 seconds before and 4.120 seconds after applying only the four reviewed Browser production files. The other three rollback cases changed from 3.945/3.864/1.762 seconds to 1.260/1.315/0.343 seconds. All 37,354 tracked blobs were verified before and after each run; tests, assertions and deadlines stayed unchanged. The Testbox was stopped.This one pair supports a substantial Browser initialization cost; the baseline did not exceed 120 seconds, so it is not an exact reproduction of the hosted timeout, a production benchmark or a guarantee against other waits. Both arms used the same machine, whose filesystem pages may remain warm, and parallel completion interleavings are scheduler-dependent. Functional ownership and real transport proof remain the basis for the repair.
Earlier required CI run 33827417711 completed all selected source checks, but four attempts failed the dependency audit on bulk-advisory response deadlines. The last audit ran from 03:13:29 to 03:15:30 UTC. Exact-request diagnostics established TLS and sent the body before a no-header stall; an identical later request succeeded. These are missing audit results, not vulnerability findings or waived checks. The refreshed base inherits the subsequently landed bounded retry/backoff owner from #137825, whose hosted production audit completed successfully. The current PR still requires its own successful checks before landing.
On preceding head
395b1d0, CI run 33832934065 retains 30 passing and 17 skipped jobs. All four attempts failed only the required npm audit and its aggregate gate after the bounded audit requests exhausted their deadlines. An initial lint-job setup failure downloading pnpm with HTTP 504 recovered on the normal failed-job retry; lint itself passed. Attempt four completed at 04:07:35 UTC on September 4; its audit exhausted three requests and ended with the existing 60-second timeout. No audit clearance was obtained. The final base refresh inherits #137881: ordinary CI records service unavailability as an explicit incomplete-coverage warning, while known findings, permanent failures and release/local callers remain blocking. The refreshed head passed its required CI: 32 jobs successful, 17 skipped, no failures. Its production audit exhausted three requests and emitted the explicit incomplete-coverage warning under #137881; this is not complete advisory clearance. No Browser code, test assertion or deadline changed.Completed current-head integration checks (32 passed, 17 skipped): CI run 33840358148.