Skip to content

fix(gateway): route multiplex profile responses through the profile's own adapter (#56854 salvage) - #59310

Merged
teknium1 merged 4 commits into
mainfrom
salvage/56854-adapter-routing
Jul 6, 2026
Merged

fix(gateway): route multiplex profile responses through the profile's own adapter (#56854 salvage)#59310
teknium1 merged 4 commits into
mainfrom
salvage/56854-adapter-routing

Conversation

@teknium1

@teknium1 teknium1 commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Summary

In multiplex mode, secondary profiles' replies now go out through their own bot: all 53 remaining self.adapters.get(source.platform) call sites in gateway/run.py are swapped to the profile-aware _adapter_for_source(source) resolver, and the resolver itself now fails closed instead of falling back to the default profile's adapter.

Salvages #56854 by @AndreasHiltner (cherry-picked, authorship preserved) plus the fail-closed resolver hunk from #57417 by @ManniBr (Co-authored-by).

Root cause: phase 3's adapter registry stamped source.profile and bb304b4 added _adapter_for_source, but only 5 of ~55 source-keyed call sites used it. Streaming replies (run.py:17533), typing indicators, media-after-streaming, footers, platform notices, and queue acks all picked self.adapters — the default profile's bot. This is the remaining half of #49634 (session keys were already profile-namespaced; delivery was not).

Changes

  • gateway/run.py: 53 sites self.adapters.get(source.platform)self._adapter_for_source(source) (@AndreasHiltner's commit, conflict-resolved onto current main preserving the _should_echo_stt_transcripts() gating that landed after the PR)
  • gateway/run.py: dropped the original PR's port-binding force-disable hunk — main's fail-fast MultiplexConfigError on secondary-profile port binders is deliberate and stays
  • gateway/authz_mixin.py: _authorization_adapter fails closed for a stamped secondary profile with no registry entry (from fix(gateway): isolate multiplexed profile routing #57417); default stamps still use the primary map
  • scripts/release.py: AUTHOR_MAP entries

Validation

Before After
Secondary-profile streaming reply default profile's bot profile's own bot
Secondary profile w/ failed adapter leaks via default bot dropped (fail closed)
tests/gateway/test_multiplex_* (4 files) 46/46 pass

Part of the multiplex isolation cluster (issues #49634, #52446, #50051). Ordered first; the config.py secret-scope fix follows separately.

Infographic

multiplex-adapter-routing

@alt-glitch alt-glitch added type/bug Something isn't working comp/gateway Gateway runner, session dispatch, delivery area/config Config system, migrations, profiles sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages P2 Medium — degraded but workaround exists labels Jul 6, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

This was generated by AI during triage.

Salvage of #56854 (@AndreasHiltner, broadest) plus the fail-closed resolver hunk from #57417 (@ManniBr). Competing/related multiplex response-delivery cluster: #57492 (44-site routing + profile prompt-stamp), #52225 (~12-site + secret-scope), #49962 (narrow dedicated route); underlying issue #49634. Marked related_to (salvage, not duplicate) — a maintainer should pick the canonical PR from this delivery cluster. Config-gated to gateway.multiplex_profiles, group-chat workaround, so priced P2.

AndreasHiltner and others added 4 commits July 5, 2026 21:37
Replace 53 instances of self.adapters.get(source.platform) with
self._adapter_for_source(source) in gateway/run.py.

self.adapters is the default profile's adapter map. In multiplex mode,
secondary profiles (lars, kira, jonas, caro) have their adapters in
_profile_adapters[profile]. _adapter_for_source() (from authz_mixin.py)
correctly resolves through _profile_adapters when source.profile is set.

Without this fix, ALL response paths for secondary profiles — streaming,
sending, media delivery, voice, typing indicators, queue operations,
startup restore, and platform notices — route through the default
profile's bot token instead of the profile's own token.

Fixes: Multiplex profiles responding with wrong bot token on Telegram,
Discord, and all other platforms.
…ry profiles

Follow-up to the routing sweep: when a stamped secondary profile has no
_profile_adapters entry (adapter failed to connect / was refused), return
None instead of falling back to the default profile's adapter — the
fallback sends replies out the wrong bot, which is the exact leak class
this cluster fixes. Also restores main's deliberate fail-fast on
port-binding platforms in secondary profiles (the cherry-picked commit
had softened it to silent force-disable).

Co-authored-by: ManniBr <m888.braun@hotmail.com>
…_adapter_for_source

The routing sweep sends these paths through _adapter_for_source, which
reads source.profile. A bare MagicMock auto-attribute is truthy, so the
fixtures looked like stamped secondary profiles and hit the new
fail-closed branch. Real SessionSource.profile is None or str
(AGENTS.md pitfall #17).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/config Config system, migrations, profiles comp/gateway Gateway runner, session dispatch, delivery P2 Medium — degraded but workaround exists sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants