Skip to content

feat(gateway): Strip NO_REPLY from both prefix AND suffix positions for robust suppression #40165

Closed as not planned

Description

@h6y3-aegis

GitHub Issue Draft: Robust NO_REPLY Token Handling

Repo: openclaw/openclaw
Related: #28874 (NO_REPLY prefix leak), #39335 (webchat leak)


Title

feat(gateway): Strip NO_REPLY from both prefix AND suffix positions for robust suppression

Labels

enhancement, reliability

Body

Problem

Models frequently misuse the NO_REPLY token in two ways:

  1. Prefix position (covered by Gateway does not strip trailing text after NO_REPLY — causes phantom messages #28874): NO_REPLY\n\nsome trailing text
  2. Suffix position (new): Task complete. NO_REPLY

The suffix case is arguably more common because models interpret "when you have nothing to say" as a completion signal rather than a silence signal. They output substantive content, then append NO_REPLY as if it were a sign-off.

Current Behavior

Gateway only suppresses messages where NO_REPLY is the exact entire content (after trimming). Any prefix or suffix text causes the full message to leak.

Proposed Fix

1. Gateway-level defense in depth:

function shouldSuppressMessage(text: string): { suppress: boolean; cleanedText?: string } {
  const trimmed = text.trim();
  
  // Exact match - full suppression
  if (trimmed === 'NO_REPLY') {
    return { suppress: true };
  }
  
  // Prefix position: "NO_REPLY\n..." or "NO_REPLY ..."
  if (/^NO_REPLY[\s\n]/i.test(trimmed)) {
    return { suppress: true }; // Discard entire message
  }
  
  // Suffix position: "...NO_REPLY" or "... NO_REPLY"
  if (/[\s\n]NO_REPLY$/i.test(trimmed) || trimmed.endsWith('NO_REPLY')) {
    const cleaned = trimmed.replace(/[\s\n]*NO_REPLY$/i, '').trim();
    if (cleaned) {
      return { suppress: false, cleanedText: cleaned }; // Strip suffix, deliver cleaned
    }
    return { suppress: true };
  }
  
  return { suppress: false };
}

2. System prompt improvement:

Current:

When you have nothing to say, respond with ONLY: NO_REPLY

Proposed:

When your entire response should be suppressed (user sees nothing), respond with ONLY: NO_REPLY

NO_REPLY is NOT a completion marker. If you have content to share, just send the content without NO_REPLY.

Rationale

  • Defense in depth: Even with perfect instructions, models will occasionally misuse tokens. The gateway should handle this gracefully.
  • User experience: Leaked NO_REPLY tokens confuse users and break trust.
  • Suffix stripping vs. suppression: For suffix position, stripping and delivering the cleaned content is better than full suppression — the model had something to say.

Test Cases

Input Expected Output
NO_REPLY (suppressed)
NO_REPLY\n\nHello (suppressed - malformed, discard)
Task complete. NO_REPLY Task complete.
Git is clean.\nNO_REPLY Git is clean.
Regular message Regular message

Environment

Observed across:

  • Telegram, WhatsApp, Webchat channels
  • Claude Opus, Claude Sonnet, GPT-5.3 Codex, Gemini models
  • OpenClaw 2026.3.x

Activity

  1. openclaw-barnacle commented on Apr 25, 2026

    @openclaw-barnacle

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

  2. added
    stale
    on Apr 25, 2026
  3. clawsweeper commented on Apr 26, 2026

    @clawsweeper
    Contributor

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

    Close as duplicate: current main has partial NO_REPLY fixes, but the remaining mixed/partial suppression policy is already tracked by the broader open canonical issue.

    Root-cause cluster
    Relationship: duplicate
    Canonical: #42472
    Summary: This issue duplicates the broader open mixed/partial NO_REPLY suppression policy issue; current main has partial fixes but the remaining decision should stay centralized there.

    Members:

    Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

    Canonical path: Close this issue as a duplicate and keep the broader NO_REPLY mixed-content policy discussion centralized in #42472.

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

    Review details

    Best possible solution:

    Close this issue as a duplicate and keep the broader NO_REPLY mixed-content policy discussion centralized in #42472.

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

    Yes, from source: current shared normalization still treats generic text followed by NO_REPLY as deliverable after stripping, while a separated leading token is not classified by the glued-leading helper.

    Is this the best way to solve the issue?

    No as a standalone issue: the remaining policy is already centralized in the broader canonical issue, and a fix should be reviewed there with the current partial fixes preserved.

    Security review:

    Security review needs attention: The underlying canonical issue remains security-relevant because mixed NO_REPLY handling can either leak internal text or suppress legitimate visible messages.

    • [medium] Centralize mixed NO_REPLY security boundary — src/auto-reply/reply/normalize-reply.ts:70
      Current normalization can still deliver generic preamble text after stripping trailing NO_REPLY, but broad suppression would intentionally drop some replies that current tests preserve.
      Confidence: 0.86

    AGENTS.md: found and applied where relevant.

    What I checked:

    Likely related people:

    • frankekn: Authored and merged the leading NO_REPLY hardening PR that changed the shared token helper, normalizer, and reply utility tests. (role: adjacent silent-token contributor; confidence: high; commits: 153e3add6885; files: src/auto-reply/tokens.ts, src/auto-reply/reply/normalize-reply.ts, src/auto-reply/reply/reply-utils.test.ts)
    • obviyus: Merged the cron hardening PR that normalized trailing NO_REPLY in cron announce delivery after the production cron report. (role: recent adjacent cron suppression merger; confidence: high; commits: 16c608e3937e; files: src/cron/isolated-agent/delivery-dispatch.ts, src/cron/isolated-agent/delivery-dispatch.double-announce.test.ts)
    • steipete: Landed the earlier mixed-content NO_REPLY stripping work from an external PR and documented the direct-reply behavior that current tests still preserve. (role: adjacent normalizer merger; confidence: high; commits: a6a742f3d067; files: src/auto-reply/tokens.ts, src/auto-reply/reply/normalize-reply.ts, src/auto-reply/reply/reply-utils.test.ts)
    • zuoanCo: The canonical issue review points to merged reasoning-prefixed NO_REPLY suppression work on the same classifier/test surface, which narrows part of the remaining policy. (role: recent shared classifier contributor; confidence: medium; commits: 0c493a161fa5; files: src/auto-reply/tokens.ts, src/auto-reply/reply/reply-utils.test.ts, src/infra/outbound/payloads.test.ts)

    Codex review notes: model internal, reasoning high; reviewed against 67c80e941ecf.

  4. removed
    stale
    on Apr 27, 2026
  5. smithstreeter commented on Apr 27, 2026

    @smithstreeter

    Confirmed on 2026.4.x / Telegram / Claude Sonnet 4.6. Exact case: model replied NO_REPLY (exact, full message) to a simple 'Thanks' acknowledgment. The sentinel was delivered verbatim to the Telegram chat instead of being suppressed. Matches the exact-match trim path described here — the issue is the gateway suppression check isn't being applied before Telegram delivery.

  6. tetesh commented on May 13, 2026

    @tetesh

    Real-world impact of this remaining gap:

    We run a cron job (every 5 minutes) that scans Alertmanager. The job invokes a deterministic Python runner and is supposed to return NO_REPLY when there are no critical alerts. Despite explicit hard output contracts in the cron payload ("reply with EXACTLY: NO_REPLY, no other text"), the LLM appends explanatory text ~0.3-0.7% of the time — e.g. "No new critical alerts found. Per contract: NO_REPLY." — and the full text reaches Telegram as-is because the cron announce delivery path only checks isSilentReplyText() (exact match /^\s*NO_REPLY\s*$/i).

    This means multiple cron jobs in our setup generate 1-2 unnecessary push notifications per day per job. For a monitoring context this is especially painful — the one thing you don't want is a channel that desensitizes people with noise. Multiply by N cron jobs and it becomes a real problem.

    A suppress-if-present mode (or equivalent determinism) would completely eliminate this class of failures. The prompt-level contract will never be 100% reliable across all LLMs — this should be handled at the system level.

    Thanks for keeping this open, would love to see it move forward.

  7. added
    P2
    clawsweeper:source-repro
    clawsweeper:no-new-fix-pr
    clawsweeper:needs-maintainer-review
    clawsweeper:needs-product-decision
    clawsweeper:needs-security-review
    impact:security
    impact:message-loss
    clawsweeper:fix-shape-clear
    issue-rating: 🦞 diamond lobster
    and removed
    clawsweeper:fix-shape-clear
    on May 16, 2026
  8. openclaw-barnacle commented on Jun 8, 2026

    @openclaw-barnacle

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

  9. added
    stale
    on Jun 8, 2026
  10. removed
    clawsweeper:needs-security-review
    on Jun 10, 2026
  11. removed
    stale
    on Jun 11, 2026
  12. added
    clawsweeper:fix-shape-clear
    clawsweeper:needs-security-review
    and removed
    clawsweeper:fix-shape-clear
    on Jun 11, 2026
  13. locked as resolved and limited conversation to collaborators on Jun 25, 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

    P2clawsweeper:needs-maintainer-reviewclawsweeper:needs-product-decisionclawsweeper:needs-security-reviewclawsweeper:no-new-fix-prclawsweeper:source-reproimpact:message-lossimpact:securityissue-rating: 🦞 diamond lobster

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions