fix: recover agent message text from item/completed when deltas are missing#266
Open
maojindao55 wants to merge 1 commit into
Open
Conversation
…issing Some Responses API providers (e.g. Volcengine Ark) emit reasoning items in output_item.added without the content/summary fields that Codex's active-item state machine expects. When this happens, the state machine fails to register an active item and all subsequent streaming deltas (including output_text.delta) are silently dropped. The model still generates text and Codex surfaces it via the item/completed notification. However, codex-acp ignored agentMessage items in completeItemEvent (return null), so the text was lost entirely and only the reasoning/thinking appeared in the client. This PR mirrors the existing reasoning fallback pattern for agentMessage: - Track item IDs that received agentMessage deltas (seenAgentMessageDeltaItemIds) in createTextEvent - In completeItemEvent, if no deltas were seen for the item, emit the text from item.text as an agent_message_chunk - If deltas were seen, skip (no duplication) This is a purely additive fallback -- providers whose streaming works correctly (e.g. OpenAI) are unaffected because seenAgentMessageDeltaItemIds will contain the item ID and the completed event returns null.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Some Responses API providers (e.g. Volcengine Ark / 火山方舟) emit reasoning items in
output_item.addedwithout thecontent/summaryarray fields that Codex's internal active-item state machine expects. When this happens, the state machine fails to register an active item, and all subsequent streaming deltas — includingoutput_text.delta— are silently dropped with errors like:The model does generate text (confirmed by
outputTokensin usage), and Codex successfully surfaces it via theitem/completednotification. However, codex-acp ignoredagentMessageitems incompleteItemEvent(return null), so the text was lost entirely. Users on affected providers only saw the reasoning/thinking content, with no actual assistant reply.Root Cause (confirmed via logs)
stream_events_utils(SSE parsing)codex_core::util(active-item state machine)The TUI mode bypasses the state machine, so
codexCLI works fine. The app-server mode uses it and drops deltas — but the full text is still available initem/completed.Fix
Mirror the existing reasoning fallback pattern for agentMessage:
item/agentMessage/deltain a newseenAgentMessageDeltaItemIdsset (increateTextEvent)completeItemEvent, if no deltas were seen for theagentMessageitem, emititem.textas anagent_message_chunknull(no duplication)This mirrors exactly how
reasoningitems are already handled (seenReasoningDeltaItemIds+createCompletedReasoningEvent).Impact
seenAgentMessageDeltaItemIdscontains the item ID, so the completed event returnsnullas beforeitem/completedinstead of being lostTesting
Added
agent-message-fallback.test.tswith two cases:All 280 existing tests still pass.
Reproduction
Provider config (Volcengine Ark):
With this config,
codexCLI (TUI) outputs text correctly, but any ACP client using codex-acp sees only thinking content and no assistant reply.