|
1 | 1 | // Gateway reload settings resolver. |
2 | | -// Normalizes reload mode and debounce config for watcher/reload handlers. |
| 2 | +// Normalizes reload mode and debounce config for watcher/reload handlers, and |
| 3 | +// owns the shared hot-mode restart policy for restart-required config changes. |
3 | 4 | import type { GatewayReloadMode } from "../config/types.gateway.js"; |
4 | 5 | import type { OpenClawConfig } from "../config/types.openclaw.js"; |
5 | 6 |
|
| 7 | +/** |
| 8 | + * Path prefixes whose restart-required edits must never be deferred by the |
| 9 | + * hot-mode warn-and-keep contract. A live runtime that keeps the old token |
| 10 | + * after `gateway.auth.token` rotates is a credential-rotation-bypass risk: |
| 11 | + * the operator rotates on disk to respond to a leak, but the gateway |
| 12 | + * continues to accept the compromised token until manual restart. |
| 13 | + * |
| 14 | + * - `gateway.auth.*` covers the gateway access boundary itself (token, |
| 15 | + * password, trusted-proxy headers). |
| 16 | + * - `auth.profiles.*` / `auth.order.*` cover model-auth profile routing at |
| 17 | + * the config root. Doctor batch repairs rename stale profiles (for example |
| 18 | + * `auth.profiles.openai-codex:*` -> `auth.profiles.openai:*`) alongside |
| 19 | + * model routes; deferring the rename leaves the runtime authenticating |
| 20 | + * through profiles that no longer exist on disk. |
| 21 | + * - `secrets.*` is deliberately excluded: provider SecretRef rotation is a |
| 22 | + * supported live operation (the committed snapshot resolves the rotated |
| 23 | + * ref without a restart), so escalating it here would replace live |
| 24 | + * credential rotation with an avoidable gateway bounce (ClawSweeper P1 |
| 25 | + * #89517). |
| 26 | + * |
| 27 | + * The set is intentionally conservative; non-auth restart-required reasons |
| 28 | + * keep the shipped warn-and-keep contract. Operators who want blanket |
| 29 | + * auto-restart for restart-required edits use `gateway.reload.mode: "hybrid"`. |
| 30 | + */ |
| 31 | +// `secrets.*` is deliberately absent: provider secret rotation applies live |
| 32 | +// through snapshot SecretRef resolution and must not trigger a restart. |
| 33 | +const SECURITY_CRITICAL_RESTART_PREFIXES = ["gateway.auth", "auth.profiles", "auth.order"] as const; |
| 34 | + |
| 35 | +function isSecurityCriticalRestartReason(reason: string): boolean { |
| 36 | + return SECURITY_CRITICAL_RESTART_PREFIXES.some( |
| 37 | + (prefix) => reason === prefix || reason.startsWith(`${prefix}.`), |
| 38 | + ); |
| 39 | +} |
| 40 | + |
| 41 | +type HotModeRestartDecision = "security-critical" | "warn-and-keep"; |
| 42 | + |
| 43 | +/** |
| 44 | + * Shared hot-mode policy for restart-required config changes. The file |
| 45 | + * watcher (config-reload.ts) and the config.patch/config.apply RPC write path |
| 46 | + * (server-methods/config-write-flow.ts) both route through this decision so |
| 47 | + * the two write surfaces cannot diverge on when hot mode escalates a |
| 48 | + * restart-required change into an actual restart. |
| 49 | + */ |
| 50 | +export function resolveHotModeRestartDecision( |
| 51 | + restartReasons: readonly string[], |
| 52 | +): HotModeRestartDecision { |
| 53 | + return restartReasons.some(isSecurityCriticalRestartReason) |
| 54 | + ? "security-critical" |
| 55 | + : "warn-and-keep"; |
| 56 | +} |
| 57 | + |
6 | 58 | type GatewayReloadSettings = { |
7 | 59 | mode: GatewayReloadMode; |
8 | 60 | debounceMs: number; |
|
0 commit comments