fix: speed up Telegram status diagnostics

This commit is contained in:
Peter Steinberger
2026-04-28 00:27:59 +01:00
parent 3ae796b649
commit fc055e2393
11 changed files with 90 additions and 22 deletions

View File

@@ -76,7 +76,10 @@ describe("telegram bot message processor", () => {
sendMessage: ReturnType<typeof vi.fn>,
) {
const runtimeError = vi.fn();
buildTelegramMessageContext.mockResolvedValue(context);
buildTelegramMessageContext.mockResolvedValue({
sendTyping: vi.fn().mockResolvedValue(undefined),
...context,
});
dispatchTelegramMessage.mockRejectedValue(new Error("dispatch exploded"));
const processMessage = createTelegramMessageProcessor({
...baseDeps,
@@ -87,12 +90,21 @@ describe("telegram bot message processor", () => {
}
it("dispatches when context is available", async () => {
buildTelegramMessageContext.mockResolvedValue({ route: { sessionKey: "agent:main:main" } });
const sendTyping = vi.fn().mockResolvedValue(undefined);
buildTelegramMessageContext.mockResolvedValue({
chatId: 123,
route: { sessionKey: "agent:main:main" },
sendTyping,
});
const processMessage = createTelegramMessageProcessor(baseDeps);
await processSampleMessage(processMessage);
expect(sendTyping).toHaveBeenCalledTimes(1);
expect(dispatchTelegramMessage).toHaveBeenCalledTimes(1);
expect(sendTyping.mock.invocationCallOrder[0]).toBeLessThan(
dispatchTelegramMessage.mock.invocationCallOrder[0],
);
});
it("skips dispatch when no context is produced", async () => {
@@ -102,6 +114,21 @@ describe("telegram bot message processor", () => {
expect(dispatchTelegramMessage).not.toHaveBeenCalled();
});
it("keeps dispatch running when the early typing cue fails", async () => {
const sendTyping = vi.fn().mockRejectedValue(new Error("typing failed"));
buildTelegramMessageContext.mockResolvedValue({
chatId: 123,
route: { sessionKey: "agent:main:main" },
sendTyping,
});
const processMessage = createTelegramMessageProcessor(baseDeps);
await processSampleMessage(processMessage);
expect(sendTyping).toHaveBeenCalledTimes(1);
expect(dispatchTelegramMessage).toHaveBeenCalledTimes(1);
});
it("sends user-visible fallback when dispatch throws", async () => {
const sendMessage = vi.fn().mockResolvedValue(undefined);
const { processMessage, runtimeError } = createDispatchFailureHarness(

View File

@@ -107,6 +107,9 @@ export const createTelegramMessageProcessor = (deps: TelegramMessageProcessorDep
(options?.ingressBuffer ? ` buffer=${options.ingressBuffer}` : ""),
);
}
void context.sendTyping().catch((err) => {
logVerbose(`telegram early typing cue failed for chat ${context.chatId}: ${String(err)}`);
});
try {
await dispatchTelegramMessage({
context,