From 2fdfd64a1aa9929d905d4aef39453c545efdbc16 Mon Sep 17 00:00:00 2001 From: Marvinthebored Date: Sat, 22 Aug 2026 14:38:52 +0800 Subject: [PATCH] fix(channels): honor queued replies without receipts (#127667) Restore compatibility-aware visible dispatch detection when legacy prepared runners return queued counters without a settled receipt. Preserve settled-receipt authority. Co-authored-by: Marvinthebored --- src/channels/turn/execution.ts | 2 +- .../turn/run-channel-turn.pipeline.test.ts | 37 +++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/channels/turn/execution.ts b/src/channels/turn/execution.ts index b8df05924ce8..7e15b6b31f84 100644 --- a/src/channels/turn/execution.ts +++ b/src/channels/turn/execution.ts @@ -9,7 +9,7 @@ import { isRecentOutboundMessageIdentity } from "../message/outbound-echo.js"; import { recordChannelBotPairLoopAndCheckSuppression } from "./bot-loop-protection.js"; import { EMPTY_CHANNEL_TURN_DISPATCH_COUNTS, - hasVisibleChannelTurnDispatchFromReceipt as hasVisibleChannelTurnDispatch, + hasVisibleChannelTurnDispatch, type ChannelTurnDispatchResultLike, type ChannelTurnVisibleDeliverySignals, } from "./dispatch-result.js"; diff --git a/src/channels/turn/run-channel-turn.pipeline.test.ts b/src/channels/turn/run-channel-turn.pipeline.test.ts index 845d2a550d41..1cc8a3c872eb 100644 --- a/src/channels/turn/run-channel-turn.pipeline.test.ts +++ b/src/channels/turn/run-channel-turn.pipeline.test.ts @@ -945,6 +945,43 @@ describe("channel turn pipeline", () => { ]); }); + it.each([ + { + name: "accepts compatibility counters when no receipt exists", + dispatchResult: { queuedFinal: true, counts: { tool: 0, block: 0, final: 1 } }, + warns: false, + }, + { + name: "keeps a non-visible settled receipt authoritative", + dispatchResult: { + queuedFinal: true, + counts: { tool: 0, block: 0, final: 1 }, + settledReceipt: { + anyVisibleDelivered: false, + counts: { final: { delivered: 0, failedAfterSend: 0 } }, + }, + }, + warns: true, + }, + ])("$name", async ({ dispatchResult, warns }) => { + const log = vi.fn(); + + await runPreparedChannelTurn({ + channel: "test", + routeSessionKey: "agent:main:test:peer", + storePath: "/tmp/sessions.json", + ctxPayload: createCtx(), + recordInboundSession: createRecordInboundSession(), + runDispatch: vi.fn(async () => dispatchResult), + log, + messageId: "msg-compat", + }); + + expect(log.mock.calls.some(([event]) => event.reason === "zero-count-visible-dispatch")).toBe( + warns, + ); + }); + it("does not warn for observed-path deliveries with zero queued counts", async () => { const events: string[] = []; const log = vi.fn();