Skip to content

bug(agents): OpenAI WS late-map buffering gates on key existence not phase validity — unphased commentary can leak to UI #61477

Closed

Description

@100yenadmin

Bug

After #59643 merged, the WS late-map buffering in src/agents/openai-ws-stream.ts can permanently misattribute early text deltas as "no phase."

Root cause

Text deltas are buffered until outputItemPhaseById has the item id. But the map is populated on the first response.output_item.added/done seen for that item, and stores undefined if event.item.phase is missing/invalid at that moment:

outputItemPhaseById.set(event.item.id, itemPhase); // may be undefined
...
if (outputItemPhaseById.has(event.item_id)) emitBufferedTextDelta(...)

The gate is presence of the map key, not validity of the phase. Once an item event arrives with undefined phase, all subsequent text for that item emits immediately as unphased — even if a later output_item.done event would carry the correct phase.

Impact

If a provider emits output_item.added before phase is populated (or emits contradictory metadata between added/done), commentary text can leak as unphased visible content. This is the "malformed/missing phase metadata" edge case that the buffering was meant to protect against.

Code location

  • src/agents/openai-ws-stream.ts:922-945, 953-969, 1029-1049, 1052-1075

Suggested fix

Gate on outputItemPhaseById.get(event.item_id) !== undefined (phase is known and valid), not just outputItemPhaseById.has(event.item_id) (any item event arrived).

Severity

P2 — requires a specific provider timing quirk to trigger, but when it does, it defeats the buffering protection entirely.

Related

  • Parent fix: #59643

Activity

  1. 100yenadmin commented on Apr 5, 2026

    @100yenadmin
    ContributorAuthor

    Part of the post-#59643 adversarial review family. See #61474 for the full list. This is the WS streaming race condition variant — affects the OpenAI Responses API late item-mapping path specifically.

  2. changed the title [-]bug(agents): WS late-map buffering gates on item key existence, not phase validity[/-] [+]bug(agents): OpenAI WS late-map buffering gates on key existence not phase validity — unphased commentary can leak to UI[/+] on Apr 5, 2026
  3. added a commit that references this issue on Apr 6, 2026
    0b9993d
  4. locked as resolved and limited conversation to collaborators on Apr 9, 2026
  5. added a commit that references this issue on Apr 28, 2026
    7772565
  6. added a commit that references this issue on May 2, 2026
    2f0ac03
  7. added a commit that references this issue on May 24, 2026
    ab9afc8
  8. added a commit that references this issue on Aug 16, 2026
    1f800a2
  9. added a commit that references this issue on Sep 29, 2026
    b6c7db1
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

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions