fix(agent): stop turn early on repeated identical tool failure - #3312
Open
lucapette wants to merge 1 commit into
Open
fix(agent): stop turn early on repeated identical tool failure#3312lucapette wants to merge 1 commit into
lucapette wants to merge 1 commit into
Conversation
When a tool fails with the same error on every call (e.g. git without credentials, or a safety-guard-blocked command), the agent loop keeps re-calling the LLM and re-executing the same broken tool until max_tool_iterations, with zero user feedback. Messages sent over channels like Telegram then appear to be silently ignored. Add a circuit breaker: track consecutive identical (tool, error) failures in turnState.recordToolExecution, and when the same tool+error repeats repeatedFailureThreshold (3) times, stop the turn early with a clear, user-visible message explaining the repeated failure instead of spinning to the cap. Fixes the root cause behind unanswered messages; self-reproducing test included (fails on v0.3.1, passes with this change). Ref: sipeed#3311
This was referenced Aug 2, 2026
|
This PR has had no activity for 7 days and has been marked as stale. If you are still working on it, please push an update or leave a comment; otherwise it will be closed automatically in 7 days. |
This was referenced Aug 10, 2026
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.
📝 Description
Fix the "stuck / never answers" behavior seen when a tool fails with the same error on every call (e.g.
gitwithout credentials, or any command blocked by the shell safety guard). Previously the agent loop kept re-calling the LLM and re-executing the identical failing tool untilmax_tool_iterations— with zero user feedback in between — so messages over channels like Telegram appeared to be silently ignored.This PR adds a circuit breaker: consecutive identical (tool, error) failures are tracked in
turnState.recordToolExecution, and when the same tool+error repeatsrepeatedFailureThreshold(3) times, the turn stops early with a clear, user-visible message explaining the repeated failure.🗣️ Type of Change
🤖 AI Code Generation
🔗 Related Issue
Fixes #3311
📚 Technical Context
pkg/agent/pipeline_execute.go:697feeds every tool result (including errors) back to the LLM as a prompt message, letting the model retry indefinitely.pkg/tools/shell.go:337returns safety-guard failures asErrorResult(an error, not a user-visible message). With no circuit breaker the loop runs toMaxIterations, and if the service restarts first the turn dies silently.recordToolExecutionalready records per-tool success/failure history, so it is the natural place to detect consecutive identical failures.🧪 Test Environment
📸 Evidence
Click to view Logs
Production repro (v0.3.1) — message 918/turn-32 spun through 39 tool iterations of identical failures, no user output:
Before fix —
go test -run TestRepeatedIdenticalToolFailure:After fix — same test:
☑️ Checklist
go test ./pkg/agent/ -count=1→ ok).