Skip to content

Avoid false OpenAI stream failures on completed responses - #272

Merged
veithly merged 3 commits into
mainfrom
codex/fix-openai-incomplete-stream
Apr 30, 2026
Merged

Avoid false OpenAI stream failures on completed responses#272
veithly merged 3 commits into
mainfrom
codex/fix-openai-incomplete-stream

Conversation

@veithly

@veithly veithly commented Apr 30, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • accept OpenAI Responses completed as a successful terminal state when it maps to canonical stop
  • classify non-streamed text attached to tool-call turns as thinking/pre_tool instead of final content
  • preserve caller-provided SpoonReactAI prompts across initialization and keep integration tests isolated from local .env

Tests

  • python -m py_compile spoon_ai\agents\toolcall.py spoon_ai\agents\spoon_react.py
  • python -m pytest tests/test_agent_llm_integration.py -q

Not included

  • local dist-local/
  • local pr-body-core.md
  • config or secrets

veithly added 3 commits April 22, 2026 20:43
The Responses streaming path treated any stream that ended without response.completed as a hard runtime error, including cancel/incomplete cases that already carried usable partial state. Accept response.incomplete, synthesize partial terminal responses when needed, and cover the behavior with focused regressions.

Constraint: keep provider-specific handling inside spoon-core and preserve existing streaming callbacks and metadata.
Rejected: surfacing the failure to spoon-bot as a generic runtime error; clearing partial output on incomplete streams.
Confidence: high
Scope-risk: medium
Reversibility: high
Directive: incomplete OpenAI Responses streams should degrade gracefully instead of poisoning agent control flow.
Tested: python -m pytest tests/test_tool_streaming_output.py::test_openai_chat_with_tools_accepts_response_incomplete_terminal_event tests/test_tool_streaming_output.py::test_openai_chat_with_tools_falls_back_to_streamed_tool_call_when_terminal_event_is_missing tests/test_tool_streaming_output.py::test_openai_chat_stream_uses_responses_reasoning_summary_when_effort_requested -q
Not-tested: full spoon-core suite
Related: OpenAI Responses stream cancel and incomplete handling
Context: OpenAI Responses can report a completed native terminal state while the canonical finish reason is stop, and text attached to tool-call turns should not be surfaced as final user-facing content.

Constraint: Keep provider-specific behavior inside core and avoid prompt-routing or bot-side hardcoding.

Rejected: Treating pre-tool text as normal content, because it can leak stale commentary into final responses when tools are still pending.

Confidence: Medium-high; covered by focused agent integration tests.

Scope-risk: Limited to ToolCallAgent streaming classification, SpoonReactAI custom prompt preservation, and related tests.

Reversibility: Revert this commit to restore prior terminal-state and streaming behavior.

Directive: Do not commit local config, build artifacts, or secrets.

Tested: python -m py_compile spoon_ai\\agents\\toolcall.py spoon_ai\\agents\\spoon_react.py; python -m pytest tests/test_agent_llm_integration.py -q

Not-tested: Full suite and live spoon-bot websocket replay.

Related: spoon-bot interrupt/session testing surfaced empty or polluted response risk.
…mplete-stream

# Conflicts:
#	spoon_ai/agents/toolcall.py
@veithly
veithly merged commit 3c50b61 into main Apr 30, 2026
1 check passed
@veithly
veithly deleted the codex/fix-openai-incomplete-stream branch April 30, 2026 02:54
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