Skip to content

fix(agents): stop repeated equivalent terminal exec failures - #118071

Merged
steipete merged 1 commit into
mainfrom
codex/issue-117637-semantic-exec-loop
Aug 2, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/issue-117637-semantic-exec-loop

Conversation

@steipete

@steipete steipete commented Aug 2, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #117637

What Problem This Solves

Forty argument-varying exec calls can repeat the same terminal failure without ever tripping loop detection because every command has a different argument hash. The agent continues consuming model calls, blocks its session, and repeats a meaningful failure indefinitely.

What Changed

  • Recognize completed or failed terminal exec results with a finite, nonzero exit code and the same meaningful output.
  • Reuse the existing canonical outcome hash and contiguous same-tool, same-run failure history without parsing command strings, paths, or provider text.
  • Ignore successful commands, timeouts, empty output, and synthetic exit-code-only footers to avoid blocking legitimate probes.
  • Preserve the existing critical threshold of 20, global circuit-breaker threshold of 30, typed loop vetoes, and reset boundaries for tool, run, success, and changed output.

Verification

Live terminal proof (current head)

The actual terminal invocation node <<'NODE' loaded the committed production src/agents/agent-tools.before-tool-call.wrapper.ts, src/agents/tool-loop-detection.ts, and src/logging/diagnostic-session-state.ts. It executed wrapToolWithBeforeToolCallHook against synthetic exit-7 fixtures; the following are the actual redacted output lines:

{"scenario":"identical-meaningful-failure","attempt":20,"status":"completed","exitCode":7,"stderr":"fixture stderr: FIXTURE_FAILURE_A"}
{"scenario":"identical-meaningful-failure","attempt":21,"status":"blocked","deniedReason":"tool-loop","detector":"generic_repeat"}
{"scenario":"identical-meaningful-failure","attempt":31,"status":"blocked","deniedReason":"tool-loop","detector":"global_circuit_breaker"}
{"scenario":"changed-output-reset","attempt":19,"status":"completed","exitCode":7,"stderr":"fixture stderr: FIXTURE_FAILURE_A"}
{"scenario":"changed-output-reset","attempt":20,"status":"completed","exitCode":7,"stderr":"fixture stderr: FIXTURE_FAILURE_B"}
{"scenario":"changed-output-reset","attempt":21,"status":"completed","exitCode":7,"stderr":"fixture stderr: FIXTURE_FAILURE_A"}

Actual terminal verdict:

{"pr":118071,"head":"66eb1cbdb7b46fc901a16298a24db2a7c6bbc859","productionWrapper":"wrapToolWithBeforeToolCallHook","criticalThreshold":20,"firstBlockedAttempt":21,"globalCircuitBreakerThreshold":30,"globalBlockedAttempt":31,"sameMeaningfulNonzeroFailureBlocked":true,"nonzeroExitCode":7,"typedVeto":"tool-loop","typedVetoHistoryEntries":11,"blockedCallsNeverExecuted":true,"changedFailureOutputReset":true,"subsequentCallPermitted":true,"nextDetectorDecision":{"stuck":false},"resetScenarioActualExecutions":22,"redacted":true}

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: M maintainer Maintainer-authored PR labels 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. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. labels Aug 2, 2026
@clawsweeper

clawsweeper Bot commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed August 2, 2026, 1:08 PM ET / 17:08 UTC.

ClawSweeper review

What this changes

The PR records meaningful nonzero terminal exec outcomes as a typed no-progress class so changing command arguments with the same failure output are blocked at the established loop thresholds.

Merge readiness

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

Keep this protected maintainer PR open for normal review. The patch cleanly extends the existing per-run no-progress owner to block a contiguous tail of equivalent non-timeout terminal exec failures across changing arguments, and current-main source plus the PR’s focused tests support that behavior; however, the supplied PR body shows automated validation only, not inspectable after-fix real-session proof.

Priority: P1
Reviewed head: 66eb1cbdb7b46fc901a16298a24db2a7c6bbc859

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The code and focused boundary coverage are solid, but merge confidence is capped until the intended runtime behavior is shown outside mocks and automated checks.
Proof confidence 🦪 silver shellfish (2/6) Needs real behavior proof before merge: The supplied body reports focused tests and CI, including a wrapper-level harness, but it contains no inspectable after-fix live-session transcript, terminal output, recording, log, or linked artifact that directly demonstrates the new veto behavior. 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 supplied body reports focused tests and CI, including a wrapper-level harness, but it contains no inspectable after-fix live-session transcript, terminal output, recording, log, or linked artifact that directly demonstrates the new veto behavior. 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 owner boundary: Current main scopes tool-call history to the active run before invoking the shared no-progress detector; the proposed change stays inside that detector rather than adding command parsing or a parallel policy path.
Patch behavior and reset boundaries: The PR marks only finite, nonzero, non-timeout exec results with meaningful output as terminal failures, and its focused tests cover changed output, success, timeout, another tool, and another run as reset boundaries.
Before-tool-call integration coverage: The PR adds an end-to-end wrapper test that executes varying exec arguments, observes the first block at the critical threshold, and preserves the existing global circuit-breaker escalation through recorded vetoes.
Findings None None.
Security None None.

How this fits together

Before each agent tool call, OpenClaw reads the current run’s compact tool history and decides whether the next invocation is safe. Completed tool results feed canonical outcome hashes back into that history, which lets the loop detector stop a session that is repeatedly failing without progress.

flowchart LR
  A[Agent proposes exec command] --> B[Before-tool-call loop check]
  B --> C[Current-run tool history]
  C --> D[Terminal failure classifier]
  D --> E[Equivalent outcome streak]
  E --> F[Critical loop veto]
  F --> G[Agent changes course or session stops]
Loading

