TestPackRecoveryDropsPartialParallelGroup: the empty-recovery path (newest is a tool result whose owner fell past a tight budget) must not resurrect a partially-answered parallel group as a dangling assistant. owner issued c1,c2 but only c1 came back; newestToolGroup recovers [assistant(c1,c2), tool
(t *testing.T)
| 257 | // but only c1 came back; newestToolGroup recovers [assistant(c1,c2), tool(c1)], |
| 258 | // which must then be stripped to nothing rather than reaching the wire and 400ing. |
| 259 | func TestPackRecoveryDropsPartialParallelGroup(t *testing.T) { |
| 260 | bigArgs := strings.Repeat("y", 4*5000) // owner far over the tight budget below |
| 261 | history := []Message{ |
| 262 | {Role: RoleUser, Content: "do two things"}, |
| 263 | {Role: RoleAssistant, ToolCalls: []ToolCall{ |
| 264 | {ID: "c1", Name: "bash", Arguments: map[string]any{"cmd": bigArgs}}, |
| 265 | {ID: "c2", Name: "bash"}, |
| 266 | }}, |
| 267 | {Role: RoleTool, ToolCallID: "c1", Content: "out1"}, // c2 result never arrived |
| 268 | } |
| 269 | r := Pack(history, 300) // forces the budget walk + drops to empty, then recovery |
| 270 | for _, m := range r.Messages { |
| 271 | if m.Role == RoleAssistant && len(m.ToolCalls) > 0 { |
| 272 | t.Fatalf("dangling partial-parallel assistant reached the wire: %+v", r.Messages) |
| 273 | } |
| 274 | if m.Role == RoleTool { |
| 275 | t.Fatalf("orphaned tool survived after its assistant was dropped: %+v", r.Messages) |
| 276 | } |
| 277 | } |
| 278 | } |
| 279 | |
| 280 | // TestPackDropsDanglingAssistantToolCalls: a turn cancelled mid-tool leaves an |
| 281 | // assistant.tool_calls in history with no answering tool message (the TUI |