Skip to content

fix(agents): avoid extra cleanup waits after cancellation - #149755

Merged
vincentkoc merged 1 commit into
mainfrom
openclaw/issue-149612-provider-reload-lane
Sep 20, 2026
Merged

vincentkoc merged 1 commit into
mainfrom
openclaw/issue-149612-provider-reload-lane

Conversation

@roboclaw-bot

@roboclaw-bot roboclaw-bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #149612

What Problem This Solves

Fixes canceled agent turns waiting through an unnecessary idle timeout when cancellation arrives during cleanup.

User Impact

Canceled turns stop optional idle waits promptly while required transcript writes and runtime disposal still finish. This does not reset session lanes, replay completed actions, or change provider-generation authority.

This fixes the demonstrated cleanup races; the full provider-reload stall and high memory usage remain unverified.

Why This Change Was Made

Cleanup now rereads cancellation after draining transcript writes and forwards the cancellation signal into the optional idle wait, including preparation-failure and compaction cleanup. The signal interrupts only that wait; persistence and resource settlement retain their existing ownership and ordering.

Evidence

  • September 19 readiness refresh: rebased onto a37efbafbec59a00bb1c2e78ad1b2f5927bb01c1 without conflicts. The prior Goal assertion and chat-pane lint error also failed on the exact tested base. Existing upstream repairs #149765 and #149826 are now included; the Goal tests and affected UI lint pass locally. No unrelated source workaround was added.
  • Before the fix, the new transcript-drain regression received stale aborted: false state, and the already-canceled / canceled-during-idle regressions failed.
  • 78 focused tests passed across 8 files on d245e363c8e6fe5aad0cf70dd57de79d0fe107f4, including the previously failing Goal case and covering cancellation timing, late rejection, timer/listener cleanup, actual SQLite write admission, runtime disposal, preparation failure, compaction, and lane timeout safeguards.
  • Changed-scope checks passed for all 10 changed files, including production and test typechecks, lint, formatting, and repository guards.
  • Independent autoreview found no actionable P0–P2 defects in the implementation; git range-diff confirms this refresh is a patch-identical rebase.
  • Validated on Linux / Node 26.8.2 with a checkout-owned frozen-lockfile dependency installation. No live Gateway or full reload-to-successor integration test was used; the broader incident remains open.
Focused test command
node scripts/run-vitest.mjs \
  src/config/sessions/goals-operations.test.ts \
  src/agents/embedded-agent-runner/run/attempt-session-cleanup.test.ts \
  src/agents/embedded-agent-runner/run/attempt.subscription-cleanup.test.ts \
  src/agents/embedded-agent-runner/wait-for-idle-before-flush.cancellation.test.ts \
  src/agents/embedded-agent-runner/wait-for-idle-before-flush.test.ts \
  src/agents/embedded-agent-runner/run/attempt-execution-phase.test.ts \
  src/agents/embedded-agent-runner/compact.abort-signal.test.ts \
  src/agents/embedded-agent-runner/run/lane-controller.test.ts \
  --maxWorkers=1

Worked on by: @RomneyDa

Work sessions

@clawsweeper

clawsweeper Bot commented Sep 16, 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.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: M maintainer Maintainer-authored PR labels Sep 16, 2026
@roboclaw-bot
roboclaw-bot marked this pull request as ready for review September 16, 2026 05:39
@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 Sep 16, 2026
@clawsweeper

clawsweeper Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 20, 2026, 11:13 AM ET / 15:13 UTC (Revision 4).

ClawSweeper review

What this changes

The PR interrupts optional agent cleanup waits when cancellation arrives, while continuing to await transcript writes and runtime disposal.

Merge readiness

✅ Ready for maintainer review

Keep open: the cancellation race remains on current main and the latest release. The focused patch has no actionable correctness or security findings; the broader provider-reload incident remains separately unresolved.

