Repository navigation
fix(agents): stop stable tool argument churn - #112620
Conversation
|
Codex review: found issues before merge. Reviewed July 27, 2026, 1:17 PM ET / 17:17 UTC. ClawSweeper reviewWhat this changesThe PR adds warning-only detection of repeated same-tool argument variants with a shared no-progress result and uses that signal to let existing stuck-session recovery abort the owning embedded run and drain its command lane. Merge readinessKeep this PR open for maintainer review. The final maintainer repair deliberately limits write no-progress evidence to Priority: P1 Review scores
Verification
How this fits togetherAgent tool calls go through the before-tool-call policy boundary, which records loop evidence and executes the tool. Diagnostic activity converts sustained semantic churn into stale-run evidence, and stuck-session recovery then acts on the associated embedded run and queued command lane. flowchart LR
A[Agent tool call] --> B[Before-tool-call policy]
B --> C[Loop detector]
C --> D[Semantic churn activity]
D --> E[Stuck-session recovery]
E --> F[Embedded run]
E --> G[Command lane drain]
Decision needed
Why: The final implementation intentionally excludes successful writes, while the linked report’s observed loop consists of successful alternating writes. Choosing a broader rule changes when agent runs may be aborted and queued work drained. Before merge
Findings
Agent review detailsSecurityNone. PR surfaceSource +661, Tests +1257, Generated 0. Total +1918 across 22 files. View PR surface stats
Review metricsNone. Merge-risk optionsMaintainer options:
Copy recommended automerge instructionTechnical reviewBest possible solution: Decide whether repeated successful writes to distinct targets with otherwise repeated intent are in scope for recovery. If they are not, narrow the PR and leave #112479 open; if they are, define a conservative write-specific semantic-progress contract and prove it preserves legitimate multi-target writes before merging. Do we have a high-confidence way to reproduce the issue? No live current-head reproduction was executed in this read-only review, but the source path is high-confidence: successful writes lack Is this the best way to solve the issue? No. The no-op-only rule is a plausible bounded improvement, but it does not solve the linked successful-write loop while the PR claims to close that report; either the scope or the semantic-progress contract must change. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 8f8e40dabe0a. LabelsLabel justifications:
EvidenceWhat 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 (6 earlier review cycles)
|
|
Maintainer fixes pushed in
Proof: Blacksmith Testbox passed 66 detector tests, 93 wrapped-tool E2E tests, 15 run-activity tests, and 7 stuck-recovery integration tests. Focused lint/format/diff checks passed. Fresh uncommitted and whole-branch autoreview are clean with no actionable findings. |
|
Merged via squash.
|
|
Post-merge maintainer resolution of the open ClawSweeper P1 ("Do not close the successful-write report with a no-op-only detector"), from an independent pre-land review that ran concurrently with the merge: The Replaying the reported repro (identical content alternating between
The regression tests cover this exact shape ( What remains intentionally excluded is repeated content-changing writes to distinct targets. That is not what #112479 reported, and classifying genuinely changing writes as no-progress could abort legitimate multi-target work — the conservative exclusion is the right product call. Independent structured review (Codex |
* fix(agents): detect stable tool argument churn * fix(agents): refine argument churn evidence * fix(agents): route argument churn through recovery * fix(agents): reconcile rewritten loop arguments * fix(agents): defer churn recovery across policy waits * fix(agents): preserve churn clocks across policy waits * fix(agents): harden concurrent churn policy tracking * fix(agents): avoid stale churn false positives * fix(agents): satisfy loop diagnostic CI guards * fix(agents): normalize write churn outcomes * fix(logging): order churn activity events * fix(agents): classify churn no-progress outcomes --------- Co-authored-by: IWhatsskill <[email protected]> Co-authored-by: Vincent Koc <[email protected]>
[AI-assisted]
What Problem This Solves
Closes #112479.
A run can repeatedly call the same tool while cycling through different arguments that all produce the same stable no-progress result. Exact-argument loop detection sees only short independent streaks, while ordinary tool and model events keep refreshing the generic activity clock, so the run can continue consuming tokens without producing a useful reply.
Why This Change Was Made
The detector now emits a warning-only argument-churn signal after at least two argument variants have each repeated three times with one shared stable result hash. The tool call remains allowed. That semantic signal owns a separate liveness clock which survives short tool/model handoffs and is suspended during policy waits; if the churn stays continuous until the existing stale-run boundary, owner-bound recovery aborts the embedded run and drains its lane. A novel argument, a distinct result, later model progress after tool activity stops, disabled loop detection, run replacement, or lifecycle cleanup clears the churn evidence.
Root Cause
Exact
(toolName, argsHash, resultHash)streaks cannot represent semantically identical no-progress work split across several argument hashes. Reusing the generic run activity timestamp also cannot solve this because each mechanical tool/model event makes a continuously churning run look fresh.Safety boundary
Argument churn is warning-only and never vetoes the next tool call. Cross-variant no-progress requires one shared stable result hash, while compatibility escapes clear the semantic clock. Existing critical exact-repeat, polling, ping-pong, and global breakers keep their precedence.
Runtime ownership
The detector classifies churn, the before-tool-call boundary records the warning and policy-wait tokens, diagnostic activity owns the semantic clock, and existing owner-bound stuck-session recovery performs the abort and lane drain.
User Impact
A continuously churning opted-in agent can now be reclaimed without prematurely blocking a legitimate call. Recurring multi-variant work with distinct successful outcomes, fresh arguments, later useful model progress, overlapping approvals, parallel calls, replacement runs, and configurations with loop detection disabled remain compatible.
Evidence
Provenance
e79faff8aa755b201302edd286976a03f9ed79ea0ab630c2cb130604d6e46557e4c74135b5e0243dmainDirect behavior
54b94d469297f9a65082314d941b13756a05a72c, the production wrapped-tool path executed 30 recurring calls whose argument variants returned distinct successful outcomes, then executed a novel call; the warning remained non-vetoing, later model progress released stale churn, and the escape call cleared churn. Result:{"proof":"recurring_multi_variant_compatibility","recurringCallsExecuted":30,"novelCallExecuted":true,"warningWasNonVetoing":true,"finalProgressReleasedChurn":true,"escapeClearedChurn":true}. Proves legitimate recurring multi-variant work is not classified as shared semantic no progress and the compatibility escapes remain live. Preserves tool execution, novel-call escape, and later-progress ownership.54b94d469297f9a65082314d941b13756a05a72c, the production wrapper recorded 42 same-tool calls spread across six simulated minutes with one shared stable result, while the active embedded-run registry and real command lane contained an owner-bound active run plus queued work. Result:{"proof":"continuous_churn_recovery","toolCallsExecutedBeforeRecovery":42,"staleReason":"tool_loop:argument_churn","staleAgeMs":360000,"recoveryStatus":"aborted","recoveryAction":"abort_embedded_run","activeResult":"aborted","queuedResult":"drained","finalLaneDepth":0}. Proves continuous semantic churn ages independently of mechanical progress and reaches the existing recovery path, which aborts the owning embedded run and drains queued work. Preserves warning-only admission before recovery and owner-bound lane cleanup.Automated verification
Behavior-proof head wrapped runtime
pnpm exec vitest run --config test/vitest/vitest.e2e.config.ts src/agents/agent-tools.before-tool-call.e2e.test.tspnpm exec vitest run --config test/vitest/vitest.e2e.config.ts src/agents/agent-tools.before-tool-call.e2e.test.ts— 1 file passed with 92/92 tests and 0 failures. Proves the complete wrapped before-tool-call boundary passes, including churn admission, final-parameter reconciliation, overlapping policy waits, failures, disabled gating, run scoping, and compatibility escapes. Preserves all existing hook, approval, diagnostic, veto, and execution contracts in the file.Behavior-proof head detector and recovery
node scripts/run-vitest.mjs src/agents/tool-loop-detection.test.ts src/logging/diagnostic-run-activity.test.ts src/logging/diagnostic-stuck-session-recovery.integration.test.ts— 3 files passed with 82/82 tests and 0 failures (62 detector, 13 activity, 7 recovery integration). Proves shared-outcome churn is classified narrowly, activity clock ownership is lifecycle-safe, and real embedded-run/lane recovery is integrated. Preserves exact-repeat, polling, ping-pong, unknown-tool, run-scope, result-hash, index, and recovery behavior.node scripts/run-vitest.mjs src/logging/diagnostic-stuck-session-recovery.runtime.test.ts src/logging/diagnostic-stability.test.ts— 2 files passed with 41/41 tests and 0 failures (28 recovery runtime, 13 stability). Proves the adjacent runtime recovery and stability contracts remain green. Preserves existing stale-session classifications, recovery outcomes, and stability recording.Behavior-proof head static verification
pnpm tsgo:core && pnpm tsgo:core:testpnpm tsgo:core && pnpm tsgo:core:test— Core typecheck and Core test typecheck both completed with exit code 0. Proves production and test changes satisfy the repository TypeScript contracts. Preserves core compile-time boundaries.pnpm exec oxlint $(git diff --name-only 97d3d60b5120a59e8cb9ccbdfca12455acaf909e...HEAD -- '*.ts')— 0 warnings and 0 errors across all 17 changed files. Proves the full production and regression surface satisfies affected lint rules. Preserves repository lint policy without new suppressions.pnpm check:max-lines-ratchet— completed with exit code 0. Proves the final patch does not regress the repository max-lines ratchet. Preserves source-size guardrails.git diff --check origin/main...HEAD— completed with exit code 0 and no whitespace errors. Proves the exact final patch is whitespace-clean. Preserves the bounded 17-file change set.Final-head post-merge CI repair
node scripts/run-vitest.mjs src/logging/diagnostic-run-activity.test.ts— 1 file passed with 13/13 tests and 0 failures. Proves the final head preserves run-id index cleanup through observable lifecycle behavior after removing the test-only production export. Preserves embedded-run replacement, completion, churn ownership, and stale-run lookup cleanup.pnpm deadcode:full— completed with exit code 0 and no unused exports. Proves the final feature surface no longer exposes internal-only churn helpers or test-only index counters. Preserves the runtime behavior while keeping the production API narrow.pnpm plugin-sdk:api:check— completed with exit code 0 against the regeneratedmodule/text-runtimehash. Proves the intentional public diagnostic union addition is recorded in the Plugin SDK API contract. Preserves Plugin SDK baseline enforcement after the current-main merge.pnpm tsgo:core pnpm tsgo:core:test— Core typecheck and Core test typecheck both completed with exit code 0. Proves the current-main merge and CI repair satisfy production and test TypeScript contracts. Preserves core compile-time boundaries at final head0ab630c2cb130604d6e46557e4c74135b5e0243d.git diff --check— completed with exit code 0 and no whitespace errors. Proves the final merged worktree is whitespace-clean. Preserves the current-main merge and bounded CI repair.Preserved boundaries
tools.loopDetection.enabled.Proof gap
A credentialed live-provider/model Gateway run was not run, so provider-specific planning and live-provider behavior are not claimed. The exact-head direct transcripts exercise the production wrapped-tool, diagnostic activity, embedded-run ownership, stuck-session recovery, and command-lane boundaries with deterministic tool results; the complete focused automated suites supplement that runtime proof.
Artifacts