fix(minimax): implement history repair and truncation to prevent tool sequence errors
- Add _repair_minimax_history to close dangling tool calls from interrupted sessions. - Add _trim_minimax_history to manage token limits and intelligently prune history. - Integrate repair and trimming into _send_minimax loop. - Resolves MiniMax error 2013 (tool call result does not follow tool call).
This commit is contained in:
+1
-1
@@ -283,5 +283,5 @@ This file tracks all major tracks for the project. Each track has its own detail
|
||||
|
||||
---
|
||||
|
||||
- [ ] **Track: Fix MiniMax history sequencing and truncation**
|
||||
- [x] **Track: Fix MiniMax history sequencing and truncation**
|
||||
*Link: [./tracks/minimax_history_fix_20260601/](./tracks/minimax_history_fix_20260601/)*
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
# Implementation Plan: MiniMax History Fix
|
||||
|
||||
## Phase 1: Implementation
|
||||
- [ ] Task: Implement History Repair
|
||||
- [ ] Create `_repair_minimax_history(history: list[dict[str, Any]])` in `src/ai_client.py`.
|
||||
- [ ] Logic: Check if the last message is `assistant` with `tool_calls`. If so, append a `tool` message for each `tool_call_id` with an error message indicating the session was interrupted.
|
||||
- [ ] Task: Implement History Truncation
|
||||
- [ ] Create `_trim_minimax_history(system_blocks: list[dict[str, Any]], history: list[dict[str, Any]])` in `src/ai_client.py` (adapt from `_trim_anthropic_history`).
|
||||
- [ ] Logic: Iteratively remove oldest assistant/user pairs if the estimated tokens exceed the context limit.
|
||||
- [ ] Task: Integrate into `_send_minimax`
|
||||
- [ ] Call `_repair_minimax_history(_minimax_history)` within the initial `_minimax_history_lock` block.
|
||||
- [ ] Call `_trim_minimax_history` at the start of the `for round_idx` loop.
|
||||
- [ ] Log dropped messages to `_append_comms`.
|
||||
- [x] Task: Implement History Repair
|
||||
- [x] Create `_repair_minimax_history(history: list[dict[str, Any]])` in `src/ai_client.py`.
|
||||
- [x] Logic: Check if the last message is `assistant` with `tool_calls`. If so, append a `tool` message for each `tool_call_id` with an error message indicating the session was interrupted.
|
||||
- [x] Task: Implement History Truncation
|
||||
- [x] Create `_trim_minimax_history(system_blocks: list[dict[str, Any]], history: list[dict[str, Any]])` in `src/ai_client.py` (adapt from `_trim_anthropic_history`).
|
||||
- [x] Logic: Iteratively remove oldest assistant/user pairs if the estimated tokens exceed the context limit.
|
||||
- [x] Task: Integrate into `_send_minimax`
|
||||
- [x] Call `_repair_minimax_history(_minimax_history)` within the initial `_minimax_history_lock` block.
|
||||
- [x] Call `_trim_minimax_history` at the start of the `for round_idx` loop.
|
||||
- [x] Log dropped messages to `_append_comms`.
|
||||
|
||||
## Phase 2: Verification
|
||||
- [ ] Task: Verification
|
||||
- [ ] Verify that switching to MiniMax and executing a tool call, then forcibly stopping (e.g., clearing the app or throwing an error in a tool), allows the next request to succeed.
|
||||
- [ ] Task: Conductor - User Manual Verification 'Phase 2: Verification' (Protocol in workflow.md)
|
||||
- [x] Task: Verification
|
||||
- [x] Verify that switching to MiniMax and executing a tool call, then forcibly stopping (e.g., clearing the app or throwing an error in a tool), allows the next request to succeed.
|
||||
- [x] Task: Conductor - User Manual Verification 'Phase 2: Verification' (Protocol in workflow.md)
|
||||
Reference in New Issue
Block a user