Skip to content

buildEmbeddedRunPayloads leaks "commentary" phase text to channel delivery for codex / phase-tagged providers #80458

Closed

Description

@tommyvd02-ui

Summary

When the active model returns assistant content as phase-tagged text blocks (type: "text" with textSignature.phase), buildEmbeddedRunPayloads ships the raw streamed assistantTexts to channel-delivery payloads, which includes the commentary phase blocks. The final_answer-only filter (extractAssistantVisibleText) is only consulted as a fallback when streaming captured nothing.

End-user impact: reasoning summaries ("Need answer. Current? ...", "Responding to user's food list...") get delivered to iMessage / Telegram / etc. alongside or instead of the final reply.

Version: 2026.5.7. Provider: openai-codex/gpt-5.5 via OAuth. The same issue would affect any provider whose responses include textSignature.phase blocks.

Reproduction

  1. Configure an agent with model: "openai-codex/gpt-5.5" (or any other provider that returns phase-tagged blocks).
  2. Send a non-trivial question (one that elicits some internal reasoning).
  3. Observe the channel-delivered reply (iMessage / Telegram / etc).

The delivered text frequently contains both a commentary-phase preamble and the final_answer. Sometimes only the commentary if the run terminated before final_answer was emitted.

An openclaw agent --json probe of the same agent + session is clean, because result.payloads[*].text comes from a separate construction path that already calls extractAssistantVisibleText correctly. So the bug isn't visible from CLI testing — only from real channel delivery.

Root cause

dist/pi-embedded-Bcz04p2i.js, function buildEmbeddedRunPayloads (around line 1346 in 2026.5.7):

const answerTexts = suppressAssistantArtifacts ? [] : (
    shouldPreferRawAnswerText && fallbackRawAnswerText ? [fallbackRawAnswerText]
    : hasAssistantTextPayload ? nonEmptyAssistantTexts     // <-- raw streamed chunks, includes commentary
    : fallbackAnswerText ? [fallbackAnswerText]            // <-- phase-filtered, only used as fallback
    : []
).filter((text) => !shouldSuppressRawErrorText(text));

nonEmptyAssistantTexts is params.assistantTexts.filter(...) — the raw streamed chunks the provider emitted during the run. The codex stream doesn't surface textSignature.phase per-chunk, so these contain both phases concatenated.

fallbackAnswerText is extractAssistantVisibleText(params.lastAssistant), which already correctly filters for phase: "final_answer" (or returns the unphased content when no phase tags exist). But it's only used when hasAssistantTextPayload is false — i.e. when streaming was empty, which is rare for non-empty turns.

The filter logic exists elsewhere in the codebase and works:

  • extractAssistantVisibleText (used by CLI/JSON output path)
  • shouldSuppressAssistantEventForLiveChat in live-chat-projector (used by TUI display)
  • The commentary enum is documented in protocol-validators with the comment "Classifies an assistant message as interim commentary or final answer text"

The channel-delivery payload builder is just the one place this filter isn't applied.

Suggested fix

When the assistant message has explicit phase metadata, route through the already-phase-filtered fallbackAnswerText instead of the raw stream. Non-phase-tagged providers (Anthropic API, OpenAI API path, etc.) are unaffected because lastAssistantHasPhaseMetadata returns false for them.

const lastAssistantHasPhaseMetadata = (() => {
    const c = params.lastAssistant && params.lastAssistant.content;
    if (!Array.isArray(c)) return false;
    for (const b of c) {
        if (!b || b.type !== "text" || !b.textSignature) continue;
        try {
            const sig = typeof b.textSignature === "string"
                ? JSON.parse(b.textSignature) : b.textSignature;
            if (sig && sig.phase) return true;
        } catch (e) {}
    }
    return false;
})();
const answerTexts = suppressAssistantArtifacts ? [] : (
    lastAssistantHasPhaseMetadata && fallbackAnswerText ? [fallbackAnswerText]
    : shouldPreferRawAnswerText && fallbackRawAnswerText ? [fallbackRawAnswerText]
    : hasAssistantTextPayload ? nonEmptyAssistantTexts
    : fallbackAnswerText ? [fallbackAnswerText]
    : []
).filter((text) => !shouldSuppressRawErrorText(text));

I've been running this patch locally against 2026.5.7 for a few hours without regressions; reasoning-trigger probes and plain conversational turns both deliver only the final_answer block.

Why this matters

Affects every channel-delivered reply on phase-tagging providers — iMessage (BlueBubbles), Telegram, etc. The CLI path being clean made it hard to spot until I started reading session JSONL files and comparing messageContent.content[*].textSignature.phase against what landed in the actual channel.

