#23549: fix: extend repairToolUseResultPairing and allowSyntheticToolResults to all non-OpenAI providers
agents
size: XS
Cluster:
Error Handling in Agent Tools
## Summary
- **Extend `repairToolUseResultPairing`** from only Google/Anthropic to all non-OpenAI providers. Moonshot, MiniMax, and other OpenAI-compatible APIs also reject orphaned `tool_result` messages after history truncation.
- **Extend `allowSyntheticToolResults`** similarly to all non-OpenAI providers, ensuring consistent behavior across third-party provider integrations.
## Motivation
When using providers like Moonshot Kimi or MiniMax via their OpenAI-compatible APIs, the gateway would not repair orphaned tool_result messages after transcript compaction/truncation, causing request failures. These providers have the same constraints as Google and Anthropic in this regard.
## Changes
- Removed the intermediate `repairToolUseResultPairing` variable that gated the feature to `isGoogle || isAnthropic`
- Changed `repairToolUseResultPairing` policy to `!isOpenAi` (all non-OpenAI providers)
- Changed `allowSyntheticToolResults` policy to `!isOpenAi` (all non-OpenAI providers)
## Test plan
- [x] Verify existing tests pass (`pnpm test`)
- [x] Test with Moonshot/MiniMax provider after history truncation to confirm orphaned tool_result messages are repaired
- [x] Verify OpenAI provider behavior is unchanged
Made with [Cursor](https://cursor.com)
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Extended `repairToolUseResultPairing` and `allowSyntheticToolResults` from only Google/Anthropic providers to all non-OpenAI providers. This fix addresses failures with providers like Moonshot Kimi and MiniMax that use OpenAI-compatible APIs but reject orphaned `tool_result` messages after history truncation, similar to Google and Anthropic.
**Key changes:**
- Removed intermediate `repairToolUseResultPairing` variable (line 112 deleted)
- Changed `repairToolUseResultPairing` policy from `!isOpenAi && (isGoogle || isAnthropic)` to `!isOpenAi` (line 122)
- Changed `allowSyntheticToolResults` policy from `!isOpenAi && (isGoogle || isAnthropic)` to `!isOpenAi` (line 130)
- Added comment explaining the rationale for the broader scope
**Impact:**
This change makes the transcript repair logic more defensive and consistent across all non-OpenAI providers, preventing request failures when tool_result messages become orphaned after compaction/truncation. The repair logic moves tool results to immediately follow their corresponding tool calls and inserts synthetic error results for missing tool results.
<h3>Confidence Score: 4/5</h3>
- This PR is safe to merge with low risk
- The change is well-scoped and defensive in nature, making the transcript repair logic apply to all non-OpenAI providers instead of just Google/Anthropic. The logic itself (`repairToolUseResultPairing` and `allowSyntheticToolResults`) is already well-tested and proven to work correctly for strict providers. The change is conservative (applying existing safety logic more broadly) rather than introducing new behavior. The comment clearly documents the rationale. One minor consideration is that this applies the repair logic to providers that may not strictly need it, but this is safer than the inverse (missing it for providers that do need it)
- No files require special attention
<sub>Last reviewed commit: 49419b9</sub>
<!-- greptile_other_comments_section -->
<sub>(3/5) Reply to the agent's comments like "Can you suggest a fix for this @greptileai?" or ask follow-up questions!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#21313: fix: repair orphaned OpenAI tool results in session history
by kelvinCB · 2026-02-19
85.3%
#19415: fix(agents): enable repairToolUseResultPairing for OpenAI models
by wu-tian807 · 2026-02-17
82.6%
#12487: fix(agents): strip orphaned tool_result when tool_use is sanitized ...
by skylarkoo7 · 2026-02-09
82.4%
#12812: fix(transcript-policy): sanitize tool call IDs for all non-OpenAI p...
by justin-nevins · 2026-02-09
81.9%
#19094: Fix empty tool_call_id and function names in provider transcript pa...
by yxshee · 2026-02-17
81.8%
#13831: fix(agents): include Anthropic in tool call ID sanitization
by lailoo · 2026-02-11
81.4%
#8345: fix: prevent synthetic error repair from creating tool_result for d...
by vishaltandale00 · 2026-02-03
80.9%
#19351: fix: enable tool_use/result pairing repair for MiniMax models
by thebtf · 2026-02-17
80.4%
#4700: fix: deduplicate tool_use IDs and enable sanitization for Anthropic
by marcelomar21 · 2026-01-30
80.3%
#8270: fix: support snake_case 'tool_use' in transcript repair (#8264)
by heliosarchitect · 2026-02-03
80.1%