#20675: fix(minimax): enable tool-use/result repair and drop malformed assistant turns
agents
size: XS
Cluster:
MiniMax API Fixes
## Problem
MiniMax has the same strict `tool_call`/`tool_result` pairing requirement as Anthropic and Google, but `repairToolUseResultPairing` and `allowSyntheticToolResults` were never enabled for it in `resolveTranscriptPolicy`.
This caused sessions to fail with:
> **Jinja template rendering failed: Message has tool role, but there was no previous assistant message with a tool call!**
Two root causes compound the issue:
1. **Missing repair flag** — orphaned/displaced `toolResult` messages are never moved or synthetically filled, so MiniMax sees a tool-result turn with no preceding tool-call turn.
2. **MiniMax API bug** — MiniMax sometimes returns `finish_reason: "tool_calls"` (`stopReason=toolUse`) with no actual function-call blocks in the content. These text-only turns end up immediately before a real tool-calling assistant turn, creating consecutive assistant messages. MiniMax's Jinja2 template then misattributes the subsequent tool results to the wrong turn.
The comment in `session-transcript-repair.ts` already named MiniMax explicitly as a strict provider — the flag just wasn't set.
## Changes
**`src/agents/transcript-policy.ts`**
- Add `MINIMAX_MODEL_HINTS` constant and `isMiniMaxModel()` helper (mirrors existing `isMistralModel()` pattern)
- Enable `repairToolUseResultPairing` for MiniMax
- Enable `allowSyntheticToolResults` for MiniMax
**`src/agents/session-transcript-repair.ts`** (in `repairToolCallInputs`)
- Drop assistant messages with `content.length === 0` — these are always error artifacts from failed/interrupted API calls and create consecutive assistant turns that strict providers reject
- Drop assistant messages where `stopReason === "toolUse"` but no tool-call blocks are present — handles the MiniMax API bug where it signals tool intent but emits no function calls
## Testing
- [x] Verified locally against a corrupted MiniMax session that was producing the Jinja error — MiniMax replies successfully after the fix
- [x] Linter clean (`pnpm check`)
- [ ] Unit tests (the repair logic is covered by existing tests; no new test cases added — happy to add if maintainers prefer)
## AI-assisted
Built with Claude (Sonnet 4.6). I understand what the code does and verified it locally.
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Enables transcript repair for MiniMax provider to handle strict tool-call/tool-result pairing requirements. After MiniMax switched to `anthropic-messages` API (PR #15297), it inherited Anthropic's strict turn ordering constraints but repair mechanisms were never enabled.
The fix adds:
- MiniMax detection helper in `transcript-policy.ts` (mirrors existing `isMistralModel()` pattern)
- Enables `repairToolUseResultPairing` and `allowSyntheticToolResults` for MiniMax
- Drops malformed assistant messages (empty content arrays or `stopReason=toolUse` with no actual tool calls) to prevent consecutive assistant turns that trigger Jinja validation errors
Changes follow established patterns for Anthropic/Google providers and address documented MiniMax API bugs where `finish_reason: "tool_calls"` is returned without function-call content.
<h3>Confidence Score: 4/5</h3>
- Safe to merge with minimal risk - addresses a documented bug with defensive repair logic
- The implementation follows established patterns for Anthropic/Google strict providers and addresses a real failure mode (Jinja template errors). The defensive repair logic is sound but lacks test coverage for MiniMax-specific scenarios. The changes are scoped and well-documented, though comprehensive unit tests would strengthen confidence.
- No files require special attention - both changes are straightforward and follow existing patterns
<sub>Last reviewed commit: 3b58ee6</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
#19351: fix: enable tool_use/result pairing repair for MiniMax models
by thebtf · 2026-02-17
88.8%
#23549: fix: extend repairToolUseResultPairing and allowSyntheticToolResult...
by imjszhang · 2026-02-22
79.1%
#8270: fix: support snake_case 'tool_use' in transcript repair (#8264)
by heliosarchitect · 2026-02-03
79.1%
#8345: fix: prevent synthetic error repair from creating tool_result for d...
by vishaltandale00 · 2026-02-03
76.9%
#6687: fix(session-repair): strip malformed tool_use blocks to prevent per...
by NSEvent · 2026-02-01
76.7%
#17179: fix: validateAnthropicTurns handles consecutive system messages for...
by Limitless2023 · 2026-02-15
76.5%
#4844: fix(agents): skip error/aborted assistant messages in transcript re...
by lailoo · 2026-01-30
76.3%
#14328: fix: strip incomplete tool_use blocks from errored/aborted messages...
by Kropiunig · 2026-02-12
75.7%
#12487: fix(agents): strip orphaned tool_result when tool_use is sanitized ...
by skylarkoo7 · 2026-02-09
75.5%
#9416: fix: drop errored/aborted assistant tool pairs in transcript repair
by xandorklein · 2026-02-05
75.5%