fix(telegram): skip updateLastRoute when dmScope isolates DM sessions#13580
fix(telegram): skip updateLastRoute when dmScope isolates DM sessions#13580lailoo wants to merge 1 commit into
Conversation
Additional Comments (1)
This new test changes Prompt To Fix With AIThis is a comment left during a code review.
Path: src/telegram/bot-message-context.dm-topic-threadid.test.ts
Line: 1:3
Comment:
**Config mock not used**
This new test changes `loadConfig()` via a module mock, but still passes `cfg: baseConfig` into `buildTelegramMessageContext`. If `buildTelegramMessageContext` (or its callees) uses the passed `cfg` instead of calling `loadConfig()`, the test will *not* actually exercise the `dmScope: "per-channel-peer"` path and can pass incorrectly. Either pass `cfg: perChannelPeerConfig` (or assert the function under test calls `loadConfigMock`) so the regression test truly covers the fix.
How can I resolve this? If you propose a fix, please make it concise. |
bfc1ccb to
f92900f
Compare
|
This pull request has been automatically marked as stale due to inactivity. |
|
Closing as AI-assisted stale-fix triage. Linked issue #13559 ("updateLastRoute overwrites webchat session deliveryContext on every Telegram DM") is currently closed and was closed on 2026-02-19T12:38:58Z with state reason completed. If this specific implementation is still needed on current main, please reopen #13580 (or open a new focused fix PR) and reference #13559 for fast re-triage. |
Summary
Fixes #13559
Problem
When
dmScopeis set toper-channel-peer(orper-peer/per-account-channel-peer), Telegram DMs get their own isolated session key (e.g.agent:main:telegram:direct:12345). However,recordInboundSessionstill unconditionally callsupdateLastRoutetargetingroute.mainSessionKey(agent:main:main), overwriting the webchat session'sdeliveryContextwith Telegram routing info. This causes webchat responses to be routed to Telegram.Fix
Gate
updateLastRouteonbaseSessionKey === route.mainSessionKey— only update the main session's delivery context when the DM session actually IS the main session (i.e.dmScope: "main").Before:
After:
Reproduction & Verification
Before fix (main branch) — Bug reproduced with real function calls:
After fix — Verified with real function calls:
Effect on User Experience
Before fix:
With
dmScope: "per-channel-peer", every Telegram DM overwrites the webchat session'sdeliveryContext, causing webchat responses and heartbeats to be routed to Telegram instead of back to the browser.After fix:
Telegram DMs with isolated sessions no longer corrupt the main session. Webchat responses are correctly routed back to the browser. Default behavior (
dmScope: "main") is unchanged.Testing
Greptile Overview
Greptile Summary
This PR prevents Telegram DM traffic from overwriting the main/webchat session’s
deliveryContextwhensession.dmScopeisolates DM sessions. The change gates therecordInboundSession({ updateLastRoute: ... })call insrc/telegram/bot-message-context.tssoupdateLastRouteonly runs when the DM’sbaseSessionKeyequalsroute.mainSessionKey(i.e.,dmScope: "main"). A regression test was added to cover the isolated-session case, and a changelog entry documents the fix.Confidence Score: 4/5
updateLastRouteon main-session equality) and aligns withrecordInboundSession’s behavior. The main concern is the new regression test: it mocksloadConfig()but still passescfg: baseConfigintobuildTelegramMessageContext, so it may not actually exercise the isolateddmScoperoute depending on how config is consumed. Fixing the test to ensure it truly covers the bug would make this PR low-risk.