Skip to content

fix(subagents): avoid cleanup failures during overlapping completion - #163741

Merged
vincentkoc merged 2 commits into
mainfrom
fix/subagent-browser-cleanup-owner-race-20261003
Oct 2, 2026
Merged

vincentkoc merged 2 commits into
mainfrom
fix/subagent-browser-cleanup-owner-race-20261003

Conversation

@vincentkoc

@vincentkoc vincentkoc commented Oct 2, 2026 •

Copy link
Copy Markdown
Member

What Problem This Solves

Fixes subagent completion failing when overlapping completion callbacks or a newer run take browser-cleanup ownership while an older callback waits to persist its cleanup claim.

User Impact

Completed subagent work can finish without a spurious cleanup failure. The current owner retains browser cleanup; genuine persistence and authority failures remain visible. No configuration change is required.

Why This Change Was Made

Retire only the original callback's positively identified pre-commit ownership rejection. A superseded session uses the existing run-retirement path. Committed or uncertain writes and unrelated errors still propagate.

Related: #163725. The failure also reproduced without that PR's authority change.

Evidence

  • A deterministic FIFO regression failed on the unchanged base with the original owner-loss error. The final six-case suite passes, covering overlapping completion, queued and pre-commit session supersession, matching-message persistence errors, authority rejection, and unknown write outcomes.
  • Six existing browser-cleanup lifecycle cases passed. The original 39-case production-boundary suite passed on the initial ownership fix; the subsequent retirement and wrapped-error corrections have focused regression coverage.
  • Final native test command: node scripts/run-vitest.mjs src/agents/subagents/registry/subagent-registry-terminal-effects.test.ts --maxWorkers=1 — 8.67 seconds wall time, including 2.9 seconds of cached worker preparation; the six cases took 354 ms. CI seconds are pending the attached run.
  • Tests exercise real controller/persistence code with an ACK transport fixture; they do not claim real SQLite transaction coverage.
  • The production change has clean independent, automated P2, and ClawSweeper reviews. Independent review also cleared the final test-only lint correction. All six tests, typed lint, and repository changed checks for that correction passed; prior core/static proof remains valid. Required hosted CI and ClawSweeper verification on the updated head are pending.

@vincentkoc vincentkoc self-assigned this Oct 2, 2026
@clawsweeper

clawsweeper Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@vincentkoc
vincentkoc marked this pull request as ready for review October 2, 2026 19:36
@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: M labels Oct 2, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 2, 2026
@clawsweeper

clawsweeper Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 2, 2026, 3:55 PM ET / 19:55 UTC (Revision 2).

ClawSweeper review

What this changes

The PR prevents overlapping subagent completions from treating a rejected browser-cleanup claim as a failure while preserving genuine persistence errors.

Merge readiness

✅ Ready for maintainer review

The fix remains useful on current main. No actionable correctness or security finding was identified, and the latest test-only correction preserves the prior review outcome.

Priority: P2
Reviewed head: 48d7af007af9c175ef9087064c0db859961b51c4

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused repair with meaningful ordering regressions, preserved failure boundaries, and no actionable findings.
Proof confidence 🌊 off-meta tidepool Not applicable: The member-authored PR is exempt from ordinary contributor proof. Its supplemental tests exercise the lifecycle and persistence owners with mocked storage acknowledgments; they do not establish real SQLite or browser transport behavior. No stored-data format or schema changes are introduced.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The member-authored PR is exempt from ordinary contributor proof. Its supplemental tests exercise the lifecycle and persistence owners with mocked storage acknowledgments; they do not establish real SQLite or browser transport behavior. No stored-data format or schema changes are introduced.
Evidence reviewed 8 items Pinned introduced change: The merge-base-to-head diff changes browser-cleanup claim error handling and adds six regression scenarios. It catches only the callback-local error object directly or as the cause of a confirmed not-committed write.
Current main still needs the fix: The pinned current-main implementation still throws the original ownership-loss error without this catch. GitHub reports the PR open and unmerged; the latest published release remains v2026.9.7. No implemented-on-main closure is supported.
Write outcomes and authority remain enforced: The persistence owner checks current authority before planning and transaction admission and distinguishes not-committed, committed, and unknown outcomes. The patch leaves those checks and the post-publication browser dispatch guards intact; it neither grants authority nor broadens eligible principals.
Findings None None.
Security None None.

How this fits together

Subagents report completion through a lifecycle controller that persists terminal state, cleans up browser resources, and returns results to the parent. Concurrent callbacks must leave cleanup to the current run owner.

flowchart TD
  A[Completion callbacks] --> B[Subagent lifecycle controller]
  B --> C[Persist terminal state]
  C --> D[Claim browser cleanup]
  D --> E{Original owner still current?}
  E -->|Yes| F[Cleanup and completion delivery]
  E -->|No| G[Retire obsolete callback]
  D --> H[Propagate persistence failures]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +20, Tests +268. Total +288 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 38 18 +20
Tests 1 268 0 +268
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 306 18 +288

Review metrics

None.

Technical review

Best possible solution:

Keep the existing lifecycle and retirement owners, treating only positively identified pre-commit ownership loss as a harmless retirement.

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

Yes, from source: a newer terminal publication or session generation can invalidate a browser-cleanup claim while it waits in the persistence queue. The supplied deterministic regression targets that ordering; no runtime reproduction was executed here.

Is this the best way to solve the issue?

Yes. Exact error identity plus the not-committed outcome confines the exception to harmless ownership loss, while existing retirement and authority owners retain responsibility.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against e42579142bca.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This is a bounded subagent completion race repair with no demonstrated urgent outage or broader regression.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The member-authored PR is exempt from ordinary contributor proof. Its supplemental tests exercise the lifecycle and persistence owners with mocked storage acknowledgments; they do not establish real SQLite or browser transport behavior. No stored-data format or schema changes are introduced.

Evidence

What I checked:

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

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.

History

Review history (1 earlier review cycle)
  • reviewed 2026-10-02T19:44:48.131Z sha 7288f78 :: needs maintainer review before merge. :: none

@vincentkoc

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

Please review head 48d7af007af9c175ef9087064c0db859961b51c4. The only delta from the completed review is the test-only lint correction: assert the explicit vi.spyOn result instead of an unbound method reference. Production code is unchanged. All six regression cases, typed lint, and the native changed checks for that delta pass.

@clawsweeper

clawsweeper Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@vincentkoc
vincentkoc enabled auto-merge (squash) October 2, 2026 19:55
@vincentkoc
vincentkoc merged commit 8af8744 into main Oct 2, 2026
118 checks passed
@vincentkoc
vincentkoc deleted the fix/subagent-browser-cleanup-owner-race-20261003 branch October 2, 2026 20:00
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 3, 2026
…penclaw#163741)

* fix(subagents): avoid cleanup failures during overlapping completion

* test(subagents): bind retirement assertion to its spy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant