Skip to content

Commit 4f1eaee

Browse files
committed
fix(cron): preserve unavailable external delivery routes
1 parent c0c2f7e commit 4f1eaee

3 files changed

Lines changed: 55 additions & 31 deletions

File tree

‎src/cron/delivery-preview.test.ts‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,27 @@ describe("resolveCronDeliveryPreview", () => {
123123
});
124124
});
125125

126+
it("keeps unavailable external plugin routes fail-closed", async () => {
127+
mocks.resolveDeliveryTarget.mockResolvedValueOnce({
128+
ok: false,
129+
channel: "unavailable-plugin",
130+
mode: "implicit",
131+
error: new Error("Channel plugin unavailable"),
132+
});
133+
const job = makeCronJob({
134+
sessionTarget: "current",
135+
sessionKey: "agent:main:dashboard:c5557dcf",
136+
delivery: undefined,
137+
});
138+
139+
const preview = await previewForJob(job);
140+
141+
expect(preview).toEqual({
142+
label: "announce -> last",
143+
detail: "last -> no route, will fail-closed: Channel plugin unavailable",
144+
});
145+
});
146+
126147
it("does not describe unresolved no-delivery message-tool targets as fail-closed", async () => {
127148
mocks.resolveDeliveryTarget.mockResolvedValueOnce({
128149
ok: false,

‎src/cron/isolated-agent/delivery-dispatch.double-announce.test.ts‎

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3535,33 +3535,36 @@ describe("dispatchCronDelivery — double-announce guard", () => {
35353535
expect(deliverOutboundPayloads).not.toHaveBeenCalled();
35363536
});
35373537

3538-
it("keeps a committed current-target run successful when its external route fails to resolve", async () => {
3539-
const params = makeBaseParams({
3540-
synthesizedText: "committed but undeliverable externally",
3541-
sessionTarget: "current",
3542-
runStartedAt: 1_500,
3543-
});
3544-
params.resolvedDelivery = {
3545-
ok: false,
3546-
channel: "telegram",
3547-
to: undefined,
3548-
accountId: undefined,
3549-
threadId: undefined,
3550-
mode: "implicit",
3551-
error: new Error("Target is required"),
3552-
};
3538+
it.each(["telegram", "unavailable-plugin"])(
3539+
"keeps a committed current-target run successful when its %s route fails to resolve",
3540+
async (channel) => {
3541+
const params = makeBaseParams({
3542+
synthesizedText: "committed but undeliverable externally",
3543+
sessionTarget: "current",
3544+
runStartedAt: 1_500,
3545+
});
3546+
params.resolvedDelivery = {
3547+
ok: false,
3548+
channel,
3549+
to: undefined,
3550+
accountId: undefined,
3551+
threadId: undefined,
3552+
mode: "implicit",
3553+
error: new Error("Target is required"),
3554+
};
35533555

3554-
const state = await dispatchCronDelivery(params);
3556+
const state = await dispatchCronDelivery(params);
35553557

3556-
expect(state.result).toBeUndefined();
3557-
expect(state).toMatchObject({
3558-
delivered: false,
3559-
deliveryAttempted: true,
3560-
deliveryError: "Target is required",
3561-
});
3562-
expect(commitBackgroundResultToSessionMock).toHaveBeenCalledTimes(1);
3563-
expect(deliverOutboundPayloads).not.toHaveBeenCalled();
3564-
});
3558+
expect(state.result).toBeUndefined();
3559+
expect(state).toMatchObject({
3560+
delivered: false,
3561+
deliveryAttempted: true,
3562+
deliveryError: "Target is required",
3563+
});
3564+
expect(commitBackgroundResultToSessionMock).toHaveBeenCalledTimes(1);
3565+
expect(deliverOutboundPayloads).not.toHaveBeenCalled();
3566+
},
3567+
);
35653568

35663569
it("requires the current-session commit in addition to one external delivery", async () => {
35673570
const params = makeBaseParams({

‎src/cron/isolated-agent/delivery-target.ts‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { resolveSessionDeliveryTarget } from "../../infra/outbound/targets-sessi
1616
import { normalizeAccountId } from "../../routing/session-key.js";
1717
import { createLazyImportLoader } from "../../shared/lazy-promise.js";
1818
import { normalizeSessionDeliveryState } from "../../utils/delivery-context.shared.js";
19-
import { isDeliverableMessageChannel } from "../../utils/message-channel.js";
19+
import { INTERNAL_MESSAGE_CHANNEL } from "../../utils/message-channel.js";
2020
import { resolveCronStoredDeliveryContext } from "../delivery-context.js";
2121
import { resolveCronAgentSessionKey } from "./session-key.js";
2222

@@ -41,15 +41,15 @@ export type DeliveryTargetResolution =
4141
};
4242

4343
/**
44-
* Returns whether a delivery resolution names an external deliverable channel
45-
* route. Internal surfaces (webchat/Control UI) and resolutions that found no
46-
* channel at all have no external route: their conversations render from
47-
* durable session history, so nothing outside the Gateway carries the message.
44+
* Returns whether a delivery resolution names an external channel route.
45+
* Registration is intentionally irrelevant: an unavailable plugin route still
46+
* owes delivery. Only webchat/Control UI and an absent route are satisfied by
47+
* the durable session commit alone.
4848
*/
4949
export function resolvedDeliveryTargetsExternalChannel(
5050
resolution: DeliveryTargetResolution,
5151
): boolean {
52-
return resolution.channel !== undefined && isDeliverableMessageChannel(resolution.channel);
52+
return resolution.channel !== undefined && resolution.channel !== INTERNAL_MESSAGE_CHANNEL;
5353
}
5454

5555
const targetsRuntimeLoader = createLazyImportLoader(

0 commit comments

Comments
 (0)