Skip to content

bug(agents): extractAssistantVisibleText leaks commentary when final_answer exists but is empty #61474

Closed

Description

@100yenadmin

Bug

After #59643 merged, extractAssistantVisibleText() in src/agents/pi-embedded-utils.ts:333-339 can still leak commentary as user-visible text.

Repro condition

When a mixed-phase assistant message has a final_answer block that sanitizes to empty (e.g. whitespace-only or stripped), the function falls back to extractAssistantTextForPhase(msg) with no phase argument, which returns unphased text. If the message also contains commentary blocks, that commentary can become the visible output.

Expected behavior

If final_answer is present but empty, visible output should be empty — not fall back to commentary/unphased text. "No answer" is safer than surfacing chain-of-thought.

Code location

  • src/agents/pi-embedded-utils.ts:333-339
  • The fallback path at extractAssistantTextForPhase(msg) (no phase) returns resolvedPhase === undefined blocks only, but the presence of explicit phased blocks changes unphased fallback behavior (:280-285, 297-321).

Severity

P1 — defeats the intended "prefer final_answer, suppress commentary" rule from #59643.

Related

  • Parent fix: #59643
  • Issue: #59150

Activity

  1. 100yenadmin commented on Apr 5, 2026

    @100yenadmin
    ContributorAuthor

    This is part of a family of 5 post-merge findings from adversarial review of #59643. All are in the OpenAI WS → embedded subscribe → delivery path:

    1. bug(agents): extractAssistantVisibleText leaks commentary when final_answer exists but is empty #61474 — empty final_answer fallback leaks commentary ← you are here
    2. bug(agents): commentary partials can still leak as visible output before final_answer arrives #61475 — commentary partials still leak during streaming
    3. bug(agents): OpenAI WS replay drops message-level phase when block has explicit textSignature — commentary leaks on history replay #61476 — replay splitting corrupts phase on mixed messages
    4. bug(agents): OpenAI WS late-map buffering gates on key existence not phase validity — unphased commentary can leak to UI #61477 — late-map buffering gates on key existence, not phase validity
    5. bug(agents): OpenAI function-call replay silently replaces malformed arguments with {} — silent data loss on tool replay #61478 — function-call replay silently loses malformed arguments

    Items 1–4 are the same family: phase-integrity gaps in the OpenAI Responses WS stream/replay/delivery layers. Item 5 is a separate data-loss issue in the same file.

    Follow-up PR addressing adjacent phase-blind surfaces: #61463

  2. 100yenadmin commented on Apr 5, 2026

    @100yenadmin
    ContributorAuthor

    Fix PR: #61481

  3. locked as resolved and limited conversation to collaborators on Apr 9, 2026
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