Skip to content

fix(gateway): multiplex primary gateways resolve bot tokens through profile secret scope (#64986 salvage) - #65525

Merged
teknium1 merged 2 commits into
mainfrom
salvage/64986-multiplex-primary-token
Jul 16, 2026
Merged

fix(gateway): multiplex primary gateways resolve bot tokens through profile secret scope (#64986 salvage)#65525
teknium1 merged 2 commits into
mainfrom
salvage/64986-multiplex-primary-token

Conversation

@teknium1

Copy link
Copy Markdown
Contributor

Summary

Under gateway.multiplex_profiles: true, the default-profile gateway now resolves platform bot tokens through its own profile secret scope instead of bare os.environ — so a token living only in a profile .env connects at startup instead of failing into an infinite 60s reconnect loop. Closes #64674.

Salvages PR #64986 by @SAMBAS123 (root cause traced line-by-line in the issue by @stupidsexyhermes), plus two hardening follow-ups.

Changes

Contributor commit (cherry-picked, authorship preserved):

  • load_gateway_config_for_runner() — when multiplex is on, reload config under the default profile's _profile_runtime_scope (the same seam secondary profiles already use since fix(gateway): read platform env overrides through the profile secret scope (#50094 salvage) #59315). Multiplex off = legacy unscoped path, unchanged.
  • Primary startup skips token platforms that still have no credential under multiplex instead of connect-fail-looping; secondary profiles that own the token still connect.
  • Reconnect watcher drops empty-token queued configs so they can't spin forever.
  • tests/gateway/test_64674_multiplex_primary_token_scope.py — 8 regression tests.

Our follow-ups:

  • _platform_has_bot_credential() now reads PLATFORM_TOKEN_ENV_NAMES, a new canonical map in gateway/config.py shared with the empty-token validation warning — replaces the PR's hardcoded 6-platform set so future token platforms can't drift between the two sites.
  • After secondary-profile startup, any platform skipped on the primary that NO secondary ended up serving triggers a loud warning: an enabled platform with no credential anywhere is a config error, not a silent dead channel.
  • AUTHOR_MAP entry for the salvage.

Validation

Check Result
test_64674_multiplex_primary_token_scope.py 8/8 passed
tests/gateway/ -k "multiplex or token" 284 passed, 0 failed
E2E (temp HERMES_HOME, token only in profile .env, absent from os.environ) token resolves through scope; empty-token gate skips; non-token platforms (Signal) never skipped; multiplex-off path unchanged
ruff clean

Related: follow-on to #49415 / #59315 (secondary-profile scoped loads). Complementary to the open multiplex cluster (#64461 authz/Slack/webhook scoping, #63256, #51115) — no file-level or semantic conflicts: this PR only touches the primary startup/reconnect path.

Infographic

multiplex-token-gate

doogie and others added 2 commits July 16, 2026 01:47
…nnect loops

When gateway.multiplex_profiles is on, the default-profile GatewayRunner
used to call load_gateway_config() unscoped. Platform tokens that lived
only in a profile .env (often a secondary profile) never reached the
primary Telegram adapter, producing "No bot token configured" and an
infinite reconnect watcher loop (#64674).

- Load primary config under the default profile secret scope when multiplex
  is enabled (same path secondary adapters already use).
- Skip starting token platforms on the default profile when no credential
  is present under multiplex; secondary profiles still connect with their
  scoped tokens.
- Drop empty-token configs from the reconnect queue so they cannot spin
  forever.

Regression coverage in tests/gateway/test_64674_multiplex_primary_token_scope.py.
…m map + unserved-platform warning

Follow-ups to @SAMBAS123's #64986 salvage:

- Replace the hardcoded token-platform set in _platform_has_bot_credential
  with PLATFORM_TOKEN_ENV_NAMES, a shared canonical map in gateway/config.py
  also used by the empty-token validation warning — one source of truth, so
  future token platforms can't silently bypass the gate or drift between
  the two sites.
- After secondary-profile startup, warn loudly for any platform skipped on
  the primary that no secondary profile ended up serving: an enabled
  platform with no credential anywhere is a config error, not a silent
  no-op.
- AUTHOR_MAP entry for the salvaged commit's author email.
@alt-glitch alt-glitch added type/security Security vulnerability or hardening P2 Medium — degraded but workaround exists comp/gateway Gateway runner, session dispatch, delivery area/auth Authentication, OAuth, credential pools sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages labels Jul 16, 2026
@teknium1
teknium1 merged commit b4e4b5a into main Jul 16, 2026
33 checks passed
@teknium1
teknium1 deleted the salvage/64986-multiplex-primary-token branch July 16, 2026 11:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/auth Authentication, OAuth, credential pools 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/security Security vulnerability or hardening

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Telegram adapter fails to start on default-profile gateway when multiplex_profiles: true and bot token lives in a secondary profile .env

2 participants