fix(llminternal): handle nil entries in parallel function-response merge#1042
Open
wolo-lab wants to merge 2 commits into
Open
fix(llminternal): handle nil entries in parallel function-response merge#1042wolo-lab wants to merge 2 commits into
wolo-lab wants to merge 2 commits into
Conversation
0ffc27e to
3de34e0
Compare
When a parallel tool call is long-running or defers its response, the producer returns early and leaves a nil slot in the pre-sized fnResponseEvents slice. mergeParallelFunctionResponseEvents then did `ev := events[0]; ev.LLMResponse = ...` (panics if index 0 is nil) and `ev.Actions = *actions` (panics if all entries are nil, leaving actions nil). v2 added the early-return, so merge started seeing nils. Base the merged event on the first non-nil entry and return (nil, nil) when every entry is nil. Add a regression test (first-nil, all-nil, mixed) that panics on the unpatched code.
3de34e0 to
1bf8e5e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Parallel function calls execute into a pre-sized slice
fnResponseEvents := make([]*session.Event, len(fnCalls)). v2 added an earlyreturnfor tools that defer (DefersResponse()) or are long-running (IsLongRunning()) with a nil result — which leaves that indexnil.mergeParallelFunctionResponseEventsthen:ev := events[0]; ev.LLMResponse = ...→ panics if index 0 is nil (first tool is long-running), andev.Actions = *actions→ panics if every entry is nil (actionsstays nil).It's a regression: the early-return is new in v2; in
mainevery goroutine reached the event-construction line, so merge never saw nils.Trigger: a model turn with ≥ 2 function calls where the first is a long-running tool (returns nil) — e.g. a long-running HITL tool alongside a normal tool, or two long-running tools in parallel. (Single-call is safe:
len == 1returns the nil event and the caller handles it.)Solution
In
mergeParallelFunctionResponseEvents, base the merged event on the first non-nil entry (instead ofevents[0]), and return(nil, nil)when every entry is nil. nil entries were already skipped while accumulating parts/actions; this just stops the post-loop code from dereferencing them.