← Back to PRs

#19351: fix: enable tool_use/result pairing repair for MiniMax models

by thebtf open 2026-02-17 18:18 View on GitHub →
agents size: XS
## 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