Skip to content

Responses stateful streaming: buffering, fail-closed, and orchestration #6

Description

@leseb

Parent

Part of #101

Scope

Stateful streaming business logic on top of the SSE parser (#501):

  • Accumulate response.function_call_arguments.delta by output item/index/call
  • Require a matching response.function_call_arguments.done before executing a tool
  • Enforce terminal event handling (response.completed, response.failed, response.incomplete)
  • Fail closed on truncated streams, incomplete tool-call arguments, or missing terminal events
  • Default policy: buffered_final_stream — consume upstream SSE internally, buffer tool-call events, return valid final output to client
  • Synthesize downstream output:
    • Valid Responses JSON when returning a non-streamed final response
    • Valid Responses SSE when returning a streamed final response
  • Preserve final response metadata (response id, model, status, output text)
  • Future-compatible progress_events mode (do not forward tool-call events to client unless explicitly configured)

Acceptance criteria

  • Interleaved function-call argument deltas are buffered by the correct output item/call
  • Incomplete function calls fail closed before any tool execution
  • Missing terminal events fail closed
  • Final-text-only streamed model response produces a valid downstream response
  • Tool-call streamed model response executes the tool only after complete arguments are available
  • Synthesized downstream JSON/SSE is valid Responses-shaped output
  • Stateless SSE pass-through remains unchanged

Dependencies

Reference

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Fields

No fields configured for Task.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions