Skip to content

Commit cc3ee61

Browse files
CaioCaio
authored andcommitted
fix(reply): use isSilentTokenOnOwnLine in all delivery paths
Extends #42873 to cover the remaining code paths where NO_REPLY on its own line was not suppressed: - parseReplyDirectives (deliver layer) — the final gate before messages reach the channel. Used isSilentReplyText (exact match) which missed 'text\n\nNO_REPLY' patterns. - Cron delivery-dispatch — synthesized text and interim checks compared with toUpperCase() === SILENT_REPLY_TOKEN (exact match). - Cron subagent-followup — descendant reply collection and grace period polling used exact match only. - Gateway chat event handlers (emitChatDelta, flushBufferedChatDelta, emitChatFinal) — streaming text suppression used exact match. - Chat history sanitization — assistant message filtering used exact match only. All six files now import and use isSilentTokenOnOwnLine() from tokens.ts (introduced in #42873) alongside the existing exact-match check, ensuring 'text\n\nNO_REPLY' is treated as silent across every path. AI-assisted: Claude Opus 4.6 (fully tested locally via dist patches)
1 parent 076a175 commit cc3ee61

6 files changed

Lines changed: 67 additions & 13 deletions

File tree

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { describe, expect, it } from "vitest";
2+
import { parseReplyDirectives } from "./reply-directives.js";
3+
4+
describe("parseReplyDirectives", () => {
5+
it("marks exact NO_REPLY as silent", () => {
6+
const result = parseReplyDirectives("NO_REPLY");
7+
expect(result.isSilent).toBe(true);
8+
expect(result.text).toBe("");
9+
});
10+
11+
it("marks own-line NO_REPLY as silent", () => {
12+
const result = parseReplyDirectives("Checked inbox, nothing new.\n\nNO_REPLY");
13+
expect(result.isSilent).toBe(true);
14+
expect(result.text).toBe("");
15+
});
16+
17+
it("marks own-line NO_REPLY with single newline as silent", () => {
18+
const result = parseReplyDirectives("Status update.\nNO_REPLY");
19+
expect(result.isSilent).toBe(true);
20+
expect(result.text).toBe("");
21+
});
22+
23+
it("marks own-line NO_REPLY with leading whitespace as silent", () => {
24+
const result = parseReplyDirectives("Nothing to report.\n NO_REPLY ");
25+
expect(result.isSilent).toBe(true);
26+
expect(result.text).toBe("");
27+
});
28+
29+
it("strips inline NO_REPLY but delivers surrounding text", () => {
30+
const result = parseReplyDirectives("😄 NO_REPLY");
31+
expect(result.isSilent).toBe(false);
32+
expect(result.text).not.toContain("NO_REPLY");
33+
});
34+
35+
it("delivers normal text without NO_REPLY", () => {
36+
const result = parseReplyDirectives("Hello, here is your update.");
37+
expect(result.isSilent).toBe(false);
38+
expect(result.text).toBe("Hello, here is your update.");
39+
});
40+
});

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { splitMediaFromOutput } from "../../media/parse.js";
22
import { parseInlineDirectives } from "../../utils/directive-tags.js";
3-
import { isSilentReplyText, SILENT_REPLY_TOKEN } from "../tokens.js";
3+
import { isSilentReplyText, isSilentTokenOnOwnLine, SILENT_REPLY_TOKEN } from "../tokens.js";
44

55
export type ReplyDirectiveParseResult = {
66
text: string;
@@ -31,7 +31,7 @@ export function parseReplyDirectives(
3131
}
3232

3333
const silentToken = options.silentToken ?? SILENT_REPLY_TOKEN;
34-
const isSilent = isSilentReplyText(text, silentToken);
34+
const isSilent = isSilentReplyText(text, silentToken) || isSilentTokenOnOwnLine(text, silentToken);
3535
if (isSilent) {
3636
text = "";
3737
}

‎src/cron/isolated-agent/delivery-dispatch.ts‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { countActiveDescendantRuns } from "../../agents/subagent-registry.js";
2-
import { SILENT_REPLY_TOKEN } from "../../auto-reply/tokens.js";
2+
import { isSilentTokenOnOwnLine, SILENT_REPLY_TOKEN } from "../../auto-reply/tokens.js";
33
import type { ReplyPayload } from "../../auto-reply/types.js";
44
import { createOutboundSendDeps, type CliDeps } from "../../cli/outbound-send-deps.js";
55
import type { OpenClawConfig } from "../../config/config.js";
@@ -367,7 +367,8 @@ export async function dispatchCronDelivery(
367367
hadDescendants &&
368368
synthesizedText.trim() === initialSynthesizedText &&
369369
isLikelyInterimCronMessage(initialSynthesizedText) &&
370-
initialSynthesizedText.toUpperCase() !== SILENT_REPLY_TOKEN.toUpperCase()
370+
initialSynthesizedText.toUpperCase() !== SILENT_REPLY_TOKEN.toUpperCase() &&
371+
!isSilentTokenOnOwnLine(initialSynthesizedText, SILENT_REPLY_TOKEN)
371372
) {
372373
// Descendants existed but no post-orchestration synthesis arrived AND
373374
// no descendant fallback reply was available. Suppress stale parent
@@ -382,7 +383,10 @@ export async function dispatchCronDelivery(
382383
...params.telemetry,
383384
});
384385
}
385-
if (synthesizedText.toUpperCase() === SILENT_REPLY_TOKEN.toUpperCase()) {
386+
if (
387+
synthesizedText.toUpperCase() === SILENT_REPLY_TOKEN.toUpperCase() ||
388+
isSilentTokenOnOwnLine(synthesizedText, SILENT_REPLY_TOKEN)
389+
) {
386390
return params.withRunSession({
387391
status: "ok",
388392
summary,

‎src/cron/isolated-agent/subagent-followup.ts‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { listDescendantRunsForRequester } from "../../agents/subagent-registry.js";
22
import { readLatestAssistantReply } from "../../agents/tools/agent-step.js";
3-
import { SILENT_REPLY_TOKEN } from "../../auto-reply/tokens.js";
3+
import { isSilentTokenOnOwnLine, SILENT_REPLY_TOKEN } from "../../auto-reply/tokens.js";
44
import { callGateway } from "../../gateway/call.js";
55

66
const FAST_TEST_MODE = process.env.OPENCLAW_TEST_FAST === "1";
@@ -95,7 +95,11 @@ export async function readDescendantSubagentFallbackReply(params: {
9595
if (!reply && typeof entry.frozenResultText === "string" && entry.frozenResultText.trim()) {
9696
reply = entry.frozenResultText.trim();
9797
}
98-
if (!reply || reply.toUpperCase() === SILENT_REPLY_TOKEN.toUpperCase()) {
98+
if (
99+
!reply ||
100+
reply.toUpperCase() === SILENT_REPLY_TOKEN.toUpperCase() ||
101+
isSilentTokenOnOwnLine(reply, SILENT_REPLY_TOKEN)
102+
) {
99103
continue;
100104
}
101105
replies.push(reply);
@@ -174,6 +178,7 @@ export async function waitForDescendantSubagentSummary(params: {
174178
if (
175179
latest &&
176180
latest.toUpperCase() !== SILENT_REPLY_TOKEN.toUpperCase() &&
181+
!isSilentTokenOnOwnLine(latest, SILENT_REPLY_TOKEN) &&
177182
(latest !== initialReply || !isLikelyInterimCronMessage(latest))
178183
) {
179184
return latest;
@@ -186,6 +191,7 @@ export async function waitForDescendantSubagentSummary(params: {
186191
if (
187192
latest &&
188193
latest.toUpperCase() !== SILENT_REPLY_TOKEN.toUpperCase() &&
194+
!isSilentTokenOnOwnLine(latest, SILENT_REPLY_TOKEN) &&
189195
(latest !== initialReply || !isLikelyInterimCronMessage(latest))
190196
) {
191197
return latest;

‎src/gateway/server-chat.ts‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { DEFAULT_HEARTBEAT_ACK_MAX_CHARS, stripHeartbeatToken } from "../auto-reply/heartbeat.js";
22
import { normalizeVerboseLevel } from "../auto-reply/thinking.js";
3-
import { isSilentReplyText, SILENT_REPLY_TOKEN } from "../auto-reply/tokens.js";
3+
import { isSilentReplyText, isSilentTokenOnOwnLine, SILENT_REPLY_TOKEN } from "../auto-reply/tokens.js";
44
import { loadConfig } from "../config/config.js";
55
import { type AgentEventPayload, getAgentRunContext } from "../infra/agent-events.js";
66
import { resolveHeartbeatVisibility } from "../infra/heartbeat-visibility.js";
@@ -359,7 +359,7 @@ export function createAgentEventHandler({
359359
return;
360360
}
361361
chatRunState.buffers.set(clientRunId, mergedText);
362-
if (isSilentReplyText(mergedText, SILENT_REPLY_TOKEN)) {
362+
if (isSilentReplyText(mergedText, SILENT_REPLY_TOKEN) || isSilentTokenOnOwnLine(mergedText, SILENT_REPLY_TOKEN)) {
363363
return;
364364
}
365365
if (isSilentReplyLeadFragment(mergedText)) {
@@ -406,7 +406,9 @@ export function createAgentEventHandler({
406406
});
407407
const text = normalizedHeartbeatText.text.trim();
408408
const shouldSuppressSilent =
409-
normalizedHeartbeatText.suppress || isSilentReplyText(text, SILENT_REPLY_TOKEN);
409+
normalizedHeartbeatText.suppress ||
410+
isSilentReplyText(text, SILENT_REPLY_TOKEN) ||
411+
isSilentTokenOnOwnLine(text, SILENT_REPLY_TOKEN);
410412
const shouldSuppressSilentLeadFragment = isSilentReplyLeadFragment(text);
411413
const shouldSuppressHeartbeatStreaming = shouldHideHeartbeatChatOutput(
412414
clientRunId,
@@ -463,7 +465,9 @@ export function createAgentEventHandler({
463465
});
464466
const text = normalizedHeartbeatText.text.trim();
465467
const shouldSuppressSilent =
466-
normalizedHeartbeatText.suppress || isSilentReplyText(text, SILENT_REPLY_TOKEN);
468+
normalizedHeartbeatText.suppress ||
469+
isSilentReplyText(text, SILENT_REPLY_TOKEN) ||
470+
isSilentTokenOnOwnLine(text, SILENT_REPLY_TOKEN);
467471
// Flush any throttled delta so streaming clients receive the complete text
468472
// before the final event. The 150 ms throttle in emitChatDelta may have
469473
// suppressed the most recent chunk, leaving the client with stale text.

‎src/gateway/server-methods/chat.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { resolveAgentTimeoutMs } from "../../agents/timeout.js";
77
import { dispatchInboundMessage } from "../../auto-reply/dispatch.js";
88
import { createReplyDispatcher } from "../../auto-reply/reply/reply-dispatcher.js";
99
import type { MsgContext } from "../../auto-reply/templating.js";
10-
import { isSilentReplyText, SILENT_REPLY_TOKEN } from "../../auto-reply/tokens.js";
10+
import { isSilentReplyText, isSilentTokenOnOwnLine, SILENT_REPLY_TOKEN } from "../../auto-reply/tokens.js";
1111
import { createReplyPrefixOptions } from "../../channels/reply-prefix.js";
1212
import { resolveSessionFilePath } from "../../config/sessions.js";
1313
import { jsonUtf8Bytes } from "../../infra/json-utf8-bytes.js";
@@ -406,7 +406,7 @@ function sanitizeChatHistoryMessages(messages: unknown[]): unknown[] {
406406
changed ||= res.changed;
407407
// Drop assistant messages whose entire visible text is the silent reply token.
408408
const text = extractAssistantTextForSilentCheck(res.message);
409-
if (text !== undefined && isSilentReplyText(text, SILENT_REPLY_TOKEN)) {
409+
if (text !== undefined && (isSilentReplyText(text, SILENT_REPLY_TOKEN) || isSilentTokenOnOwnLine(text, SILENT_REPLY_TOKEN))) {
410410
changed = true;
411411
continue;
412412
}

0 commit comments

Comments
 (0)