Merged
Size
M
Change Breakdown
Bug Fix85%
Security15%
#61282fix(agents): suppress commentary-phase output leaks

Internal planning text now blocked from user output

A bug in the embedded subscribe layer was letting internal assistant reasoning bleed through to users via Telegram partials and final replies.

Internal planning messages from the assistant—things like "Need send..." or "Need update tracker..."—were leaking into user-visible outputs. These commentary-phase messages, used for internal reasoning, should never reach end users, but a gap in the embedded subscribe boundary meant they were being streamed to Telegram partials and included in final replies.

The fix operates at the shared delivery bridge that controls what actually gets sent to users. When an assistant message carries a phase:"commentary" marker, output is now suppressed before it can enter partial-reply buffers, block-reply flush paths, or final text emission. The system handles both direct phase metadata and cases where the phase information is embedded inside textSignature metadata.

Normal assistant responses with final_answer phase and regular assistant messages continue to flow unchanged. The change only affects commentary-phase content.

In the agent pipeline, this closes the gap where internal reasoning could reach users before the real answer arrived.

View Original GitHub Description

Summary

  • Problem: assistant messages carrying phase:"commentary" were already being preserved by the OpenAI Responses conversion path, but the embedded subscribe delivery bridge still treated them like normal user-visible assistant output.
  • Why it matters: internal planning shards like Need send... or Need update tracker... could leak into Telegram partials and final reply paths before the real answer.
  • What changed: suppress commentary-phase assistant output at the shared embedded subscribe boundary, whether the phase arrives as message.phase or only inside textSignature metadata.
  • Hardening: commentary text_* updates now bail out before mutating visible-output buffers, partial-reply state, or block-reply flush paths.

Root Cause

  • Root cause: src/agents/pi-embedded-subscribe.handlers.messages.ts ignored assistant delivery phase when deciding what to stream or flush to the user.
  • Existing evidence in code: phase metadata is already preserved upstream, including the textSignature-only shape covered by src/agents/openai-ws-stream.test.ts.
  • Failure mode: commentary text could enter onPartialReply, block-reply flush, or final assistant text emission even though it was internal-only output.

Why This Layer

  • This is the correct production boundary for OpenClaw because it controls the actual user-visible delivery paths.
  • A Pi-side render/print fix is still reasonable upstream hygiene, but it does not replace fixing the OpenClaw delivery bridge that Telegram and other embedded surfaces actually use here.
  • Fixing only Telegram lane wiring would be too narrow; the bug is broader than one preview transport.

Red-Team / Hardening Review

  • Checked whether the fix only covered message.phase: it did not originally, so this PR explicitly covers the textSignature-only commentary shape too.
  • Checked whether commentary still polluted internal visible-output state even when suppressed: it did originally, so this PR now returns early before mutating partial/block buffers on commentary text_* updates.
  • Checked whether the change accidentally suppresses legitimate final answers: suppression is limited to phase:"commentary"; final_answer and normal assistant messages still flow unchanged.
  • Checked whether this belongs in a refactor instead: no. The minimal root-cause fix is small and local; broader dedupe with other phase helpers can wait.

Change Type

  • Bug fix
  • Feature
  • Refactor required for the fix
  • Docs
  • Security hardening
  • Chore/infra

Scope

  • Gateway / orchestration
  • Skills / tool execution
  • Auth / tokens
  • Memory / storage
  • Integrations
  • API / contracts
  • UI / DX
  • CI/CD / infra

User-visible / Behavior Changes

  • Commentary-phase planning text no longer leaks into user-visible assistant partials or final replies.
  • This applies both to direct message.phase commentary and to replay/live shapes that only carry the phase in textSignature metadata.

Tests

Targeted serial verification on mb-air:

bunx vitest run \
  src/agents/pi-embedded-subscribe.handlers.messages.test.ts \
  src/agents/pi-embedded-subscribe.subscribe-embedded-pi-session.suppresses-commentary-phase-output.test.ts \
  src/agents/pi-embedded-subscribe.subscribe-embedded-pi-session.subscribeembeddedpisession.test.ts \
  --pool forks --maxWorkers 1

Result: 3 files, 38 tests passed.

AI / Testing Notes

  • AI-assisted: yes
  • Testing: targeted local serial tests passed
© 2026 · via Gitpulse