Skip to content

Commit 774c24a

Browse files
Kiran MagicKiran Magic
authored andcommitted
Fix media delivery identity accounting
1 parent f1b8827 commit 774c24a

2 files changed

Lines changed: 50 additions & 6 deletions

File tree

src/infra/outbound/deliver.test.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3553,6 +3553,46 @@ describe("deliverOutboundPayloads", () => {
35533553
expect(mocks.appendAssistantMessageToSessionTranscript).not.toHaveBeenCalled();
35543554
});
35553555

3556+
it("does not count no-identity media results as delivered", async () => {
3557+
hookMocks.runner.hasHooks.mockReturnValue(true);
3558+
const sendText = vi.fn();
3559+
const sendMedia = vi.fn().mockResolvedValue({
3560+
channel: "matrix",
3561+
messageId: "",
3562+
meta: { error: "media path is not allowed" },
3563+
});
3564+
setActivePluginRegistry(
3565+
createTestRegistry([
3566+
{
3567+
pluginId: "matrix",
3568+
source: "test",
3569+
plugin: createOutboundTestPlugin({
3570+
id: "matrix",
3571+
outbound: { deliveryMode: "direct", sendText, sendMedia },
3572+
}),
3573+
},
3574+
]),
3575+
);
3576+
3577+
const results = await deliverOutboundPayloads({
3578+
cfg: {},
3579+
channel: "matrix",
3580+
to: "!room:1",
3581+
payloads: [{ text: "caption", mediaUrl: "file:///tmp/generated-tts.opus" }],
3582+
mirror: {
3583+
sessionKey: "agent:main:main",
3584+
agentId: "main",
3585+
text: "caption",
3586+
},
3587+
});
3588+
3589+
expect(results).toStrictEqual([]);
3590+
expect(sendMedia).toHaveBeenCalledTimes(1);
3591+
expect(sendText).not.toHaveBeenCalled();
3592+
expect(hookMocks.runner.runMessageSent).not.toHaveBeenCalled();
3593+
expect(mocks.appendAssistantMessageToSessionTranscript).not.toHaveBeenCalled();
3594+
});
3595+
35563596
it("emits message_sent success for sendPayload deliveries", async () => {
35573597
hookMocks.runner.hasHooks.mockReturnValue(true);
35583598
const sendPayload = vi.fn().mockResolvedValue({ channel: "matrix", messageId: "mx-1" });

src/infra/outbound/deliver.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1891,6 +1891,9 @@ async function deliverOutboundPayloadsCore(
18911891
unit.overrides,
18921892
)
18931893
: await deliveryHandler.sendMedia(unit.caption ?? "", unit.mediaUrl, unit.overrides);
1894+
if (!hasDeliveryResultIdentity(delivery)) {
1895+
continue;
1896+
}
18941897
results.push(delivery);
18951898
firstMessageId ??= delivery.messageId;
18961899
lastMessageId = delivery.messageId;
@@ -1916,20 +1919,21 @@ async function deliverOutboundPayloadsCore(
19161919
results: deliveredResults,
19171920
});
19181921
recordDeliveredMirrorPayload(payloadSummary, deliveredResults);
1922+
completeDeliveryDiagnostics(deliveredResults.length);
1923+
emitMessageSent({
1924+
success: true,
1925+
content: payloadSummary.hookContent ?? payloadSummary.text,
1926+
messageId: lastMessageId,
1927+
});
19191928
} else {
19201929
recordPayloadOutcome(
19211930
suppressedPayloadOutcome({
19221931
index: payloadIndex,
19231932
reason: "adapter_returned_no_identity",
19241933
}),
19251934
);
1935+
completeDeliveryDiagnostics(0);
19261936
}
1927-
completeDeliveryDiagnostics(results.length - beforeCount);
1928-
emitMessageSent({
1929-
success: true,
1930-
content: payloadSummary.hookContent ?? payloadSummary.text,
1931-
messageId: lastMessageId,
1932-
});
19331937
} catch (err) {
19341938
recordPayloadOutcome({
19351939
index: payloadIndex,

0 commit comments

Comments
 (0)