Skip to content

fix(codex): preserve streamed output text deltas#2967

Merged
afjcjsbx merged 2 commits into
sipeed:mainfrom
miruchigawa:main
May 31, 2026
Merged

fix(codex): preserve streamed output text deltas#2967
afjcjsbx merged 2 commits into
sipeed:mainfrom
miruchigawa:main

Conversation

@miruchigawa
Copy link
Copy Markdown
Contributor

📝 Description

Fixes OpenAI/Codex OAuth empty responses when the backend streams valid text through response.output_text.delta but sends a final response.completed event with response.output set to null.

The Codex provider now accumulates streamed output_text delta events while reading the response stream. If the final parsed response has no content, PicoClaw falls back to the accumulated streamed text instead of reporting a false empty model response.

This also adds a regression test for the issue #2953 stream shape: response.output_text.delta contains OK, followed by response.completed with null output.

🗣️ Type of Change

  • 🐞 Bug fix (non-breaking change which fixes an issue)
  • ✨ New feature (non-breaking change which adds functionality)
  • 📖 Documentation update
  • ⚡ Code refactoring (no functional changes, no api changes)

🤖 AI Code Generation

  • 🤖 Fully AI-generated (100% AI, 0% Human)
  • 🛠️ Mostly AI-generated (AI draft, Human verified/modified)
  • 👨‍💻 Mostly Human-written (Human lead, AI assisted or none)

🔗 Related Issue

Fixes #2953

📚 Technical Context (Skip for Docs)

  • Reference URL: https://developers.openai.com/api/docs/guides/streaming-responses?api-mode=responses
  • Reasoning: OpenAI Responses streaming is event-driven, and text can arrive incrementally in response.output_text.delta events. The final response.completed event should be treated as stream completion; for Codex OAuth it may not include populated response.output, so PicoClaw needs to preserve streamed deltas before parsing the final response.

� Test Environment

  • Hardware: Linux development workspace / PC
  • OS: Linux
  • Model/Provider: OpenAI/Codex OAuth (gpt-5.3-codex issue path; local regression uses mocked Codex Responses stream)
  • Channels: CLI agent

📸 Evidence (Optional)

Click to view Logs/Screenshots
go test ./pkg/providers/oauth -run TestCodexProvider_ChatRoundTrip_OutputTextDeltaFallback -count=1
# ok   github.com/sipeed/picoclaw/pkg/providers/oauth

go test ./pkg/providers/oauth -count=1
# ok   github.com/sipeed/picoclaw/pkg/providers/oauth

make build
# Build complete: build/picoclaw-linux-amd64
# Build complete: build/picoclaw

./build/picoclaw agent -m "hai" --model "gpt-5.4" --no-color
# ██████╗ ██╗ ██████╗ ██████╗  ██████╗██╗      # █████╗ ██╗    ██╗
# ██╔══██╗██║██╔════╝██╔═══██╗██╔════╝██# ║     ██╔══██╗██║    ██║
# ██████╔╝██║██║     ██║   ██║██║     ██║     # ███████║██║ █╗ ██║
# ██╔═══╝ ██║██║     ██║   ██║██║     ██║     # ██╔══██║██║███╗██║
# ██║     # ██║╚██████╗╚██████╔╝╚██████╗███████╗██# ║  ██║╚███╔███╔╝
# ╚═╝     ╚═╝ ╚═════╝ ╚═════╝  # ╚═════╝╚══════╝╚═╝  ╚═╝ ╚══╝╚══╝
#
#
# � hai 😄 what’s up?

☑️ Checklist

  • My code/docs follow the style of this project.
  • I have performed a self-review of my own changes.
  • I have updated the documentation accordingly.

OpenAI/Codex OAuth streams can return text through response.output_text.delta while the final response.completed payload has response.output set to null. That made PicoClaw report an empty model response even though the backend returned valid content.

Accumulate streamed output_text delta events during the Codex response stream and use them as a fallback when the parsed final response has no content. Add a regression test covering the null final output case from issue sipeed#2953.
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented May 30, 2026

CLA assistant check
All committers have signed the CLA.

@afjcjsbx
Copy link
Copy Markdown
Collaborator

@miruchigawa Hi thanks for the PR, pls fix lint 🙏

@miruchigawa
Copy link
Copy Markdown
Contributor Author

@afjcjsbx pls review it asap 🔥

@afjcjsbx afjcjsbx merged commit 13e1833 into sipeed:main May 31, 2026
5 checks passed
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.

Bug: OpenAI/Codex OAuth returns empty response because response.output_text.delta stream events are ignored

4 participants