Skip to content

Commit 2fda1fb

Browse files
author
silas-dandelion-cult
committed
fix(auto-reply): suppress entire payload when trailing NO_REPLY token present
Previously normalizeReplyPayload stripped trailing NO_REPLY tokens but delivered any preamble text because hasContent() passed on the remainder. When agents prefixed a silent reply with internal reasoning (e.g. "Here's my analysis: ...\n\nNO_REPLY"), the preamble would ship to users as a visible bot message. The trailing NO_REPLY was the agent's signal to suppress the entire turn, not 'deliver this with the token cleaned up'. The fix: track whether stripSilentToken actually removed a trailing token (stripped.length < text.length). When it did, suppress the entire payload regardless of remaining content. Updates two #30916 tests that previously encoded the strip-and-deliver behavior, flipping them to assert suppression. Adds a new test covering the chain-of-thought leak case explicitly. Scope: fixes the non-streaming delivery path (block.enabled=false or streaming.mode=off). Does NOT fix streaming-on with intermediate block delivery, where blocks may already be sent before the final NO_REPLY arrives. That case requires turn-level buffering and is out of scope for this PR.
1 parent cb2fc70 commit 2fda1fb

2 files changed

Lines changed: 18 additions & 10 deletions

File tree

‎src/auto-reply/reply/normalize-reply.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,13 @@ export function normalizeReplyPayload(
7070
text = stripLeadingSilentToken(text, silentToken);
7171
}
7272
if (hasLeadingSilentToken || text.toLowerCase().includes(silentToken.toLowerCase())) {
73-
text = stripSilentToken(text, silentToken);
74-
if (!hasContent(text)) {
73+
const stripped = stripSilentToken(text, silentToken);
74+
const hadTrailingToken = stripped.length < text.length;
75+
text = stripped;
76+
// A trailing NO_REPLY means the model intended to suppress the entire
77+
// turn — the preamble is internal reasoning, not user-facing content.
78+
// Suppress the full message to prevent CoT/reasoning leaks. (#TBD)
79+
if (!hasContent(text) || hadTrailingToken) {
7580
opts.onSkip?.("silent");
7681
return null;
7782
}

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,20 +109,23 @@ describe("normalizeReplyPayload", () => {
109109
}
110110
});
111111

112-
it("strips NO_REPLY from mixed emoji message (#30916)", () => {
112+
it("suppresses message when trailing NO_REPLY follows emoji content (#30916)", () => {
113113
const result = normalizeReplyPayload({ text: "😄 NO_REPLY" });
114-
expect(result).not.toBeNull();
115-
expect(result!.text).toContain("😄");
116-
expect(result!.text).not.toContain("NO_REPLY");
114+
expect(result).toBeNull();
117115
});
118116

119-
it("strips NO_REPLY appended after substantive text (#30916)", () => {
117+
it("suppresses message when trailing NO_REPLY follows substantive text (#30916)", () => {
120118
const result = normalizeReplyPayload({
121119
text: "File's there. Not urgent.\n\nNO_REPLY",
122120
});
123-
expect(result).not.toBeNull();
124-
expect(result!.text).toContain("File's there");
125-
expect(result!.text).not.toContain("NO_REPLY");
121+
expect(result).toBeNull();
122+
});
123+
124+
it("suppresses message when trailing NO_REPLY follows internal reasoning (CoT leak fix)", () => {
125+
const result = normalizeReplyPayload({
126+
text: "Here's my analysis: user is asking X, the right move is Y.\n\nNO_REPLY",
127+
});
128+
expect(result).toBeNull();
126129
});
127130

128131
it("strips glued leading NO_REPLY text without leaking the token", () => {

0 commit comments

Comments
 (0)