← Back to PRs

#11417: fix: add defense against consecutive tool misuse loops

by seojoonkim open 2026-02-07 19:47 View on GitHub →
agents
Adds toolMisuseCount tracking with [DEFENSE] warning after 3+ consecutive failures. Fixes #11228. <!-- greptile_comment --> <h2>Greptile Overview</h2> <h3>Greptile Summary</h3> This PR adds a small defense mechanism in the embedded Pi session subscription pipeline to detect repeated misuse of the `read` tool (calls without a `path`). It introduces new state (`toolMisuseCount`, `lastToolMisuseWarned`) initialized in `subscribeEmbeddedPiSession`, and updates `handleToolExecutionStart` to increment/reset the counter and emit an additional `[DEFENSE]` warning after 3 consecutive failures. <h3>Confidence Score: 5/5</h3> - This PR appears safe to merge with minimal risk. - Changes are localized to tool execution start handling and state initialization, and do not affect core tool execution or message emission flows beyond adding warnings and updating new state fields. No behavioral regressions were found in the reviewed paths. - No files require special attention <!-- greptile_other_comments_section --> <sub>(4/5) You can add custom instructions or style guidelines for the agent [here](https://app.greptile.com/review/github)!</sub> **Context used:** - Context from `dashboard` - CLAUDE.md ([source](https://app.greptile.com/review/custom-context?memory=fd949e91-5c3a-4ab5-90a1-cbe184fd6ce8)) - Context from `dashboard` - AGENTS.md ([source](https://app.greptile.com/review/custom-context?memory=0d0c8278-ef8e-4d6c-ab21-f5527e322f13)) <!-- /greptile_comment -->

Most Similar PRs