Priority: P2
Reviewed head: d245e363c8e6fe5aad0cf70dd57de79d0fe107f4

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, maintainable repair with meaningful regression coverage and no actionable findings.
Proof confidence 🌊 off-meta tidepool Not applicable: The maintainer/bot PR is exempt from the external-contributor proof gate. Its reported Linux tests exercise cleanup owners, SQLite admission, and disposal; they do not establish live Gateway reload recovery, which the body explicitly disclaims.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The maintainer/bot PR is exempt from the external-contributor proof gate. Its reported Linux tests exercise cleanup owners, SQLite admission, and disposal; they do not establish live Gateway reload recovery, which the body explicitly disclaims.
Evidence reviewed 8 items Current main still contains both cleanup races: Current main's idle helper races only idle completion against a 30-second timer. Its session cleanup also samples cancellation before awaiting beginCleanup, allowing cancellation during that drain to leave the sampled state stale.
Latest release lacks cancellable idle cleanup: The supplied latest release, v2026.9.5, contains the same idle-versus-timeout race without an AbortSignal input.
Cancellation remains limited to optional waiting: The introduced signal races the idle wait and its listener is removed in finally. Pending tool results still await withSessionManagerWrite; resource cleanup still awaits MCP and LSP disposal. Normal, preparation-failure, and compaction callers forward cancellation.
Findings None None.
Security None None.

How this fits together

The embedded agent runner cleans up completed or cancelled turns before releasing their resources. It drains transcript callbacks, flushes pending tool results through the database writer, and disposes the session and its runtimes.

flowchart TD
  A[Turn enters cleanup] --> B[Drain transcript callbacks]
  B --> C[Check cancellation]
  C --> D[Optional idle wait]
  E[Cancellation signal] --> D
  D --> F[Await transcript writer]
  F --> G[Dispose session and runtimes]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +21, Tests +169. Total +190 across 10 files.

View PR surface stats
Area Files Added Removed Net
Source 5 25 4 +21
Tests 5 172 3 +169
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 10 197 7 +190

Review metrics

Metric Value Why it matters
Production versus regression coverage Production net +21 lines; tests net +169 lines Production growth is justified by cancellation propagation and listener cleanup; regression coverage checks timing and persistence ordering.

Technical review

Best possible solution:

Keep cancellation confined to optional idle waiting while preserving writer admission and resource settlement, with broader reload recovery tracked separately.

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

Yes, from source: cancel while transcript draining or a pending idle wait is in progress; current main can retain stale cancellation state or wait until the timer expires. This review did not execute a reproduction.

Is this the best way to solve the issue?

Yes. Extending the existing cleanup owner is a narrow repair, and the signal does not bypass required transcript persistence or runtime disposal.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: This is a bounded fix for unnecessary cancellation cleanup delays, without proof that it resolves the broader stuck-session incident.
  • 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 maintainer/bot PR is exempt from the external-contributor proof gate. Its reported Linux tests exercise cleanup owners, SQLite admission, and disposal; they do not establish live Gateway reload recovery, which the body explicitly disclaims.

Evidence

What I checked:

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; 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 (3 earlier review cycles)
  • reviewed 2026-09-16T05:45:58.418Z sha 6490a91 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-19T23:14:01.231Z sha 6490a91 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-19T23:29:54.333Z sha d245e36 :: needs maintainer review before merge. :: none

Read cancellation after transcript draining and interrupt only the optional idle wait. Keep pending transcript writes and runtime disposal awaited, and forward cancellation through preparation-failure and compaction cleanup.

Related to #149612.

Co-authored-by: RomneyDa <[email protected]>
@roboclaw-bot
roboclaw-bot force-pushed the openclaw/issue-149612-provider-reload-lane branch from 6490a91 to d245e36 Compare September 19, 2026 23:20
@roboclaw-bot

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Sep 19, 2026

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

@clawsweeper

clawsweeper Bot commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@vincentkoc

Copy link
Copy Markdown
Member

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@vincentkoc
vincentkoc merged commit 09b2a86 into main Sep 20, 2026
213 checks passed
@vincentkoc
vincentkoc deleted the openclaw/issue-149612-provider-reload-lane branch September 20, 2026 15:22
@vincentkoc

Copy link
Copy Markdown
Member

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 21, 2026
…49755)

Read cancellation after transcript draining and interrupt only the optional idle wait. Keep pending transcript writes and runtime disposal awaited, and forward cancellation through preparation-failure and compaction cleanup.

Related to openclaw#149612.

Co-authored-by: RomneyDa <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling maintainer Maintainer-authored PR 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.

2 participants