From df896b49dfbf8bccbcf2924ef168da96b981b36c Mon Sep 17 00:00:00 2001 From: Sergio Date: Sun, 15 Mar 2026 16:56:56 -0500 Subject: [PATCH] fix: preserve shared-delivery flags in error guard early return When skipMessagingToolDelivery is true (agent already sent via message tool), the error guard early return was hardcoding delivered/ deliveryAttempted to false, overwriting the existing delivery state. This caused cron metadata to report not-delivered even though the message tool send already happened. Now uses skipMessagingToolDelivery for the initial flag values in the early return, matching the behavior of the rest of the function. Co-Authored-By: Claude Opus 4.6 (1M context) --- .../delivery-dispatch.error-guard.test.ts | 17 +++++++++++++++++ src/cron/isolated-agent/delivery-dispatch.ts | 8 ++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/cron/isolated-agent/delivery-dispatch.error-guard.test.ts b/src/cron/isolated-agent/delivery-dispatch.error-guard.test.ts index 638db06f389..0df33d927e4 100644 --- a/src/cron/isolated-agent/delivery-dispatch.error-guard.test.ts +++ b/src/cron/isolated-agent/delivery-dispatch.error-guard.test.ts @@ -319,4 +319,21 @@ describe("dispatchCronDelivery — error output guard", () => { expect(state.deliveryAttempted).toBe(false); expect(deliverOutboundPayloads).not.toHaveBeenCalled(); }); + + it("preserves shared-delivery flags when skipMessagingToolDelivery is true", async () => { + const errorJson = JSON.stringify({ + type: "error", + error: { type: "server_error", message: "fail" }, + }); + const params = makeBaseParams({ synthesizedText: errorJson }); + // Simulate shared-delivery path: agent already sent via message tool + (params as Record).skipMessagingToolDelivery = true; + const state = await dispatchCronDelivery(params); + + // Error guard should suppress announce delivery but preserve the + // existing message-tool delivery state. + expect(state.delivered).toBe(true); + expect(state.deliveryAttempted).toBe(true); + expect(deliverOutboundPayloads).not.toHaveBeenCalled(); + }); }); diff --git a/src/cron/isolated-agent/delivery-dispatch.ts b/src/cron/isolated-agent/delivery-dispatch.ts index 2ddbf3711a2..41248c992c7 100644 --- a/src/cron/isolated-agent/delivery-dispatch.ts +++ b/src/cron/isolated-agent/delivery-dispatch.ts @@ -340,9 +340,13 @@ export async function dispatchCronDelivery( logWarn( `[cron:${params.job.id}] suppressed announce delivery of raw error output (${source}, ${chars} chars)`, ); + // Preserve shared-delivery state: when skipMessagingToolDelivery is true, + // the agent already sent via the message tool — suppressing the error + // guard's announce delivery should not overwrite that existing delivery + // state in cron logs/metadata. return { - delivered: false, - deliveryAttempted: false, + delivered: skipMessagingToolDelivery, + deliveryAttempted: skipMessagingToolDelivery, summary, outputText, synthesizedText,