← Back to PRs

#6464: fix: trigger model failover on malformed tool-call JSON

by ai-fanatic open 2026-02-01 17:47 View on GitHub →
agents
## Summary - Adds detection for JSON parse errors to trigger model failover - Covers OpenAI-style errors ("is not valid JSON") - Covers Node JSON.parse errors ("Unexpected token") - Covers truncated JSON errors ("Unexpected end of JSON input") - Adds test coverage for new error patterns ## Test plan - [x] Unit tests pass (`pnpm test src/agents/pi-embedded-helpers.classifyfailoverreason.test.ts`) - [x] Linting passes (`pnpm lint`) - [x] Formatting passes (`pnpm format`) <!-- greptile_comment --> <h2>Greptile Overview</h2> <h3>Greptile Summary</h3> This PR extends the model failover classification logic to treat malformed tool-call JSON parse errors as a `format` failover reason, and adds unit coverage for several common error message variants (OpenAI-style “is not valid JSON”, Node `JSON.parse` “Unexpected token …”, and truncated JSON “Unexpected end of JSON input”). The change plugs a gap where tool-call argument parse failures wouldn’t previously trigger a retry/failover path, improving robustness when models emit malformed tool argument payloads. <h3>Confidence Score: 4/5</h3> - This PR is likely safe to merge, with a small risk of over-triggering failover on non-parse errors. - Change is localized to failover classification and backed by targeted tests, but the new regex is broad enough that it may classify some non-JSON-parse failures as `format`, causing unnecessary failovers in edge cases. - src/agents/pi-embedded-helpers/errors.ts <!-- greptile_other_comments_section --> <!-- /greptile_comment -->

Most Similar PRs