fix: mark buffered reply typing runs complete

This commit is contained in:
Peter Steinberger
2026-03-28 07:54:38 +00:00
parent be38986141
commit bd4632b9c1
2 changed files with 36 additions and 4 deletions

View File

@@ -1,6 +1,10 @@
import { describe, expect, it, vi } from "vitest";
import type { OpenClawConfig } from "../config/config.js";
import { dispatchInboundMessage, withReplyDispatcher } from "./dispatch.js";
import {
dispatchInboundMessage,
dispatchInboundMessageWithBufferedDispatcher,
withReplyDispatcher,
} from "./dispatch.js";
import type { ReplyDispatcher } from "./reply/reply-dispatcher.js";
import { buildTestCtx } from "./reply/test-ctx.js";
@@ -90,4 +94,32 @@ describe("withReplyDispatcher", () => {
expect(order).toEqual(["sendFinalReply", "markComplete", "waitForIdle"]);
});
it("dispatchInboundMessageWithBufferedDispatcher cleans up typing after a resolver starts it", async () => {
const typing = {
onReplyStart: vi.fn(async () => {}),
startTypingLoop: vi.fn(async () => {}),
startTypingOnText: vi.fn(async () => {}),
refreshTypingTtl: vi.fn(),
isActive: vi.fn(() => true),
markRunComplete: vi.fn(),
markDispatchIdle: vi.fn(),
cleanup: vi.fn(),
};
await dispatchInboundMessageWithBufferedDispatcher({
ctx: buildTestCtx(),
cfg: {} as OpenClawConfig,
dispatcherOptions: {
deliver: async () => undefined,
},
replyResolver: async (_ctx, opts) => {
opts?.onTypingController?.(typing);
return { text: "ok" };
},
});
expect(typing.markRunComplete).toHaveBeenCalledTimes(1);
expect(typing.markDispatchIdle).toHaveBeenCalled();
});
});

View File

@@ -60,9 +60,8 @@ export async function dispatchInboundMessageWithBufferedDispatcher(params: {
replyOptions?: Omit<GetReplyOptions, "onToolResult" | "onBlockReply">;
replyResolver?: typeof import("./reply.js").getReplyFromConfig;
}): Promise<DispatchInboundResult> {
const { dispatcher, replyOptions, markDispatchIdle } = createReplyDispatcherWithTyping(
params.dispatcherOptions,
);
const { dispatcher, replyOptions, markDispatchIdle, markRunComplete } =
createReplyDispatcherWithTyping(params.dispatcherOptions);
try {
return await dispatchInboundMessage({
ctx: params.ctx,
@@ -75,6 +74,7 @@ export async function dispatchInboundMessageWithBufferedDispatcher(params: {
},
});
} finally {
markRunComplete();
markDispatchIdle();
}
}