Skip to content

fix(reply): suppress entire message when NO_REPLY appears on its own line - #42873

Closed
caiop91 wants to merge 2 commits into
openclaw:mainfrom
caiop91:fix/suppress-mixed-no-reply-on-own-line
Closed

caiop91 wants to merge 2 commits into
openclaw:mainfrom
caiop91:fix/suppress-mixed-no-reply-on-own-line

Conversation

@caiop91

@caiop91 caiop91 commented Mar 11, 2026

Copy link
Copy Markdown

Problem

When the model outputs internal narration/reasoning followed by NO_REPLY on a separate line, the preceding text leaks to the user as a visible message.

Model output:    "Checked inbox, nothing new.\n\nNO_REPLY"
User sees:       "Checked inbox, nothing new."
Expected:        (nothing — the model intended silence)

This is especially common with heartbeat tasks and weaker models that output internal status summaries before appending NO_REPLY, but it also affects stronger models (Claude Opus 4.6) during heartbeat runs.

The current stripSilentToken removes the trailing NO_REPLY but delivers the preceding text. This violates the model's intent — when NO_REPLY appears on its own line, the preceding text is internal narration, not user-facing content.

Fix

Introduces isSilentTokenOnOwnLine() in src/auto-reply/tokens.ts which checks whether NO_REPLY appears on its own line (preceded by \n or at the start of text). When it does, the entire response is treated as silent.

Inline occurrences like "😄 NO_REPLY" continue to use stripSilentToken and deliver the non-token text, preserving the existing behavior from #30916.

Decision matrix

Pattern Before After
"NO_REPLY" (exact) ✅ Silent ✅ Silent (unchanged)
"😄 NO_REPLY" (inline) Delivers 😄 Delivers 😄 (unchanged)
"text...\n\nNO_REPLY" (own line) ❌ Delivers text... ✅ Silent
"tasks:\n• ok\nNO_REPLY" (own line) ❌ Delivers tasks: • ok ✅ Silent
"NO_REPLY -- nope" (leading) Delivers as-is Delivers as-is (unchanged)

Changes

  • src/auto-reply/tokens.ts: Add isSilentTokenOnOwnLine()
  • src/auto-reply/reply/normalize-reply.ts: Use own-line check before falling back to stripSilentToken
  • src/auto-reply/tokens.test.ts: Add tests for isSilentTokenOnOwnLine
  • src/auto-reply/reply/reply-utils.test.ts: Update normalizeReplyPayload tests

+99 / -15 lines, 4 files.

Closes #42472
Refs #30916, #33544, #27959, #30955

…line

When the model outputs internal narration followed by NO_REPLY on a
separate line, the preceding text is not user-facing content — it is
reasoning/status that should be suppressed along with the token.

Previously, stripSilentToken would remove the trailing NO_REPLY but
deliver the preceding text to the user. This caused heartbeat narration,
internal status summaries, and reasoning traces to leak as visible
messages on Telegram and other channels.

The fix introduces isSilentTokenOnOwnLine() which checks whether
NO_REPLY appears on its own line (preceded by newline). When it does,
the entire response is treated as silent. Inline occurrences like
'😄 NO_REPLY' continue to strip only the token and deliver the emoji.

Closes #42472
Refs #30916, #33544, #27959
@greptile-apps

greptile-apps Bot commented Mar 11, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a message-leakage bug where internal model narration preceding NO_REPLY on its own line was incorrectly delivered to the user instead of being suppressed. The change is focused, well-reasoned, and well-tested.

Key changes:

  • Adds isSilentTokenOnOwnLine() in src/auto-reply/tokens.ts — uses a lightweight regex to detect whether NO_REPLY (or a custom token) occupies its own line at the end of the message.
  • Updates normalizeReplyPayload in normalize-reply.ts to call isSilentTokenOnOwnLine before falling back to stripSilentToken, so entire-message suppression is applied when the model intended silence.
  • Existing inline-token behaviour ("😄 NO_REPLY" → delivers "😄") is preserved unchanged.
  • Tests are comprehensive and cover all branches in the decision matrix, including custom tokens, whitespace-padded lines, and media/channelData payloads.

Minor concern: isSilentTokenOnOwnLine compiles a new RegExp on every invocation, while the other regex helpers in the same file cache their compiled patterns. This is a code consistency issue worth addressing by extracting a private helper that follows the same memoization pattern.

Confidence Score: 4/5

  • This PR is safe to merge — the logic is correct, all edge cases are covered by tests, and the only concern is a minor regex caching consistency issue.
  • The new isSilentTokenOnOwnLine() function correctly implements the own-line detection logic with proper regex handling. The decision matrix shows all cases are handled correctly (exact token suppressed, inline tokens stripped, own-line tokens fully suppressed with media preservation). Tests comprehensively cover custom tokens, whitespace variations, and edge cases. The only finding is a style consistency improvement: the regex should be cached like its sibling helpers for code uniformity and to avoid unnecessary compilation in streaming scenarios.
  • src/auto-reply/tokens.ts — consider extracting a getSilentOwnLineRegex() helper to cache the compiled regex pattern, matching the memoization pattern of sibling functions.

Last reviewed commit: 1e3e88e

Comment thread src/auto-reply/tokens.ts Outdated
Comment on lines +59 to +68
export function isSilentTokenOnOwnLine(
text: string,
token: string = SILENT_REPLY_TOKEN,
): boolean {
if (!text) {
return false;
}
const escaped = escapeRegExp(token);
return new RegExp(`(\\n|^)\\s*${escaped}\\s*$`).test(text);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The regex pattern in isSilentTokenOnOwnLine is compiled fresh on every invocation, while the other regex-producing helpers in this file (getSilentExactRegex, getSilentTrailingRegex) cache their compiled patterns in a Map.

For consistency and to avoid unnecessary regex compilation in hot paths (like streaming message normalization), consider extracting a private getSilentOwnLineRegex(token) helper that follows the same memoization pattern as the sibling functions — check the map first, build and store on miss, then return the cached instance. This aligns the implementation with the established pattern in this file.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/auto-reply/tokens.ts
Line: 59-68

Comment:
The regex pattern in `isSilentTokenOnOwnLine` is compiled fresh on every invocation, while the other regex-producing helpers in this file (`getSilentExactRegex`, `getSilentTrailingRegex`) cache their compiled patterns in a `Map`.

For consistency and to avoid unnecessary regex compilation in hot paths (like streaming message normalization), consider extracting a private `getSilentOwnLineRegex(token)` helper that follows the same memoization pattern as the sibling functions — check the map first, build and store on miss, then return the cached instance. This aligns the implementation with the established pattern in this file.

How can I resolve this? If you propose a fix, please make it concise.

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!

@openclaw-barnacle

Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added the stale Marked as stale due to inactivity label Apr 27, 2026
@clawsweeper

clawsweeper Bot commented Apr 27, 2026 •

Copy link
Copy Markdown
Contributor

Thanks for the context here. I swept through the related work, and this is now duplicate or superseded.

Close as superseded: this conflicting normalizer-only branch is fully included in the same author's broader open follow-up, while the canonical issue remains open for the unresolved silent-token policy and delivery-proof decision.

Canonical path: #42472 is still open and already tracks the same partial-leak problem with maintainer-review, product-decision, and linked-PR labels.

So I’m closing this here and keeping the remaining discussion on #42472.

Review details

Best possible solution:

Close this stale branch and keep review focused on the broader canonical follow-up and issue, where maintainers can choose one case-insensitive, all-path silent-token policy with real delivery proof.

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

Yes, source-level: current main still strips trailing mixed NO_REPLY and returns the non-empty preamble in normalizeReplyPayload, and the adjacent test asserts that behavior. I did not run live channel proof because this review is read-only.

Is this the best way to solve the issue?

No. The branch is useful source work, but the maintainable solution is the broader current-main follow-up or replacement that applies one case-insensitive classifier across delivery/display paths with compatibility and real-behavior proof.

Security review:

Security review needs attention: Needs attention because the patch is security-relevant silent-reply leakage work, but the new own-line detector is case-sensitive while the existing silent-token contract accepts lowercase variants.

  • [medium] Preserve lowercase own-line silent suppression — src/auto-reply/tokens.ts:64
    The proposed isSilentTokenOnOwnLine regex has no case-insensitive flag, so text\nno_reply can miss the new whole-message suppression path even though exact no_reply is currently treated as silent.
    Confidence: 0.86

What I checked:

  • Current main still strips and delivers mixed trailing-token text: normalizeReplyPayload still strips a trailing silent token and skips only when the remaining payload has no content, so the central behavior is not implemented on current main. (src/auto-reply/reply/normalize-reply.ts:72, 2c0c9c92f485)
  • Current tests preserve the old strip-and-deliver contract: The colocated test still expects File's there...NO_REPLY to return a visible reply containing the preamble with the token removed. (src/auto-reply/reply/reply-utils.test.ts:148, 2c0c9c92f485)
  • This branch is narrow and stale against main: The diff only adds the helper, normalizer wiring, and adjacent tests; live PR metadata reports the branch as conflicting at head 076a1754e8f072b621ba2e1d072c756046ad5492. (src/auto-reply/tokens.ts:49, 076a1754e8f0)
  • Broader follow-up supersedes this branch: fix(reply): use isSilentTokenOnOwnLine in all delivery paths #46626 is open, includes this PR's commits, and extends the same own-line classifier to directive, cron, gateway, and chat-history paths. (cc3ee61992c7)
  • Canonical issue remains open: Feature: post-process NO_REPLY to suppress partial leaks #42472 is still open and already tracks the same partial-leak problem with maintainer-review, product-decision, and linked-PR labels.
  • Related search found the same canonical cluster: Live GitHub search returns this PR, the broader same-author follow-up, and other silent-token proposals, confirming this branch is not the unique remaining work item.

Likely related people:

  • scoootscooob: Opened the original mixed-content silent-token PR that was landed into main and shaped the strip-and-deliver behavior this PR changes. (role: introduced related behavior; confidence: high; commits: a6a742f3d067; files: src/auto-reply/reply/normalize-reply.ts, src/auto-reply/tokens.ts, src/auto-reply/reply/reply-utils.test.ts)
  • steipete: Landed the mixed-content strip behavior and is the top shortlog contributor across the central reply/token files sampled for this review. (role: merger and frequent area contributor; confidence: high; commits: a6a742f3d067, 62edfdffbdd0; files: src/auto-reply/reply/normalize-reply.ts, src/auto-reply/tokens.ts, src/auto-reply/reply/reply-utils.test.ts)
  • frankekn: Authored merged leading NO_REPLY hardening in the same token, normalizer, and gateway chat surfaces. (role: recent silent-token hardening contributor; confidence: high; commits: 153e3add6885; files: src/auto-reply/tokens.ts, src/auto-reply/reply/normalize-reply.ts, src/gateway/server-chat.ts)
  • neo1027144-creator: Authored merged cron trailing NO_REPLY suppression, which partially overlaps the cross-path policy this branch tries to start. (role: recent cron delivery contributor; confidence: high; commits: ee6b7daca37d; files: src/cron/isolated-agent/delivery-dispatch.ts, src/cron/isolated-agent/delivery-dispatch.double-announce.test.ts)
  • vincentkoc: Has recent reply payload/dispatcher refactors and is the live assignee on the PR, making them a practical routing candidate for the remaining policy decision. (role: reply payload area contributor and current assignee; confidence: medium; commits: 38f61564ac1d, 796d4dfc4973, a88fbf0f6476; files: src/auto-reply/reply/normalize-reply.ts, src/auto-reply/reply/reply-dispatcher.ts, src/auto-reply/types.ts)

Codex review notes: model gpt-5.5, reasoning high; reviewed against 2c0c9c92f485.

@openclaw-barnacle openclaw-barnacle Bot removed the stale Marked as stale due to inactivity label Apr 28, 2026
@vincentkoc vincentkoc self-assigned this May 3, 2026
@openclaw-barnacle

Copy link
Copy Markdown

This assigned pull request has been automatically marked as stale after being open for 27 days.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added the stale Marked as stale due to inactivity label May 4, 2026
@clawsweeper clawsweeper Bot added the mantis: telegram-visible-proof Mantis should capture Telegram visible proof. label May 10, 2026
@openclaw-barnacle openclaw-barnacle Bot added the triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. label May 10, 2026
@clawsweeper clawsweeper Bot added mantis: telegram-visible-proof Mantis should capture Telegram visible proof. and removed mantis: telegram-visible-proof Mantis should capture Telegram visible proof. labels May 10, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the stale Marked as stale due to inactivity label May 11, 2026
@openclaw-barnacle

Copy link
Copy Markdown

This assigned pull request has been automatically marked as stale after being open for 27 days.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added the stale Marked as stale due to inactivity label May 11, 2026
@clawsweeper clawsweeper Bot added mantis: telegram-visible-proof Mantis should capture Telegram visible proof. and removed mantis: telegram-visible-proof Mantis should capture Telegram visible proof. labels May 11, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the stale Marked as stale due to inactivity label May 12, 2026
@openclaw-barnacle

Copy link
Copy Markdown

This assigned pull request has been automatically marked as stale after being open for 27 days.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added the stale Marked as stale due to inactivity label May 17, 2026
@clawsweeper clawsweeper Bot added impact:security Security boundary, credential, authz, sandbox, or sensitive-data risk. impact:message-loss Channel message delivery can be lost, duplicated, or misrouted. labels May 17, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the stale Marked as stale due to inactivity label May 18, 2026
@openclaw-barnacle

Copy link
Copy Markdown

This assigned pull request has been automatically marked as stale after being open for 27 days.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added the stale Marked as stale due to inactivity label May 18, 2026
@clawsweeper clawsweeper Bot added rating: 🌊 off-meta tidepool PR readiness rating does not apply to this item. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. mantis: telegram-visible-proof Mantis should capture Telegram visible proof. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. and removed mantis: telegram-visible-proof Mantis should capture Telegram visible proof. rating: 🌊 off-meta tidepool PR readiness rating does not apply to this item. labels May 18, 2026
@openclaw openclaw deleted a comment from openclaw-mantis Bot May 18, 2026
@clawsweeper clawsweeper Bot added status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed impact:security Security boundary, credential, authz, sandbox, or sensitive-data risk. impact:message-loss Channel message delivery can be lost, duplicated, or misrouted. labels May 18, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the stale Marked as stale due to inactivity label May 19, 2026
@openclaw-barnacle

Copy link
Copy Markdown

This assigned pull request has been automatically marked as stale after being open for 27 days.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added stale Marked as stale due to inactivity and removed stale Marked as stale due to inactivity labels May 19, 2026
@openclaw-barnacle

Copy link
Copy Markdown

This assigned pull request has been automatically marked as stale after being open for 27 days.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added the stale Marked as stale due to inactivity label May 20, 2026
@clawsweeper

clawsweeper Bot commented May 20, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper PR egg

🎁 Pass real behavior proof to wake the egg and unlock a hatchable treat.

Where did the egg go?
  • The egg game starts only after the PR passes the real-behavior proof check.
  • Before that, no creature or rarity is rolled. The treat waits for real proof.
  • This is still just collectible flavor: proof affects review readiness, not creature quality.

@clawsweeper

clawsweeper Bot commented May 21, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper applied the proposed close for this PR.

@clawsweeper clawsweeper Bot closed this May 21, 2026
@miluo-star

Copy link
Copy Markdown

Reviving this PR with fresh production evidence (Sep 3–4, 2026).

The bug this PR targets is still active in 2026.9.1 (commit ad6fe23, current stable). We hit it on a default heartbeat schedule every ~30 minutes.

Reproduction (live)

  • OpenClaw 2026.9.1 (ad6fe23)
  • Plugin: openclaw-lark (Feishu official), WebSocket
  • Channel: feishu direct DM
  • Trigger: system-owned heartbeat-main cron running the default HEARTBEAT.md prompt on a 30-min schedule

Model output we observed (verbatim):

✅ heartbeat updated: 2026-09-04T14:34:00+08:00
无紧急事项 → NO_REPLY

Expected: nothing (the model intended silence). Actual: that literal text was delivered to the Feishu DM as a user-visible message (msgId om_x100b6692dcea04a8b276de2dff9a58d).

Why the runtime didn't suppress it

The runtime correctly does not request delivery — lastDeliveryStatus: "not-requested" on every recent heartbeat-main run, and lastPushToUser in heartbeat-state.json is still 2026-08-16T16:00:00+08:00 (19 days stale). The leak is in the channel adapter path: it ships the model output text to Feishu even when delivery was never requested.

Same shape as #42873

#42873 documented:

Model: "Checked inbox, nothing new.\n\nNO_REPLY"
User sees: "Checked inbox, nothing new."   ← leak

Field report:

Model: "无紧急事项 → NO_REPLY"
User sees: "无紧急事项 → NO_REPLY"          ← leak

Same shape. Different narration language, same silent token on its own line.

Closing the original hold reasons

This PR was closed with triage: needs-real-behavior-proof and merge-risk: 🚨 message-delivery / 🚨 compatibility. Evidence attached above addresses both:

  1. Real behavior proof — actual Feishu DM message om_x100b6692dcea04a8b276de2dff9a58d at 2026-09-04 14:34 Asia/Shanghai.
  2. Risk scope — isSilentTokenOnOwnLine() is narrow: only affects replies where NO_REPLY appears on its own line. Inline (😄 NO_REPLY) and exact-match (NO_REPLY) behavior unchanged. Single helper + one call-site in normalize-reply.ts.

Behavior matrix (preserved from #42873)

Pattern Before After
"NO_REPLY" (exact) Silent Silent (unchanged)
"😄 NO_REPLY" (inline) Delivers 😄 Delivers 😄 (unchanged)
"text...\n\nNO_REPLY" (own line) LEAKS Silent
"tasks:\n• ok\nNO_REPLY" (own line) LEAKS Silent
"NO_REPLY -- nope" (leading) Sends Sends (unchanged)

Related (still open / closed-stale, same root cause)


Happy to test the patch once rebased onto main against a live Feishu DM. Body + evidence mirror available at C:\Users\Lenovo\Desktop\PR_42873_Revive_Body.md if maintainers want the full document.

This branch had an error being deployed

1 failed deployment
qa-live-shared — 076a1754 Deployed May 18, 2026 by clawsweeper[bot] via Run agentic native Telegram proof #10961
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mantis: telegram-visible-proof Mantis should capture Telegram visible proof. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: S stale Marked as stale due to inactivity status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature: post-process NO_REPLY to suppress partial leaks

4 participants