#22720: fix: notify sessions on invalid config during hot-reload
gateway
size: S
Cluster:
Gateway Hot-Reload Improvements
## Summary
- Config hot-reload (`config-reload.ts:299`) silently drops invalid configs with only a `warn()` log — no notification reaches active sessions or channels
- Added an optional `onInvalidConfig` callback to `startGatewayConfigReloader` that fires with the list of validation issues
- The gateway server wires this to broadcast a `config.invalid` event to all connected sessions, so users/agents get immediate feedback when config is broken
## Impact
When an agent or user edits config incorrectly, they now get notified immediately instead of discovering the issue only after a gateway restart causes downtime.
## Files changed
- `src/gateway/config-reload.ts` — Added `onInvalidConfig` optional callback to opts, invoke it on invalid snapshot
- `src/gateway/server.impl.ts` — Wire `onInvalidConfig` to `broadcast("config.invalid", ...)`
- `src/gateway/config-reload.test.ts` — Added test for `startGatewayConfigReloader` with `onInvalidConfig`
## Test plan
- [x] Existing tests pass: `pnpm vitest run src/gateway/config-reload.test.ts` (9/9 passed)
- [x] Build passes: `pnpm build`
- [ ] E2E: Corrupt config while gateway running → verify session receives `config.invalid` event
🤖 Generated with [Claude Code](https://claude.com/claude-code)
AI was used to generate this PR. Code has been reviewed and lightly tested locally.
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Added `onInvalidConfig` callback to config hot-reload system that broadcasts `config.invalid` events to all connected sessions when validation fails during reload, giving users immediate feedback instead of silent failure.
Changes:
- `src/gateway/config-reload.ts`: Added optional `onInvalidConfig` callback parameter, invokes it with validation issues array when config snapshot is invalid
- `src/gateway/server.impl.ts`: Wires callback to broadcast `config.invalid` event with `dropIfSlow: true`
- `src/gateway/config-reload.test.ts`: Added test verifying callback signature is accepted (type-level check only, not functional test)
The implementation correctly uses optional chaining (`?.`) and follows the existing broadcast pattern used for other events like `voicewake.changed` and `heartbeat`.
<h3>Confidence Score: 4/5</h3>
- Safe to merge with one test improvement suggestion
- Clean implementation following existing patterns. Optional callback correctly uses `?.` operator, broadcast signature matches other events, early return preserves control flow. Test is weak (type-check only) but PR description notes E2E testing needed. No logical errors or runtime issues.
- No files require special attention
<sub>Last reviewed commit: 4899f1c</sub>
<!-- greptile_other_comments_section -->
<sub>(4/5) You can add custom instructions or style guidelines for the agent [here](https://app.greptile.com/review/github)!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#13408: fix(gateway): skip SIGUSR1 restart in config.patch for noop reload ...
by rwmjhb · 2026-02-10
81.7%
#7747: Gateway: add zero-latency hot-reload for agent bindings
by NikolasP98 · 2026-02-03
79.9%
#5823: fix(config): exit cleanly on invalid config instead of high CPU loop
by gavinbmoore · 2026-02-01
79.0%
#4108: gateway: hot-reload heartbeat when agents.list changes
by jifanchn · 2026-01-29
77.9%
#11746: fix: treat meta config paths as no-op to prevent unnecessary gatewa...
by QDenka · 2026-02-08
76.3%
#8473: fix(gateway): prevent spurious restarts on meta.lastTouchedAt changes
by adam-smeth · 2026-02-04
75.7%
#18801: fix(routing): use fresh config in resolveAgentRoute to prevent stal...
by mcaxtr · 2026-02-17
75.6%
#21994: Config: load valid backup when primary config is invalid
by islavutin · 2026-02-20
74.8%
#11280: fix(gateway): add meta prefix to reload rules to prevent double SIG...
by cheenu1092-oss · 2026-02-07
74.8%
#19510: fix(config): preserve configured values on invalid config validatio...
by yash27-lab · 2026-02-17
74.5%