Repository navigation
feat(agent): bound repeated failed tool calls with a recovery checkpoint (#285) - #295
Merged
Merged
Conversation
…int (#285) Every refused or failed tool result reset the host progress deadline, so a model could spend its whole turn budget re-requesting the same invalid call, denied command or unavailable operation under fresh call ids. The host-executed loops (hostLoop for `aether agent`, runLocalTurn for local chat) now share a per-turn ToolFailureBudget (src/core/tool_failure_budget.ts): - Classify failures: invalid_arguments, permission_refused, unavailable, stale_precondition, transient, unknown_outcome, execution_failure. Cancellation is never counted. - Fingerprint the canonical operation (sha256 of the approval binding / raw args / policy tool name). Host decisions (policy, validation, operator denial) are bound to the operation alone; tool-produced failures are bound to relevant state (git working-tree revision, target file stat, shell context, configured test command, edit epoch), comparing each attempt's pre-state with the previous post-state. - Per-class budget, then refuse-then-stop BEFORE executing or prompting: the first spent repeat is answered with a refusal that spells out recovery; a request in a later model reply stops the cycle. Calls batched into one reply (Brain.modelRound, implemented by OllamaBrain) never stop a run before the model has seen a result. An 8-failure streak backstop warns first. - A stop delivers one result under the call's own id, closes the brain, emits done{ok:false, reason:"no-progress"}, and settles the coding turn incomplete (a green check cannot turn a stop into success; session filed no-progress). The checkpoint names operation, reason, attempts, preserved work and one recovery choice; --json gains a `checkpoint` object. - Successful calls are never deduplicated; read-only transient failures are retried once by the host; unknown mutation outcomes are never replayed. - The git probe is one bounded, lock-free `status --porcelain=v2 --branch`, run only for failed shell/git calls; unmeasurable state reads as changed. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #285.
A model stuck re-requesting the same invalid, denied or unavailable tool call used to burn its whole turn budget: every refused result reset the progress deadline, and fresh call ids made each repeat look new. The host-executed loops (
hostLoopforaether agent,runLocalTurnfor local chat) now share a per-turn repeated-failure budget that classifies failures, recognizes a repeat of the same operation under unchanged state, warns the model once, and then stops the cycle with a checkpoint that says what happened and how to recover.What changed
src/core/tool_failure_budget.ts(new)OllamaBrainreports reply boundaries through the new optionalBrain.modelRound(). An 8-failure streak backstop covers the varied-call case and warns from the 6th failure.done{ok:false, reason:"no-progress"}flows through the normal event path.incomplete. A green host check still runs over the preserved work but cannot turn the stop into a success, and the session is filedno-progress.--jsonadds acheckpointrecord: operation, class and reason, attempts, preserved work, one recovery choice. A refusal never suggests a broader permission mode.status --porcelain=v2 --branch, run only for failed shell/git calls. A timeout or error reads as "changed" and never as a stop.docs/CONTRACTS.md→ "Repeated tool-failure budget ([feature] Stop repeated failed tool calls and explain how to recover #285)".Acceptance evidence (
test/tool_failure_budget.test.ts,test/tool_failure_budget_local.test.ts: 50 tests, realhostLoop/runLocalTurn/OllamaBrain/ToolExecutor; assertions on execution counts, prompt counts and per-id delivery)OllamaBrainstops in 4 model turns (cap is 24), on both paths--jsonrecord testrun_shellruns once per model request, then refuse → stophostLoopandrunLocalTurnExtra coverage
lsalternated with a red test is still bounded;npm installresets the count.write_fileproof errors.Verification
origin/mainbefore the change: 3037 tests, 2 failures in the win32 Job Object kill tests (pid-reuse-blocked). These are environmental and passed on every later run.Out of scope (documented in the contract)
aether execloop and smoke loop.🤖 Generated with Claude Code