Skip to content

Commit 82307ac

Browse files
committed
fix(matrix): preserve approval reactions after Gateway failures
1 parent d38ffa3 commit 82307ac

2 files changed

Lines changed: 47 additions & 1 deletion

File tree

‎extensions/matrix/src/matrix/monitor/reaction-events.test.ts‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,52 @@ describe("matrix approval reactions", () => {
372372
).toBeNull();
373373
});
374374

375+
it("retains approval anchors and propagates transient Gateway failures for replay", async () => {
376+
const core = buildCore();
377+
const cfg = buildConfig();
378+
registerMatrixApprovalReactionTarget({
379+
roomId: "!ops:example.org",
380+
eventId: "$approval-msg",
381+
approvalId: "req-123",
382+
approvalKind: "exec",
383+
allowedDecisions: ["allow-once"],
384+
});
385+
const client = createReactionClient();
386+
resolveMatrixApproval.mockRejectedValueOnce(new Error("gateway 503"));
387+
388+
await expect(handleReaction({ client, core, cfg })).rejects.toThrow("gateway 503");
389+
expect(
390+
await resolveMatrixApprovalReactionTargetWithPersistence({
391+
accountId: "default",
392+
roomId: "!ops:example.org",
393+
eventId: "$approval-msg",
394+
reactionKey: "✅",
395+
}),
396+
).not.toBeNull();
397+
398+
await handleReaction({ client, core, cfg });
399+
400+
expect(
401+
await resolveMatrixApprovalReactionTargetWithPersistence({
402+
accountId: "default",
403+
roomId: "!ops:example.org",
404+
eventId: "$approval-msg",
405+
reactionKey: "✅",
406+
}),
407+
).toBeNull();
408+
expect(resolveMatrixApproval).toHaveBeenCalledTimes(2);
409+
expect(resolveMatrixApproval).toHaveBeenLastCalledWith({
410+
cfg,
411+
approvalId: "req-123",
412+
approvalKind: "exec",
413+
decision: "allow-once",
414+
channel: "matrix",
415+
accountId: "default",
416+
senderId: "@owner:example.org",
417+
});
418+
expect(core.system.enqueueSystemEvent).not.toHaveBeenCalled();
419+
});
420+
375421
it("terminalizes every sibling prompt when this surface wins", async () => {
376422
const core = buildCore();
377423
const cfg = buildConfig();

‎extensions/matrix/src/matrix/monitor/reaction-events.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ async function maybeResolveMatrixApprovalReaction(params: {
166166
params.logVerboseMessage(
167167
`matrix: approval reaction failed id=${params.target.approvalId} sender=${params.senderId}: ${String(err)}`,
168168
);
169-
return true;
169+
throw err;
170170
}
171171
}
172172

0 commit comments

Comments
 (0)