Skip to content

Commit 2bedc60

Browse files
author
Friday
committed
fix(auto-reply): suppress silent tokens with trailing punctuation or quotes
The silent-reply matcher (isSilentReplyText) only accepted a token-only reply matching /^\s*NO_REPLY(?:\s+NO_REPLY)*\s*$/. When a model emitted a near-miss such as NO_REPLY., NO_REPLY!, or "NO_REPLY", the strict match failed and the literal token leaked to the user across every suppression site (cron announce, channel sends, subagent announce, etc.). Widen the exact matcher to tolerate optional wrapping quotes and trailing terminal punctuation (. ! ? …) around an otherwise token-only reply, while still rejecting substantive replies that merely end with the token (regression guard for #19537, which has word content before the token). Add unit coverage for the trailing-punctuation and quoted-token cases.
1 parent 6aa8337 commit 2bedc60

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,21 @@ describe("isSilentReplyText", () => {
9696
expect(isSilentReplyText("")).toBe(false);
9797
});
9898

99+
it("returns true for a bare token with trailing terminal punctuation", () => {
100+
expect(isSilentReplyText("NO_REPLY.")).toBe(true);
101+
expect(isSilentReplyText("NO_REPLY!")).toBe(true);
102+
expect(isSilentReplyText("NO_REPLY?")).toBe(true);
103+
expect(isSilentReplyText("NO_REPLY\u2026")).toBe(true);
104+
expect(isSilentReplyText(" NO_REPLY. ")).toBe(true);
105+
});
106+
107+
it("returns true for a bare token wrapped in quotes", () => {
108+
expect(isSilentReplyText('"NO_REPLY"')).toBe(true);
109+
expect(isSilentReplyText("'NO_REPLY'")).toBe(true);
110+
expect(isSilentReplyText('"NO_REPLY."')).toBe(true);
111+
expect(isSilentReplyText("\u201cNO_REPLY\u201d")).toBe(true);
112+
});
113+
99114
it("returns false for substantive text ending with token (#19537)", () => {
100115
const text = "Here is a helpful response.\n\nNO_REPLY";
101116
expect(isSilentReplyText(text)).toBe(false);

‎src/auto-reply/tokens.ts‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,17 @@ function getSilentExactRegex(token: string): RegExp {
2626
return cached;
2727
}
2828
const escaped = escapeRegExp(token);
29-
const regex = new RegExp(`^\\s*${escaped}(?:\\s+${escaped})*\\s*$`, "i");
29+
// Allow optional wrapping quotes and trailing terminal punctuation/whitespace
30+
// around an otherwise token-only reply (e.g. `NO_REPLY.`, `"NO_REPLY"`, `NO_REPLY!`).
31+
// Models occasionally append a period or wrap the token in quotes; the strict
32+
// matcher used to let those leak through to the user verbatim.
33+
// The `^` anchor + quote/whitespace-only lead still rejects substantive replies
34+
// that merely END with the token (regression guard for #19537), since those have
35+
// word content before it.
36+
const regex = new RegExp(
37+
`^[\\s"'\u00ab\u201c\u2018]*${escaped}(?:[\\s"'\u00bb\u201d\u2019]+${escaped})*[\\s"'\u00bb\u201d\u2019.!?\u2026]*$`,
38+
"i",
39+
);
3040
silentExactRegexByToken.set(token, regex);
3141
return regex;
3242
}

0 commit comments

Comments
 (0)