Skip to content

fix(reply): register composed upstream abort signal sources for identity lookups - #118057

Closed
pacocartones wants to merge 1 commit into
openclaw:mainfrom
pacocartones:fix/followup-abort-signal-identity
Closed

pacocartones wants to merge 1 commit into
openclaw:mainfrom
pacocartones:fix/followup-abort-signal-identity

Conversation

@pacocartones

@pacocartones pacocartones commented Aug 2, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

chat.abort can report a run as aborted while its reply operation is actually still finalizing and delivering. The abort gate resolves abortability by signal identity, but the followup-admission path registers operations under a fresh AbortSignal.any() composite — so the gate's lookup always misses and defaults to "abortable".

Refs #118028 (the reply-run-registry site of the signal-identity class; same class as #117884, different site and path).

Root cause

  • Every enqueued followup gets a queueAbortSignal (queue/enqueue.ts:189), so admission always composes: followup-turn-admission.ts:152 → resolveFollowupAbortSignal (queue/types.ts:219) → AbortSignal.any(...) — a new object per admission.
  • The operation is registered under that composite: reply-run-registry.ts:1059 (WeakMap<AbortSignal, ReplyOperation>).
  • The chat.abort gate asks with the raw controller signal: gateway/server-methods/chat-send-admission.ts:287 → chat-abort.ts:488-494,530-533 → isReplyRunAbortableForSignal (reply-run-registry.ts:398-401), which returns true on a WeakMap miss.
  • Net effect: when the operation is frozen/finalizing (freezeAbort → non-abortable), the gate should say false but says true; abortChatRunById then marks the run aborted and broadcasts it while the operation keeps finalizing and delivering. A direct (non-followup) chat.send registers the raw signal and is not affected.

Fix

createReplyOperation accepts upstreamAbortSignalAliases and registers each source signal as an alias key to the same operation; the followup admission passes the composite's two sources through. The abort listener stays on the composite, so cancellation semantics are unchanged — identity lookups made with either the composite or any raw source now resolve to the same operation.

4 files, +42/−0.

Evidence

Runtime proof — real chain, no mocks

Loopback harness driving the real production path on this head and on main — no mocks of the logic under test, no fake timers (Windows, Node v24.14.1):

chat.send admission (registerChatAbortController; gate verbatim from chat-send-admission.ts:287)
-> enqueueFollowupRun (real queue assigns queueAbortSignal, queue/enqueue.ts:189)
-> resolveFollowupAbortSignal (AbortSignal.any -> fresh identity, queue/types.ts:219)
-> admitReplyTurn -> createReplyOperation (identity WeakMap under test, reply-run-registry.ts:1059)
-> freezeAbort() (finalization, as in agent-runner-execution.ts:531)
-> isChatAbortControllerEntryAbortable -> abortChatRunById (chat-abort.ts:488,516) over real createChatRunState()

Declared simplifications: minimal FollowupRun literal; broadcast/nodeSendToSession captured in arrays; no SQLite session store (blocked on this Node by the repo's own WAL guard, node-sqlite.ts:81); no real model turn — "delivery" is the operation's real lifecycle (freezeAbort → complete), exactly the span the bug desynchronizes from the chat run.

Run 1 — pre-fix (the three touched source files reverted to upstream/main for the run, restored after):

[+0.033s] probe     post-freeze isReplyRunAbortableForSignal(raw)=true isReplyRunAbortableForSignal(composed)=false
[+0.048s] gate      isChatAbortControllerEntryAbortable(entry)=true
[+0.050s] abort     abortChatRunById -> {"aborted":true} abortBroadcasts=1 rawSignal.aborted=true
[+0.050s] abort     broadcast "chat" payload.state=aborted stopReason=rpc partialMessage=included
[+0.064s] operation after chat.abort: operation.result=null operation.abortSignal.aborted=false phase=queued
[+0.065s] delivery  final delivery settled AFTER the chat.abort attempt: operation.result=completed

Bug reproduced end to end: the composite answers correctly (composed=false), but the gate asks with the raw signal — unregistered on main — so it misses and returns true; the gateway marks the run aborted and broadcasts it (partial draft included) while the frozen operation keeps going and completes delivery afterwards.

Run 2 — post-fix (this head f1f170a8839):

[+0.031s] probe     post-freeze isReplyRunAbortableForSignal(raw)=false isReplyRunAbortableForSignal(composed)=false
[+0.042s] gate      isChatAbortControllerEntryAbortable(entry)=false
[+0.043s] abort     abortChatRunById -> {"aborted":false} abortBroadcasts=0 rawSignal.aborted=false
[+0.057s] operation after chat.abort: operation.result=null operation.abortSignal.aborted=false phase=queued
[+0.058s] delivery  final delivery settled AFTER the chat.abort attempt: operation.result=completed

Fix verified: both identities agree, the gate closes, no abort broadcast, no controller abort, and finalization completes delivery intact.

Run 3 — post-fix control (live, non-frozen operation):

[+0.103s] gate      isChatAbortControllerEntryAbortable(entry)=true
[+0.106s] abort     abortChatRunById -> {"aborted":true} abortBroadcasts=1 rawSignal.aborted=true
[+0.118s] operation after chat.abort: operation.result={"kind":"aborted","code":"aborted_by_user"} operation.abortSignal.aborted=true phase=aborted

Control verified: a genuinely abortable run still aborts through the composite (aborted_by_user, own signal aborted) — the fix does not over-block.

Unit coverage and local gates

New regression test in reply-run-registry.test.ts mirroring the admission path (AbortSignal.any composite as the registry key, gate asking with the raw signal):

  • Red (before the fix): AssertionError: expected true to be false at isReplyRunAbortableForSignal(upstreamAbort.signal) (51/52 passing, only the new test failing).
  • Green (after the fix): 52/52.

Verification:

  • vitest run (area): reply-run-registry 52/52 ✅ · followup-turn-admission 36/36 ✅ · chat-abort 126/126 ✅
  • reply-turn-admission.test.ts: 27 failures also present on clean main on this machine — the repo's SQLite runtime guard rejects Node 24.14.1's embedded SQLite 3.51.2 (node-sqlite.ts:81); verified identical via git stash. Unrelated to this diff.
  • oxlint: 0 errors ✅ · oxfmt --check ✅ · tsgo -p tsconfig.core.json ✅

AI-assisted: the defect was found and the fix drafted with AI assistance; every link of the causal chain above was opened and verified against main (38a5d39b), and both the red→green unit cycle and the three harness runs were executed locally (and re-executed by the author) before this update. I understand the change and stand by it.

…ity lookups

The chat.abort gate asks isReplyRunAbortableForSignal with the raw
controller signal (chat-send-admission.ts:287), but followup admission
registers the operation under a fresh AbortSignal.any() composite
(followup-turn-admission.ts:152 -> queue/types.ts:219 ->
reply-run-registry.ts:1059). The WeakMap lookup misses by identity and
returns true (abortable) even when the operation is frozen/finalizing,
so chat.abort reports {aborted: true} while delivery continues.

Register the composite's source signals as aliases of the same
operation; the abort listener stays on the composite, so cancellation
semantics are unchanged.

Refs openclaw#118028.
@chatgpt-codex-connector

Copy link
Copy Markdown
Contributor

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@openclaw-barnacle openclaw-barnacle Bot added size: XS triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Aug 2, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Aug 2, 2026
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. labels Aug 2, 2026
@clawsweeper

clawsweeper Bot commented Aug 2, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 2, 2026, 2:01 PM ET / 18:01 UTC.

ClawSweeper review

What this changes

This PR registers the raw cancellation signals behind a queued follow-up’s composed abort signal as aliases of the same reply operation, allowing Gateway abort checks to respect finalizing delivery.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

No blocking correctness or security finding surfaced. Current main still keys reply abortability by the exact upstream signal, while queued follow-ups create a fresh composed signal; this PR narrowly registers the two source signals at the owner boundary so the Gateway abort gate sees the same operation. The updated PR body now supplies a pre-fix, post-fix, and abortable-control runtime transcript, so it is no longer blocked on the earlier proof request.

Priority: P2
Reviewed head: f1f170a883998261d05c5498e0fca0f098c279d4

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch is focused, source-backed, and now has convincing after-fix runtime evidence; ordinary exact-head merge gating remains.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The updated PR body provides a redacted terminal-style loopback transcript for the real admission, registry, Gateway abort, and delivery lifecycle, including pre-fix, post-fix, and still-abortable control runs.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The updated PR body provides a redacted terminal-style loopback transcript for the real admission, registry, Gateway abort, and delivery lifecycle, including pre-fix, post-fix, and still-abortable control runs.
Evidence reviewed 5 items Current-main identity mismatch: Current main stores one reply operation under upstreamAbortSignal and returns abortable on a missing signal key, while the Gateway gate queries with its raw controller signal.
Composed queued-follow-up signal: Queued follow-up admission resolves both the source abort signal and the queue signal through AbortSignal.any, which creates the distinct identity that the current registry cannot look up.
Patch follows the owner boundary: The proposed change passes the two known composition sources from follow-up admission through reply-turn admission and registers them with the same operation without changing the composite signal’s abort listener.
Findings None None.
Security None None.

How this fits together

Queued follow-up admission combines the original chat-run signal with a queue-lifecycle signal before creating a reply operation. Later, the Gateway’s chat.abort command queries abortability with the raw chat-run signal; the reply registry determines whether to broadcast an abort or let protected delivery finish.

flowchart LR
  A[Chat send controller] --> B[Queued follow-up]
  Q[Queue lifecycle controller] --> B
  B --> C[Composed cancellation signal]
  C --> D[Reply operation registry]
  A --> E[Gateway abort gate]
  E --> D
  D --> F[Abortability result]
  F --> G[Abort broadcast or final delivery]
Loading

Before merge

  • Resolve merge risk (P1) - The branch is behind current main, although the provided GitHub state reports it cleanly mergeable; use the normal exact-head merge gate rather than treating base drift as a code regression.
  • Complete next step (P2) - No mechanical repair is indicated; this PR needs ordinary maintainer review and exact-head merge gating rather than a ClawSweeper repair job.
Agent review details

Security

None.

PR surface

Source +18, Tests +24. Total +42 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 3 18 0 +18
Tests 1 24 0 +24
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 42 0 +42

Review metrics

None.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Keep the reply registry as the single owner of signal-to-operation identity, register only the known queued-follow-up source signals there, and land after normal exact-head checks confirm the clean merge result.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Keep the reply registry as the single owner of signal-to-operation identity, register only the known queued-follow-up source signals there, and land after normal exact-head checks confirm the clean merge result.

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

Yes: current-main source establishes the mismatch between a fresh queued-follow-up composite and the raw signal used by the Gateway abort gate, and the PR supplies a focused regression plus a claimed before/after runtime chain.

Is this the best way to solve the issue?

Yes: aliasing the two sources at the only admission point that knows both source identities and the created operation is narrower than adding Gateway-specific fallback logic or changing cancellation semantics.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. The updated PR body provides a redacted terminal-style loopback transcript for the real admission, registry, Gateway abort, and delivery lifecycle, including pre-fix, post-fix, and still-abortable control runs.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The updated PR body provides a redacted terminal-style loopback transcript for the real admission, registry, Gateway abort, and delivery lifecycle, including pre-fix, post-fix, and still-abortable control runs.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: 📣 needs proof: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: The patch repairs a bounded but user-visible inconsistency where chat.abort can report an aborted run while protected reply delivery completes.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The updated PR body provides a redacted terminal-style loopback transcript for the real admission, registry, Gateway abort, and delivery lifecycle, including pre-fix, post-fix, and still-abortable control runs.
  • proof: sufficient: Contributor real behavior proof is sufficient. The updated PR body provides a redacted terminal-style loopback transcript for the real admission, registry, Gateway abort, and delivery lifecycle, including pre-fix, post-fix, and still-abortable control runs.

Evidence

What I checked:

  • Current-main identity mismatch: Current main stores one reply operation under upstreamAbortSignal and returns abortable on a missing signal key, while the Gateway gate queries with its raw controller signal. (src/auto-reply/reply/reply-run-registry.ts:398, eef59b572b8f)
  • Composed queued-follow-up signal: Queued follow-up admission resolves both the source abort signal and the queue signal through AbortSignal.any, which creates the distinct identity that the current registry cannot look up. (src/auto-reply/reply/queue/types.ts:213, eef59b572b8f)
  • Patch follows the owner boundary: The proposed change passes the two known composition sources from follow-up admission through reply-turn admission and registers them with the same operation without changing the composite signal’s abort listener. (src/auto-reply/reply/reply-run-registry.ts:1058, f1f170a88399)
  • Regression coverage and real-behavior proof: The patch adds a composed-signal regression case; the updated PR body also records a pre-fix false abort, a post-fix protected finalization, and a control where a genuinely abortable operation still cancels. (src/auto-reply/reply/reply-run-registry.test.ts:891, f1f170a88399)
  • Current-main and provenance check: The PR head is not an ancestor of current main, whereas its base is; no local release tag contains the PR head. git blame attributes the current lookup lines to the recent reply-registry integration, but older promisor history could not be fully materialized because network access was unavailable. (src/auto-reply/reply/reply-run-registry.ts:368, bd486b670a03)

Likely related people:

  • SunnyShu: git blame attributes the current signal-keyed registry and abortability lookup lines to this recent integration commit; deeper feature provenance was limited by unavailable promisor objects. (role: current-line attribution; confidence: low; commits: bd486b670a03; files: src/auto-reply/reply/reply-run-registry.ts)

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-02T17:20:37.886Z sha f1f170a :: needs real behavior proof before merge. :: none

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. 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. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 2, 2026
@vincentkoc vincentkoc self-assigned this Aug 2, 2026
@vincentkoc

Copy link
Copy Markdown
Member

Closing without landing because the patch repairs a real signal-identity mismatch at a lookup the production chat.abort route does not use for queued runs.

On current main, exact-run abort loses the active controller after chat.send terminalizes, then finds the still-registered entry in chatQueuedTurns and calls abortQueuedChatTurnById directly. That path bypasses isReplyRunAbortableForSignal, so registering aliases in the reply registry does not protect finalizing delivery. The focused test invokes the helper directly and therefore misses the actual RPC dispatcher. Collect and overflow ownership also compose another signal not covered by these aliases.

The canonical fix belongs at queued cancellation retirement: retire Gateway cancellation ownership through the existing onCancellationRetired lifecycle when execution freezes, with coverage for individual followups, collect/overflow, execution-started failures, and active/queued overlap. That is broader lifecycle work and should remain tracked in #118028, not be approximated by this PR.

Thanks for isolating the identity mismatch. No code from this PR was landed.

@vincentkoc vincentkoc closed this Aug 2, 2026
@pacocartones

Copy link
Copy Markdown
Contributor Author

Understood — thank you for the precise read. I re-verified it against the dispatcher: for a queued runId the handler takes the queued fork and calls abortQueuedChatTurnById directly (chat-abort-handler.ts:241), which consults the entry's own abortable flag and never reaches isReplyRunAbortableForSignal; its controller.abort() still propagates to the operation through the composite's listener (reply-run-registry.ts:1082). So the alias registration repairs a lookup the queued path indeed never asks, and my harness drove the helper rather than the dispatcher fork — fair correction.

Agreed the canonical fix is at queued cancellation retirement (onCancellationRetired when execution freezes, including collect/overflow ownership and the active/queued overlap). I'll fold this clarification into #118028 so the tracking stays accurate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XS 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