← Back to Pull requests

fix(runtime): stream and fold non-streaming Codex OAuth calls #5723

Closed
unknown closed this pull request without merging on Sep 27, 2026 02:30 UTC
View on GitHub
unknown unknown commented on Sep 25, 2026 12:50 UTC
Author

Summary

On an openai-codex (ChatGPT subscription) connection every tool-free auxiliary call failed: Session titles, goal evaluation, recap, Daily Review and prompt suggestions. Main turns kept working. As a result, Codex Sessions never get a generated title; they fall back to the truncated first message.

The backend rejects the non-streaming request generateText sends, for three separate reasons:

  • 400 "Stream must be set to true"

  • 400 "Unsupported parameter: max_output_tokens"

  • once the request streams, the terminal response.completed event can carry an empty output
  • The fix stays inside buildOpenAiCodexFetch, the adapter that already reshapes Codex requests. For a caller that did not ask to stream, it:

  • sends stream: true and drops max_output_tokens;

  • reads the stream to its terminal event and restores output from response.output_item.done when the terminal event omits it;

  • returns the single Responses body the non-streaming parser expects.
  • A failed, incomplete or truncated stream surfaces as an error rather than an empty or partial success. Streaming callers (main turns) are forwarded exactly as built, including any configured max_output_tokens; see #5736 for that separate failure.

    The stream is recognised by its body, not by content-type. Against the live backend, the stream did not reach this layer with an event-stream content type, and a first version gated on the header never folded anything.

    Trade-off: Codex auxiliary calls no longer carry an output cap. They are bounded by their prompts and by each caller's own result validation.

    Fixes #5711

    Verification

  • subscription-model-fetch.test.ts: 22/22 pass. The five new cases fail without the change:

  • - fold with an empty terminal output, through doGenerate;
    - a streamed turn passed through unfolded, keeping its configured output cap;
    - truncated stream;
    - response.failed;
    - response.incomplete with partial output (content_filter).
  • The test SSE carries no content-type, matching what the live backend delivered.

  • Real backend. I ran a Runtime Host from this branch on a copy of a Desktop workspace with a ChatGPT-subscription connection, did one turn, then read the Session name and the session_title usage row:
  • | model | main | this branch |
    |---|---|---|
    | gpt-6-astra | error, HTTP 400 {"detail":"Stream must be set to true"}; name = truncated first message | success (82 in / 14 out); "Planning a Small Refactor of a Large React Component" |
    | gpt-5.6-sol | (same 400 in the workspace's usage history) | success; "Planning a Large React Component Refactor" |
    | gpt-5.5 | (same 400 in the workspace's usage history) | success; "Refactoring a Large React Component" |

    That workspace's usage_llm_calls had 18 Codex auxiliary rows (titles and goal evaluation), all failed, none succeeded.

  • biome check on the changed files passes, and so does tsc --noEmit for @maka/runtime.

  • The full @maka/runtime suite ran on Windows. Its failures are all in unrelated files and are environmental: EBUSY on temp SQLite cleanup, EPERM on symlink creation, macOS seatbelt tests, and shell tests. I did not run the other workspaces' suites.

  • The pre-commit hook could not run on this Windows machine. scripts/biome-staged-check.mjs spawns node_modules/.bin/biome.cmd with spawnSync and no shell, which Node 22 rejects with EINVAL. I ran its steps manually and all passed: biome check, asf-license-headers check-staged, protocol-epoch-check --staged and git diff --cached --check. The hook problem itself is not part of this PR.
  • AI use

  • No generative tool made a substantive contribution

  • Generative tooling made a substantive contribution
  • Tool(s) and scope: Claude Code (Claude Opus) diagnosed the backend responses, implemented the fix and tests, and ran the verification above; liugddx reviewed. The commit carries a Generated-by trailer.

    Checklist

  • Tests cover the change and fail without it

  • Lint, format, typecheck and the affected suites pass locally
  • Does this PR entail a change in behavior?

  • Yes — described under Summary above

  • No
  • 🤖 Generated with Claude Code

    Diff: 531 lines (+398 / -133) across 6 files Reviewer: liugddx Review duration: 2260m
    All Vouch review confidence checks passed
    Residual risk 0.30 = Change Risk (0.76) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.76 · 531 lines diff across 6 files
    0.76
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.376
    Shallow Review Depth shallow_review_depth
    0.289
    Sensitive Paths sensitive_paths
    0.076
    Ai Authored ai_authored
    0.050
    Real PR Conversation Timeline
    1 comments
    "Review active on #5723"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed sensitive_module
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 76% (HIGH) · Higher = larger blast radius
    76%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 30% · Safe to merge
    30%
    Repository