Skip to content

fix(gateway): prevent interrupt failures from blocking session lifecycle - #126546

Merged
steipete merged 3 commits into
openclaw:mainfrom
NianJiuZst:codex/fix-chat-interrupt-admission-cleanup
Aug 25, 2026
Merged

steipete merged 3 commits into
openclaw:mainfrom
NianJiuZst:codex/fix-chat-interrupt-admission-cleanup

Conversation

@NianJiuZst

@NianJiuZst NianJiuZst commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

An interrupting chat.send could leave a hidden session-work admission and abort registration behind when either an existing reply backend or another active session admission threw during cancellation. Subsequent session reset, archive, and deletion could hang behind that leaked ownership, and Gateway shutdown could remain blocked until its drain timeout.

Why This Change Was Made

admitChatSend acquires its new session admission and abort registration before invoking either direct reply cancellation or identity-scoped session-work interruption. Both interruption contracts may throw, but the previous owner did not clean up those resources on either exception path.

The admission owner now has one canonical pre-dispatch cleanup path for its abort registration, session admission, and optional Gateway-root continuation. Direct interruption, fallback interruption, an unsettled predecessor, and rejected or throwing admission-owner callbacks all release the same resources before returning or propagating their original error. This replaces duplicated cleanup branches and removes five production lines overall.

User Impact

Cancellation failures still surface to the operator, but normal session lifecycle actions and Gateway drain recover immediately. Successful sends, ordinary interruptions, and retained post-admission request ownership keep their existing behavior.

Evidence

  • Exact reviewed head: e234b446817dca6b8686cc718bcb493d960811a4.

  • Both new owner-boundary regressions were first run against the unchanged current-main implementation and failed: direct reply cancellation left one active session admission, and identity-scoped fallback interruption left a second leaked admission.

  • Both then passed through the real in-process Gateway and authenticated WebSocket chat.send flow. Each independently verifies the session-admission and Gateway-root counts return to zero, then successfully performs a real sessions.reset RPC.

  • Full focused owner and sibling verification:

    node scripts/run-vitest.mjs \
      src/gateway/server.chat.gateway-server-chat.test.ts \
      src/gateway/server.sessions.worker-placement-lifecycle.test.ts \
      src/sessions/session-lifecycle-admission.test.ts \
      src/auto-reply/reply/reply-run-registry.test.ts \
      --reporter=dot

    Result: 206 tests passed across Gateway chat, cloud-worker session lifecycle, session admission, and reply-run cancellation.

  • Targeted formatting, core lint, and git diff --check passed.

  • Fresh independent structured review completed with no actionable findings.

  • Production LOC: +52/-57 (net -5); tests: +86/-1.

  • No external provider or cloud lease is required for this Gateway-owned failure; the live product proof is the actual Gateway/WebSocket/session lifecycle with a deliberately failing cancellation backend.

Original fix and regression by @NianJiuZst; contributor authorship and co-author credit are preserved.

AI-assisted: yes

@clawsweeper

clawsweeper Bot commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: S labels Aug 20, 2026
@NianJiuZst
NianJiuZst marked this pull request as ready for review August 20, 2026 05:28
@clawsweeper

clawsweeper Bot commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed August 23, 2026, 7:13 PM ET / 23:13 UTC.

ClawSweeper review

What this changes

The PR ensures an interrupting Gateway chat request releases its abort registration and session-work admission when cancellation of the active reply throws.

Regression provenance

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

Merge readiness

⛔ Blocked until real behavior proof from a real setup is added - 5 items remain

No blocking code finding: the patch releases the admission at the owner boundary before dispatch can take custody. This PR remains necessary because current main still lets a throwing reply-backend cancellation bypass that cleanup; merge is blocked on real after-fix behavior proof and fresh exact-head CI.

Priority: P2
Reviewed head: e3c56aafe2970eebf7bed9fa0be73718f00cbc55

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The owner-boundary repair and regression test are sound, but mock-only validation does not yet meet the real-behavior proof gate.
Proof confidence 🦪 silver shellfish (2/6) Needs real behavior proof before merge: The PR reports a passing focused Gateway test, but its throwing reply backend is injected by a mock; add a redacted after-fix Gateway request/response or lifecycle-recovery trace, with private endpoints and identifiers removed. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Needs proof Needs real behavior proof before merge: The PR reports a passing focused Gateway test, but its throwing reply backend is injected by a mock; add a redacted after-fix Gateway request/response or lifecycle-recovery trace, with private endpoints and identifiers removed. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed 6 items Current-main failure boundary: Current main awaits reply interruption without an exception boundary; only the non-settled return path releases the newly acquired abort registration and session-work admission.
Cancellation can throw: The reply-operation abort path calls the attached backend cancel function in a finally-only block, so a thrown cancellation propagates to the admission caller after reply-state cleanup.
Caller cannot perform downstream cleanup: The setup helper awaits admission before returning an admitted value, while the later setup-error owner only exists after that value has been created; a throw during interruption therefore needs cleanup inside admission itself.
Findings None None.
Security None None.

Live Verification

Command: node scripts/run-vitest.mjs src/gateway/server.chat.gateway-server-chat.test.ts --reporter=dot

Result: FAIL (partial) — step 2 expect_output chat.send interrupt releases its admission when backend cancellation throws: expected terminal output was not visible within 30 seconds: "chat.send interrupt releases its admission when backend cancellation throws"

node scripts/run-vitest.mjs src/gateway/server.chat.gateway-server-chat.test.ts --reporter=dot
runner@runnervm76f27:/tmp/clawsweeper-live-proof-126546-iyRCXs/target$ node scripts/run-vitest.mjs src/gateway/server.chat.gateway-server-chat.test.ts --reporte
r=dot
node scripts/run-vitest.mjs src/gateway/server.chat.gateway-server-chat.test.ts --reporter=dot
[test] starting test/vitest/vitest.gateway.config.ts

 RUN  v4.1.10 /tmp/clawsweeper-live-proof-126546-iyRCXs/target

