Skip to content

fix(agents): preserve reply cleanup when cancellation throws - #122252

Merged
vincentkoc merged 2 commits into
mainfrom
refactor/reply-operation-abort
Aug 11, 2026
Merged

vincentkoc merged 2 commits into
mainfrom
refactor/reply-operation-abort

Conversation

@vincentkoc

@vincentkoc vincentkoc commented Aug 11, 2026 •

Copy link
Copy Markdown
Member

What Problem This Solves

Fixes an issue where a reply backend whose cancellation callback throws could leave queued reply ownership active indefinitely or leave running ownership without its terminal-settle deadline.

Why This Change Was Made

The reply-operation owner now uses one canonical abort path for direct user aborts, restart aborts, and upstream cancellation. It records the terminal result, detaches upstream cancellation, aborts the local signal, invokes backend cancellation, and guarantees the phase-appropriate cleanup in finally.

The change preserves public abortability guards, upstream settled-result handling, user/restart result codes, the Plugin SDK contract, and backend cancellation exception propagation.

User Impact

Reply lanes no longer remain wedged when backend cancellation throws. Normal cancellation behavior is unchanged.

Evidence

  • Prepared head: 1cdc152df420ad323b02c6d07db9ab1233976d52.
  • Landed via squash: f30e67298a59384295d120198b083bae2e925577; GitHub reports a valid verified signature, and the commit is live on origin/main.
  • Pre-fix regression on current main: all four queued/running x user/restart cases fail. Queued ownership remains active; running ownership has no terminal-settle timer.
  • Focused local test: node scripts/run-vitest.mjs src/auto-reply/reply/reply-run-registry.test.ts -> 80 passed.
  • Plugin SDK baseline check: generate-plugin-sdk-api-baseline.ts --check -> OK docs/.generated/plugin-sdk-api-baseline.
  • Blacksmith Testbox: workflow 31540936563, job 93942917774, lease tbx_01kzsds47j67jj8pn91wfrzpaj; exact tree 169e267f3fdd8a872d317d8fc4753ed0f9284c5c; four files / 151 tests, check:test-types, and the exact two-file changed gate passed. The full workflow, teardown, and post steps completed successfully.
  • AWS Crabbox: run run_3b1147852239, lease cbx_904d5b7bb03e; exact head verified, 151/151 lifecycle tests passed, built CLI and launcher version/help smokes passed, and the lease was released.
  • Hosted CI: workflow 31543742410 completed successfully with 70 jobs and zero failures.
  • Exact-head ClawSweeper review: no findings.
  • Production LOC: +26/-41 (net -15). Tests: +67/-0.

AI-assisted: yes.

@clawsweeper

clawsweeper Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@vincentkoc vincentkoc self-assigned this Aug 11, 2026
@openclaw-barnacle openclaw-barnacle Bot added size: S maintainer Maintainer-authored PR labels Aug 11, 2026
@vincentkoc
vincentkoc force-pushed the refactor/reply-operation-abort branch from 03896d1 to ef800d4 Compare August 11, 2026 20:41
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. 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 Aug 11, 2026
@clawsweeper

clawsweeper Bot commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 11, 2026, 6:05 PM ET / 22:05 UTC.

ClawSweeper review

What this changes

This PR moves reply-abort cleanup into a shared finally path so queued ownership is released and running ownership receives its terminal-settle deadline even if backend cancellation throws.

Regression provenance

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

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Current main still bypasses reply cleanup when backend cancellation throws; this focused owner-boundary fix addresses that path cleanly. Keep it open for normal maintainer review and exact-head validation.

Priority: P1
Reviewed head: 1cdc152df420ad323b02c6d07db9ab1233976d52

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch is a compact, tested owner-boundary repair with no correctness or security finding; readiness still depends on exact-head validation.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored PR is exempt from the external-contributor real-behavior-proof gate; its body reports focused exact-head regression coverage.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored PR is exempt from the external-contributor real-behavior-proof gate; its body reports focused exact-head regression coverage.
Evidence reviewed 6 items Current-main defect: The current abort helper invokes backend cancellation before callers release queued ownership or schedule terminal settlement, so a thrown callback bypasses both cleanup paths.
Owner-boundary repair: The PR records the terminal state, invokes cancellation, and performs the existing phase-specific release or settle behavior in finally, preserving cancellation exception propagation.
Regression coverage: The added table cases cover queued and running operations for both user and restart aborts, asserting preserved thrown errors, active-slot release, callbacks, and the terminal-settle timer.
Findings None None.
Security None None.

How this fits together

Reply operations own a reply lane from queueing through backend execution and terminal cleanup. User, restart, and upstream cancellation flow through this owner before the next reply can be admitted.

flowchart LR
  A[User restart or upstream cancellation] --> B[Reply operation owner]
  B --> C[Record aborted result]
  C --> D[Backend cancellation]
  D --> E[Finally cleanup decision]
  E --> F[Release queued reply lane]
  E --> G[Schedule running terminal settle]
  F --> H[Admit next reply]
  G --> H
Loading

Before merge

  • Resolve merge risk (P1) - The branch is still a draft and its GitHub checks are skipped; confirm the reported focused regression result and required exact-head validation before merge.
  • Complete next step (P2) - The current-main defect and repair are concrete, but this maintainer-owned draft requires normal ready-for-review and exact-head validation rather than an automated repair lane.
Agent review details

Security

None.

PR surface

Source -15, Tests +67. Total +52 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 26 41 -15
Tests 1 67 0 +67
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 93 41 +52

Review metrics

Metric Value Why it matters
Production versus regression coverage production +26/-41 (net -15); tests +67/-0 The repair removes duplicated caller cleanup while adding focused coverage for the previously unprotected exception path.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Land the shared reply-operation cleanup after it is marked ready and exact-head validation confirms the four throwing-cancellation cases.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Land the shared reply-operation cleanup after it is marked ready and exact-head validation confirms the four throwing-cancellation cases.

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

Yes: on current main, a backend cancel() throw exits before the phase-specific cleanup immediately following it; the PR supplies focused queued/running regression cases for that path.

Is this the best way to solve the issue?

Yes: centralizing the invariant in the reply-operation owner covers user, restart, and upstream cancellation without duplicating caller cleanup.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P1: A thrown cancellation callback can leave an agent reply lane occupied, blocking subsequent replies for that session.
  • 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: This maintainer-authored PR is exempt from the external-contributor real-behavior-proof gate; its body reports focused exact-head regression coverage.

Evidence

What I checked:

Likely related people:

  • Kevin Lin: Current-main blame attributes the exact cancellation helper and its caller cleanup lines to this shallow-history-boundary commit; deeper provenance is unavailable locally. (role: recent area contributor; confidence: medium; commits: 2d0c30fd654e; files: src/auto-reply/reply/reply-run-registry.operation.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Mark the draft ready and confirm the reported focused regression suite plus required exact-head checks.

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-08-11T21:05:39.741Z sha ef800d4 :: needs maintainer review before merge. :: none

@vincentkoc
vincentkoc marked this pull request as ready for review August 11, 2026 22:45
@vincentkoc
vincentkoc merged commit f30e672 into main Aug 11, 2026
184 of 185 checks passed
@vincentkoc
vincentkoc deleted the refactor/reply-operation-abort branch August 11, 2026 23:04
@vincentkoc

Copy link
Copy Markdown
Member Author

Merged via squash.

vincentkoc added a commit that referenced this pull request Aug 11, 2026
* origin/main: (1725 commits)
  fix(agents): preserve reply cleanup when cancellation throws (#122252)
  fix(ui): render disallowed link schemes as plain text (#122311)
  fix(test): isolate gateway helper env stubs (#122319)
  fix(ui): keep chat Markdown block rhythm consistent (#122289)
  test(cli): trim duplicate Hooks process cases (#122278)
  fix(ui): retain identity while agent roster loads
  fix(ui): preserve configured agent labels
  fix(plugins): keep startup convergence read-only (#122330)
  fix: preserve WebChat reply context after reloads (#122169)
  fix(ui): make DONE moves visibly reversible (#122303)
  fix(ui): keep inline-code punctuation attached (#122291)
  fix(google-meet): publish exports atomically (#122306)
  fix(channels): preserve failed agent run reactions (#122009)
  fix(ui): label patch file operations accurately (#122287)
  fix(windows): preserve Unicode LAN route aliases (#122263)
  test(media): synchronize transcode pool completion (#122279)
  fix(android): keep completed subagent activity visible for sixty seconds (#122089)
  fix(ui): humanize bare GitHub item links (#122285)
  refactor(qqbot): install plugin from Tencent package (#107295)
  chore: scope SQLite session lifecycle CI (#121917)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 12, 2026
…w#122252)

* refactor(agents): canonicalize reply abort cleanup

* refactor(agents): document reply abort cleanup invariant
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR P1 High-priority user-facing bug, regression, or broken workflow. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S 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