Skip to content

fix(llminternal): handle nil entries in parallel function-response merge#1042

Open
wolo-lab wants to merge 2 commits into
v2from
wolo/v2-h2-merge-nil
Open

fix(llminternal): handle nil entries in parallel function-response merge#1042
wolo-lab wants to merge 2 commits into
v2from
wolo/v2-h2-merge-nil

Conversation

@wolo-lab

@wolo-lab wolo-lab commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Problem

Parallel function calls execute into a pre-sized slice fnResponseEvents := make([]*session.Event, len(fnCalls)). v2 added an early return for tools that defer (DefersResponse()) or are long-running (IsLongRunning()) with a nil result — which leaves that index nil.

mergeParallelFunctionResponseEvents then:

  • does ev := events[0]; ev.LLMResponse = ...panics if index 0 is nil (first tool is long-running), and
  • does ev.Actions = *actionspanics if every entry is nil (actions stays nil).

It's a regression: the early-return is new in v2; in main every 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 == 1 returns the nil event and the caller handles it.)

Solution

In mergeParallelFunctionResponseEvents, base the merged event on the first non-nil entry (instead of events[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.

@wolo-lab wolo-lab force-pushed the wolo/v2-h2-merge-nil branch from 0ffc27e to 3de34e0 Compare June 15, 2026 22:13
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.
@wolo-lab wolo-lab force-pushed the wolo/v2-h2-merge-nil branch from 3de34e0 to 1bf8e5e Compare June 15, 2026 22:15
@wolo-lab wolo-lab requested a review from dpasiukevich June 16, 2026 12:36
@wolo-lab wolo-lab marked this pull request as ready for review June 16, 2026 12:36
@wolo-lab wolo-lab self-assigned this Jun 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant