Skip to content

fix(query): stop repeated tool-failure loops#1219

Open
chioarub wants to merge 1 commit into
Gitlawb:mainfrom
chioarub:codex/tool-failure-loop-guard
Open

fix(query): stop repeated tool-failure loops#1219
chioarub wants to merge 1 commit into
Gitlawb:mainfrom
chioarub:codex/tool-failure-loop-guard

Conversation

@chioarub
Copy link
Copy Markdown
Contributor

Summary

  • Add a query-level tool failure loop guard that tracks repeated failing tool results by tool/error category, error category, and normalized path.
  • Stop the query loop with a clear assistant-visible diagnostic before another model call when repeated failures hit the threshold.
  • Cover repeated write/edit failures, invalid fallback tool calls, synthetic user interruptions/rejections, success resets, threshold parsing, and integration ordering.

Why

Issue #1102 reports runaway loops where the model repeatedly retries failed file writes/edits or invalid fallback tool calls, burning tokens without making progress. This change adds a small circuit breaker in the query loop rather than refactoring individual tools.

This does not repair the underlying file-write failure or provider/tool-schema issue. It stops the runaway loop and gives the user a concrete diagnostic so they can inspect permissions, paths, or tool schema before retrying.

Validation

  • bun test src/query/toolFailureLoopGuard.test.ts passed: 22 tests.
  • bun run build passed.
  • git diff --check passed.
  • bun run typecheck still fails on existing repo-wide snapshot/type issues unrelated to this change, including missing modules/exports and pre-existing src/query.ts references outside the guard path.

@chioarub chioarub marked this pull request as ready for review May 17, 2026 08:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant