Skip to content

fix(gateway): preserve interrupt session routing - #47458

Closed
markoub wants to merge 1 commit into
NousResearch:mainfrom
markoub:markoub/preserve-interrupt-session-source
Closed

fix(gateway): preserve interrupt session routing#47458
markoub wants to merge 1 commit into
NousResearch:mainfrom
markoub:markoub/preserve-interrupt-session-source

Conversation

@markoub

@markoub markoub commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Summary

Preserve the cached source for a gateway session when a pending or interrupting event is replayed under the original session key, so streaming and status sends can keep Mattermost/Telegram thread routing instead of falling back to the flat channel.

Changes

  • keep the first cached SessionSource for an active session instead of replacing it during replayed follow-ups
  • add _thread_metadata_for_session_source() so current-source thread metadata still wins, while missing metadata falls back to the cached session source
  • add regression coverage for Mattermost thread fallback, current-thread precedence, and Telegram topic fallback

Fixes #47445.

Validation

  • uv sync --frozen --extra dev --extra messaging
  • uv run scripts/run_tests.sh tests/gateway/test_session_source_cache.py tests/gateway/test_mattermost.py tests/gateway/test_stream_consumer_thread_routing.py -- --tb=long (71 passed)
  • uv run ruff check gateway/run.py tests/gateway/test_session_source_cache.py
  • uv run ty check tests/gateway/test_session_source_cache.py
  • git diff --check
  • git diff --check origin/main...HEAD

@alt-glitch alt-glitch added type/bug Something isn't working comp/gateway Gateway runner, session dispatch, delivery P2 Medium — degraded but workaround exists labels Jun 16, 2026
@teknium1

teknium1 commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Closing along with #47445 — after tracing the issue's mechanism against current main, the described cross-thread session-source corruption can't occur: build_session_key() embeds thread_id, so a message from a different thread/channel lands in a different session and never touches the running session's source. The fallback-to-cached-source half is already on main via #21206. Full trace in #47445 (comment) (closing comment there).

Appreciate the clean implementation and tests — the premise just doesn't hold on current main. If you can reproduce wrong-thread delivery on a current build, please comment on #47445 with a gateway.log excerpt.

@teknium1 teknium1 closed this Jul 6, 2026
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 type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: preserve session source and thread metadata across cross-thread interrupts

3 participants