#22858: Gateway: add eager secrets runtime snapshot activation
gateway
commands
agents
maintainer
size: XL
Cluster:
Gateway Hot-Reload Improvements
## Summary
- add a new secrets runtime snapshot service that eagerly resolves `${ENV}` and `file+sops` SecretRefs
- activate resolved secrets at gateway startup (fail-fast) and on config reload with last-known-good rollback on apply failures
- add runtime in-memory snapshots for config + auth profiles so hot paths read resolved secrets without disk/sops/env provider calls
- add auth-profile value-level refs (`keyRef`/`tokenRef`) with ref-over-plaintext precedence warnings
## What changed
- new `src/secrets/runtime.ts` resolver/activation module
- gateway startup/reload wiring in `src/gateway/server.impl.ts`
- reload sequencing improvements in `src/gateway/config-reload.ts` (don’t advance current config on hot-reload failures)
- runtime config snapshot hooks in `src/config/io.ts` (+ exports)
- runtime auth-profile snapshot hooks in `src/agents/auth-profiles/store.ts` (+ exports)
- model provider `apiKey` type widened to `SecretInput` and related call-sites adjusted
- tests: `src/secrets/runtime.test.ts`
## Validation
- `pnpm lint`
- `pnpm vitest src/secrets/runtime.test.ts src/gateway/config-reload.test.ts src/agents/pi-auth-json.test.ts`
- `pnpm vitest src/config/config.secrets-schema.test.ts`
- `pnpm tsgo` (fails on pre-existing repo issues in `src/agents/google-gemini-switch.live.test.ts` and `src/discord/voice/manager.ts`)
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Introduces eager secrets resolution with runtime snapshots for `${ENV}` and `file+sops` SecretRefs. The implementation activates resolved secrets at gateway startup with fail-fast validation, and on config reload with last-known-good rollback on failures. Auth-profile value-level refs (`keyRef`/`tokenRef`) are added with ref-over-plaintext precedence warnings. Config reload sequencing now advances `currentConfig` only after successful hot-reload application, preventing partial state updates on failures.
<h3>Confidence Score: 4/5</h3>
- This PR is safe to merge with minimal risk.
- The implementation is well-structured with comprehensive error handling, fail-fast validation, and rollback mechanisms. The double activation issue from the previous thread has been fixed. Test coverage validates the core functionality. Minor risk remains around edge cases in JSON pointer handling and sops timeout scenarios.
- No files require special attention
<sub>Last reviewed commit: f814a5b</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#22980: Gateway: add manual secrets reload command
by joshavant · 2026-02-21
84.9%
#22766: fix(security): enable gateway auth rate limiting by default (CWE-307)
by brandonwise · 2026-02-21
74.1%
#23355: Gateway: fail closed on untrusted proxy headers
by bmendonca3 · 2026-02-22
73.2%
#22765: docs(gateway): add secrets providers guide (env/keyring/1Password/c...
by alexmelges · 2026-02-21
72.9%
#23364: Gateway: add risk-ack interlock for dangerous Control UI flags
by bmendonca3 · 2026-02-22
72.4%
#23410: Gateway: require prefixes for hook request session-key overrides
by bmendonca3 · 2026-02-22
72.3%
#23000: Secrets: add migrate rollback and skill ref support
by joshavant · 2026-02-21
72.2%
#23444: Gateway: move auth token storage to state dotenv by default
by bmendonca3 · 2026-02-22
72.1%
#21120: Security/Gateway: guard dangerous HTTP /tools/invoke re-enables
by bmendonca3 · 2026-02-19
71.8%
#16663: feat: GCP Secret Manager integration for external secrets management
by amor71 · 2026-02-15
71.6%