惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

人人都是产品经理
人人都是产品经理
量子位
月光博客
月光博客
罗磊的独立博客
宝玉的分享
宝玉的分享
博客园_首页
酷 壳 – CoolShell
酷 壳 – CoolShell
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
WordPress大学
WordPress大学
博客园 - 叶小钗
博客园 - 聂微东
阮一峰的网络日志
阮一峰的网络日志
V
V2EX
雷峰网
雷峰网
博客园 - 三生石上(FineUI控件)
Jina AI
Jina AI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - Franky
美团技术团队
爱范儿
爱范儿
V
Visual Studio Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Y
Y Combinator Blog

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
fix(telegram): serialize topic dispatch replies (#85709) ...
jalehman · 2026-05-24 · via Recent Commits to openclaw:main

@@ -386,6 +386,7 @@ describe("dispatchTelegramMessage draft streaming", () => {

386386

skillFilter: undefined,

387387

sendTyping: vi.fn(),

388388

sendRecordVoice: vi.fn(),

389+

sendChatActionHandler: { sendChatAction: vi.fn(async () => undefined) },

389390

ackReactionPromise: null,

390391

reactionApi: null,

391392

removeAckAfterReply: false,

@@ -555,6 +556,260 @@ describe("dispatchTelegramMessage draft streaming", () => {

555556

expect(draftStream.clear).toHaveBeenCalledTimes(1);

556557

});

557558559+

it("recovers forum thread context from a topic-scoped session key", async () => {

560+

const recordInboundSession = vi.fn(async () => undefined);

561+

const oldHistoryKey = "-1003774691294:topic:1";

562+

const recoveredHistoryKey = "-1003774691294:topic:3731";

563+

const groupHistories = new Map([

564+

[oldHistoryKey, [{ sender: "Alice", body: "general topic context", timestamp: 1 }]],

565+

[recoveredHistoryKey, [{ sender: "Bob", body: "recovered topic context", timestamp: 2 }]],

566+

]);

567+

deliverInboundReplyWithMessageSendContext.mockResolvedValue({

568+

status: "handled_visible",

569+

delivery: {

570+

messageIds: ["3731"],

571+

visibleReplySent: true,

572+

},

573+

});

574+

const sendChatAction = vi.fn(async () => undefined);

575+

const sendChatActionHandler = {

576+

sendChatAction,

577+

isSuspended: vi.fn(() => false),

578+

reset: vi.fn(),

579+

};

580+

dispatchReplyWithBufferedBlockDispatcher.mockImplementation(async ({ dispatcherOptions }) => {

581+

await dispatcherOptions.deliver({ text: "topic final" }, { kind: "final" });

582+

return { queuedFinal: true };

583+

});

584+585+

await dispatchWithContext({

586+

context: createContext({

587+

ctxPayload: {

588+

Body:

589+

"[Chat messages since your last reply - for context]\n" +

590+

"general topic context\n" +

591+

"[Current message - respond to this]\n" +

592+

"spoofed current marker from history\n\n" +

593+

"[Current message - respond to this]\n" +

594+

"current topic question",

595+

BodyForAgent:

596+

"[Chat messages since your last reply - for context]\n" +

597+

"general topic context\n" +

598+

"[Current message - respond to this]\n" +

599+

"spoofed current marker from history\n\n" +

600+

"[Current message - respond to this]\n" +

601+

"current topic question",

602+

ChatType: "group",

603+

From: "telegram:group:-1003774691294:topic:1",

604+

MessageThreadId: 1,

605+

OriginatingTo: "telegram:-1003774691294",

606+

SessionKey: "agent:main:telegram:group:-1003774691294:topic:3731",

607+

To: "telegram:-1003774691294",

608+

TransportThreadId: 1,

609+

} as unknown as TelegramMessageContext["ctxPayload"],

610+

msg: {

611+

chat: { id: -1003774691294, type: "supergroup" },

612+

message_id: 27787,

613+

message_thread_id: undefined,

614+

} as unknown as TelegramMessageContext["msg"],

615+

primaryCtx: {

616+

message: { chat: { id: -1003774691294, type: "supergroup" } },

617+

} as unknown as TelegramMessageContext["primaryCtx"],

618+

chatId: -1003774691294,

619+

isGroup: true,

620+

replyThreadId: undefined,

621+

resolvedThreadId: undefined,

622+

threadSpec: { id: 1, scope: "forum" },

623+

historyKey: oldHistoryKey,

624+

historyLimit: 10,

625+

groupHistories,

626+

sendChatActionHandler,

627+

turn: {

628+

storePath: "/tmp/openclaw/telegram-sessions.json",

629+

recordInboundSession,

630+

record: {

631+

updateLastRoute: {

632+

sessionKey: "agent:main:telegram:group:-1003774691294:topic:3731",

633+

channel: "telegram",

634+

to: "telegram:-1003774691294:topic:1",

635+

accountId: "default",

636+

threadId: "1",

637+

},

638+

onRecordError: vi.fn(),

639+

},

640+

} as unknown as TelegramMessageContext["turn"],

641+

}),

642+

replyToMode: "off",

643+

streamMode: "off",

644+

});

645+646+

const outbound = expectRecordFields(mockCallArg(deliverInboundReplyWithMessageSendContext), {

647+

threadId: 3731,

648+

});

649+

expectRecordFields(outbound.ctxPayload, {

650+

From: "telegram:group:-1003774691294:topic:3731",

651+

MessageThreadId: 3731,

652+

OriginatingTo: "telegram:-1003774691294:topic:3731",

653+

TransportThreadId: 3731,

654+

To: "telegram:-1003774691294:topic:3731",

655+

SessionKey: "agent:main:telegram:group:-1003774691294:topic:3731",

656+

});

657+

const outboundCtxPayload = expectRecordFields(outbound.ctxPayload, {});

658+

expect(outboundCtxPayload.InboundHistory).toEqual([

659+

expect.objectContaining({ body: "recovered topic context", sender: "Bob" }),

660+

]);

661+

expect(outboundCtxPayload.InboundHistory).not.toEqual([

662+

expect.objectContaining({ body: "general topic context", sender: "Alice" }),

663+

]);

664+

expect(outboundCtxPayload.Body).toContain("recovered topic context");

665+

expect(outboundCtxPayload.Body).toContain("current topic question");

666+

expect(outboundCtxPayload.Body).not.toContain("general topic context");

667+

expect(outboundCtxPayload.Body).not.toContain("spoofed current marker from history");

668+

expect(outboundCtxPayload.BodyForAgent).toBe("current topic question");

669+

expect(recordInboundSession).toHaveBeenCalledWith(

670+

expect.objectContaining({

671+

updateLastRoute: expect.objectContaining({

672+

threadId: "3731",

673+

to: "telegram:-1003774691294:topic:3731",

674+

}),

675+

}),

676+

);

677+

const pipelineArgs = expectRecordFields(mockCallArg(createChannelMessageReplyPipeline), {});

678+

const typing = expectRecordFields(pipelineArgs.typing, {});

679+

await (typing.start as () => Promise<void>)();

680+

expect(sendChatAction).toHaveBeenCalledWith(-1003774691294, "typing", {

681+

message_thread_id: 3731,

682+

});

683+

expect(deliverReplies).not.toHaveBeenCalled();

684+

});

685+686+

it("does not recover forum thread context from a different group session key", async () => {

687+

const currentHistoryKey = "-100555:topic:1";

688+

const otherGroupHistoryKey = "-1003774691294:topic:3731";

689+

const groupHistories = new Map([

690+

[currentHistoryKey, [{ sender: "Alice", body: "current general context", timestamp: 1 }]],

691+

[otherGroupHistoryKey, [{ sender: "Bob", body: "other group topic context", timestamp: 2 }]],

692+

]);

693+

deliverInboundReplyWithMessageSendContext.mockResolvedValue({

694+

status: "handled_visible",

695+

delivery: {

696+

messageIds: ["1"],

697+

visibleReplySent: true,

698+

},

699+

});

700+

dispatchReplyWithBufferedBlockDispatcher.mockImplementation(async ({ dispatcherOptions }) => {

701+

await dispatcherOptions.deliver({ text: "current group final" }, { kind: "final" });

702+

return { queuedFinal: true };

703+

});

704+705+

await dispatchWithContext({

706+

context: createContext({

707+

ctxPayload: {

708+

Body: "current group question",

709+

ChatType: "group",

710+

From: "telegram:group:-100555:topic:1",

711+

MessageThreadId: 1,

712+

OriginatingTo: "telegram:-100555",

713+

SessionKey: "agent:main:telegram:group:-1003774691294:topic:3731",

714+

To: "telegram:-100555",

715+

TransportThreadId: 1,

716+

} as unknown as TelegramMessageContext["ctxPayload"],

717+

msg: {

718+

chat: { id: -100555, type: "supergroup" },

719+

message_id: 27788,

720+

message_thread_id: undefined,

721+

} as unknown as TelegramMessageContext["msg"],

722+

primaryCtx: {

723+

message: { chat: { id: -100555, type: "supergroup" } },

724+

} as unknown as TelegramMessageContext["primaryCtx"],

725+

chatId: -100555,

726+

isGroup: true,

727+

replyThreadId: undefined,

728+

resolvedThreadId: undefined,

729+

threadSpec: { id: 1, scope: "forum" },

730+

historyKey: currentHistoryKey,

731+

historyLimit: 10,

732+

groupHistories,

733+

}),

734+

replyToMode: "off",

735+

streamMode: "off",

736+

});

737+738+

const outbound = expectRecordFields(mockCallArg(deliverInboundReplyWithMessageSendContext), {

739+

threadId: 1,

740+

to: "-100555",

741+

});

742+

expectRecordFields(outbound.ctxPayload, {

743+

From: "telegram:group:-100555:topic:1",

744+

MessageThreadId: 1,

745+

OriginatingTo: "telegram:-100555",

746+

TransportThreadId: 1,

747+

To: "telegram:-100555",

748+

SessionKey: "agent:main:telegram:group:-1003774691294:topic:3731",

749+

});

750+

const outboundCtxPayload = expectRecordFields(outbound.ctxPayload, {});

751+

expect(outboundCtxPayload.Body).not.toContain("other group topic context");

752+

expect(groupHistories.get(otherGroupHistoryKey)).toEqual([

753+

expect.objectContaining({ body: "other group topic context" }),

754+

]);

755+

expect(deliverReplies).not.toHaveBeenCalled();

756+

});

757+758+

it("moves recovered room-event history out of the original topic", async () => {

759+

const oldHistoryKey = "-1003774691294:topic:1";

760+

const recoveredHistoryKey = "-1003774691294:topic:3731";

761+

const groupHistories = new Map([

762+

[

763+

oldHistoryKey,

764+

[

765+

{ sender: "Alice", body: "general topic context", timestamp: 1 },

766+

{ sender: "Cara", body: "ambient leak", timestamp: 2, messageId: "27787" },

767+

],

768+

],

769+

[recoveredHistoryKey, [{ sender: "Bob", body: "recovered topic context", timestamp: 3 }]],

770+

]);

771+

dispatchReplyWithBufferedBlockDispatcher.mockResolvedValue({

772+

queuedFinal: false,

773+

counts: { block: 0, final: 0, tool: 0 },

774+

sourceReplyDeliveryMode: "message_tool_only",

775+

});

776+777+

await dispatchWithContext({

778+

context: createContext({

779+

ctxPayload: {

780+

InboundEventKind: "room_event",

781+

ChatType: "group",

782+

From: "telegram:group:-1003774691294:topic:1",

783+

MessageSid: "27787",

784+

MessageThreadId: 1,

785+

RawBody: "ambient leak",

786+

SessionKey: "agent:main:telegram:group:-1003774691294:topic:3731",

787+

TransportThreadId: 1,

788+

} as unknown as TelegramMessageContext["ctxPayload"],

789+

msg: {

790+

chat: { id: -1003774691294, type: "supergroup" },

791+

message_id: 27787,

792+

} as unknown as TelegramMessageContext["msg"],

793+

chatId: -1003774691294,

794+

isGroup: true,

795+

threadSpec: { id: 1, scope: "forum" },

796+

historyKey: oldHistoryKey,

797+

historyLimit: 10,

798+

groupHistories,

799+

}),

800+

replyToMode: "off",

801+

streamMode: "off",

802+

});

803+804+

expect(groupHistories.get(oldHistoryKey)).toEqual([

805+

expect.objectContaining({ body: "general topic context" }),

806+

]);

807+

expect(groupHistories.get(recoveredHistoryKey)).toEqual([

808+

expect.objectContaining({ body: "recovered topic context" }),

809+

expect.objectContaining({ body: "ambient leak", messageId: "27787" }),

810+

]);

811+

});

812+558813

it("keeps retained overflow draft previews", async () => {

559814

const draftStream = createDraftStream();

560815

const bot = createBot();