Skip to content

Commit ab609f0

Browse files
committed
fix(reply): preserve failed operation state after partial recovery
1 parent 6a67980 commit ab609f0

2 files changed

Lines changed: 42 additions & 0 deletions

File tree

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export async function executeDispatch(state: PrepareDispatchExecutionReadyState)
3232
ctx,
3333
deliveryChannel,
3434
dispatcher,
35+
failDispatchReplyOperation,
3536
flushPendingCommentaryProgress,
3637
getDispatchAbortOperation,
3738
getDispatchAbortSignal,
@@ -507,6 +508,7 @@ export async function executeDispatch(state: PrepareDispatchExecutionReadyState)
507508
) {
508509
throw error;
509510
}
511+
failDispatchReplyOperation(error);
510512
return buildTerminalAgentRunFailureReplyPayload({
511513
visibleReplyDelivered: true,
512514
sessionCtx: ctx,

‎src/auto-reply/reply/dispatch-from-config.terminal-recovery.test.ts‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,44 @@ describe("dispatchReplyFromConfig terminal visible admission recovery", () => {
9797
expect(replyResolver).toHaveBeenCalledTimes(1);
9898
expect(dispatchParams.dispatcher.sendFinalReply).toHaveBeenCalledTimes(1);
9999
});
100+
101+
it("records a failed reply operation when recovering a visible partial", async () => {
102+
const resolverError = new Error("provider failed after partial");
103+
let replyOperation: ReturnType<typeof createReplyOperation> | undefined;
104+
const replyResolver: NonNullable<DispatchFromConfigParams["replyResolver"]> = async (
105+
_ctx,
106+
options,
107+
) => {
108+
if (!options) {
109+
throw new Error("reply options required for partial recovery");
110+
}
111+
replyOperation = options.replyOperation;
112+
await options.onPartialReply?.({ text: "partial telegram reply" });
113+
throw resolverError;
114+
};
115+
const dispatchParams = {
116+
...createVisibleDispatchParams(replyResolver),
117+
replyOptions: {
118+
onPartialReply: vi.fn(async () => undefined),
119+
},
120+
};
121+
122+
const result = await dispatchReplyFromConfig(dispatchParams);
123+
124+
expect(replyOperation?.result).toEqual({
125+
kind: "failed",
126+
code: "run_failed",
127+
cause: resolverError,
128+
});
129+
expect(result).toMatchObject({
130+
queuedFinal: true,
131+
counts: { tool: 0, block: 0, final: 0 },
132+
});
133+
expect(dispatchParams.replyOptions.onPartialReply).toHaveBeenCalledWith({
134+
text: "partial telegram reply",
135+
});
136+
expect(dispatchParams.dispatcher.sendFinalReply).toHaveBeenCalledWith(
137+
expect.objectContaining({ text: expect.stringContaining("Something went wrong") }),
138+
);
139+
});
100140
});

0 commit comments

Comments
 (0)