Repository navigation
fix(agents): CLI-backed agents stop replying when a long turn trips stuck-session recovery - #137372
anandnsharma wants to merge 7 commits into
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs real behavior proof before merge. Reviewed September 4, 2026, 7:17 AM ET / 11:17 UTC. ClawSweeper reviewWhat this changesThe branch shares stream-progress reporting between model backends, propagates CLI quiet allowances into stuck-session recovery, and preserves replies while their delivery finalizes. Merge readiness⛔ Blocked before merge - 6 items remain Keep open: the prior P1 remains because the CLI quiet allowance is published only after first stdout, leaving a silent child eligible for the generic watchdog abort. The supplied real-gateway logs prove streamed liveness, but not post-recovery channel delivery for the new committed-outcome guard. Priority: P1 Review scores
Verification
How this fits togetherCLI-backed agent turns feed output and timeout facts into diagnostic activity; stuck-session recovery uses those facts to decide whether to abort active work. Completed replies then pass through finalization before channel delivery. flowchart LR
A[CLI process] --> B[Diagnostic activity]
B --> C[Stuck-session watchdog]
C --> D[Recovery decision]
D --> E[Reply finalization]
E --> F[Channel delivery]
Before merge
Findings
Agent review detailsSecurityNone. PR surfaceSource +99, Tests +308, Other 0. Total +407 across 21 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Register the resolved CLI quiet allowance at process activation through a path that does not refresh stream progress, cover a silent child beyond the generic floor, and prove that recovery preserves and delivers a committed reply. Do we have a high-confidence way to reproduce the issue? Yes: the source establishes that a configured allowance cannot exist before stdout, while watchdog recovery can run during that interval; the submitted gateway logs independently demonstrate the streaming portion. Is this the best way to solve the issue? No: shared stream reporting is appropriate, but timeout publication must be decoupled from first output so the configured allowance also protects a silent startup. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 191e3da816c6. LabelsLabel justifications:
EvidenceAcceptance criteria:
What I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (10 earlier review cycles; latest 8 shown)
|
|
Thanks — the P1 caught a real defect in my test, and I've fixed that. I do want to push back on part of the conclusion, with evidence. Where the finding is correctThe deadline test drove Fixed in Where I read it differently
The gate is A CLI-backed turn does not run through that attempt path — it dispatches via Direct check — register an embedded run the way the CLI route does, emit the real ownerless start, read the snapshot: The originating incident agrees: its The residual gap, now pinnedThere is a narrower version of the concern, and I had not covered it either. When an owner-bound attempt (direct provider or compaction) holds the same session activity, an ownerless CLI deadline is suppressed and the generic floor still governs:
Real behavior proofUnderstood and in progress; I'll update the PR body when I have it. Unrelated CI failure
|
9c3dac3 to
e8c27be
Compare
A CLI-backed agent turn that ran longer than ~6 minutes could be killed by stuck-session recovery while it was still streaming, and its completed reply was then never delivered to the channel. Three producer-side gaps, all in how liveness facts reach the watchdog: - The CLI backend counted stdout bytes for its own no-output watchdog but never published them as diagnostic run progress, so the freshness clock only advanced at tool boundaries. The core runtime already publishes per-chunk stream progress; the two implementations are now one shared reporter, and every CLI backend publishes through it. - The CLI backend never published its resolved no-output deadline, so the generic 360s model-call floor preempted a backend allowance the operator had already configured. That deadline now rides `model.call.started` as `requestTimeoutMs` and bounds the generic floor, matching the direct provider path. - Stale-expiry recovery ignored the `freezeAbort()` completion-wins seam that `supersede()` honors, so it could abort a turn whose terminal outcome was already committed and only delivery remained. Recovery now reports `keep_lane / terminal_outcome_committed` and leaves that owner to the existing finalization lease. No new configuration surface: `agents.defaults.timeoutSeconds` and the backend's `reliability.watchdog` settings now govern this path. Claude-Session: https://claude.ai/code/session_0122p4qSQzsjwFgYUCDNrwMK
…he turn Stdout keeps flowing on the CLI protocol stream while a parsed tool is open. Publishing that as model-stream progress would refresh the same clock blocked-tool recovery reads, so a wedged tool could never age into its 15-minute window. Mirror the core sibling, where stream progress is only observed on model response chunks: skip the progress mark while a parsed tool owns the turn. Claude-Session: https://claude.ai/code/session_0122p4qSQzsjwFgYUCDNrwMK
The deadline test drove markDiagnosticModelStartedForTest, which passes coreRequestForTest and bypasses the active-owner gate that ordinary starts hit, so it proved nothing about the production path. Drive the real trusted event instead, and pin the companion case where an owner-bound attempt holds the same session activity and an ownerless deadline is dropped. Claude-Session: https://claude.ai/code/session_0122p4qSQzsjwFgYUCDNrwMK
The no-output deadline rode claude-cli's model-call diagnostics, and that factory returns for every other backend id, so a supported non-Claude CLI backend published no allowance and its configured quiet window could still be preempted by the generic 360s recovery floor. Carry the deadline on the stream-progress update every CLI backend already reports, record it on the session activity, and let both the embedded-run and model-call recovery predicates extend their floor to it. This replaces the claude-cli-only requestTimeoutMs field on model.call.started, so the ownerless start gate no longer gates the allowance either. Claude-Session: https://claude.ai/code/session_01VhcCrpA9PB6VWSWAkFoLgY
The deadline reaches recovery through the shared stream path rather than the Claude-only model-call diagnostics, so pin that at the execution boundary with a backend whose diagnostics helper never arms. Claude-Session: https://claude.ai/code/session_01VhcCrpA9PB6VWSWAkFoLgY
The new CLI diagnostics cases enabled diagnostics process-wide, started run activity tracking, then forced both off at teardown without draining the event queue. The agents-support lane runs `--isolate=false`, so those globals and the listener leaked into every later file in the same worker. Restore the prior enabled value, drain queued events, and reset the event state before handing the worker on. Claude-Session: https://claude.ai/code/session_01VhcCrpA9PB6VWSWAkFoLgY
623d265 to
3d3ee15
Compare
openclaw#138157 removed docs/clawhub/publishing.md because ClawHub pages are authored upstream and mirrored at publish time, but left this scenario referencing the deleted file, so the catalog check fails for any change set that runs the qa-lab config shard. Reference the OpenClaw-owned plugin CLI guide that commit names as the home for this guidance. Claude-Session: https://claude.ai/code/session_01VhcCrpA9PB6VWSWAkFoLgY
|
PR CI Sweeper closed this PR to re-fire a dropped CI run but could not reopen it. Please reopen manually. |
|
Continued in #138280. The PR CI Sweeper closed this PR to re-fire a dropped CI run and could not reopen it. Reopening is refused from both the GraphQL and REST APIs ( Nothing about the change itself was rejected: the ClawSweeper findings addressed here, the reproduce-and-fix gateway evidence, and the review discussion above all carry over to #138280. |
Publish real CLI stream progress and the backend's existing quiet allowance through the exact current diagnostic owner. Release only the settling attempt, reject stale observations after closure or replacement, and keep active-tool recovery independent. Preserve committed replies under the existing bounded finalization lease. Remove the separate session-ref deadline store and share the model stream-progress reporter. Continue the contributor work from #137372. This does not claim to fix the distinct direct-provider issue #137263. Co-authored-by: Anand Sharma <[email protected]> Co-authored-by: Ayaan Zaidi <[email protected]>
Publish real CLI stream progress and the backend's existing quiet allowance through the exact current diagnostic owner. Release only the settling attempt, reject stale observations after closure or replacement, and keep active-tool recovery independent. Preserve committed replies under the existing bounded finalization lease. Remove the separate session-ref deadline store and share the model stream-progress reporter. Continue the contributor work from openclaw#137372. This does not claim to fix the distinct direct-provider issue openclaw#137263. Co-authored-by: Anand Sharma <[email protected]> Co-authored-by: Ayaan Zaidi <[email protected]>
Related: #137263
What Problem This Solves
Fixes an issue where operators running a
claude-cli-backed agent would see theagent silently stop replying in a chat channel when a single turn ran longer than
about six minutes. The turn completes and its answer lands in the session
transcript, but no message is ever delivered to the channel. The only trace is a
WARN line —
visible channel turn dispatched with no queued reply payloads ... cause=skipped:reply_operation_aborted— so from the chat surface the agent justlooks broken, which pushes operators toward resetting the session and throwing
away good history to "fix" a problem that was never in the session.
Reported from a live incident on 2026.8.2: a WhatsApp group agent hit this twice
in ~34 minutes on turns of 406s and 486s.
Why This Change Was Made
The stuck-session watchdog was making a kill decision from facts the CLI backend
never published, and then that kill overruled a turn that had already finished.
Three producer-side gaps, all fixed at the owner:
Stream liveness was never published.
classifySessionAttentionaborts amodel_calloncelastProgressAgeMs >= 360s. The core runtime refreshes thatclock per streamed chunk (
model_call:stream_progress); the CLI backendcounted stdout bytes for its own no-output watchdog but never published them
as run progress, so the clock only advanced at tool boundaries. That is the
lastProgress=tool:Agent:ended lastProgressAge=383ssignature in the incidentlogs: a turn that is actively streaming looks frozen. The duplicated core
implementation and the missing CLI one are now a single shared reporter, wired
at
consumeStdoutso it covers every CLI backend, not justclaude-cli.The backend's own deadline was preempted. For model calls the effective
abort is
max(360s, activeModelCallRequestTimeoutMs). Direct providers publishtheir request timeout there; the CLI backend published nothing, so a hardcoded
360s overruled the no-output allowance the operator had already configured
(~390-480s in the incident, which is why the CLI's own watchdog never fired).
That resolved deadline now rides
model.call.startedasrequestTimeoutMsandbounds the generic floor, matching the direct provider path.
Recovery ignored the existing completion-wins seam.
freezeAbort()marks aturn whose terminal outcome is committed and only delivery/finalization remains;
supersede()honors it, but the stale-expiry path did not, so recovery couldabort a turn that had already produced its reply. Recovery now reports
keep_lane / terminal_outcome_committedand leaves that owner bounded by theexisting finalization lease and terminal-settle timer.
Non-goal: no new configuration surface. The linked report asked for a tunable
stall threshold. This change instead makes the knobs that already exist
authoritative for this path — raise
agents.defaults.timeoutSeconds(or thebackend's
reliability.watchdogsettings) and the stuck-session watchdog followsit. The retired
diagnostics.stuckSessionAbortMskey stays retired.Scope boundary. This is the CLI-backend liveness path. #137263 reports the same
outward symptom on the direct provider path, where
model_call:stream_progressisalready firing and the model call is instead never marked complete — a different
root cause that this PR does not claim to fix.
User Impact
CLI-backed agents no longer go silent on long-but-healthy turns. A turn that keeps
streaming output is no longer treated as stalled, a backend that declares its own
liveness deadline owns recovery timing inside that deadline, and a turn that has
already produced its answer is not killed while the reply is being delivered.
Operators who need a longer allowance raise the existing agent/backend timeout
instead of hitting an undocumented 360s constant, and a retained turn is now
visible as a distinct
keep_lane / terminal_outcome_committedrecovery outcomerather than an indistinguishable abort.
Production diff is +160/-70 (net +90), which buys one canonical stream-progress
reporter replacing two divergent implementations, liveness publication for every
CLI backend, backend-deadline publication, and the recovery guard.
Evidence
Four regression tests, each confirmed to fail on pre-fix code (stashed the
corresponding production file, reran, observed the failure):
src/agents/cli-runner/execute.supervisor-capture.test.ts— "publishes streamed stdout as run progress so a live turn is not reclaimed"src/logging/diagnostic-run-activity.test.ts— "surfaces a non-core backend request timeout in the activity snapshot"activeModelCallRequestTimeoutMssrc/logging/diagnostic.test.ts— "defers stale model call recovery to a longer backend-declared deadline"src/logging/diagnostic-stuck-session-recovery.runtime— "keeps the lane once the turn committed its terminal outcome"Plus
reply-run-registry.test.ts— "reports a committed terminal outcome onlywhile delivery is still finalizing" — pinning the new predicate to the
freezeAbort()→complete()window.Real behavior proof: the bug reproduced and fixed on a live gateway
Isolated gateway profile (own state dir, own port, never the operator's gateway), real
claude-clibackend, same prompt both sides. The only difference issrc/agents/cli-runner/execute-process.tsat the merge base versus this branch.Before — the reported failure, reproduced on demand. A real 380s streaming turn is classified stalled and killed:
The client received
status: "timeout", summary: "aborted", stopReason: "aborted"— 380 seconds of real streamed output, killed at the 360s floor.lastProgressAgetracks the whole turn because nothing on the CLI path refreshes it.After — the same workload crosses the same threshold and is left alone. Runs of 312s, 339s and 365s, the last past the 360s abort floor, all completing and delivering:
Zero
recovery=checking, zerostuck session recovery, zeroabort_embedded_runacross every after-fix run.Note on log cadence: long-running attention warnings back off to
max(last + 120s, last * 2), so after the 290s line the next would land at 578s, longer than these turns. The absence of any recovery line is the load-bearing evidence and is not subject to that backoff: recovery arming is evaluated on every 30s tick and logs unconditionally, as the before-run shows at 381s.Why recovery cannot arm after the fix: the abort predicate keys off
lastProgressAgeMs, not session age. Streaming pins that near zero, so total turn length stops being the trigger.Local validation:
Known proof gaps, stated plainly:
gateway and a real CLI backend, but delivery is the local agent route rather
than a chat channel; the >360s abort itself is not reproduced, only the
progress signal that prevents it.
extensions/codex/src/app-serveraborts with"Worker exited unexpectedly". Confirmed to reproduce identically on clean
origin/mainwith these changes stashed, so it is not introduced here.diagnostic-stuck-session-recovery.runtime.test.tspast the 1000-linemax-lineslimit, so its mock preamble moved to a shared harness and its casesinto two suites. No test bodies were changed by the move.
https://claude.ai/code/session_0122p4qSQzsjwFgYUCDNrwMK