fix(gateway): read platform env overrides through the profile secret scope (#50094 salvage) - #59315
Merged
Merged
Conversation
Contributor
Salvage of #50094 (@izumi0uu, earliest open). Related open work in the multiplex profile-secret-scope cluster: #55277 / #51115 (platform-token facet, both dup of #50094), #52399 (API_SERVER facet), #59076 (email-adapter facet). Marked |
This was referenced Jul 6, 2026
Fixes #50051 by preserving nested gateway.multiplex_profiles and routing gateway config env reads through the active profile secret scope when present. This keeps secondary profile adapter startup from inheriting default-profile platform tokens or port-binding enables while preserving legacy single-profile behavior outside a scope. Constraint: latest upstream main f57ff7a still reproduced both nested-config loss and cross-profile env leakage Rejected: special-casing API_SERVER_* only | left other profile-scoped tokens vulnerable to the same leak Confidence: high Scope-risk: moderate Directive: keep future gateway/config env reads on the scoped helper path unless a variable is explicitly process-global Tested: pytest -q tests/gateway/test_multiplex_phase0.py tests/gateway/test_multiplex_credential_isolation.py tests/gateway/test_config.py -k 'multiplex or scope or getenv or api_server or relay' Not-tested: full gateway startup across live platform adapters
teknium1
force-pushed
the
salvage/50094-config-secret-scope
branch
from
July 6, 2026 04:51
6ef61a1 to
9492356
Compare
This was referenced Jul 15, 2026
19 tasks
8 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Multiplexed secondary profiles now read their own platform tokens:
gateway/config.py::_apply_env_overridesroutes all ~174 env reads through a scope-aware_getenv()that prefers the active profile secret scope and falls back to legacyos.environonly when no scope is installed.Salvages #50094 by @izumi0uu (cherry-picked, authorship preserved). Fixes the root cause of #50051 / #52446 / #49415 / #54675.
Root cause: phase 2's fail-closed credential isolation covered
runtime_providerandhermes_cli/config.py, butgateway/config.pynever learned aboutagent.secret_scope. The multiplexer loads each secondary profile's config inside_profile_runtime_scope— which installs the profile's.envas a contextvar without touchingos.environ— soload_gateway_config()read the PRIMARY profile's TELEGRAM_BOT_TOKEN/DISCORD_BOT_TOKEN/etc. for every profile. The profile's own tokens were never seen; the collision guard then refused the duplicate and killed the secondary adapter.Changes
gateway/config.py: new_getenv/_getenv_str/_getenv_inthelpers — scoped read whencurrent_secret_scope()is installed, legacyos.environotherwise (crash-safe for the ~15 unscopedload_gateway_config()call sites in run.py, unlike the competing blanket-get_secretapproaches);_apply_env_overridesswept to use them; boolean reads use the sharedis_truthy_valuehelpertests/gateway/test_config.py: regression test proving a scoped secondary profile resolves its own DISCORD_BOT_TOKEN and does not inherit the default profile's API_SERVER_ENABLEDgateway:section merge + its test — that fix ships separately (fix(gateway): read multiplex_profiles from nested gateway section #51372 salvage, next in this cluster)scripts/release.py: AUTHOR_MAP entryValidation
.envload_gateway_config()(single-profile)Second PR in the multiplex isolation cluster, after the adapter-routing sweep (#59310).
Infographic