Skip to content

openai responses API: tool call arguments not accumulated during streaming #940

Closed

Description

@chaholl

Bug

When using the OpenAI Responses API streaming path (gpt-4.1 via type: openai), tool call arguments are not being fully accumulated from response.function_call_arguments.delta events. The resulting tool calls have args: null (empty/partial JSON), causing the tool validator to fail with EOF.

Evidence

Running a single-turn scenario where the model should call lookup_order(order_id: "1023"):

{
  "role": "assistant",
  "tool_calls": [
    {
      "id": "call_rUoQolYZYjHXo1k6jxeAgT2V",
      "name": "lookup_order",
      "args": null
    }
  ]
}

The model correctly identifies the tool to call (3 consecutive attempts), but args are always null. The tool validator then fails:

Error: validation error for tool lookup_order: EOF

The model retries 3 times, gets the same EOF error each time, then gives up and responds without tool data.

Root cause analysis

In runtime/providers/openai/openai_responses_integration.go:

  1. handleOutputAdded (line 799-802) creates the tool call with Args: json.RawMessage("") and maps both item.Item.ID and item.Item.CallID to the tool call index in idMap.

  2. handleFuncArgsDelta (line 741-778) looks up the tool call index via delta.ItemID or delta.CallID in the idMap.

  3. Suspected issue: The ID used in response.function_call_arguments.delta events doesn't match either ID stored in idMap from the response.output_item.added event. This causes the idx < 0 check at line 768 to skip the argument accumulation entirely.

    The output JSON shows "id": "call_rUoQolYZYjHXo1k6jxeAgT2V" (Chat Completions format), but the Responses API typically uses fc_ prefixed IDs. transformToResponsesCallID exists for outbound ID conversion, but the inbound delta events may use a different ID field or format than what handleOutputAdded stored.

  4. Result: Args stay as json.RawMessage("") (len 0), get replaced with {} in the validator, but if any partial delta DID land (e.g., just {), the incomplete JSON causes the schema validator to fail with EOF rather than a missing-field error.

Reproduction

promptarena run \
  -c acme-apparel-support/config.arena.yaml \
  --scenario smoke-test-single-turn \
  --provider openai-direct \
  -v

Where openai-direct is type: openai, model: gpt-4.1, base_url: https://api.openai.com/v1.

The scenario sends: "Hi, my order #1023 still hasn't arrived..." — the model calls lookup_order but args are empty.

Suggested investigation

  1. Add debug logging in handleFuncArgsDelta to print delta.ItemID, delta.CallID, and the current idMap contents — this will show whether the lookup is failing
  2. Check whether the Responses API function_call_arguments.delta events use item_id (matching output_item.added.item.id) or call_id (matching output_item.added.item.call_id) — the code checks both but the actual API may use a field not being captured
  3. The capability matrix tests may not cover this path if they use Chat Completions or non-streaming

Version

promptarena version dev

Activity

  1. chaholl commented on Apr 12, 2026

    @chaholl
    ContributorAuthor

    Investigation findings

    Tested the handleOutputAdded and handleFuncArgsDelta handlers in isolation — they work correctly. The ID matching logic is sound:

    1. handleOutputAdded stores item.id (e.g., fc_abc123) and item.call_id (e.g., call_xyz789) in idMap
    2. handleFuncArgsDelta looks up delta.item_id then falls back to delta.call_id in idMap
    3. Unit tests pass for both item_id and call_id lookup paths, including the no-match case

    Also wrote an end-to-end test (TestStreamResponsesResponse_ToolCallAccumulation) that simulates a full SSE stream with output_item.added → two function_call_arguments.delta events → completed — args accumulate correctly to {"order_id":"1023"}.

    What this rules out:

    • ID format mismatch between events
    • idMap population failure
    • Slice mutation / pass-by-value issues in the streaming loop
    • JSON parsing failures on well-formed SSE data

    What this doesn't rule out (and where to look next):

    1. SSE framing issue — if the real OpenAI API sends multi-line data: fields or uses chunked transfer encoding that splits a JSON payload across multiple scanner.Scan() reads, the current line-by-line SSE parser would silently skip the partial lines. The streamResponsesResponse function at line 909 requires each SSE event to be a single line starting with data: .

    2. response.function_call_arguments.done event — the code has no handler for this event type. If the API sends a done event with the complete arguments (which it does per OpenAI docs), this could be a safety net. Adding a handler for response.function_call_arguments.done that sets the full args from item.arguments in the completed response would make the accumulation resilient to missed deltas.

    3. Event ordering / race — if function_call_arguments.delta arrives before output_item.added (unlikely but possible with SSE), idMap would be empty and the delta would be silently dropped. No logging exists for this case.

    Recommended next steps:

    1. Add debug logging in handleFuncArgsDelta when idx < 0 (ID lookup fails) — this will prove or disprove the ID mismatch theory in production
    2. Add handler for response.function_call_arguments.done as a safety net
    3. Capture a raw SSE transcript from the failing scenario to see the actual event IDs

    The tests I wrote are on feat/azure-openai-platform (not yet merged) — will include them in the PR or split out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions