Skip to content

fix(codex): fall back to stream items when turn.items is empty - #362

Merged
Waishnav merged 1 commit into
Waishnav:mainfrom
rome-xi:fix/361-codex-empty-turn-items
Sep 18, 2026
Merged

Waishnav merged 1 commit into
Waishnav:mainfrom
rome-xi:fix/361-codex-empty-turn-items

Conversation

@rome-xi

@rome-xi rome-xi commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

Summary

Codex app-server can finish a turn with turn.items: [] and itemsView: "notLoaded" while the assistant text only arrived on item/completed (agentMessage). parseCompletedTurn treated any array turn.items as authoritative, so an empty array discarded the stream-collected items and the run failed with PROVIDER_PROTOCOL_ERROR: Codex did not return a final assistant response.

This prefers non-empty turn.items and otherwise uses the items collected from the event stream. I hit this on 1.0.8 with codex-cli 0.139.0 while driving devspace agents run codex for a short smoke prompt; codex exec on the same machine was fine, so the drop was in the app-server turn parse path. v1.1.0-beta.4 still has the same empty-array preference.

Fixes #361

Test plan

  • pnpm exec tsx --test --test-concurrency=1 src/local-agent-codex.test.ts
  • New regression: mock app-server emits item/completed then turn/completed with items: [] / itemsView: "notLoaded"finalResponse === "CODEXOK"

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of completed turns when item details are unavailable in the final response.
    • Streamed agent responses are now correctly preserved and returned during runtime execution.
    • Ensured only the most recent turn items are processed when multiple items are available.

Codex app-server can complete a turn with items: [] and itemsView:
notLoaded while the assistant text only arrived via item/completed.
parseCompletedTurn treated any array turn.items as authoritative, so an
empty array dropped the stream-collected messages and failed with
PROVIDER_PROTOCOL_ERROR.

Prefer non-empty turn.items; otherwise use the collected items.
Regression covers the notLoaded empty-array path.

Fixes Waishnav#361
@coderabbitai

coderabbitai Bot commented Sep 18, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 49937774-e038-4e43-90dc-88553078c17d

📥 Commits

Reviewing files that changed from the base of the PR and between 8e4669c and fc80277.

📒 Files selected for processing (2)
  • src/local-agent-codex.test.ts
  • src/local-agent-codex.ts

Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

The Codex completed-turn parser now uses streamed items when turn.items is empty. Tests simulate itemsView: "notLoaded" and verify that runtime execution returns "CODEXOK".

Changes

Codex turn response handling

Layer / File(s) Summary
Fallback parsing and integration coverage
src/local-agent-codex.ts, src/local-agent-codex.test.ts
parseCompletedTurn falls back to collected streamed items and keeps the MAX_TURN_ITEMS limit. Tests cover a notLoaded turn and verify the "CODEXOK" response.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: waishnav

Merge Risk: ⚪ Minimal · up to fc802

The parser now preserves streamed assistant responses for unloaded turns, and the regression test verifies successful completion.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: using streamed items when turn.items is empty.
Linked Issues check ✅ Passed The change satisfies issue #361. parseCompletedTurn now uses stream-collected items when turn.items is empty, including itemsView: "notLoaded". The regression test emits an item/completed ag…
Out of Scope Changes check ✅ Passed The pull request changes only src/local-agent-codex.ts and its regression test. The parser change and test directly support issue #361. No unrelated behavior or files are changed.
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

A rabbit watched the streamers flow
The empty turn had more to show
CODEXOK hopped into the light
The parser caught the text just right
And tests now guard the trail tonight

Comment @coderabbitai help to get the list of available commands.

@greptile-apps

greptile-apps Bot commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

Safe to merge.

What we checked:

  • Reviewed the completed-turn parsing and regression case for empty turn.items with itemsView notLoaded as part of general contract validation. T-Rex
  • Ran the focused Codex app-server regression flow on the current commit and confirmed the flow emitted an assistant item/completed event before completion with an empty item snapshot, returning CODEXOK with one passing test, zero failures, and exit code 0. T-Rex
  • Executed the regression validation script trex-artifacts/codex-empty-turn-items-regression-command.sh to exercise the empty-turn scenario. T-Rex
  • Reviewed the test output in trex-artifacts/codex-empty-turn-items-02-after.log, confirming the expected result and exit code, with no before-capture applicable since validation ran only against the current commit. T-Rex
  • Linked the two regression artifacts to their proofs to support evaluation of the regression scenario and its command-based validation. T-Rex

Summary

This change preserves assistant responses when Codex completes a turn with an empty item snapshot by using items already received from the event stream. The focused regression flow confirms the response is returned for itemsView: "notLoaded".

Reviews (1) · Last reviewed commit: "fix(codex): fall back to stream items wh..."

@Waishnav

Copy link
Copy Markdown
Owner

Thanks for the clear repro and focused fix — confirmed locally against Codex 0.139.0 and newer. Much appreciated!

@Waishnav
Waishnav merged commit 531d3f9 into Waishnav:main Sep 18, 2026
2 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.

codex subagent fails with "did not return a final assistant response" when app-server returns empty turn.items

2 participants