#19351: fix: enable tool_use/result pairing repair for MiniMax models
agents
size: XS
Cluster:
MiniMax API Fixes
## Summary
MiniMax's API strictly requires `tool_result` messages to immediately follow the `assistant` message containing the corresponding `tool_call`. When MiniMax is accessed through a proxy (e.g. OpenCode Zen, Unleashed) rather than directly, the provider is reported as the proxy name (e.g. `unleashed-openai`) and the API as `openai-responses`. This caused the transcript policy to skip the pairing repair.
Previously, when MiniMax used `anthropic-messages` API directly, it was covered by the `isAnthropic` check. After the migration to OpenAI-compatible APIs, that coverage was lost.
After history truncation (`limitHistoryTurns`), orphaned `tool_result` blocks trigger MiniMax error 2013: `"tool call result does not follow tool call"`.
### Changes
- Add `isMinimaxModel()` detection function following the existing `isMistralModel()` pattern — matches by provider (`minimax`, `minimax-cn`) or model ID hint (`minimax`)
- Enable `repairToolUseResultPairing` and `allowSyntheticToolResults` for MiniMax models
- Remove stale comment about MiniMax API migration
- Add unit tests covering direct MiniMax, proxied MiniMax, and MiniMax-CN
## Test plan
- [x] Unit tests pass (`transcript-policy.test.ts` — 7/7)
- [x] Build succeeds
- [ ] Verify heartbeat sessions using MiniMax through a proxy no longer return error 2013
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
This PR adds `isMinimaxModel()` detection to `resolveTranscriptPolicy`, enabling `repairToolUseResultPairing` and `allowSyntheticToolResults` for MiniMax models regardless of how they are accessed (direct provider, CN variant, or through an OpenAI-compatible proxy).
**What changed:**
- `src/agents/transcript-policy.ts`: New `MINIMAX_MODEL_HINTS` constant and `isMinimaxModel()` function following the existing `isMistralModel()` pattern. Detection works by provider ID (`minimax`, `minimax-cn`) or model ID substring (`minimax`). Both `repairToolUseResultPairing` and `allowSyntheticToolResults` now include `isMinimax`. The stale comment about MiniMax API migration is removed.
- `src/agents/transcript-policy.test.ts`: Three new tests added for direct MiniMax, proxied MiniMax (e.g. `unleashed-openai`), and MiniMax-CN.
**Issues found:**
- The first test (`provider: "minimax"`, `modelApi: "anthropic-messages"`) is redundant: `isAnthropicApi()` already returns `true` for `anthropic-messages`, so both assertions passed before this fix. This test does not exercise the newly added `isMinimaxModel()` path. The important scenario missing from tests is the post-migration direct access case: `provider: "minimax"` with `modelApi: "openai-completions"` (or similar OpenAI-compatible API).
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge — the fix is minimal, well-scoped, and follows established patterns.
- The core change is 19 lines in `transcript-policy.ts` following an identical pattern already used for Mistral. The `!isOpenAi` guard correctly excludes native OpenAI providers. The proxied MiniMax case (`unleashed-openai`) is correctly handled because that provider is not in `OPENAI_PROVIDERS`. The only issue is that one test is redundant (covers a case that already worked), while the true post-migration direct scenario (`provider=minimax` + `modelApi=openai-completions`) lacks a test. This is a minor gap and not a correctness issue with the implementation.
- No files require special attention — the test coverage gap is minor.
<sub>Last reviewed commit: 52327e8</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#20675: fix(minimax): enable tool-use/result repair and drop malformed assi...
by jamesbuddy-claw · 2026-02-19
88.8%
#23549: fix: extend repairToolUseResultPairing and allowSyntheticToolResult...
by imjszhang · 2026-02-22
80.4%
#4734: fix: auto-detect China region for MiniMax API endpoint selection
by akramcodez · 2026-01-30
76.1%
#13831: fix(agents): include Anthropic in tool call ID sanitization
by lailoo · 2026-02-11
75.5%
#8660: fix: respect agents.defaults.models.*.params.maxTokens in image tool
by dbottme · 2026-02-04
74.8%
#20779: fix(providers): rename MiniMax M2.5 Lightning to M2.5 highspeed
by ccclyt · 2026-02-19
74.6%
#21313: fix: repair orphaned OpenAI tool results in session history
by kelvinCB · 2026-02-19
74.4%
#19415: fix(agents): enable repairToolUseResultPairing for OpenAI models
by wu-tian807 · 2026-02-17
74.2%
#17602: fix: correct MiniMax M2.5 pricing constants (75x overcharge)
by ghostllm · 2026-02-15
74.2%
#8270: fix: support snake_case 'tool_use' in transcript repair (#8264)
by heliosarchitect · 2026-02-03
74.2%