Skip to content

fix(streaming): suppress NO_REPLY prefix tokens in partial replies - #33663

Closed
Sid-Qin wants to merge 1 commit into
openclaw:mainfrom
Sid-Qin:fix/33544-streaming-noreply-leak
Closed

Sid-Qin wants to merge 1 commit into
openclaw:mainfrom
Sid-Qin:fix/33544-streaming-noreply-leak

Conversation

@Sid-Qin

@Sid-Qin Sid-Qin commented Mar 4, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Problem: With streaming: partial enabled, the first streamed tokens of NO_REPLY (e.g., "NO") are emitted to clients via onPartialReply before the full directive is recognized. Channels like Telegram briefly display "NO" as a visible message to the user before the reply is suppressed.
  • Why it matters: Users see confusing partial text ("NO") flash briefly in their chat before it disappears, degrading the user experience.
  • What changed: src/agents/pi-embedded-subscribe.handlers.messages.ts — imported isSilentReplyPrefixText and SILENT_REPLY_TOKEN; added a check before onPartialReply that suppresses emission when the accumulated text matches a known silent reply prefix.
  • What did NOT change: The final NO_REPLY detection, non-streaming paths, and the isSilentReplyPrefixText utility itself are unchanged.

Change Type (select all)

  • Bug fix
  • Feature
  • Refactor
  • Docs
  • Security hardening
  • Chore/infra

Scope (select all touched areas)

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

Linked Issue/PR

User-visible / Behavior Changes

  • Channels with streaming enabled no longer flash partial "NO" text before suppressing NO_REPLY directives.

Security Impact (required)

  • New permissions/capabilities? No
  • Secrets/tokens handling changed? No
  • New/changed network calls? No
  • Command/tool execution surface changed? No
  • Data access scope changed? No

Repro + Verification

Environment

  • OS: Any
  • Runtime: Node.js
  • Integration/channel: Telegram with streaming: partial

Steps

  1. Configure an agent with streaming: partial and connect via Telegram
  2. Trigger a scenario where the agent responds with NO_REPLY
  3. Observe the Telegram chat

Expected

  • No visible message is sent (the directive is fully suppressed)

Actual

  • Before fix: "NO" briefly appears then vanishes
  • After fix: No partial text is emitted

Evidence

The isSilentReplyPrefixText utility is already well-tested in src/auto-reply/tokens.test.ts. The change adds a single guard clause that leverages this existing utility.

Human Verification (required)

  • Verified scenarios: NO_REPLY token, normal reply text, partial NO_REPLY prefix
  • Edge cases checked: text starting with "NO" that is NOT a NO_REPLY directive (handled by the existing prefix check logic)
  • What I did not verify: Real Telegram streaming end-to-end

Compatibility / Migration

  • Backward compatible? Yes
  • Config/env changes? No
  • Migration needed? No

Failure Recovery (if this breaks)

  • How to disable/revert: Revert this commit; partial "NO" would reappear
  • Files/config to restore: src/agents/pi-embedded-subscribe.handlers.messages.ts
  • Known bad symptoms: If the prefix check is too broad, legitimate messages starting with "NO" might be delayed (mitigated by isSilentReplyPrefixText only matching exact NO_REPLY prefixes)

Risks and Mitigations

isSilentReplyPrefixText is a narrow check — it only suppresses text that is an exact prefix of the configured SILENT_REPLY_TOKEN. Normal messages starting with "No" or "Not" are unaffected.

With streaming: partial, the first tokens of NO_REPLY ("NO") leak
to channels like Telegram as a visible message before the full
directive is recognized.  Check isSilentReplyPrefixText before calling
onPartialReply so all channels benefit from early suppression.

Closes openclaw#33544
@greptile-apps

greptile-apps Bot commented Mar 4, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a UX bug where partial NO_REPLY tokens (e.g. "NO") were briefly emitted to user-facing channels (such as Telegram) during streaming before the full directive was recognized and suppressed. The fix adds a single guard in handleMessageUpdate that calls the existing, well-tested isSilentReplyPrefixText utility to block onPartialReply from firing when the accumulated cleaned text is a known prefix of SILENT_REPLY_TOKEN.

  • Guard logic is correct and narrow: isSilentReplyPrefixText only matches all-uppercase, A-Z/underscore-only text that is a true prefix of NO_REPLY. Mixed-case natural language starting with "No" or "Not" is unaffected.
  • onAgentEvent / emitAgentEvent are unguarded: These callbacks still receive partial NO_REPLY tokens (e.g. "NO") before the new check. If any current or future consumer of onAgentEvent drives user-visible output, it would exhibit the same flash. This should be confirmed as intentional if onAgentEvent is purely internal/logging.
  • No new handler-level tests: The PR relies on the existing tokens.test.ts coverage for isSilentReplyPrefixText. A unit test for handleMessageUpdate covering the suppression path would increase confidence.

Confidence Score: 4/5

  • Safe to merge with a minor open question about whether onAgentEvent consumers also need the same guard.
  • The change is minimal (one guard clause), the underlying utility is already well-tested, and the prefix-detection logic is carefully narrowed to avoid false positives. The only uncertainty is whether onAgentEvent — which is still called with suppressed partial tokens — could drive user-visible output in any integration.
  • No files require special attention beyond the single changed file.

Last reviewed commit: 7c9faa0

@greptile-apps

greptile-apps Bot commented Mar 4, 2026

Copy link
Copy Markdown
Contributor
Additional Comments (1)

src/agents/pi-embedded-subscribe.handlers.messages.ts, line 241
onAgentEvent still emits suppressed NO_REPLY prefix tokens

The new guard correctly blocks onPartialReply from seeing partial NO_REPLY tokens, but emitAgentEvent (line 216) and ctx.params.onAgentEvent (line 225) are still called with the same cleanedText (e.g. "NO") before the prefix check runs. If any current or future consumer of onAgentEvent renders partial text to end users (e.g. a channel adapter that hooks into the general event bus), it would still flash the unwanted prefix.

If the intent is strictly to protect only the channel-specific onPartialReply callback, this is fine as-is. But if onAgentEvent can drive user-visible output in any integration, the same guard should wrap those calls too:

const isSilentPrefix = isSilentReplyPrefixText(cleanedText, SILENT_REPLY_TOKEN);
if (!isSilentPrefix) {
  emitAgentEvent({ ... });
  void ctx.params.onAgentEvent?.({ ... });
}
ctx.state.emittedAssistantUpdate = true;
if (ctx.params.onPartialReply && ctx.state.shouldEmitPartialReplies) {
  if (!isSilentPrefix) {
    void ctx.params.onPartialReply({ ... });
  }
}

Worth confirming this is intentional before merging.

@obviyus obviyus self-assigned this Mar 4, 2026
@obviyus

obviyus commented Mar 4, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the fix proposal.

We re-verified this path in current main and this specific NO_REPLY lead-fragment leak is already handled upstream in the shared streaming runner (before channel partial callbacks), with additional Telegram boundary/silent-token hardening already landed.

So this PR is now redundant. The fix is already queued for the next release line (2026.3.3).

Closing this PR so we keep one source of truth for the behavior.

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

Labels

agents Agent runtime and tooling size: XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Telegram streaming leaks partial NO_REPLY as visible message

2 participants