Before merge

  • Add real behavior proof - Needs real behavior proof before merge: The supplied body reports focused tests and CI, including a wrapper-level harness, but it contains no inspectable after-fix live-session transcript, terminal output, recording, log, or linked artifact that directly demonstrates the new veto behavior. 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) - Merging changes the existing agent-session availability policy: one run with 20 contiguous nonzero exec failures sharing an outcome hash will now be vetoed even when command arguments differ. The focused reset tests are strong, but a real after-fix session transcript would confirm the intended operator-visible recovery behavior.
  • Complete next step (P2) - The maintainer label keeps this PR in the human review lane, and the only remaining merge gate is contributor-supplied real behavior proof rather than an automatable code repair.
Agent review details

Security

None.

PR surface

Source +40, Tests +301. Total +341 across 5 files.

View PR surface stats
Area Files Added Removed Net
Source 3 45 5 +40
Tests 2 301 0 +301
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 346 5 +341

Review metrics

None.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #117637
Summary: This PR is a concrete candidate fix for the canonical report about argument-varying terminal exec failures evading loop detection.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Require observed loop behavior (recommended)
    Before merge, add redacted live-session or terminal proof that varying failed exec calls are vetoed at the threshold and a changed outcome resets the tail.
  2. Accept the bounded policy change
    Merge with the focused test evidence if maintainers accept that a run with 20 equivalent terminal failures should stop even without additional real-session proof.

Technical review

Best possible solution:

Retain this shared, output-hash-based detector repair and add redacted after-fix proof showing a live or terminal-driven agent session blocks the repeated failure at the threshold while a meaningful changed result lets the run continue.

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

Yes, source-reproducible: current main records exact argument hashes, so changing exec arguments prevent the existing generic no-progress streak from reaching the critical threshold; the PR’s focused tests exercise the repaired path and its reset boundaries.

Is this the best way to solve the issue?

Yes: extending the existing per-run outcome-history detector is a narrower and more maintainable fix than parsing shell commands or resource paths, and it preserves the current thresholds, veto accounting, and run isolation.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P1: The patch addresses an agent-runaway path that can consume model turns and block a session’s queued work.
  • add merge-risk: 🚨 availability: The new terminal-failure classification can deliberately veto future exec calls in an active session after the critical threshold.
  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • add status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The supplied body reports focused tests and CI, including a wrapper-level harness, but it contains no inspectable after-fix live-session transcript, terminal output, recording, log, or linked artifact that directly demonstrates the new veto behavior. 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.

Label justifications:

  • P1: The patch addresses an agent-runaway path that can consume model turns and block a session’s queued work.
  • merge-risk: 🚨 availability: The new terminal-failure classification can deliberately veto future exec calls in an active session after the critical threshold.
  • 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 supplied body reports focused tests and CI, including a wrapper-level harness, but it contains no inspectable after-fix live-session transcript, terminal output, recording, log, or linked artifact that directly demonstrates the new veto behavior. 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:

  • Current owner boundary: Current main scopes tool-call history to the active run before invoking the shared no-progress detector; the proposed change stays inside that detector rather than adding command parsing or a parallel policy path. (src/agents/tool-loop-detection.ts:85, 19aad4ac2a40)
  • Patch behavior and reset boundaries: The PR marks only finite, nonzero, non-timeout exec results with meaningful output as terminal failures, and its focused tests cover changed output, success, timeout, another tool, and another run as reset boundaries. (src/agents/tool-loop-detection.test.ts:978, 66eb1cbdb7b4)
  • Before-tool-call integration coverage: The PR adds an end-to-end wrapper test that executes varying exec arguments, observes the first block at the critical threshold, and preserves the existing global circuit-breaker escalation through recorded vetoes. (src/agents/agent-tools.before-tool-call.e2e.test.ts:498, 66eb1cbdb7b4)
  • Current implementation provenance: The current outcome-hashing and no-progress helper lines are attributed by blame to the same current-main feature introduction, providing a common historical owner for the repair surface. (src/agents/tool-loop-detection.ts:161, c4d355133ff6)
  • Merge applicability: A local three-way merge of the PR head with current main produces merged versions of all three production files, and the PR head is not already contained in current main. (src/agents/tool-loop-no-progress.ts:7, 66eb1cbdb7b4)
  • Dependency contract: The imported nullable-string normalizer trims whitespace and rejects empty strings, so the PR’s synthetic exit-footer exclusion compares normalized meaningful output rather than raw whitespace-only output. (packages/normalization-core/src/string-coerce.ts:7, 19aad4ac2a40)

Likely related people:

  • Shakker: Blame attributes the current exec outcome hashing and no-progress helper to the current-main feature introduction that established this repair surface. (role: current implementation introducer; confidence: high; commits: c4d355133ff6; files: src/agents/tool-loop-detection.ts, src/agents/tool-loop-no-progress.ts)
  • steipete: History shows prior work on agent session and tool-loop paths, and this PR adds the focused repair and integration coverage on top of that area. (role: recent agent-loop contributor; confidence: high; commits: 71a59512ba47, 4ed28c355913, 66eb1cbdb7b4; files: src/agents/tool-loop-detection.ts, src/agents/tool-loop-detection.test.ts, src/agents/agent-tools.before-tool-call.e2e.test.ts)

Rank-up moves

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

  • Add a redacted after-fix terminal or live-session transcript demonstrating the threshold block and a changed-output reset.

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.

@steipete
steipete merged commit e92a98c into main Aug 2, 2026
135 of 146 checks passed
@steipete
steipete deleted the codex/issue-117637-semantic-exec-loop branch August 2, 2026 18:42
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling maintainer Maintainer-authored PR merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: M 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.

[Bug]: semantically identical failed exec calls evade tool-loop detection when command arguments vary

1 participant