Skip to content

NO_REPLY silent reply suppression fails when model prefaces with reasoning or emits doubled token #69470

Closed as not planned

Description

@pdd-cli

Bug

When an agent is configured to reply with the NO_REPLY sentinel (for example during spam/ad handling in Discord), the agent's model can emit reasoning as plain text content instead of (or in addition to) structured thinking events. The resulting message is posted to the messaging channel verbatim.

Observed Discord output:

think
The user's message is from "Aftermath" in the #general channel.
The channel topic is: "Topics of general interest around PDD. No advertisement or soliciting."
Aftermath's message is a self-promotional advertisement offering assistance with automation projects, websites, mobile apps, and AI systems.

According to the summary of progress and key decisions:
"NO_REPLY to Spam/Ads: Although ads violate the channel rules, the bot lacks moderation capabilities and its primary directive is PDD support. Silence is the required action."

Therefore, I should output NO_REPLY.NO_REPLY

This should have been suppressed (the agent correctly decided not to reply), but the user sees the model's reasoning instead.

Root Cause

Three layered issues in src/auto-reply/tokens.ts:

  1. isSilentReplyText requires the message to be exactly NO_REPLY. Per isSilentReplyText regex too permissive — suppresses substantive replies ending with NO_REPLY #19537, anything else is considered substantive and passes through. When Gemini (or any reasoning model) emits reasoning as plain text content followed by the silent token, the content disqualifies the message from suppression.

  2. stripSilentToken does not collapse doubled tokens or tolerate punctuation. The regex (?:^|\s+|\*+)${token}\s*$ matches only when the trailing token is preceded by whitespace, start-of-string, or asterisks. The observed output "...NO_REPLY.NO_REPLY" has a literal . between the two tokens, so neither token gets stripped and the tail is not recognized as silent.

  3. stripReasoningTagsFromText (in src/shared/text/reasoning-tags.ts) only matches XML-style tags (<think>, <thinking>, <thought>, <antthinking>, <final>). It cannot catch Markdown-style reasoning preambles like a bare think\n... heading at the start of the message.

Why Now

The same silent-reply path has existed for a while. This became visible once the gateway stabilized around 2026-04-16 (google-vertex ADC auth, dist/plugin-sdk build, context-overflow thrash all resolved). Prior to that, the agent frequently failed before ever reaching the silent-reply check. Additionally, raising agents.defaults.contextTokens from 80000 to 500000 gave Gemini more headroom to emit verbose reasoning as content.

Proposed Fix

Narrow, channel-agnostic change in src/auto-reply/tokens.ts:

  1. Iterate stripSilentToken so repeated NO_REPLY occurrences with intervening punctuation collapse to empty.
  2. Add isReasoningPrefacedSilentReply(text, token) that returns true when the message ends with the silent token and the preceding content is a bare reasoning preamble (a word like think, thinking, thought, reasoning, or analysis on its own line). This preserves the isSilentReplyText regex too permissive — suppresses substantive replies ending with NO_REPLY #19537 semantics — substantive replies ending with NO_REPLY are still delivered — while suppressing reasoning-wrapped silent replies.
  3. Include the new check in isSilentReplyPayloadText so the single gate at src/auto-reply/reply/reply-directives.ts:34 catches it.

Scope

Activity

  1. martingarramon commented on Apr 26, 2026

    @martingarramon
    Contributor

    Confirmed all three sub-claims on current main (edb618c6c4).

    1. isSilentReplyText requires exactly the token, modulo whitespace. src/auto-reply/tokens.ts:10-19 builds the matcher as /^\s*${escaped}\s*$/i. The check is intentional per the comment at line 40 ("This prevents substantive replies ending with NO_REPLY from being suppressed (#19537)"). So any reasoning preamble + token combo bypasses suppression as designed — your example payload ends up returning false from isSilentReplyText.

    2. stripSilentToken regex doesn't handle .NO_REPLY boundary. tokens.ts:21-30 builds /(?:^|\s+|\*+)${escaped}\s*$/i. The trailing-token alternation accepts only start-of-string, whitespace, or asterisks before the token. Your "...output NO_REPLY.NO_REPLY" has a literal . between the doubled tokens — the trailing token's preceding char is Y (from the first NO_REPLY), which doesn't match either; even if you peeled the second one, the first token's preceding char is .. Neither token gets stripped.

    Worth noting the leading side has analogous coverage that the trailing side lacks: stripLeadingSilentToken (tokens.ts:124) handles (?:\s*${escaped})+ — one or more leading occurrences with whitespace. The trailing side has no equivalent iteration.

    3. stripReasoningTagsFromText is XML-only. src/shared/text/reasoning-tags.ts:5 defines QUICK_TAG_RE = /<\s*\/?\s*(?:(?:antml:)?(?:think(?:ing)?|thought)|antthinking|final)\b/i;. The function early-returns at line 30-32 when this regex doesn't match, so any non-angle-bracketed reasoning preamble (Markdown think\n..., bare Thinking: headers) is passed through verbatim.

    On the proposed fix: the three-step plan (iterate stripSilentToken to collapse repeated tokens with intervening punctuation, add isReasoningPrefacedSilentReply, wire it into isSilentReplyPayloadText) lands cleanly in this layer without touching stripReasoningTagsFromText. The single-gate threading via src/auto-reply/reply/reply-directives.ts:34 keeps the change channel-agnostic.

    One subtle case worth covering in the iteration step: punctuation characters between repeated tokens vary by model (., :, ,, sometimes \n). Anchoring on \s*[\.\,\:\;\!\?\n]*\s* between repeats — rather than just punctuation — keeps Gemini-style NO_REPLY.NO_REPLY and Claude-style NO_REPLY\nNO_REPLY both covered, while still preserving the #19537 boundary (a substantive sentence ending with one bare NO_REPLY should still pass through).

    Happy to take a swing at the PR if no one else is on it.

  2. clawsweeper commented on Apr 26, 2026

    @clawsweeper
    Contributor

    Closing this as duplicate or superseded after Codex automated review.

    Issue #69470 should close as superseded by the directly linked open PR #69472, which is the active code/test vehicle for the same remaining bug. Current main does not yet implement the requested tolerant reasoning-prefaced NO_REPLY suppression, so this is not an implemented-on-main close.

    Best possible solution:

    Use PR #69472 as the canonical active tracker and review or land that shared src/auto-reply/tokens.ts fix, preserving #19537 exact-token semantics while adding narrowly tested reasoning-prefaced/doubled-token suppression.

    What I checked:

    So I’m closing this here and keeping the remaining discussion on the canonical linked item.

    Codex Review notes: model gpt-5.5, reasoning high; reviewed against 4a3030df9efa.

  3. locked as resolved and limited conversation to collaborators on Apr 29, 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

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions