Skip to content

Commit 7c42910

Browse files
committed
fix(auto-reply): attest message-tool source replies in every delivery mode and gate eligibility on resolved settlement
Route-aware completed source-reply evidence now marks observed delivery regardless of sourceReplyDeliveryMode, matching the followup-runner contract, so an automatic-mode turn answered via the message tool plus NO_REPLY no longer draws the no-visible-reply fallback into the source conversation (reported live on Discord). The result eligibility flag now requires resolved settlement and no delivered fallback, so channel-level recovery cannot double-send while a queued payload is still unresolved.
1 parent e6e0f52 commit 7c42910

3 files changed

Lines changed: 35 additions & 5 deletions

File tree

‎src/auto-reply/reply/agent-runner-result-payloads.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,13 @@ export async function prepareReplyAgentPayloads(state: {
175175
});
176176
return recovery.kind === "diagnostic" ? recovery.payload : undefined;
177177
};
178-
if (opts?.sourceReplyDeliveryMode === "message_tool_only" && completedSourceReplyDelivery) {
179-
await opts.onObservedReplyDelivery?.();
178+
// Completed source-reply evidence is already route-aware (the message tool
179+
// delivered THIS conversation's reply), so it attests observed delivery in
180+
// every mode; the followup runner applies the same contract. Without this, an
181+
// automatic-mode turn answered via the message tool plus NO_REPLY draws the
182+
// no-visible-reply fallback into the source conversation.
183+
if (completedSourceReplyDelivery) {
184+
await opts?.onObservedReplyDelivery?.();
180185
}
181186
const currentMessageId = sessionCtx.MessageSidFull ?? sessionCtx.MessageSid;
182187
// A terminal fallback is built separately after normal payload filtering.

‎src/auto-reply/reply/agent-runner.misc.runreplyagent.test.ts‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3313,6 +3313,7 @@ describe("runReplyAgent private message_tool_only final warning (#85714)", () =>
33133313
strandedReplyRetry?: boolean;
33143314
sendPolicyDenied?: boolean;
33153315
isHeartbeat?: boolean;
3316+
onObservedReplyDelivery?: () => Promise<void> | void;
33163317
replyOperation?: ReturnType<typeof createReplyOperation>;
33173318
turnAdoptionLifecycle?: FollowupRun["turnAdoptionLifecycle"];
33183319
}) {
@@ -3427,7 +3428,16 @@ describe("runReplyAgent private message_tool_only final warning (#85714)", () =>
34273428
resolvedBlockStreamingBreak: "message_end",
34283429
shouldInjectGroupIntro: false,
34293430
typingMode: "instant",
3430-
...(params.isHeartbeat ? { opts: { isHeartbeat: true } } : {}),
3431+
...(params.isHeartbeat || params.onObservedReplyDelivery
3432+
? {
3433+
opts: {
3434+
...(params.isHeartbeat ? { isHeartbeat: true } : {}),
3435+
...(params.onObservedReplyDelivery
3436+
? { onObservedReplyDelivery: params.onObservedReplyDelivery }
3437+
: {}),
3438+
},
3439+
}
3440+
: {}),
34313441
...(params.replyOperation ? { replyOperation: params.replyOperation } : {}),
34323442
});
34333443
return { storePath, tmp, sessionKey, result, finalAssistantText };
@@ -3439,6 +3449,17 @@ describe("runReplyAgent private message_tool_only final warning (#85714)", () =>
34393449
expect(warnPrivateFinalSpy.mock.calls[0]?.[0]).toMatchObject({ sessionKey: "stranded" });
34403450
});
34413451

3452+
it("attests observed delivery for message-tool source replies outside message_tool_only", async () => {
3453+
// A source-routed message-tool answer plus NO_REPLY must not draw the
3454+
// no-visible-reply fallback into the source conversation (#114799).
3455+
const onObservedReplyDelivery = vi.fn(async () => {});
3456+
await runPrivateFinalCase({
3457+
didDeliverSourceReplyViaMessageTool: true,
3458+
onObservedReplyDelivery,
3459+
});
3460+
expect(onObservedReplyDelivery).toHaveBeenCalledTimes(1);
3461+
});
3462+
34423463
it("enqueues a one-shot recovery retry by default for substantive stranded finals", async () => {
34433464
const parentOnComplete = vi.fn();
34443465
const parentLifecycle = { onAdopted: async () => {}, onSettled: parentOnComplete };

‎src/auto-reply/reply/dispatch-from-config.finalize.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,12 @@ export async function finalizeDispatchAndAudit(state: ExecuteDispatchReadyState)
374374
...(getObservedReplyDelivery() ? { observedReplyDelivery: true } : {}),
375375
// Eligibility keys off settled visible delivery: a suppressed or cancelled
376376
// final (including the core fallback itself) leaves channel-level recovery
377-
// eligible, while any settled visible delivery clears it.
378-
...(!turnLedger.hasVisibleDelivery() &&
377+
// eligible, while any settled visible delivery clears it. An aborted or
378+
// timed-out settle leaves delivery unresolved, and a fallback reported as
379+
// delivered must not stay recoverable — either could double-send.
380+
...(queuedSettleResult === "settled" &&
381+
!turnLedger.hasVisibleDelivery() &&
382+
!noVisibleReplyFallbackDelivered &&
379383
!getObservedReplyDelivery() &&
380384
!emptyFinalAllowedAsSilent
381385
? { noVisibleReplyFallbackEligible: true }

0 commit comments

Comments
 (0)