Skip to content

fix(sessions): keep one agent's queue cleanup from cancelling another agent's work - #162179

Merged
steipete merged 6 commits into
mainfrom
fix/scope-remaining-session-queue-cleanup
Oct 1, 2026
Merged

steipete merged 6 commits into
mainfrom
fix/scope-remaining-session-queue-cleanup

Conversation

@steipete

Copy link
Copy Markdown
Contributor

Related: #161736

What Problem This Solves

Fixes: one agent's worker placement move, rewind, provider-review pause, broad sessions.abort, or interrupt-mode reply could cancel a different agent's queued follow-ups and session-lane commands when both agents used the same raw session key (for example global).

User Impact

Stopping, rewinding, moving, or interrupting one agent's conversation now only cancels that agent's queued work. Other agents sharing a global or bare-alias session keep their queued follow-ups and commands. Behavior for a single agent is unchanged, except that a broad Stop now also cancels its own key-only queued follow-ups when no session row exists yet.

Why This Change Was Made

#161736 added the agent-scoped queue cleanup owner (clearSessionLifecycleQueues) for delete/reset/archive and /stop. Six production callers still used the raw-key clearSessionQueues or a whole-lane clearCommandLane, which wipe process-wide queues for every agent under that key. This PR moves them onto the same owner:

Caller Before (two-agent repro) Now
Provider-review precaution settlement cleared main's global queue from research scoped, exact incarnation
Worker placement local dispatch rejected main's tagged + untagged lane commands scoped; unconditional post-commit settlement
Worker placement move / abandon same scoped; unconditional post-commit settlement
Session rewind (non-fork) same scoped to the original incarnation; unconditional post-commit settlement
Broad sessions.abort fallback cleared main's follow-ups under a shared bare key scoped, all incarnations of the target agent's session
Interrupt-mode admission rejected main's lane commands on session:global lane-only scoped clear via new clearSessionLifecycleLanes; keyless runs keep their own sessionId lane clear

Owner contract change: an omitted sessionId in SessionLifecycleQueueTarget now means "every incarnation of this agent's session" (previously: no follow-ups, untagged lanes only). All existing callers that can omit it were audited (reset, delete, drain, fast abort, /stop); none relied on the old behavior. Calls with a sessionId keep exact-incarnation matching.

Not changed: subagent kill and sweep still use clearSessionQueues. Sweep only receives strict agent-qualified keys. Direct kill has a remaining gap for raw-key children registered by a watched sessions_send, because the subagent registry doesn't record the target agent. That needs a registry schema decision and is tracked as a follow-up, so clearSessionQueues stays for now.

Evidence

Every boundary regression drives the real entry point with agents main and research sharing a raw key. Each one failed on main and failed again when only the production changes were reverted. Proof ran on Blacksmith Testbox because the local host was saturated.

  • Fail-before: provider settlement (1), placement dispatch/move/abandon (3 + 3 post-commit revocation), rewind (1 + 1 post-commit revocation), broad abort (2), interrupt (1), keyless interrupt (1), owner all-incarnation matching (2).
  • After: 18 focused runs, 252 tests passing, including the existing abort, reset-cleanup, archive-lifecycle, and /stop suites.
  • pnpm tsgo, targeted oxlint, and oxfmt --check all pass. Autoreview is scoped-clean at P2.
Test cost (pnpm test <file> --maxWorkers=1, Testbox wall)
File Tests Wall
provider-review-run.test.ts 1 3.5s
queue/cleanup.session-authority.test.ts 21 36.6s
get-reply-run-admission.session-file.test.ts 7 35.9s
server-worker-placement-move-barrier.test.ts 16 13.8s
sessions-rewind.test.ts 36 31.5s
sessions.abort-queue-authority.test.ts 8 34.4s
sessions.abort-agent-scope.test.ts 30 26.2s

Most of each wall time is compilation. No real timers, sleeps, or per-test Gateway boots were added.

Use the existing lifecycle queue owner for provider precautions, worker
placement dispatch and move barriers, and transcript rewind/branch switches.
Preserve other agents' work in shared raw-key lanes while cancelling the
selected agent and session incarnation.

Revalidate existing authority at cleanup and retain rewind's original session
ID after history rotation. Boundary regressions exercise real settlement,
barrier, and Gateway handler entry points and fail again when the production
changes are temporarily reverted.
Cancel all incarnations only within the selected agent and conversation when no session ID is supplied. Keep dispatch, move, and rewind queue settlement unconditional after committed effects. Retain subagent raw-key cleanup pending target ownership in the registry.
@clawsweeper

clawsweeper Bot commented Sep 30, 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 gateway Gateway runtime agents Agent runtime and tooling size: L labels Sep 30, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. 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 30, 2026
@clawsweeper

clawsweeper Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 30, 2026, 7:59 PM ET / 23:59 UTC (Revision 3).

ClawSweeper review

What this changes

The branch scopes pending follow-up and command-queue cancellation to the selected agent during provider review, worker placement, session rewind, broad abort, and interrupt admission.

Merge readiness

✅ Ready for maintainer review

Keep open. Current main still has unscoped cleanup at the additional entry points, and the related merged PR explicitly deferred them. This is a distinct, coherent follow-up with no discrete introduced defect established in this review.

Priority: P1
Reviewed head: 0d6a1dadf5cde23f525931ba470349f6afd5ea3b

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A coherent owner-level repair has meaningful two-agent boundary coverage, with no discrete introduced defect established.
Proof confidence 🐚 platinum hermit (4/6) Not applicable: The trusted-author proof gate does not apply. The PR reports Testbox runs of the production queue owner and Gateway abort handler with two agents sharing a key; the tests observe selected work canceled and foreign work completing. No stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The trusted-author proof gate does not apply. The PR reports Testbox runs of the production queue owner and Gateway abort handler with two agents sharing a key; the tests observe selected work canceled and foreign work completing. No stored-data contract changes.
Evidence reviewed 8 items Introduced queue selection: The proposed matcher requires the queued work's agent and session key to match; an omitted session ID selects that agent's incarnations. The cleanup owner applies the selection to follow-ups and command lanes.
Current-main gap: At the fetched main revision, broad session abort still calls raw-key clearSessionQueues; the PR head calls the scoped owner with the target agent and canonical key.
Gateway boundary coverage: The added broad-abort cases send a Gateway request for one agent while both agents have follow-ups and lane commands under a shared key; assertions check that selected work is canceled and the other agent's work completes.
Findings None None.
Security None None.

How this fits together

The Gateway and reply runner place session work into shared follow-up and command queues. Cleanup receives an agent and session target, then removes pending work before later replies or commands run.

flowchart LR
  A[Stop, rewind, move, pause, or interrupt] --> B[Gateway or reply runner]
  B --> C[Agent and session target]
  C --> D[Shared queue cleanup]
  D --> E[Selected work canceled]
  D --> F[Other agent work preserved]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +46, Tests +674. Total +720 across 21 files.

View PR surface stats
Area Files Added Removed Net
Source 7 76 30 +46
Tests 14 771 97 +674
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 21 847 127 +720

Review metrics

Metric Value Why it matters
Production versus test growth production +46 net lines; tests and test support +674 net lines The test growth covers distinct queue-owner and Gateway entry points, including other-agent preservation and post-commit settlement.

Root-cause cluster

Relationship: canonical
Canonical: #162179
Summary: The earlier merged PR established scoped cleanup and explicitly deferred the additional callers addressed here.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Technical review

Best possible solution:

Use one agent-scoped cleanup owner across these entry points so a session action cancels its selected queued work while preserving other agents' work and the existing keyless interrupt behavior.

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

Yes, from source: current main still clears shared keys at the affected callers, and the PR supplies two-agent boundary regressions reported to fail before and pass after the change. This read-only review did not execute them.

Is this the best way to solve the issue?

Yes. Reusing the existing queue cleanup owner is a narrow repair for the remaining callers, and the tests check both selected cancellation and preservation of another agent's work.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

No label changes.

Label justifications:

  • P1: The existing raw-key cleanup can silently discard another agent's pending replies or commands in a multi-agent setup.
  • merge-risk: 🚨 message-delivery: Changing which queued work is canceled directly affects whether pending agent replies and commands are delivered.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit 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 trusted-author proof gate does not apply. The PR reports Testbox runs of the production queue owner and Gateway abort handler with two agents sharing a key; the tests observe selected work canceled and foreign work completing. No stored-data contract changes.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit c773890 adds src/auto-reply/reply/queue/cleanup.ts:42 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: c77389060af9; files: src/auto-reply/reply/queue/cleanup.ts)
  • Vincent Koc: 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 (2 earlier review cycles)
  • reviewed 2026-09-30T22:26:01.860Z sha 658cc77 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-30T22:51:47.486Z sha 960fb9a :: needs maintainer review before merge. :: none

@steipete

Copy link
Copy Markdown
Contributor Author

The stale interrupt expectation is corrected to require clearCommandLane("session:session-key", expect.any(Function)). The media-only file passes all 91 tests on Blacksmith Testbox (29.259 s wall), formatting passes, and the focused P2 review is clean.

The previous CI run's embedded Stop job failed these two cases in src/gateway/server-methods/sessions.abort-embedded.test.ts:

  • exact embedded Stop cancels running and queued collectors without dispatching the queued sibling
  • sessions.abort controller-backed Stop respects parent acceptance (finalizing=false)

The reported assertion was expect(isSwarmRunActive("running")).toBe(false), with true received.

I compared a freshly fetched main, fa9e01430460eaac3eaf9bf25d34ff7c73435ff5, with this PR's 960fb9aecc54fb6cea5d376be0528940ca474b3e merged locally onto that exact main. The temporary merge was 6f54b5ef73be51af7f93e0d34799a58339224bff, with tree e74890c04739a81f71f8b4898820d0fc7b2bc576; it was not pushed.

Each run used:

pnpm test src/gateway/server-methods/sessions.abort-embedded.test.ts --maxWorkers=1
Source Run Result Failing tests Wall
Pinned main 1 12/12 passed None 72.441 s
Pinned main 2 12/12 passed None 34.974 s
PR merged onto pinned main 1 12/12 passed None 70.330 s
PR merged onto pinned main 2 12/12 passed None 34.411 s

Per the maintainer's decision for a clean comparison on both sources, the original Stop failure is treated as flaky. These passing replays do not establish a fix for that failure; its original CI evidence remains recorded above.

Provider: Blacksmith Testbox, lease tbx_01m3t9pye3e9wajg7d0phgxaw4, provisioning run. The lease is stopped. Downloaded proof logs were verified against their recorded SHA-256 hashes.

@steipete
steipete merged commit 45a3d17 into main Oct 1, 2026
185 checks passed
@steipete
steipete deleted the fix/scope-remaining-session-queue-cleanup branch October 1, 2026 00:45
@steipete

steipete commented Oct 1, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

steipete added a commit that referenced this pull request Oct 1, 2026
#162179 (45a3d17) added an explained @ts-expect-error to
get-reply-run-admission.session-file.test.ts so the test can exercise the
runtime fallback for a missing session key. It did not register that
suppression in the type-suppression inventory, so "keeps unchecked any
casts at zero and negative type assertions explicit" saw 17 entries
instead of 16 and turned scheduled main CI red (run 36800483241,
checks-node-compact-small-49).

Add the exact file:excerpt entry. The inventory still binds each
suppression to its file and explanation text, and the any-cast counters
stay at zero.

Test cost: node scripts/run-vitest.mjs test/scripts/type-suppression-inventory.test.ts --maxWorkers=1 = 29.6s wall (4 tests). No new tests.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 1, 2026
… agent's work (openclaw#162179)

* fix(sessions): scope provider, placement, and rewind queue cleanup

Use the existing lifecycle queue owner for provider precautions, worker
placement dispatch and move barriers, and transcript rewind/branch switches.
Preserve other agents' work in shared raw-key lanes while cancelling the
selected agent and session incarnation.

Revalidate existing authority at cleanup and retain rewind's original session
ID after history rotation. Boundary regressions exercise real settlement,
barrier, and Gateway handler entry points and fail again when the production
changes are temporarily reverted.

* fix(sessions): scope broad stop and interrupt queue cleanup

Cancel all incarnations only within the selected agent and conversation when no session ID is supplied. Keep dispatch, move, and rewind queue settlement unconditional after committed effects. Retain subagent raw-key cleanup pending target ownership in the registry.

* fix(sessions): keep keyless interrupt clearing its own lane

* test(sessions): fail keyless interrupt regression fast

* test(sessions): document keyless runtime fixture

* test(sessions): expect scoped interrupt lane clear

Co-authored-by: Peter Steinberger <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 1, 2026
openclaw#162179 (88a22af) added an explained @ts-expect-error to
get-reply-run-admission.session-file.test.ts so the test can exercise the
runtime fallback for a missing session key. It did not register that
suppression in the type-suppression inventory, so "keeps unchecked any
casts at zero and negative type assertions explicit" saw 17 entries
instead of 16 and turned scheduled main CI red (run 36800483241,
checks-node-compact-small-49).

Add the exact file:excerpt entry. The inventory still binds each
suppression to its file and explanation text, and the any-cast counters
stay at zero.

Test cost: node scripts/run-vitest.mjs test/scripts/type-suppression-inventory.test.ts --maxWorkers=1 = 29.6s wall (4 tests). No new tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling gateway Gateway runtime merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: L 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