Skip to content

Commit 19d621e

Browse files
SunnyShu0925claudesteipete
authored
fix(auto-reply): strip stray punctuation before silent-reply token detection (#98224)
* [AI] fix(auto-reply): strip stray punctuation before silent-reply token detection When the model emits .NO_REPLY or *NO_REPLY* instead of bare NO_REPLY, isSilentReplyText() failed to detect it because the regex requires the text to consist only of the token with optional whitespace. Add stripEdgeNonAlnum() that strips leading/trailing non-letter, non-number characters (Unicode-aware) before the regex test. This catches stray punctuation while preserving the existing safeguard against suppressing mixed-content text. Related to #98166 Co-Authored-By: Claude <[email protected]> * [AI] fix: strip only punct not emoji before silent-reply detection Change stripEdgeNonAlnum to stripEdgePunct: strip only punctuation (\p{P}) instead of all non-letter/non-number characters. Emoji would be stripped by the former, causing false silent-reply on mixed content. Related to #98166 Co-Authored-By: Claude <[email protected]> * [AI] fix: preserve exact custom-token match before edge-punct normalization Try exact regex match first, then fall back to stripEdgePunct. This preserves exact matching for custom tokens whose first/last character is punctuation (e.g. *SILENT*, #QUIET#), while still catching the common case of NO_REPLY wrapped in stray punctuation. Add regression test for punctuation-edged custom tokens. ClawSweeper: #98224 (comment) Related to #98166 Co-Authored-By: Claude <[email protected]> * [AI] fix: handle whitespace-wrapped punctuation in silent-reply fallback Trim whitespace before stripping edge punctuation in the fallback path so variants like " .NO_REPLY " and "NO_REPLY. " are also caught by the silent-reply detector. Add regression coverage for whitespace-wrapped edge punctuation. ClawSweeper: #98224 (comment) Related to #98166 Co-Authored-By: Claude <[email protected]> * test(auto-reply): tighten silent-token boundaries --------- Co-authored-by: Claude <[email protected]> Co-authored-by: Peter Steinberger <[email protected]>
1 parent e0b2dda commit 19d621e

2 files changed

Lines changed: 41 additions & 1 deletion

File tree

‎src/auto-reply/tokens.test.ts‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,37 @@ describe("isSilentReplyText", () => {
109109
it("returns false for token embedded in text", () => {
110110
expect(isSilentReplyText("Please NO_REPLY to this")).toBe(false);
111111
});
112+
113+
it.each([
114+
".NO_REPLY",
115+
"*NO_REPLY",
116+
"...NO_REPLY",
117+
"NO_REPLY.",
118+
"NO_REPLY*",
119+
"NO_REPLY...",
120+
"*NO_REPLY*",
121+
'"NO_REPLY"',
122+
".NO_REPLY.",
123+
" .NO_REPLY ",
124+
" NO_REPLY. ",
125+
" *NO_REPLY* ",
126+
])("returns true for punctuation-wrapped token-only text: %j (#98166)", (text) => {
127+
expect(isSilentReplyText(text)).toBe(true);
128+
});
129+
130+
it.each(["the sentinel is NO_REPLY, fyi", "💬NO_REPLY", "NO_REPLY👍"])(
131+
"keeps substantive punctuation or symbols: %j",
132+
(text) => {
133+
expect(isSilentReplyText(text)).toBe(false);
134+
},
135+
);
136+
137+
it("preserves exact custom-token matches with punctuation-edged tokens", () => {
138+
// Custom tokens whose first/last character is punctuation must still match
139+
expect(isSilentReplyText("*SILENT*", "*SILENT*")).toBe(true);
140+
expect(isSilentReplyText("#QUIET#", "#QUIET#")).toBe(true);
141+
expect(isSilentReplyText("^^MUTE^^", "^^MUTE^^")).toBe(true);
142+
});
112143
});
113144

114145
describe("isSilentReplyPayloadText", () => {

‎src/auto-reply/tokens.ts‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ function getSilentTrailingRegex(token: string): RegExp {
4242
return regex;
4343
}
4444

45+
function stripEdgePunctuation(text: string): string {
46+
return text.replace(/^\p{P}+|\p{P}+$/gu, "");
47+
}
48+
4549
/** Returns true only for token-only silent replies. */
4650
export function isSilentReplyText(
4751
text: string | undefined,
@@ -52,7 +56,12 @@ export function isSilentReplyText(
5256
}
5357
// Match only token-only replies, including repeated tokens separated by whitespace.
5458
// This prevents substantive replies ending with NO_REPLY from being suppressed (#19537).
55-
return getSilentExactRegex(token).test(text);
59+
// Models sometimes wrap the token in punctuation. Preserve exact custom-token matching,
60+
// but keep symbols such as emoji substantive so they are still delivered.
61+
return (
62+
getSilentExactRegex(token).test(text) ||
63+
getSilentExactRegex(token).test(stripEdgePunctuation(text.trim()))
64+
);
5665
}
5766

5867
type SilentReplyActionEnvelope = { action?: unknown };

0 commit comments

Comments
 (0)