Happy to open a PR if helpful.

Activity

  1. clawsweeper commented on May 10, 2026

    @clawsweeper
    Contributor

    Thanks for the context here. I did a careful shell check against current main, and this is already implemented.

    Close: current main no longer lets a single raw streamed commentary-plus-final assistant text win over the canonical final answer, and the same behavior is present in the v2026.6.6 release.

    So I’m closing this as already implemented rather than keeping a duplicate issue open.

    Review details

    Best possible solution:

    Keep the current canonical final-answer payload selection and regression coverage; no further OpenClaw core work is needed for this report.

    Do we have a high-confidence way to reproduce the issue?

    Yes. The historical failure is source-reproducible with one raw streamed assistantTexts entry containing commentary plus final text and structured assistant blocks carrying commentary and final_answer; current tests now lock that case down.

    Is this the best way to solve the issue?

    Yes. The current implementation is the better fix because it prefers canonical structured final-answer text before raw accumulated assistant text while preserving existing media-directive behavior.

    Security review:

    Security review: Non-PR issue triage; no patch security review applies.

    AGENTS.md: found and applied where relevant.

    What I checked:

    Likely related people:

    • joshavant: Authored and merged the generic final assistant payload hardening in fix(agents): harden final assistant payload assembly #82850, which passed the current attempt assistant into payload assembly and reduced reliance on streamed preview fragments. (role: merged fix author; confidence: high; commits: 7d1317634e5b; files: src/agents/pi-embedded-runner/run.ts, src/agents/pi-embedded-runner/run/payloads.ts, src/agents/pi-embedded-runner/run/payloads.test.ts)
    • compoodment: Added the focused one-chunk commentary-plus-final payload regression that directly matches this report's failing shape. (role: regression coverage contributor; confidence: high; commits: 6ebe91d92b2a; files: src/agents/pi-embedded-runner/run/payloads.test.ts)
    • steipete: Authored nearby canonical embedded reply payload selection and related payload hardening history before the current file rename. (role: recent area contributor; confidence: medium; commits: 83a108080de7, c3ab2def0a93; files: src/agents/pi-embedded-runner/run/payloads.ts, src/agents/pi-embedded-runner/run/payloads.test.ts)
    • ragesaq: Current main blame for the renamed embedded-runner payload file points to this commit carrying the fixed payload selection into the current path. (role: current-path carrier; confidence: medium; commits: a15427d605fe; files: src/agents/embedded-agent-runner/run/payloads.ts, src/agents/embedded-agent-runner/run/payloads.test.ts)

    Codex review notes: model internal, reasoning high; reviewed against f1b8827d20c8; fix evidence: release v2026.6.6, commit 8c802aa68351.

  2. added
    P1
    impact:message-loss
    on May 17, 2026
  3. added a commit that references this issue on May 25, 2026
    0feed6a
  4. HangGlidersRule commented on May 27, 2026

    @HangGlidersRule
    Contributor

    Confirming this bug still reproduces on 2026.5.22 (a374c3a) against openai-responses provider pointing at Azure AI Foundry's OpenAI Responses endpoint with gpt-5.5, on Slack channel delivery.

    Environment

    • OpenClaw: 2026.5.22 (a374c3a) (Homebrew global)
    • Node: v26.0.0
    • Channel: Slack (Socket Mode), group channel
    • Provider: openai-responses against Azure AI Foundry's OpenAI Responses API
    • Model: gpt-5.5
    • Model catalog entry:
      {
        "id": "gpt-5.5",
        "api": "openai-responses",
        "reasoning": true,
        "input": ["text", "image"]
      }
    • Reasoning effort: medium (session override; problem also reproduces at high)
    • streaming.mode: partial (channel-level and global)

    Reproduction

    1. Configure an agent on a Slack channel with gpt-5.5 via the openai-responses provider against Azure AI Foundry. Reasoning enabled, summary auto (the OpenClaw transport default).
    2. Send a non-trivial multi-step message that elicits internal planning, e.g. a code-review request with several files to inspect.
    3. Observe the delivered Slack message.

    What lands in the channel

    A delivered Slack message containing first-person stream-of-consciousness commentary, often in fragmented prose with no markdown formatting, e.g. (real captured leak, redacted secrets and project names):

    It displayed redacted SLACK_BOT_TOKEN = ***"SLACK_BOT_TOKEN", ""). That may be output masking, but could be real corruption? Need cat with od maybe. Use python repr produced redacted by tool display maybe the actual string contains os.environ.get. But if compile passed, ***"SLACK... would be syntax error. compile passed. so redaction. Good.

    Potential issue: <module_a> still imports separately and also _get_db uses from <module_b>; if env <ENV_VAR> changes after import? same behavior likely.

    Potential issue: circular import eliminated? command files no <module_a> imports, yes.

    Need compare behavior? There is an issue: ClassA imports SymbolB no longer? It doesn't in import list. The handler probably calls SymbolB(). Need grep.

    That is GPT-5.5's commentary-phase content. It's not the model's final answer — the model also emits a real answer in a separate final_answer-phase block in the same turn. The CLI / agent JSON path delivers only the final_answer; only channel delivery is affected.

    Session JSONL evidence

    In the agent session file, one assistant turn shows up as paired blocks:

    • type: "thinking" block — Anthropic-style reasoning summary captured from response.reasoning_summary_text.delta events (OK — this stays hidden).
    • type: "text" block with a textSignature carrying phase metadata, containing the commentary-style prose.

    When this single text block makes it to channel delivery, the commentary becomes the visible Slack reply.

    Root cause confirmation

    Source-tracing on the installed dist matches the codex review of 2026-05-10 against 758a5f1eda7f:

    pi-embedded-CsSFzly6.js buildEmbeddedRunPayloads (the function this issue's title references, in 5.22 still in the same shape):

    const nonEmptyAssistantTexts = params.assistantTexts.filter((text) => text.trim().length > 0);
    // ...
    const fallbackAnswerText = assistantForPayload ? extractAssistantVisibleText(assistantForPayload) : "";
    // ...
    const hasAssistantTextPayload = nonEmptyAssistantTexts.length > 0;
    const answerTexts = (... // simplified
      shouldUseCanonicalFinalAnswer ? [fallbackAnswerSourceText]
      : hasAssistantTextPayload ? nonEmptyAssistantTexts
      : fallbackAnswerText ? [fallbackAnswerText]
      : []
    ).filter(...);

    extractAssistantVisibleText correctly prefers phase: "final_answer" text blocks when phase metadata is present. But hasAssistantTextPayload wins ahead of it whenever there's a single raw streamed entry — which is exactly the GPT-5.5 Responses shape when commentary + final_answer arrive as one streamed block.

    So when GPT-5.5 streams commentary text then final answer text into the same streamed text payload entry, the payload builder ships the raw streamed text (commentary included) to the channel instead of consulting the phase-filtered fallbackAnswerText.

    Why the existing channel-side guards do not catch this

    • streaming.mode config has no effect — the leak happens in payload selection for the final reply, not in the live preview path.
    • pushReasoningProgress early-returns when streamMode !== "progress", so changing streaming mode does not help.
    • stripReasoningTagsFromText only strips <thinking> / <think> style XML tags. GPT-5.5 commentary-phase content has no such tags; it's plain prose with phase metadata on the block envelope, not in the text.
    • The type: "thinking" block for the same turn is correctly hidden — only the commentary-phase type: "text" block leaks.
    • redact-thinking-* controls do not apply: commentary is not a thinking block, it's a text block.

    What 5.26 did not fix

    5.26 (current latest) includes reply/perf, transcript, and provider improvements, but no entry that touches buildEmbeddedRunPayloads phase selection. We verified the same code shape remains in the 5.26 dist. The PRs that attempted #80458 fixes (#80491, #82645, #83340) are all closed without merge.

    Workarounds we tried

    • compat.supportedReasoningEfforts — only affects effort level routing; doesn't change phase handling.
    • Switching streaming.mode between partial/block/progress — leak persists; only off suppresses it by removing the streaming path entirely.
    • Channel-level reasoning suppression / /reasoning off — model still emits commentary because OpenClaw's openai-transport-stream always requests reasoning.summary: "auto" for any reasoning-capable OpenAI model (options?.reasoningSummary || "auto" is hardcoded), so we get summary blocks regardless of channel display settings.

    Recommended fix direction (echoing the May 10 review)

    In buildEmbeddedRunPayloads, prefer the phase-filtered fallbackAnswerText whenever lastAssistant content blocks carry explicit phase metadata, regardless of nonEmptyAssistantTexts.length. The current length > 1 guard misses the single-streamed-entry case.

    Adding regression coverage for:

    • nonEmptyAssistantTexts.length === 1, single entry containing commentary + final_answer concatenated.
    • lastAssistant.content[*].textSignature.phase === "final_answer" on at least one block.
    • Channel-delivered payload matches the final_answer-only text, not the raw streamed entry.

    Happy to test a candidate fix against this Slack repro path before any merge.

  5. WarrenJones commented on May 27, 2026

    @WarrenJones
  6. locked as resolved and limited conversation to collaborators on Jun 25, 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

    P1impact:message-loss

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions