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) <noreply@anthropic.com>
This commit is contained in:
Sergio 2026-03-15 16:56:56 -05:00
parent f179173819
commit df896b49df
2 changed files with 23 additions and 2 deletions

View File

@ -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<string, unknown>).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();
});
});

View File

@ -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,