Repository navigation
fix: suppress silent-reply partial tokens during streaming - #19648
bradleypriest wants to merge 1 commit into
Conversation
During streaming, partial tokens like NO_R or HEARTBEAT_ would leak to Telegram before the full NO_REPLY/HEARTBEAT_OK check could match. Add isSilentReplyPrefix() that checks if accumulated text is a prefix of any silent reply token. Applied in normalizeStreamingText, parseChunk, and startTypingOnText to hold back output until the token either completes (suppress) or diverges (flush normally).
|
|
||
| const silentToken = options?.silentToken ?? SILENT_REPLY_TOKEN; | ||
| const isSilent = isSilentReplyText(text, silentToken); | ||
| const isSilent = isSilentReplyText(text, silentToken) || isSilentReplyPrefix(text, silentToken); |
There was a problem hiding this comment.
Missing HEARTBEAT_TOKEN prefix check
In agent-runner-execution.ts (lines 141-143), normalizeStreamingText checks prefixes for both SILENT_REPLY_TOKEN and HEARTBEAT_TOKEN, but here parseChunk only checks the single silentToken parameter (which defaults to SILENT_REPLY_TOKEN).
This means if parseChunk is ever invoked in a context where partial HEARTBEAT_OK tokens could appear (e.g., "HEART", "HEARTBEAT") without first passing through normalizeStreamingText, they would not be suppressed.
Currently this is mitigated because:
- The main streaming path goes through
normalizeStreamingTextwhich handles both tokens. stripHeartbeatTokenhandles complete tokens upstream.
However, for consistency with the intent of this fix, consider either:
- Also checking
HEARTBEAT_TOKENhere, or - Documenting that heartbeat prefix suppression is intentionally handled only at the
normalizeStreamingTextlevel.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/auto-reply/reply/streaming-directives.ts
Line: 50:50
Comment:
**Missing `HEARTBEAT_TOKEN` prefix check**
In `agent-runner-execution.ts` (lines 141-143), `normalizeStreamingText` checks prefixes for **both** `SILENT_REPLY_TOKEN` and `HEARTBEAT_TOKEN`, but here `parseChunk` only checks the single `silentToken` parameter (which defaults to `SILENT_REPLY_TOKEN`).
This means if `parseChunk` is ever invoked in a context where partial `HEARTBEAT_OK` tokens could appear (e.g., "HEART", "HEARTBEAT") without first passing through `normalizeStreamingText`, they would not be suppressed.
Currently this is mitigated because:
1. The main streaming path goes through `normalizeStreamingText` which handles both tokens.
2. `stripHeartbeatToken` handles complete tokens upstream.
However, for consistency with the intent of this fix, consider either:
- Also checking `HEARTBEAT_TOKEN` here, or
- Documenting that heartbeat prefix suppression is intentionally handled only at the `normalizeStreamingText` level.
<sub>Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!</sub>
How can I resolve this? If you propose a fix, please make it concise.There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ec795c902a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if ( | ||
| isSilentReplyPrefix(text, SILENT_REPLY_TOKEN) || | ||
| isSilentReplyPrefix(text, HEARTBEAT_TOKEN) | ||
| ) { |
There was a problem hiding this comment.
Scope prefix suppression to cumulative stream text
normalizeStreamingText now drops any text that is a prefix of NO_REPLY/HEARTBEAT_OK, but this helper is reused for block-stream delivery via createBlockReplyDeliveryHandler, where payload.text is a chunk delta, not the full accumulated message. In that path, if an early chunk is a prefix (for example "N" followed by "ow..."), the prefix chunk is skipped permanently and later chunks do not restore it, so streamed block replies can be truncated rather than merely delayed.
Useful? React with 👍 / 👎.
|
|
||
| const silentToken = options?.silentToken ?? SILENT_REPLY_TOKEN; | ||
| const isSilent = isSilentReplyText(text, silentToken); | ||
| const isSilent = isSilentReplyText(text, silentToken) || isSilentReplyPrefix(text, silentToken); |
There was a problem hiding this comment.
Avoid prefix-based silent detection on directive deltas
parseChunk now marks any prefix of the silent token as isSilent, but createStreamingDirectiveAccumulator.consume() is fed streaming deltas (not cumulative text) from the subscribe pipeline. Applying prefix checks to each delta can clear ordinary leading chunks like "N"/"NO" before divergence arrives, causing later emitted chunks to miss the dropped prefix (for example "otice"), which corrupts streamed output under chunked delivery.
Useful? React with 👍 / 👎.
|
This might already be covered: PR #19576 by @aldoeliacim seems to address the same problem. Both address isSilentReplyText() being too permissive — the suffix regex can match NO_REPLY at the end of substantive replies, silently suppressing real content. Both approaches have merit — might be worth coordinating. Related issue(s): #19537 If any of these links don't look right, let me know and I'll correct them. |
|
Thanks for the PR and the solid streaming-prefix direction here. These changes have been merged into #19576 (consolidated there with the exact Appreciate the contribution. |
|
Extra thank-you to @bradleypriest for the PR and streaming investigation here. The final consolidated fix path is in #19576, but your input directly helped shape it. |
Summary
NO_R,HEARTBEATleak to Telegram before the fullNO_REPLY/HEARTBEAT_OKsilent-reply check can match. Users briefly see ghost text before it disappears.streamMode: "partial", webchat). Same root cause as Webchat: ghost bubble artifact when model replies with NO_REPLY during streaming #15060.isSilentReplyPrefix()that checks if accumulated stream text is a prefix of a silent token. Applied innormalizeStreamingText,parseChunk, andstartTypingOnTextto hold back output until the token completes (suppress) or diverges (flush normally).isSilentReplyText) is untouched. Non-streaming paths are unaffected. No config changes.Change Type (select all)
Scope (select all touched areas)
Linked Issue/PR
User-visible / Behavior Changes
NO_REPLY,HEARTBEAT_OK) no longer flash partial tokens on streaming channels before being suppressed.Security Impact (required)
NoNoNoNoNoRepro + Verification
Environment
streamMode: "partial"Steps
NO_REPLY)Expected
Actual
NO_RorNO_REetc. before the message disappearsEvidence
New test file
src/auto-reply/tokens.test.tscoversisSilentReplyPrefix(prefix matching, whitespace trimming, non-matches, undefined input) and existingisSilentReplyTextbehavior.Human Verification (required)
NO_REPLYandHEARTBEAT_OKtokens, including edge cases (empty string, whitespace, partial divergence likeNOPE)"N"(matches, causes one-token delay — acceptable since normal responses diverge immediately), empty/whitespace input (returns false), full token as prefix of itself (returns true, consistent withisSilentReplyText)tscfull build (timed out on Pi — lint + vitest passed)Compatibility / Migration
YesNoNoFailure Recovery (if this breaks)
streamMode: "off") as a workaround.src/auto-reply/tokens.ts,src/auto-reply/reply/agent-runner-execution.ts,src/auto-reply/reply/streaming-directives.ts,src/auto-reply/reply/typing.tsNorHcould experience a one-token delay before the first stream flush. This is by design and should be imperceptible.Risks and Mitigations
NO_(e.g."NO_RULES apply here") are delayed by a few tokens before the prefix check diverges and flushes.Appendix
Log of debug/fix conversation with LLM
Greptile Summary
This PR adds streaming-time suppression of partial silent-reply tokens (
NO_REPLY,HEARTBEAT_OK) to prevent ghost text from leaking to external messaging channels (e.g., Telegram). A newisSilentReplyPrefix()utility function intokens.tschecks whether accumulated stream text is a prefix of a known silent token, and this check is wired into the three streaming code paths:normalizeStreamingText(agent runner),parseChunk(streaming directives), andstartTypingOnText(typing controller).isSilentReplyPrefixfunction is clean, well-tested, and handles edge cases (undefined, empty, whitespace).agent-runner-execution.tschecks bothSILENT_REPLY_TOKENandHEARTBEAT_TOKENprefixes, whilestreaming-directives.tsandtyping.tsonly check the configuredsilentToken(defaults toSILENT_REPLY_TOKEN). This is acceptable because: (1) heartbeat runs disable typing entirely viaresolveTypingMode, and (2)normalizeStreamingTextin the agent runner handles both tokens and wraps the lower-level paths.tokens.test.tsprovides thorough coverage including incremental prefix matching, whitespace handling, divergence cases, and existingisSilentReplyTextregression tests.Confidence Score: 4/5
streaming-directives.tsparseChunkonly checksSILENT_REPLY_TOKENprefix (notHEARTBEAT_TOKEN), creating a minor inconsistency withagent-runner-execution.ts— though this is mitigated by the higher-level heartbeat handling. The PR was not verified with live Telegram streaming or a fulltscbuild.src/auto-reply/reply/streaming-directives.ts— only checksSILENT_REPLY_TOKENprefix, notHEARTBEAT_TOKEN, unlike the agent runner.Last reviewed commit: ec795c9