Repository navigation
fix: recover terminal session status on visible inbound turns - #89045
Conversation
|
Codex review: needs maintainer review before merge. Reviewed June 28, 2026, 6:22 PM ET / 22:22 UTC. Summary PR surface: Source +176, Tests +588. Total +764 across 12 files. Reproducibility: yes. The linked issue includes live Octo evidence, current main source still reuses terminal session state and busy admission paths, and the PR body provides before/after production-module driver output; I did not run a fresh live transport repro in this read-only pass. Review metrics: 1 noteworthy metric.
Stored data model Root-cause cluster Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Mantis proof suggestion Risk before merge
Maintainer options:
Next step before merge
Security Review detailsBest possible solution: Land or replace the shared core recovery policy after maintainers accept in-place terminal-session recovery semantics and decide whether transport-level proof is required. Do we have a high-confidence way to reproduce the issue? Yes. The linked issue includes live Octo evidence, current main source still reuses terminal session state and busy admission paths, and the PR body provides before/after production-module driver output; I did not run a fresh live transport repro in this read-only pass. Is this the best way to solve the issue? Yes as an implementation direction, pending maintainer policy acceptance. The patch fixes shared session and reply-operation paths rather than adding a channel-specific workaround; rotation or visible-error behavior remains the policy alternative. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against a54206f0f5d1. Label changesLabel justifications:
Evidence reviewedPR surface: Source +176, Tests +588. Total +764 across 12 files. View PR surface stats
What I checked:
Likely related people:
What the crustacean ranks mean
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. How this review workflow works
|
6503187 to
3fa658b
Compare
|
Rebased on latest upstream/main (965e680, clean rebase, no conflicts). |
3fa658b to
9c8ec76
Compare
|
Rebased on latest upstream/main (646df2d, clean rebase, no conflicts). |
9c8ec76 to
03149fb
Compare
|
Rebased on latest upstream/main (8a9acd2, clean rebase, no conflicts). |
03149fb to
68668af
Compare
|
Rebased on latest upstream/main (57ea5af, clean rebase, no conflicts). |
68668af to
fd71257
Compare
|
Rebased on latest upstream/main (ffbd02f, clean rebase, no conflicts). |
fd71257 to
ac79b73
Compare
|
Rebased on latest upstream/main (85d2dd8). Resolved import conflict in |
Real behavior proof
|
b2b7996 to
bc38886
Compare
|
Rebased onto the latest upstream/main and pushed (new head 1a6fa03a3d, clean rebase, 8 commits replayed, no conflicts). Requesting a fresh review against the current head. @clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
|
Rebased onto the latest upstream/main and pushed (new head 2af8d39400, clean rebase, 8 commits replayed, no conflicts). Requesting a fresh review against the current head. @clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
|
Rebased onto the latest upstream/main and pushed (new head 415c3d4302, clean rebase, 8 commits replayed, no conflicts). Requesting a fresh review against the current head. @clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
|
@clawsweeper re-review Rebased onto the latest upstream/main and pushed (new head 1baf08131c, clean rebase, 8 commits replayed, no conflicts). Requesting a fresh review against the current head. |
|
🦞🧹 I asked ClawSweeper to review this item again. |
|
@clawsweeper re-review Rebased onto the latest upstream/main and pushed (new head 5e3547e4e0, clean rebase, 8 commits replayed, no conflicts). Requesting a fresh review against the current head. |
|
🦞🧹 I asked ClawSweeper to review this item again. |
|
@clawsweeper re-review Rebased onto the latest upstream/main and pushed (new head d9fc37ec47, clean rebase, 8 commits replayed, no conflicts). Requesting a fresh review against the current head. |
|
🦞🧹 I asked ClawSweeper to review this item again. |
|
@clawsweeper re-review Rebased onto the latest upstream/main and pushed (new head cc73d465cd, clean rebase, 8 commits replayed, no conflicts). Requesting a fresh review against the current head. |
|
🦞🧹 I asked ClawSweeper to review this item again. |
|
@clawsweeper re-review Rebased onto the latest upstream/main and pushed (new head 66942e3d7d, clean rebase, 8 commits replayed, no conflicts). Requesting a fresh review against the current head. |
|
🦞🧹 I asked ClawSweeper to review this item again. |
…aw#86827) When a group chat session enters a terminal status (failed/timeout/killed), subsequent visible inbound messages now automatically recover the session by clearing stale lifecycle fields while preserving the session ID and transcript continuity. Changes: - session.ts: detect terminal status on visible turns and clear status/ startedAt/endedAt/runtimeMs/abortedLastRun without rotating sessionId - dispatch-from-config.ts: force-clear stale active reply operations for terminal sessions and retry admission once - agent.ts: mirror terminal recovery in the agent API dispatch path - kernel.ts: add zero-count visible dispatch warning diagnostic - types.ts: add 'warning' to ChannelTurnLogEvent event union
When two visible messages arrive against the same terminal session snapshot, the second turn could force-fail the first turn's freshly admitted recovery operation, dropping the very message the recovery path exists to save. Add a terminalRecovery flag on ReplyOperation that is set after a recovery turn clears the proven stale leftover and admits its own operation. The force-clear branch now skips operations marked as in-flight terminal recoveries, letting concurrent turns fall through to normal busy/wait handling instead. Add a two-turn regression test that gates the first recovery turn open, races a second visible turn against the same terminal snapshot, and asserts neither turn's operation is incorrectly killed. Also fix missing FinalizedMsgContext import in kernel.ts.
A heartbeat/control turn can pass the early active-run short-circuit, reach the terminal force-clear branch, and abort an in-flight visible recovery operation that a concurrent visible turn just admitted (before that op is marked terminalRecovery). Gate the force-clear to visible reply turns so non-visible turns fall through to normal busy/skip handling instead of killing the recovery they are meant to protect. Adds a focused regression test exercising a heartbeat turn that reaches the force-clear branch against a terminal session snapshot with an active recovery operation present; it must leave that operation intact and skip.
…ble turn The same-session terminal-recovery race could still drop a reply when two visible turns raced the same failed snapshot. The terminalRecovery marker was set only on the post-force-clear re-admission path, never on the clean no-stale admission path. So when the first turn admitted cleanly (no stale op to clear), its recovery op stayed terminalRecovery=false and a second concurrent visible turn force-cleared it, dropping the first reply (openclaw#86827). Consolidate marking to the single owned-admission choke point that both the clean no-stale admission and the re-admission-after-force-clear flow through. Genuine stale leftovers from the original failed run never pass through this admission, so they stay unmarked and remain force-clearable. Add a no-stale regression twin to the existing stale-race test.
…ry turns maybeWarnZeroCountVisibleDispatch re-implemented a partial visibility check that omitted observedReplyDelivery, so visible turns delivered via the observed-delivery path (queuedFinal=false, zero counts, observedReplyDelivery=true) falsely tripped the silent-drop sentinel and emitted a bogus zero-count-visible-dispatch warning/event. Use the canonical hasVisibleChannelTurnDispatch helper for the warning suppression so all non-count delivery paths (observedReplyDelivery, fallback, summary, queuedFinal) are honored. Add regression tests covering the observed-delivery case (no warning) and a genuinely empty visible dispatch (still warns).
|
Rebased onto latest upstream/main (a54206f) — clean replay of 8 commits, no conflicts, no diff changes. New head c0b56f9. @clawsweeper re-review |
Summary
Fixes #86827 — group chat sessions stuck in
failedstatus silently drop all subsequent messages.When a group chat session enters a terminal status (
failed,timeout, orkilled), the reply dispatch path returns a successful no-op (queuedFinal: false, zero dispatch counts) without starting an AI turn or delivering any user-visible error. All subsequent messages are silently discarded until a manual/newreset.Root Cause
Three independent mechanisms conspire to create the silent drop:
initSessionState()reuses the existing session entry with its terminalstatusfield intact, passing it downstream unchanged.ReplyOperationfrom the failed run remains registered inreplyRunRegistry, causingadmitReplyTurn()to returnskippedwith reasonactive-run.skippedadmission produces a valid dispatch result with zero counts, and no warning is logged — the message simply vanishes.Changes
1. Auto-recover terminal sessions (
session.ts)When a visible (non-cron/heartbeat) inbound message hits a session with recoverable terminal status, automatically clear the stale lifecycle fields (
status,startedAt,endedAt,runtimeMs,abortedLastRun) while preserving thesessionIdand transcript continuity — no session rotation.2. Clear stale reply operations with race guard (
dispatch-from-config.ts)When
admitReplyTurn()returnsskippedwith reasonactive-runbut the persisted session is in terminal status, force-clear the stale reply operation viaforceClearReplyRunBySessionId()and retry admission once. This breaks the deadlock without risking infinite retry loops.Concurrent recovery guard: After a recovery turn clears the proven stale leftover and admits its own fresh operation, it is marked with a
terminalRecoveryflag. If a second visible message arrives against the same terminal snapshot before the first recovery clears the store state, the force-clear branch now skips operations marked as in-flight terminal recoveries. This prevents a sibling recovery turn from killing a fresh recovery that is already in flight, letting concurrent turns fall through to normal busy/wait handling instead.3. Agent API path (
agent.ts)Mirror the same terminal recovery logic in the agent API dispatch path so agent API requests also clear terminal state for visible requests.
4. Diagnostics (
kernel.ts,types.ts)Add a structured warning log when a visible channel turn dispatch completes with
queuedFinal: falseand zero tool/block/final counts — a sentinel for future silent message drops. Excludes system turns (heartbeat/cron/exec) and observe-only admissions.Real behavior proof
Captured by driving the real runtime modules (
dispatchReplyFromConfig,initSessionState,reply-run-registry) with verbose logging on, no vitest and no module mocks — only the production parameters the Gateway supplies plus a real on-disk JSON session store. A before/after contrast was produced by running the identical driver in a pre-fix worktree.failed/timeout/killed) silently drops every later message — the stale lifecycle entry plus a leftover "active" reply operation block turn admission, so a subsequent visible inbound message gets no AI turn and no reply (Group chat session stuck in 'failed' state silently drops all subsequent messages #86827).ac52eb0b24; macOS 15.3.1 (Darwin 24.3.0, arm64), Nodev24.10.0. Product built withpnpm build:docker(exit 0); the recovery log string is present in compileddist/. Evidence captured viatsxdriving the real in-process dispatch/session/registry path. Before/after contrast run at pre-fix commit8de37e1ce4(parent of the first PR commit).8de37e1ce4, identical driver + input): realdispatchReplyFromConfig()for a visible group turn on astatus="failed"session with a stale running reply op —initSessionState()against an on-disk store:RESULT: STILL-TERMINAL — session entry remains status=failed after a visible inbound turn.failedgroup entry, registers a real stale running reply operation, then calls the realdispatchReplyFromConfig()for a visible inbound group message.ac52eb0b24): copied live console output from running the real in-process drivernode_modules/.bin/tsx ./_dispatch_driver.mts(drives the productiondispatchReplyFromConfig()); redacted runtime log:initSessionState -> isNewSession=false sessionId=<same> abortedLastRun=false, andAFTER turn -> status=undefined ... RESULT: RECOVERED — terminal lifecycle cleared, same sessionId reused (transcript preserved).isActive=false), (3) produces a real queued reply (queuedFinal:true, counts.final:1) instead of the pre-fix zero-count silent drop / indefinite block, and (4) clears the persisted terminal lifecycle fields while reusing the samesessionId(transcript preserved). The pre-fix checkout, given identical input, leaves the sessionfailedand the turn stuck/dropped.pnpm install --frozen-lockfilelayer due to transient npm-registry CDN errors fetching optional native packages (network, not OOM and not code), so no end-to-end live channel socket round-trip was performed; the proof drives the real in-process dispatch/session/registry runtime that a channel turn funnels into. Theagent.tsGateway RPC path and thekernel.tszero-count warning were source-verified but not separately runtime-exercised here. Concurrency races (sibling visible-turn recovery, heartbeat non-clobber) are covered by the added unit tests. Architecture: arm64 (macOS) only; CI truth is Linux x64 Node 24.Tests
ReplyOperationstubs with newterminalRecoveryfield andmarkTerminalRecoverymethodAll focused tests pass across 2 Vitest shards (512 cases).