[vitest] still running with no output for 30000ms (test/vitest/vitest.gateway.config.ts).










































Assertions:

  • FAIL expect_output: chat.send interrupt releases its admission when backend cancellation throws

How this fits together

Gateway chat sends reserve session lifecycle ownership and an abort handle before interrupting an active reply. That pre-dispatch phase must either transfer ownership to dispatch or release it, so later reset, archive, delete, and gateway-drain work are not blocked.

flowchart LR
  Request[Gateway chat request] --> Admission[Reserve session work]
  Admission --> Abort[Register abort handle]
  Abort --> Interrupt[Interrupt active reply]
  Interrupt --> Decision{Cancellation fails?}
  Decision -->|Yes| Cleanup[Release both owners]
  Decision -->|No| Dispatch[Transfer to chat dispatch]
  Cleanup --> Lifecycle[Session lifecycle remains available]
  Dispatch --> Lifecycle
Loading

Before merge

  • Add real behavior proof - Needs real behavior proof before merge: The PR reports a passing focused Gateway test, but its throwing reply backend is injected by a mock; add a redacted after-fix Gateway request/response or lifecycle-recovery trace, with private endpoints and identifiers removed. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Resolve merge risk (P1) - The supplied validation is an automated Gateway test with an injected mock backend; it does not yet provide an inspectable after-fix request/response or lifecycle-recovery trace.
  • Resolve merge risk (P1) - The branch is behind current main and the reported CI gate is failing, so exact-head merge validation remains required even though GitHub reports the PR cleanly mergeable.
  • Resolve merge risk (P1) - Production is net +8 lines; the shared cleanup and exception boundary appear justified, but the refreshed head should retain that single owner rather than reintroducing duplicated releases.
  • Complete next step (P2) - The patch has no identified mechanical defect; the remaining blocker is contributor-owned real behavior proof and normal exact-head validation, not a repair-lane task.
Agent review details

Security

None.

PR surface

Source +8, Tests +45. Total +53 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 38 30 +8
Tests 1 46 1 +45
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 84 31 +53

Review metrics

Metric Value Why it matters
Production versus test LOC production +38/-30 (net +8); tests +46/-1 (net +45) The production growth centralizes three paired-release exits and adds the missing exception boundary; the regression coverage is concentrated in the Gateway chat flow.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Keep the pre-dispatch cleanup at the admission owner, then attach a redacted Gateway trace showing the thrown interrupt error followed by a successful lifecycle operation or zero active admission, and obtain green exact-head CI.
  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 pre-dispatch cleanup at the admission owner, then attach a redacted Gateway trace showing the thrown interrupt error followed by a successful lifecycle operation or zero active admission, and obtain green exact-head CI.

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

Yes, from source: attach a reply backend whose cancellation throws, issue an interrupting chat request, and observe that current main bypasses the only pre-dispatch release path. The branch's focused Gateway test encodes this path but was not executed in this read-only review.

Is this the best way to solve the issue?

Yes: cleanup belongs in admission because the setup caller has no admitted object when interruption throws. A downstream catch would not reliably own the newly registered abort handle or session admission.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: A bounded interrupt failure can leave a session lifecycle operation waiting, but the report does not establish a broad current-user outage.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The PR reports a passing focused Gateway test, but its throwing reply backend is injected by a mock; add a redacted after-fix Gateway request/response or lifecycle-recovery trace, with private endpoints and identifiers removed. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Current-main blame attributes the implicated admission block to a recent Gateway-area commit, and history shows the strongest concentration of work across the admission and reply-runtime files. (role: recent gateway and reply-runtime contributor; confidence: high; commits: 7c7e10ab853e; files: src/gateway/server-methods/chat-send-admission.ts, src/auto-reply/reply/reply-run-registry.operation.ts)
  • Vincent Koc: Authored the earlier reply-cleanup change for throwing cancellation paths, a directly adjacent invariant. (role: adjacent cancellation-cleanup contributor; confidence: medium; commits: f30e67298a59; files: src/auto-reply/reply/reply-run-registry.operation.ts)

Rank-up moves

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

  • Add a redacted trace that shows the interrupt error and then confirms the same session can reset, archive, delete, or has no active admission.
  • Refresh the branch against current main and provide green exact-head CI; update the PR body so ClawSweeper can re-review automatically.

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-08-20T05:26:50.081Z sha e3c56aafe2970eebf7bed9fa0be73718f00cbc55 :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-20T06:08:53.584Z sha e3c56aafe2970eebf7bed9fa0be73718f00cbc55 :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-22T19:15:41.044Z sha e3c56aafe2970eebf7bed9fa0be73718f00cbc55 :: needs real behavior proof before merge. :: none

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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. clawsweeper-recovery-stuck and removed clawsweeper-recovery-stuck labels Aug 20, 2026
@steipete
steipete force-pushed the codex/fix-chat-interrupt-admission-cleanup branch from e3c56aa to 0786ac9 Compare August 25, 2026 10:02
@steipete
steipete merged commit f830b8c into openclaw:main Aug 25, 2026
455 of 457 checks passed
@steipete

Copy link
Copy Markdown
Contributor

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 26, 2026
…cle (openclaw#126546)

* fix(gateway): release interrupted chat admission

* fix(gateway): unify interrupted chat admission cleanup

Co-authored-by: NianJiuZst <[email protected]>

* chore(gateway): leave changelog to release generation

---------

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

Labels

gateway Gateway runtime P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: S status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants