Skip to content

stripHeartbeatToken fails to strip repeated _OK suffixes, causing spam messages #41

Closed

Description

@arun-8687

Description:
Problem
When the LLM outputs a malformed heartbeat response like HEARTBEAT_OK_OK_OK instead of the expected HEARTBEAT_OK, the
stripHeartbeatToken function fails to fully clean the response, resulting in spam messages like _OK_OK_OK... being sent to users at random intervals.

Root Cause
The function at src/web/auto-reply.ts uses a regex that only replaces exact matches of HEARTBEAT_OK. When the LLM hallucinates repetitive patterns, the trailing _OK_OK remains and gets sent as a message.

Current behavior:

Input: "HEARTBEAT_OK_OK_OK"
After token strip: "_OK_OK"
After underscore->space: " OK OK"
After trim: "OK OK"
Result: shouldSkip=false, text="OK OK" ← SENT TO USER!

Expected Behavior
All HEARTBEAT_OK* patterns should be stripped, including any trailing _OK repetitions.

Proposed Fix
Add a regex to strip trailing _OK patterns after the initial token replacement:

// After removing HEARTBEAT_OK token
processed = processed.replace(/(\s*_?OK)+$/gi, "");

Test Cases (in
auto-reply.test.ts
)

expect(stripHeartbeatToken("HEARTBEAT_OK_OK_OK")).toEqual({ shouldSkip: true, text: "" });
expect(stripHeartbeatToken("HEARTBEAT_OK_OK")).toEqual({ shouldSkip: true, text: "" });
expect(stripHeartbeatToken("HEARTBEAT_OK _OK")).toEqual({ shouldSkip: true, text: "" });

Environment

  • Clawdis version: (latest)
  • LLM Provider: Gemini / Google

Activity

  1. steipete commented on Dec 23, 2025

    @steipete
    Contributor

    Thanks for the detailed repro. Fixed: strip repeated HEARTBEAT_OK tails so malformed heartbeat replies won’t leak "OK OK" spam. Added tests; will ship in next beta.

  2. steipete commented on Dec 23, 2025

    @steipete
    Contributor

    This is quite specific, but I'm ok with making this more resilient. 56245d5

  3. added a commit that references this issue on Feb 2, 2026
  4. added a commit that references this issue on Feb 16, 2026
  5. added a commit that references this issue on Feb 27, 2026
    63b776d
  6. locked as resolved and limited conversation to collaborators on Mar 8, 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