fix: allow explicit reset delivery retry

This commit is contained in:
Shakker
2026-08-03 00:24:36 +01:00
parent 59e5b5e3e6
commit eeb2b260af
2 changed files with 42 additions and 0 deletions
+1
View File
@@ -86,6 +86,7 @@ const resetRetryState = (
...entry,
sendAttempts: 0,
sendError: undefined,
sendRequestStartedAtMs: undefined,
sendRunId: entry.sendState === "failed" ? generateUUID() : entry.sendRunId,
sendState,
});
+41
View File
@@ -4541,6 +4541,47 @@ describe("handleSendChat", () => {
expect(replacementRequest).not.toHaveBeenCalled();
});
it("retries an explicitly approved unconfirmed reset with the same run id", async () => {
const runId = "unconfirmed-reset-run";
const item = {
...createQueuedLocalCommand("unconfirmed-reset-retry", "/reset"),
sendAttempts: 1,
sendError: "Delivery could not be confirmed after reconnect.",
sendRequestStartedAtMs: 10,
sendRunId: runId,
sendState: "unconfirmed" as const,
};
const host = makeHost({
requestHandlers: {
"chat.send": (params: unknown) => {
const payload = requireRecord(params, "retried reset payload");
return { runId: payload.idempotencyKey, status: "ok" };
},
},
chatQueue: [item],
confirmConversationReset: vi.fn(async () => true),
hello: {
type: "hello-ok",
protocol: 4,
auth: { role: "operator", scopes: ["operator.admin"] },
features: { methods: ["chat.send"] },
},
});
admitHostQueueItems(host);
await retryQueuedChatMessage(host, item.id);
expect(host.confirmConversationReset).toHaveBeenCalledOnce();
expect(host.request).toHaveBeenCalledWith(
"chat.send",
expect.objectContaining({
idempotencyKey: runId,
message: "/reset",
}),
);
expect(listStoredChatOutboxes(host)).toStrictEqual([]);
});
it("retires a queued local command without applying its late result after a route switch", async () => {
const command = createDeferred<Awaited<ReturnType<ExecuteSlashCommand>>>();
executeSlashCommandMock.mockImplementationOnce(() => command.promise);