TestPackDropsDanglingPartialParallelGroup: cancelling a parallel round after only some results return leaves assistant(c1,c2)+tool(c1). The assistant has an unanswered call (c2), so it must be dropped, and dropOrphanTools must then clean up the now-orphaned tool(c1).
(t *testing.T)
| 306 | // an unanswered call (c2), so it must be dropped, and dropOrphanTools must then |
| 307 | // clean up the now-orphaned tool(c1). |
| 308 | func TestPackDropsDanglingPartialParallelGroup(t *testing.T) { |
| 309 | history := []Message{ |
| 310 | {Role: RoleUser, Content: "do two things"}, |
| 311 | {Role: RoleAssistant, ToolCalls: []ToolCall{ |
| 312 | {ID: "c1", Name: "bash"}, {ID: "c2", Name: "bash"}, |
| 313 | }}, |
| 314 | {Role: RoleTool, ToolCallID: "c1", Content: "out1"}, // c2 never answered |
| 315 | {Role: RoleUser, Content: "next"}, |
| 316 | } |
| 317 | r := Pack(history, 100000) |
| 318 | for _, m := range r.Messages { |
| 319 | if m.Role == RoleAssistant && len(m.ToolCalls) > 0 { |
| 320 | t.Fatalf("partial parallel assistant survived: %+v", r.Messages) |
| 321 | } |
| 322 | if m.Role == RoleTool { |
| 323 | t.Fatalf("orphaned tool(c1) survived after its assistant was dropped: %+v", r.Messages) |
| 324 | } |
| 325 | } |
| 326 | } |
| 327 | |
| 328 | // TestPackDropsDanglingAssistantDespiteIDReuse: pairing is positional, not a |
| 329 | // global ID lookup. Local backends commonly reuse index-derived IDs ("call_0") |