Skip to content

Commit 16c608e

Browse files
committed
fix: harden cron announce NO_REPLY suppression (#65016) (thanks @BKF-Gitty)
1 parent 1d41ef7 commit 16c608e

6 files changed

Lines changed: 214 additions & 33 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ Docs: https://docs.openclaw.ai
4444
- Gateway/startup: fix spurious SIGUSR1 restart loop on Linux/systemd when plugin auto-enable is the only startup config write; the config hash guard was not captured for that write path, causing chokidar to treat each boot write as an external change and trigger a reload → restart cycle that corrupts manifest.db after repeated cycles. Fixes #67436. (#67557) thanks @openperf
4545
- OpenAI Codex/CLI: keep resumed `codex exec resume` runs on the safe non-interactive path without reintroducing the removed dangerous bypass flag by passing the supported `--skip-git-repo-check` resume arg that real Codex CLI requires outside trusted git directories. (#67666) Thanks @plgonzalezrx8.
4646
- Codex/app-server: parse Desktop-originated app-server user agents such as `Codex Desktop/0.118.0`, keeping the version gate working when the Codex CLI inherits a multi-word originator. (#64666) Thanks @cyrusaf.
47+
- Cron/announce delivery: keep isolated announce `NO_REPLY` stripping case-insensitive across direct and text delivery, preserve structured media-only sends when a caption strips silent, and derive main-session awareness from the cleaned payloads so silent captions no longer leak stale `NO_REPLY` text. (#65016) Thanks @BKF-Gitty.
4748

4849
## 2026.4.15-beta.1
4950

‎src/agents/subagent-announce.ts‎

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import { isSilentReplyText, SILENT_REPLY_TOKEN } from "../auto-reply/tokens.js";
1+
import {
2+
isSilentReplyText,
3+
SILENT_REPLY_TOKEN,
4+
startsWithSilentToken,
5+
stripLeadingSilentToken,
6+
stripSilentToken,
7+
} from "../auto-reply/tokens.js";
28
import { defaultRuntime } from "../runtime.js";
39
import { isCronSessionKey } from "../sessions/session-key-utils.js";
410
import { normalizeOptionalString } from "../shared/string-coerce.js";
@@ -127,6 +133,27 @@ function isWakeContinuationRun(runId: string): boolean {
127133
return stripWakeRunSuffixes(trimmed) !== trimmed;
128134
}
129135

136+
function stripAndClassifyReply(text: string): string | null {
137+
let result = text;
138+
let didStrip = false;
139+
const hasLeadingSilentToken = startsWithSilentToken(result, SILENT_REPLY_TOKEN);
140+
if (hasLeadingSilentToken) {
141+
result = stripLeadingSilentToken(result, SILENT_REPLY_TOKEN);
142+
didStrip = true;
143+
}
144+
if (hasLeadingSilentToken || result.toLowerCase().includes(SILENT_REPLY_TOKEN.toLowerCase())) {
145+
result = stripSilentToken(result, SILENT_REPLY_TOKEN);
146+
didStrip = true;
147+
}
148+
if (
149+
didStrip &&
150+
(!result.trim() || isSilentReplyText(result, SILENT_REPLY_TOKEN) || isAnnounceSkip(result))
151+
) {
152+
return null;
153+
}
154+
return result;
155+
}
156+
130157
async function wakeSubagentRunAfterDescendants(params: {
131158
runId: string;
132159
childSessionKey: string;
@@ -385,10 +412,29 @@ export async function runSubagentAnnounceFlow(params: {
385412

386413
if (isAnnounceSkip(reply) || isSilentReplyText(reply, SILENT_REPLY_TOKEN)) {
387414
if (fallbackReply && !fallbackIsSilent) {
388-
reply = fallbackReply;
415+
const cleaned = stripAndClassifyReply(fallbackReply);
416+
if (cleaned === null) {
417+
return true;
418+
}
419+
reply = cleaned;
389420
} else {
390421
return true;
391422
}
423+
} else if (reply) {
424+
const cleaned = stripAndClassifyReply(reply);
425+
if (cleaned === null) {
426+
if (fallbackReply && !fallbackIsSilent) {
427+
const cleanedFallback = stripAndClassifyReply(fallbackReply);
428+
if (cleanedFallback === null) {
429+
return true;
430+
}
431+
reply = cleanedFallback;
432+
} else {
433+
return true;
434+
}
435+
} else {
436+
reply = cleaned;
437+
}
392438
}
393439
}
394440

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export function normalizeReplyPayload(
6969
if (hasLeadingSilentToken) {
7070
text = stripLeadingSilentToken(text, silentToken);
7171
}
72-
if (hasLeadingSilentToken || text.includes(silentToken)) {
72+
if (hasLeadingSilentToken || text.toLowerCase().includes(silentToken.toLowerCase())) {
7373
text = stripSilentToken(text, silentToken);
7474
if (!hasContent(text)) {
7575
opts.onSkip?.("silent");

‎src/auto-reply/tokens.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function getSilentTrailingRegex(token: string): RegExp {
2424
return cached;
2525
}
2626
const escaped = escapeRegExp(token);
27-
const regex = new RegExp(`(?:^|\\s+|\\*+)${escaped}\\s*$`);
27+
const regex = new RegExp(`(?:^|\\s+|\\*+)${escaped}\\s*$`, "i");
2828
silentTrailingRegexByToken.set(token, regex);
2929
return regex;
3030
}

‎src/cron/isolated-agent/delivery-dispatch.double-announce.test.ts‎

Lines changed: 96 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ function makeBaseParams(overrides: {
122122
runSessionId?: string;
123123
sessionTarget?: string;
124124
deliveryBestEffort?: boolean;
125-
}) {
125+
}): Parameters<typeof dispatchCronDelivery>[0] {
126126
const resolvedDelivery = makeResolvedDelivery();
127127
return {
128128
cfg: {} as never,
@@ -327,6 +327,32 @@ describe("dispatchCronDelivery — double-announce guard", () => {
327327
});
328328
});
329329

330+
it("skips awareness text when direct delivery strips a silent caption", async () => {
331+
vi.mocked(countActiveDescendantRuns).mockReturnValue(0);
332+
vi.mocked(isLikelyInterimCronMessage).mockReturnValue(false);
333+
334+
const params = makeBaseParams({ synthesizedText: undefined });
335+
params.deliveryPayloadHasStructuredContent = true;
336+
params.deliveryPayloads = [
337+
{ mediaUrl: "https://example.com/image.png", text: "All done\n\nNO_REPLY" },
338+
];
339+
params.outputText = "All done\n\nNO_REPLY";
340+
params.summary = "All done\n\nNO_REPLY";
341+
342+
const state = await dispatchCronDelivery(params);
343+
344+
expect(state.result).toBeUndefined();
345+
expect(state.delivered).toBe(true);
346+
expect(state.deliveryAttempted).toBe(true);
347+
expect(deliverOutboundPayloads).toHaveBeenCalledTimes(1);
348+
expect(deliverOutboundPayloads).toHaveBeenCalledWith(
349+
expect.objectContaining({
350+
payloads: [{ mediaUrl: "https://example.com/image.png", text: undefined }],
351+
}),
352+
);
353+
expect(enqueueSystemEvent).not.toHaveBeenCalled();
354+
});
355+
330356
it("keeps the cron run successful when awareness queueing throws after delivery", async () => {
331357
vi.mocked(countActiveDescendantRuns).mockReturnValue(0);
332358
vi.mocked(isLikelyInterimCronMessage).mockReturnValue(false);
@@ -986,4 +1012,73 @@ describe("dispatchCronDelivery — double-announce guard", () => {
9861012
expect.objectContaining({ status: "ok", delivered: false, deliveryAttempted: true }),
9871013
);
9881014
});
1015+
1016+
it("delivers substantive text that mentions NO_REPLY in non-trailing content (text delivery)", async () => {
1017+
vi.mocked(countActiveDescendantRuns).mockReturnValue(0);
1018+
vi.mocked(isLikelyInterimCronMessage).mockReturnValue(false);
1019+
1020+
const params = makeBaseParams({
1021+
synthesizedText:
1022+
"The NO_REPLY sentinel tells the agent to skip delivery when nothing changes.",
1023+
});
1024+
const state = await dispatchCronDelivery(params);
1025+
1026+
expect(state.deliveryAttempted).toBe(true);
1027+
expect(state.delivered).toBe(true);
1028+
expect(deliverOutboundPayloads).toHaveBeenCalledTimes(1);
1029+
});
1030+
1031+
it("delivers substantive text that mentions NO_REPLY in non-trailing content (direct delivery)", async () => {
1032+
vi.mocked(countActiveDescendantRuns).mockReturnValue(0);
1033+
vi.mocked(isLikelyInterimCronMessage).mockReturnValue(false);
1034+
1035+
const params = makeBaseParams({
1036+
synthesizedText:
1037+
"Reminder: reply NO_REPLY when there is nothing to announce, otherwise send a summary.",
1038+
});
1039+
(params as Record<string, unknown>).deliveryPayloadHasStructuredContent = true;
1040+
const state = await dispatchCronDelivery(params);
1041+
1042+
expect(state.deliveryAttempted).toBe(true);
1043+
expect(state.delivered).toBe(true);
1044+
expect(deliverOutboundPayloads).toHaveBeenCalledTimes(1);
1045+
});
1046+
1047+
it("delivers non-trailing NO_REPLY mention with trailing whitespace", async () => {
1048+
vi.mocked(countActiveDescendantRuns).mockReturnValue(0);
1049+
vi.mocked(isLikelyInterimCronMessage).mockReturnValue(false);
1050+
1051+
const params = makeBaseParams({
1052+
synthesizedText: "Use NO_REPLY when nothing actionable changed.\n",
1053+
});
1054+
const state = await dispatchCronDelivery(params);
1055+
1056+
expect(state.deliveryAttempted).toBe(true);
1057+
expect(state.delivered).toBe(true);
1058+
expect(deliverOutboundPayloads).toHaveBeenCalledTimes(1);
1059+
});
1060+
1061+
it("drops only the payload with trailing NO_REPLY in a multi-payload direct delivery", async () => {
1062+
vi.mocked(countActiveDescendantRuns).mockReturnValue(0);
1063+
vi.mocked(isLikelyInterimCronMessage).mockReturnValue(false);
1064+
1065+
const params = makeBaseParams({ synthesizedText: undefined });
1066+
params.deliveryPayloads = [
1067+
{ text: "Working on it..." },
1068+
{ text: "Final weather summary\n\nNO_REPLY" },
1069+
];
1070+
params.summary = "Working on it...";
1071+
params.outputText = "Working on it...";
1072+
1073+
const state = await dispatchCronDelivery(params);
1074+
1075+
expect(state.deliveryAttempted).toBe(true);
1076+
expect(state.delivered).toBe(true);
1077+
expect(deliverOutboundPayloads).toHaveBeenCalledTimes(1);
1078+
expect(deliverOutboundPayloads).toHaveBeenCalledWith(
1079+
expect.objectContaining({
1080+
payloads: [{ text: "Working on it..." }],
1081+
}),
1082+
);
1083+
});
9891084
});

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

Lines changed: 67 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import type { ReplyPayload } from "../../auto-reply/reply-payload.js";
2-
import { isSilentReplyText, stripSilentToken, SILENT_REPLY_TOKEN } from "../../auto-reply/tokens.js";
2+
import {
3+
isSilentReplyText,
4+
SILENT_REPLY_TOKEN,
5+
startsWithSilentToken,
6+
stripLeadingSilentToken,
7+
stripSilentToken,
8+
} from "../../auto-reply/tokens.js";
39
import type { CliDeps } from "../../cli/outbound-send-deps.js";
410
import {
511
resolveAgentMainSessionKey,
@@ -10,6 +16,7 @@ import { sleepWithAbort } from "../../infra/backoff.js";
1016
import { formatErrorMessage } from "../../infra/errors.js";
1117
import type { OutboundDeliveryResult } from "../../infra/outbound/deliver.js";
1218
import { normalizeTargetForProvider } from "../../infra/outbound/target-normalization.js";
19+
import { hasReplyPayloadContent } from "../../interactive/payload.js";
1320
import {
1421
normalizeLowercaseStringOrEmpty,
1522
normalizeOptionalLowercaseString,
@@ -18,7 +25,7 @@ import {
1825
import { hasScheduledNextRunAtMs } from "../service/jobs.js";
1926
import type { CronJob, CronRunTelemetry } from "../types.js";
2027
import type { DeliveryTargetResolution } from "./delivery-target.js";
21-
import { pickSummaryFromOutput } from "./helpers.js";
28+
import { pickLastNonEmptyTextFromPayloads, pickSummaryFromOutput } from "./helpers.js";
2229
import type { RunCronAgentTurnResult } from "./run.types.js";
2330
import { expectsSubagentFollowup, isLikelyInterimCronMessage } from "./subagent-followup-hints.js";
2431

@@ -27,6 +34,39 @@ function normalizeDeliveryTarget(channel: string, to: string): string {
2734
return normalizeTargetForProvider(channel, toTrimmed) ?? toTrimmed;
2835
}
2936

37+
type NormalizedSilentReplyText = {
38+
text: string | undefined;
39+
strippedTrailingSilentToken: boolean;
40+
};
41+
42+
function normalizeSilentReplyText(text: string | undefined): NormalizedSilentReplyText {
43+
if (!text) {
44+
return { text, strippedTrailingSilentToken: false };
45+
}
46+
if (isSilentReplyText(text, SILENT_REPLY_TOKEN)) {
47+
return { text: undefined, strippedTrailingSilentToken: false };
48+
}
49+
50+
let next = text;
51+
const hasLeadingSilentToken = startsWithSilentToken(next, SILENT_REPLY_TOKEN);
52+
if (hasLeadingSilentToken) {
53+
next = stripLeadingSilentToken(next, SILENT_REPLY_TOKEN);
54+
}
55+
56+
let strippedTrailingSilentToken = false;
57+
if (hasLeadingSilentToken || next.toLowerCase().includes(SILENT_REPLY_TOKEN.toLowerCase())) {
58+
const trimmedBefore = next.trim();
59+
const stripped = stripSilentToken(next, SILENT_REPLY_TOKEN);
60+
strippedTrailingSilentToken = stripped !== trimmedBefore;
61+
next = stripped;
62+
}
63+
64+
if (!next.trim() || isSilentReplyText(next, SILENT_REPLY_TOKEN)) {
65+
return { text: undefined, strippedTrailingSilentToken };
66+
}
67+
return { text: next, strippedTrailingSilentToken };
68+
}
69+
3070
export function matchesMessagingToolDeliveryTarget(
3171
target: { provider?: string; to?: string; accountId?: string },
3272
delivery: { channel?: string; to?: string; accountId?: string },
@@ -293,9 +333,12 @@ async function queueCronAwarenessSystemEvent(params: {
293333
deliveryIdempotencyKey: string;
294334
outputText?: string;
295335
synthesizedText?: string;
336+
deliveryPayloads?: ReplyPayload[];
296337
}): Promise<void> {
297-
const text =
298-
normalizeOptionalString(params.outputText) ?? normalizeOptionalString(params.synthesizedText);
338+
const text = params.deliveryPayloads
339+
? pickLastNonEmptyTextFromPayloads(params.deliveryPayloads)
340+
: (normalizeOptionalString(params.outputText) ??
341+
normalizeOptionalString(params.synthesizedText));
299342
if (!text) {
300343
return;
301344
}
@@ -462,21 +505,18 @@ export async function dispatchCronDelivery(
462505
: synthesizedText
463506
? [{ text: synthesizedText }]
464507
: [];
465-
// Suppress NO_REPLY sentinel so it never leaks to external channels.
466-
// Also suppress payloads where the agent appended a trailing NO_REPLY
467-
// after other text (e.g. "summary...\n\nNO_REPLY") — the token signals
468-
// "do not deliver" regardless of preceding content.
469-
const payloadsForDelivery = rawPayloads.filter((p) => {
470-
const text = p.text ?? "";
471-
if (isSilentReplyText(text, SILENT_REPLY_TOKEN)) {
472-
return false;
473-
}
474-
// Case-insensitive trailing check: uppercase before stripping since
475-
// stripSilentToken's regex is case-sensitive.
476-
const upper = text.toUpperCase();
477-
const stripped = stripSilentToken(upper, SILENT_REPLY_TOKEN);
478-
return stripped === upper.trim();
479-
});
508+
const payloadsForDelivery = rawPayloads
509+
.map((p) => {
510+
if (!p.text) {
511+
return p;
512+
}
513+
const normalized = normalizeSilentReplyText(p.text);
514+
return {
515+
...p,
516+
text: normalized.strippedTrailingSilentToken ? undefined : normalized.text,
517+
};
518+
})
519+
.filter((p) => hasReplyPayloadContent(p, { trimText: true }));
480520
if (payloadsForDelivery.length === 0) {
481521
return await finishSilentReplyDelivery();
482522
}
@@ -583,6 +623,7 @@ export async function dispatchCronDelivery(
583623
deliveryIdempotencyKey,
584624
outputText,
585625
synthesizedText,
626+
deliveryPayloads: payloadsForDelivery,
586627
});
587628
}
588629
if (delivered) {
@@ -700,17 +741,15 @@ export async function dispatchCronDelivery(
700741
...params.telemetry,
701742
});
702743
}
703-
// Suppress delivery when synthesizedText is (or ends with) NO_REPLY.
704-
// isSilentReplyText handles case-insensitive exact matches (e.g. "No_Reply");
705-
// stripSilentToken catches trailing tokens after other text.
706-
if (isSilentReplyText(synthesizedText, SILENT_REPLY_TOKEN)) {
707-
return await finishSilentReplyDelivery();
708-
}
709-
const upperSynthesized = synthesizedText.toUpperCase();
710-
const strippedSynthesized = stripSilentToken(upperSynthesized, SILENT_REPLY_TOKEN);
711-
if (strippedSynthesized !== upperSynthesized.trim()) {
744+
const normalizedSynthesizedText = normalizeSilentReplyText(synthesizedText);
745+
if (
746+
normalizedSynthesizedText.text === undefined ||
747+
normalizedSynthesizedText.strippedTrailingSilentToken
748+
) {
712749
return await finishSilentReplyDelivery();
713750
}
751+
synthesizedText = normalizedSynthesizedText.text;
752+
outputText = synthesizedText;
714753
if (params.isAborted()) {
715754
return params.withRunSession({
716755
status: "error",

0 commit comments

Comments
 (0)