diff --git a/src/cron/isolated-agent/delivery-dispatch.double-announce.test.ts b/src/cron/isolated-agent/delivery-dispatch.double-announce.test.ts index 4ed41f7de3a..1602b9d1b4d 100644 --- a/src/cron/isolated-agent/delivery-dispatch.double-announce.test.ts +++ b/src/cron/isolated-agent/delivery-dispatch.double-announce.test.ts @@ -467,4 +467,59 @@ describe("dispatchCronDelivery — double-announce guard", () => { vi.unstubAllEnvs(); } }); + + it("suppresses NO_REPLY payload in direct delivery so sentinel never leaks to external channels", async () => { + vi.mocked(countActiveDescendantRuns).mockReturnValue(0); + vi.mocked(isLikelyInterimCronMessage).mockReturnValue(false); + + const params = makeBaseParams({ synthesizedText: "NO_REPLY" }); + // Force the useDirectDelivery path (structured content) to exercise + // deliverViaDirect without going through finalizeTextDelivery. + (params as Record).deliveryPayloadHasStructuredContent = true; + const state = await dispatchCronDelivery(params); + + // NO_REPLY must be filtered out before reaching the outbound adapter. + expect(deliverOutboundPayloads).not.toHaveBeenCalled(); + // Mark as silently delivered so the job is persisted as successful. + expect(state.delivered).toBe(true); + // deliveryAttempted must be true so the heartbeat timer does not fire + // a fallback enqueueSystemEvent with the NO_REPLY sentinel text. + expect(state.deliveryAttempted).toBe(true); + + // Verify timer guard agrees: shouldEnqueueCronMainSummary returns false + expect( + shouldEnqueueCronMainSummary({ + summaryText: "NO_REPLY", + deliveryRequested: true, + delivered: state.delivered, + deliveryAttempted: state.deliveryAttempted, + suppressMainSummary: false, + isCronSystemEvent: () => true, + }), + ).toBe(false); + }); + + it("suppresses NO_REPLY payload with surrounding whitespace", async () => { + vi.mocked(countActiveDescendantRuns).mockReturnValue(0); + vi.mocked(isLikelyInterimCronMessage).mockReturnValue(false); + + const params = makeBaseParams({ synthesizedText: " NO_REPLY " }); + (params as Record).deliveryPayloadHasStructuredContent = true; + const state = await dispatchCronDelivery(params); + + expect(deliverOutboundPayloads).not.toHaveBeenCalled(); + expect(state.delivered).toBe(true); + expect(state.deliveryAttempted).toBe(true); + + expect( + shouldEnqueueCronMainSummary({ + summaryText: " NO_REPLY ", + deliveryRequested: true, + delivered: state.delivered, + deliveryAttempted: state.deliveryAttempted, + suppressMainSummary: false, + isCronSystemEvent: () => true, + }), + ).toBe(false); + }); }); diff --git a/src/cron/isolated-agent/delivery-dispatch.ts b/src/cron/isolated-agent/delivery-dispatch.ts index eda32740e4a..9584c711bc2 100644 --- a/src/cron/isolated-agent/delivery-dispatch.ts +++ b/src/cron/isolated-agent/delivery-dispatch.ts @@ -1,5 +1,5 @@ import { countActiveDescendantRuns } from "../../agents/subagent-registry.js"; -import { SILENT_REPLY_TOKEN } from "../../auto-reply/tokens.js"; +import { isSilentReplyText, SILENT_REPLY_TOKEN } from "../../auto-reply/tokens.js"; import type { ReplyPayload } from "../../auto-reply/types.js"; import { createOutboundSendDeps, type CliDeps } from "../../cli/outbound-send-deps.js"; import type { OpenClawConfig } from "../../config/config.js"; @@ -331,14 +331,28 @@ export async function dispatchCronDelivery( delivery, }); try { - const payloadsForDelivery = + const rawPayloads = deliveryPayloads.length > 0 ? deliveryPayloads : synthesizedText ? [{ text: synthesizedText }] : []; + // Suppress NO_REPLY sentinel so it never leaks to external channels. + const payloadsForDelivery = rawPayloads.filter( + (p) => !isSilentReplyText(p.text, SILENT_REPLY_TOKEN), + ); if (payloadsForDelivery.length === 0) { - return null; + // Mark as silently delivered so the heartbeat timer does not fire a fallback + // and the job is persisted as successfully delivered. + deliveryAttempted = true; + delivered = true; + return params.withRunSession({ + status: "ok", + summary, + outputText, + delivered: true, + ...params.telemetry, + }); } if (params.isAborted()) { return params.withRunSession({