Repository navigation
fix: strip volatile output from exec result hash to fix no-progress detection (#93917) - #94050
sunlit-deng wants to merge 7 commits into
Conversation
|
Codex review: found issues before merge. Reviewed July 17, 2026, 10:32 AM ET / 14:32 UTC. Summary PR surface: Source +144, Tests +582, Docs +11. Total +737 across 11 files. Reproducibility: yes. from source: repeat the same exec arguments with a nonzero exit while the output carries meaningful changing state, with occasional other tool calls; the proposed hash remains identical and matching history continues accumulating. 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. Rank-up moves:
Risk before merge
Maintainer options:
Next step before merge
Maintainer decision needed
Security Review findings
Review detailsBest possible solution: Preserve structured failure identity while retaining a bounded progress signal for completed nonzero results, such as hashing normalized output with known volatile identifiers removed, and add coverage for both volatile-only retries and genuinely progressing nonzero retries. Do we have a high-confidence way to reproduce the issue? Yes, from source: repeat the same exec arguments with a nonzero exit while the output carries meaningful changing state, with occasional other tool calls; the proposed hash remains identical and matching history continues accumulating. Is this the best way to solve the issue? No, not yet; stable structured failure metadata is the right owner boundary, but discarding all completed-nonzero output is broader than necessary and creates a competing availability failure mode. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against b319493a529c. Label changesLabel changes:
Label justifications:
Evidence reviewedPR surface: Source +144, Tests +582, Docs +11. Total +737 across 11 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
Review history (37 earlier review cycles; latest 8 shown)
|
75df1b9 to
8b30b85
Compare
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
32f191d to
d846372
Compare
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
d846372 to
177d6dd
Compare
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
This assigned pull request has been automatically marked as stale after being open for 27 days. |
|
|
This assigned pull request has been automatically marked as stale after being open for 27 days. |
|
This assigned pull request has been automatically marked as stale after being open for 27 days. |
2 similar comments
|
This assigned pull request has been automatically marked as stale after being open for 27 days. |
|
This assigned pull request has been automatically marked as stale after being open for 27 days. |
|
This assigned pull request has been automatically marked as stale after being open for 27 days. |
What Problem This Solves
Repeated failing
execcalls never tripped the no-progress circuit breaker when their output text varied across calls. This covers both hard failures (command-not-found, timeouts, killed processes) and — the canonical #93917 case — ordinary nonzero exits likegrepexit 1 or SSH/Docker retries, whose stdout/stderr carries fresh timestamps, PIDs, or session ids each retry while the actual outcome is identical. The stuck agent kept looping forever.Fixes #93917
Why This Change Was Made
Foreground
execreports an ordinary nonzero exit (e.g.exit 1) asstatus: "completed", notfailed— only shell 126/127, timeout, signal, and abort becomefailed. The previous fix stripped volatile output only on thefailedbranch, so the most common loop (a command that keeps exiting nonzero with changing output) still hashed its output and never accumulated a streak.hashExecToolOutcomenow fingerprints any nonzero outcome by stable facts (status,exitCode,timedOut,exitSignal,failureKind) and drops the volatile output, whether the result iscompletedwith a nonzero code or a hardfailed. Exit 0 still keeps its output in the hash, because changing output from a successful command is real progress. A sharedhashStableExecFailurehelper backs both branches so the two paths cannot drift.The foreground producers carry those discriminators end to end (
ExecToolDetailspropagatesfailureKind/exitSignal, tightened toExecToolFailureKind), addressing @vincentkoc's earlier finding that they were absent on the real result.For hard
failedoutcomes that carry no exit code and no signal — the broad catch-all kinds (node-run-failed,runtime-error,approval-denied) — the exec producers now carry the actual failure reason as a structuredfailureReason(the node error / runtime error / gateway denial reason, not the volatile leading stdout).hashStableExecFailurefingerprints thatfailureReason, keeping stable text including numeric status/error codes (500vs503) and stripping only per-instance identifiers (gateway ids, uuids, hex handles). Genuinely different failures — including two node failures with identical leading stdout but different errors — stay distinct instead of collapsing into one no-progress streak, while repeats of the same failure (varying only in a unique id) still accumulate. Outcomes that already carry a real exit code or signal (including thecompletednonzero path) keep their structured fingerprint and are unaffected.User Impact
Stuck agents that loop retrying the same failing
execcommand — including the commonexit 1/ SSH / Docker retry loop — now hit the global circuit breaker after the configured threshold instead of burning tokens forever. Successful commands with changing output stay progress-sensitive, and genuinely different failure modes keep distinct fingerprints.Changes
src/agents/tool-loop-detection.tscompletedbranch by exit code: nonzero exits use the stable failure fingerprint; exit 0 keeps output. Extract sharedhashStableExecFailurefor thecompleted-nonzero andfailedpaths. Forfailedoutcomes with null exit code and signal, fingerprint the producer's stablefailureReason(not the volatile stdout first line) so distinct catch-all failures stay distinctsrc/agents/bash-tools.exec-types.ts,bash-tools.exec-runtime.ts,bash-tools.exec.ts,bash-tools.exec-host-node-phases.ts,bash-tools.exec-host-gateway.tsfailureKind/exitSignaland a stablefailureReason(the actual node/runtime/gateway error, not stdout) through the real foreground producerssrc/agents/tool-loop-detection.exec-foreground.test.tscompletedexec with volatile output trips the breaker; exit-0 volatile output does not. Also drives the productionbefore_tool_callhook (wrapToolWithBeforeToolCallHook) to prove the wrapped exec is vetoed withdeniedReason:"tool-loop"src/agents/tool-loop-detection.test.tsdocs/tools/loop-detection.mdEvidence
Live agent run — real DeepSeek model trips the production breaker (exact head)
An embedded agent run at this PR's head (
openclaw agent --local), driven by a real DeepSeek model, was told to keep callingexecwith the same failing commandsh -c 'date +%s%N; exit 1'. That command prints a fresh timestamp and exits 1 on every call — the canonical #93917 volatile-output-with-nonzero-exit case. Loop detection was enabled with low thresholds (criticalThreshold: 3), and the production circuit breaker fired in the real run and blocked the loop:The command's stdout changes every call (a fresh timestamp), yet loop detection records the outcomes as identical — the nonzero exit is fingerprinted by stable facts and the volatile output is dropped — so the no-progress streak accumulates and the breaker blocks the call. Before this fix the changing output hashed differently every call, the streak never formed, and the agent would loop forever. Model, provider, real exec child process, and the loop-detection breaker here are all the production path.
Live proof — the real changed module trips the breaker (before/after)
nonzero-exit-live-proof.tsimports the real changed module (src/agents/tool-loop-detection.ts) and drives its exportedrecordToolCall/recordToolCallOutcome/detectToolCallLoopwith exec details shaped exactly as the real foreground producer emits for a normal exit (status:"completed", numericexitCode,exitSignal:null, aggregated text with the trailing(Command exited with code N)). Output is fresh every call — the #93917 volatile-output case. The exit-0 run is also how a nonzero exit behaved before this fix (output-sensitive), so it is the pre-fix control.completedexec with volatile output tripsglobal_circuit_breakerat the threshold.nonzero-exit-live-proof.ts
Real foreground exec regression (production tool path)
tool-loop-detection.exec-foreground.test.tsdrives the actual exec tool (createOpenClawCodingTools->execTool.execute) against a real child process, then feeds each real result through the production recorders and detector. It proves the nonzero case with a realexit 1(a realstatus:"completed",exitCode:1result) tripping the breaker despite fresh output, keeps the exit-0 control below the breaker, and still covers the hardfailedcommand-not-found / timeout paths and their distinctness. Two added cases also drive the realbefore_tool_callorchestration hook (wrapToolWithBeforeToolCallHook) — the same path a live agent turn runs — and prove the wrapped exec is vetoed withdeniedReason:"tool-loop"after the repeated volatile nonzero exits, while exit-0 volatile output is never vetoed. Thetool-loop-detection.test.tsunit suite additionally proves that distinct catch-all failure reasons — including ones differing only by a stable numeric code (500vs503) — stay distinct, while repeats varying only in a per-instance id still collapse to the breaker.AI-assisted: built with Codex