Skip to content

Commit 3ee5490

Browse files
committed
fix(auto-reply): avoid duplicate reset hook acknowledgements
1 parent e2bcec3 commit 3ee5490

3 files changed

Lines changed: 14 additions & 6 deletions

File tree

src/auto-reply/reply/commands-reset-hooks.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ describe("handleCommands reset hooks", () => {
251251
},
252252
);
253253

254-
await maybeHandleResetCommand(params);
254+
const result = await maybeHandleResetCommand(params);
255255

256256
expect(routeReplyMock).toHaveBeenCalledWith(
257257
expect.objectContaining({
@@ -262,6 +262,7 @@ describe("handleCommands reset hooks", () => {
262262
threadId: "thread-1",
263263
}),
264264
);
265+
expect(result).toEqual({ shouldContinue: false });
265266
});
266267

267268
it("prefers the target session entry when emitting reset hooks", async () => {

src/auto-reply/reply/commands-reset-hooks.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export async function emitResetCommandHooks(params: {
104104
sessionEntry?: HandleCommandsParams["sessionEntry"];
105105
previousSessionEntry?: HandleCommandsParams["previousSessionEntry"];
106106
workspaceDir: string;
107-
}): Promise<void> {
107+
}): Promise<{ routedReply: boolean }> {
108108
const hookEvent = createInternalHookEvent("command", params.action, params.sessionKey ?? "", {
109109
sessionEntry: params.sessionEntry,
110110
previousSessionEntry: params.previousSessionEntry,
@@ -116,6 +116,7 @@ export async function emitResetCommandHooks(params: {
116116
await triggerInternalHook(hookEvent);
117117
params.command.resetHookTriggered = true;
118118

119+
let routedReply = false;
119120
if (hookEvent.messages.length > 0) {
120121
const channel = params.ctx.OriginatingChannel || params.command.channel;
121122
const to = params.ctx.OriginatingTo || params.command.from || params.command.to;
@@ -134,6 +135,7 @@ export async function emitResetCommandHooks(params: {
134135
threadId: params.ctx.MessageThreadId,
135136
cfg: params.cfg,
136137
});
138+
routedReply = true;
137139
}
138140
}
139141

@@ -160,4 +162,5 @@ export async function emitResetCommandHooks(params: {
160162
}
161163
})();
162164
}
165+
return { routedReply };
163166
}

src/auto-reply/reply/commands-reset.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ export async function maybeHandleResetCommand(
156156

157157
const targetSessionEntry = params.sessionStore?.[params.sessionKey] ?? params.sessionEntry;
158158

159-
await emitResetCommandHooks({
159+
const hookResult = await emitResetCommandHooks({
160160
action: commandAction,
161161
ctx: params.ctx,
162162
cfg: params.cfg,
@@ -169,9 +169,13 @@ export async function maybeHandleResetCommand(
169169
if (!resetTail) {
170170
return {
171171
shouldContinue: false,
172-
reply: {
173-
text: commandAction === "reset" ? "✅ Session reset." : "✅ New session started.",
174-
},
172+
...(hookResult.routedReply
173+
? {}
174+
: {
175+
reply: {
176+
text: commandAction === "reset" ? "✅ Session reset." : "✅ New session started.",
177+
},
178+
}),
175179
};
176180
}
177181
return null;

0 commit comments

Comments
 (0)