Skip to content

Commit daa4188

Browse files
author
Sid
authored
fix(cron): avoid marking queued announce paths as delivered (#29716)
Cron announce flow treated queued/steered outcomes as delivered even when no direct outbound send was confirmed, which could report false-positive delivery state. This change keeps cron delivery strict: only direct-path announce results count as delivered. Closes #29660
1 parent 3096837 commit daa4188

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

src/agents/subagent-announce.format.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,6 +1064,32 @@ describe("subagent announce formatting", () => {
10641064
expect(params.accountId).toBe("kev");
10651065
});
10661066

1067+
it("does not report cron announce as delivered when it was only queued", async () => {
1068+
embeddedRunMock.isEmbeddedPiRunActive.mockReturnValue(true);
1069+
embeddedRunMock.isEmbeddedPiRunStreaming.mockReturnValue(false);
1070+
sessionStore = {
1071+
"agent:main:main": {
1072+
sessionId: "session-cron-queued",
1073+
lastChannel: "telegram",
1074+
lastTo: "123",
1075+
queueMode: "collect",
1076+
queueDebounceMs: 0,
1077+
},
1078+
};
1079+
1080+
const didAnnounce = await runSubagentAnnounceFlow({
1081+
childSessionKey: "agent:main:subagent:test",
1082+
childRunId: "run-cron-queued",
1083+
requesterSessionKey: "main",
1084+
requesterDisplayKey: "main",
1085+
announceType: "cron job",
1086+
...defaultOutcomeAnnounce,
1087+
});
1088+
1089+
expect(didAnnounce).toBe(false);
1090+
expect(agentSpy).toHaveBeenCalledTimes(1);
1091+
});
1092+
10671093
it("keeps queued idempotency unique for same-ms distinct child runs", async () => {
10681094
embeddedRunMock.isEmbeddedPiRunActive.mockReturnValue(true);
10691095
embeddedRunMock.isEmbeddedPiRunStreaming.mockReturnValue(false);

src/agents/subagent-announce.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1346,7 +1346,17 @@ export async function runSubagentAnnounceFlow(params: {
13461346
directIdempotencyKey,
13471347
signal: params.signal,
13481348
});
1349-
didAnnounce = delivery.delivered;
1349+
// Cron delivery state should only be marked as delivered when we have a
1350+
// direct path result. Queue/steer means "accepted for later processing",
1351+
// not a confirmed channel send, and can otherwise produce false positives.
1352+
if (
1353+
announceType === "cron job" &&
1354+
(delivery.path === "queued" || delivery.path === "steered")
1355+
) {
1356+
didAnnounce = false;
1357+
} else {
1358+
didAnnounce = delivery.delivered;
1359+
}
13501360
if (!delivery.delivered && delivery.path === "direct" && delivery.error) {
13511361
defaultRuntime.error?.(
13521362
`Subagent completion direct announce failed for run ${params.childRunId}: ${delivery.error}`,

0 commit comments

Comments
 (0)