assistantHasUnresolvedLocalToolCalls reports whether the assistant message at assistantIdx contains local tool calls that lack matching tool results. It returns true when content parsing fails because full-history replay is safer than chaining from state that cannot be inspected.
( messages []database.ChatMessage, assistantIdx int, )
| 314 | // returns true when content parsing fails because full-history replay is safer |
| 315 | // than chaining from state that cannot be inspected. |
| 316 | func assistantHasUnresolvedLocalToolCalls( |
| 317 | messages []database.ChatMessage, |
| 318 | assistantIdx int, |
| 319 | ) bool { |
| 320 | if assistantIdx < 0 || assistantIdx >= len(messages) { |
| 321 | return false |
| 322 | } |
| 323 | |
| 324 | parts, err := chatprompt.ParseContent(messages[assistantIdx]) |
| 325 | if err != nil { |
| 326 | // Use full replay when persisted assistant content cannot be parsed. |
| 327 | return true |
| 328 | } |
| 329 | |
| 330 | localCallIDs := make(map[string]struct{}) |
| 331 | for _, part := range parts { |
| 332 | if part.Type != codersdk.ChatMessagePartTypeToolCall || |
| 333 | part.ProviderExecuted { |
| 334 | continue |
| 335 | } |
| 336 | localCallIDs[part.ToolCallID] = struct{}{} |
| 337 | } |
| 338 | if len(localCallIDs) == 0 { |
| 339 | return false |
| 340 | } |
| 341 | |
| 342 | resolvedCallIDs := make(map[string]struct{}) |
| 343 | for i := assistantIdx + 1; i < len(messages); i++ { |
| 344 | if messages[i].Role != database.ChatMessageRoleTool { |
| 345 | break |
| 346 | } |
| 347 | parts, err := chatprompt.ParseContent(messages[i]) |
| 348 | if err != nil { |
| 349 | // Use full replay when persisted tool content cannot be parsed. |
| 350 | return true |
| 351 | } |
| 352 | for _, part := range parts { |
| 353 | if part.Type != codersdk.ChatMessagePartTypeToolResult { |
| 354 | continue |
| 355 | } |
| 356 | if _, ok := localCallIDs[part.ToolCallID]; ok { |
| 357 | resolvedCallIDs[part.ToolCallID] = struct{}{} |
| 358 | } |
| 359 | } |
| 360 | } |
| 361 | |
| 362 | return len(resolvedCallIDs) != len(localCallIDs) |
| 363 | } |
| 364 | |
| 365 | // providerHasMissingToolResults reports whether the assistant message at |
| 366 | // assistantIdx has local tool calls whose results exist in the database but |
no test coverage detected