


























@@ -481,4 +481,91 @@ describe("telegram message cache", () => {
481481expect(context.find((entry) => entry.node.messageId === "33868")?.isReplyTarget).toBe(true);
482482expect(context.find((entry) => entry.node.messageId === "34477")).toBeUndefined();
483483});
484+485+it("does not select messages before the latest session reset command", () => {
486+const cache = createTelegramMessageCache();
487+const beforeSession = Date.parse("2026-05-10T12:40:00.000Z");
488+const sessionStartedAt = Date.parse("2026-05-10T17:30:43.980Z");
489+const afterSession = Date.parse("2026-05-11T23:36:00.000Z");
490+const staleInstruction = "okay so we just flip in openclaw? if yes do it up";
491+const record = (params: {
492+id: number;
493+text: string;
494+timestampMs: number;
495+replyTo?: { id: number; text: string; timestampMs: number };
496+}) =>
497+cache.record({
498+accountId: "default",
499+chatId: 7,
500+threadId: 22534,
501+msg: {
502+chat: { id: 7, type: "supergroup", title: "Ops", is_forum: true },
503+message_thread_id: 22534,
504+message_id: params.id,
505+date: Math.floor(params.timestampMs / 1000),
506+text: params.text,
507+from: { id: params.id, is_bot: false, first_name: "Requester" },
508+ ...(params.replyTo
509+ ? {
510+reply_to_message: {
511+chat: { id: 7, type: "supergroup", title: "Ops", is_forum: true },
512+message_thread_id: 22534,
513+message_id: params.replyTo.id,
514+date: Math.floor(params.replyTo.timestampMs / 1000),
515+text: params.replyTo.text,
516+from: { id: params.replyTo.id, is_bot: false, first_name: "Requester" },
517+} as Message["reply_to_message"],
518+}
519+ : {}),
520+} as Message,
521+});
522+523+record({ id: 84669, text: "earlier topic setup", timestampMs: beforeSession - 1000 });
524+record({ id: 84670, text: staleInstruction, timestampMs: beforeSession });
525+record({ id: 84671, text: "old reply context", timestampMs: beforeSession + 1000 });
526+record({ id: 85000, text: "/new", timestampMs: sessionStartedAt });
527+record({
528+id: 87183,
529+text: "post-reset context",
530+timestampMs: afterSession - 60_000,
531+replyTo: { id: 84670, text: staleInstruction, timestampMs: beforeSession },
532+});
533+record({ id: 87184, text: "how does this determine stability?", timestampMs: afterSession });
534+535+const replyChainNodes = buildTelegramReplyChain({
536+ cache,
537+accountId: "default",
538+chatId: 7,
539+msg: {
540+chat: { id: 7, type: "supergroup", title: "Ops", is_forum: true },
541+message_thread_id: 22534,
542+message_id: 87185,
543+date: Math.floor(afterSession / 1000) + 30,
544+text: "follow up",
545+from: { id: 87185, is_bot: false, first_name: "Requester" },
546+reply_to_message: {
547+chat: { id: 7, type: "supergroup", title: "Ops", is_forum: true },
548+message_thread_id: 22534,
549+message_id: 84670,
550+date: Math.floor(beforeSession / 1000),
551+text: staleInstruction,
552+from: { id: 84670, is_bot: false, first_name: "Requester" },
553+} as Message["reply_to_message"],
554+} as Message,
555+});
556+557+const context = buildTelegramConversationContext({
558+ cache,
559+accountId: "default",
560+chatId: 7,
561+messageId: "87185",
562+threadId: 22534,
563+ replyChainNodes,
564+recentLimit: 10,
565+replyTargetWindowSize: 1,
566+});
567+568+expect(context.map((entry) => entry.node.messageId)).toEqual(["87183", "87184"]);
569+expect(context.map((entry) => entry.node.body)).not.toContain(staleInstruction);
570+});
484571});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。