Skip to content

fix(telegram): pass source.thread_id explicitly on auto-reset notice (carve-out of #7404)#23440

Merged
teknium1 merged 1 commit into
mainfrom
salvage/pr-7404
May 10, 2026
Merged

fix(telegram): pass source.thread_id explicitly on auto-reset notice (carve-out of #7404)#23440
teknium1 merged 1 commit into
mainfrom
salvage/pr-7404

Conversation

@teknium1

Copy link
Copy Markdown
Contributor

Summary

Telegram auto-reset notices ("◐ Session automatically reset…") could land in the wrong forum topic — General or a sibling topic — instead of the topic the user was last active in. Now the notice carries source.thread_id explicitly via the existing _thread_metadata_for_source helper.

What was wrong

gateway/run.py:7026-7028 sent the notice with metadata=getattr(event, 'metadata', None). The event.metadata isn't guaranteed to carry the originating thread_id (varies by adapter and by which code path constructed the event), so the notice could route to a different topic.

Fix

await adapter.send(
    source.chat_id, notice,
    metadata=self._thread_metadata_for_source(source),
)

The helper builds {thread_id, ...} and also handles Telegram DM topic reply-fallback metadata (telegram_dm_topic_reply_fallback, telegram_reply_to_message_id) — used everywhere else in the gateway for thread-aware sends.

Carve-out from PR #7404

PR #7404 by @keyuyuan had two hunks:

Validation

tests/gateway/test_telegram_thread_fallback.py, test_session_reset_notify.py, test_fresh_reset_skill_injection.py: 56/56 pass.

The existing helper is covered by test_base_gateway_metadata_marks_telegram_dm_topics_as_reply_fallback and adjacent fallback tests; this one-line change opts the auto-reset path into that contract.

Note on issue #7355

This is path B (auto-reset notice). Path A (final response chunk) was already on main via _status_thread_metadata. Path C (stream consumer first message) was closed in PR #23437 (salvage of #13077). With this carve-out, all three paths in #7355 are addressed.

Closes #7355 (final).
Carve-out of #7404; @keyuyuan's authorship preserved.

…(carve-out of #7404)

The auto-reset notice ("◐ Session automatically reset…") was being sent
with metadata=getattr(event, 'metadata', None), which can drop or
mis-route in Telegram forum topics: the event's metadata isn't
guaranteed to carry the originating thread_id, so the notice could leak
into General or another topic.

Use the existing self._thread_metadata_for_source(source) helper, which
already handles thread_id construction plus the Telegram DM topic
reply-fallback shape used everywhere else in the gateway.

Carve-out of #7404. The PR's other hunk (line 7578, queued first
response) is already redundant on main — gateway/run.py:15782 has used
_status_thread_metadata since the _thread_metadata_for_source plumbing
landed.

Closes #7355 (path B; paths A and C closed via prior salvage merges).
@github-actions

Copy link
Copy Markdown
Contributor

🔎 Lint report: salvage/pr-7404 vs origin/main

ruff

Total: 0 on HEAD, 0 on base (➖ 0)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 0 pre-existing issues carried over.

ty (type checker)

Total: 8075 on HEAD, 8075 on base (➖ 0)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 4255 pre-existing issues carried over.

Diagnostics are surfaced as warnings — this check never fails the build.

@alt-glitch alt-glitch added type/bug Something isn't working comp/gateway Gateway runner, session dispatch, delivery platform/telegram Telegram bot adapter P2 Medium — degraded but workaround exists labels May 10, 2026
@teknium1 teknium1 merged commit 2f00559 into main May 10, 2026
15 of 18 checks passed
@teknium1 teknium1 deleted the salvage/pr-7404 branch May 10, 2026 23:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/gateway Gateway runner, session dispatch, delivery P2 Medium — degraded but workaround exists platform/telegram Telegram bot adapter type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Telegram: Final response chunks lose thread_id, breaking forum topic routing

3 participants