Skip to content

Chat-to-Responses bridge may render the final answer twice in Codex App when message phase is omitted #542

Closed

Description

@Eleven-is-cool

Client or integration

Codex App

Area

Provider adapter / Chat Completions → Responses bridge

Summary

A terminal assistant answer from an openai-chat provider can be rendered twice in Codex App when the synthesized Responses message omits phase.

The duplicated copies are separated by the App's processing summary (for example, "Processed 23s"), so the first copy appears to be classified as processing/commentary and the second as the final answer.

Only one upstream request and one assistant answer were produced. The duplication occurs while the App consumes the Responses-shaped events generated by OpenCodex.

Reproduction

  1. Configure a generic OpenAI-compatible Chat Completions provider with the openai-chat adapter.
  2. Expose a placeholder model such as example-chat-model to Codex App through OpenCodex's /v1/responses endpoint.
  3. Start a turn that returns one plain-text terminal answer and no tool calls.
  4. In an affected turn, observe the same answer once above the processing summary and again below it.

This may be timing-sensitive; the affected turn completed in about 23 seconds.

Version

@bitkyc08/opencodex 2.7.41

Operating system

macOS 26.4

Provider and model

Redacted generic OpenAI-compatible Chat Completions provider / example-chat-model

Redacted evidence

For the affected turn:

upstream HTTP requests:        1
upstream status:               200
agent_message events:          1
assistant response_item items: 1
task_complete events:          1
all recorded message texts:    identical
assistant message phase:       null / omitted

The single answer is represented in the session as:

event_msg.agent_message       (live event)
response_item.message         (persisted assistant item)
task_complete.last_agent_message (completion metadata)

The App displayed the live copy and then displayed the persisted/final copy again.

A native Responses comparison carries:

{"type":"message","role":"assistant","phase":"final_answer"}

The bridged Chat Completions output carries the same message without phase.

The reasoning item in the affected turn contained only a blank summary, so the duplicate was not generated reasoning content. No retry or second upstream completion occurred.

Expected behavior

One terminal assistant answer should be rendered once as the final answer.

OpenCodex should preserve or synthesize enough phase information for Codex App to classify bridged output consistently.

Suggested mapping / implementation notes

The Chat Completions parser currently emits text deltas without a phase, and the Responses bridge only includes phase when the adapter event supplies one.

A safe fix likely needs turn-aware classification rather than assigning every text delta to final_answer:

  • intermediate text before a tool call → commentary
  • terminal assistant text after successful completion, with no pending tool call → final_answer
  • keep phase consistent across response.output_item.added, response.output_item.done, and the terminal response snapshot

A client-side deduplication fallback would also be useful, but OpenCodex owns the synthesized Responses shape for this adapter.

Relevant public source locations:

  • src/adapters/openai-chat.ts
  • src/bridge.ts

Upstream documentation

Checks

  • I searched existing issues and documentation.
  • The request and response evidence is redacted.
  • No secrets, account details, request IDs, conversation IDs, local paths, provider names, or private model names are included.
  • The expected behavior is based on a concrete Codex App compatibility problem.

Activity

  1. added
    bug
    on Jul 27, 2026
  2. github-actions commented on Jul 27, 2026

    @github-actions
    Contributor
  3. Ingwannu commented on Jul 27, 2026

    @Ingwannu
    Owner

    Confirmed against current dev: this is a real bridge bug. openai-chat emits unphased text_delta events, and bridgeToResponsesSSE() currently finalizes the corresponding message without a phase in both response.output_item.done and the terminal response.completed.output snapshot. The non-streaming builder has the same omission. That matches the redacted session evidence and leaves Codex App to classify the live and persisted forms differently.

    Implementation plan:

    1. Keep an unphased streamed message unresolved while deltas are arriving; do not eagerly label every Chat Completions token as final.
    2. At an authoritative boundary, synthesize the phase: text closed by a tool/search/next-output boundary becomes commentary, while the current text closed by a clean successful done becomes final_answer. Explicit adapter-provided phases remain unchanged.
    3. Put the inferred phase on response.output_item.done and the terminal response snapshot, using the same item ID, and mirror the rule in non-streaming JSON. The initial streaming output_item.added must remain unphased until the future boundary is known; buffering the whole answer just to label that provisional event would regress live streaming.
    4. Add regressions for a plain terminal answer, pre-tool commentary, and explicit-phase preservation, then run the full pre-push gate before pushing to dev.
  4. Ingwannu commented on Jul 27, 2026

    @Ingwannu
    Owner

    Fixed and pushed to dev in d2cc3f65.

    The bridge now keeps unphased live Chat Completions text provisional and assigns the authoritative phase at the boundary where it becomes knowable:

    • a tool/search/reasoning/assistant boundary finalizes preceding text as commentary;
    • a clean terminal done finalizes the current text as final_answer;
    • an adapter-supplied phase always wins.

    The inferred phase is preserved on the same message ID in response.output_item.done and response.completed.output, and the non-streaming JSON path uses the same rule. The initial output_item.added remains unphased rather than buffering and delaying the live stream.

    Regression coverage includes one unphased terminal answer, pre-tool commentary, and explicit-phase preservation. Validation passed: 118 focused tests, typecheck, and the full pre-push gate (5,022 passed / 0 failed), including GUI lint and privacy scan. Closing as fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions