Skip to content

[codex] fix gateway hot-mode restart reloads - #89517

Closed
amittell wants to merge 2 commits into
openclaw:mainfrom
amittell:codex/gateway-restart-required-diagnostics
Closed

amittell wants to merge 2 commits into
openclaw:mainfrom
amittell:codex/gateway-restart-required-diagnostics

Conversation

@amittell

@amittell amittell commented Jun 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Closes the silent-staleness hole in gateway.reload.mode: "hot" for security-critical config, without adding any config surface. Hot mode keeps the shipped warn-and-keep contract for routine restart-required edits; restart reasons under gateway.auth.*, auth.profiles.* / auth.order.*, and secrets.providers.* now always schedule a supervised restart. Without this, a gateway.auth.token rotation, a doctor batch that renames auth.profiles.openai-codex:* profiles, or a secrets.providers.* credential rotation on disk sits behind warn-and-keep while the runtime keeps honoring the stale credential/profile state.

Design trim per review: earlier revisions of this PR added a gateway.reload.autoRestartOnRequired opt-in key. Review correctly pointed out that gateway.reload.mode: "hybrid" (the default) already provides exactly hot-then-restart for restart-required edits, so the key duplicated an existing mode on a compatibility-sensitive config surface. The key is now removed entirely (types, zod schema, schema help/labels, docs, tests); operators who want blanket auto-restart for restart-required edits use mode: "hybrid", and the docs say so. What remains is the PR's unique value: the always-on security carve-out in hot mode, plus watcher/RPC decision parity.

The hot-mode restart policy is one shared decision (resolveHotModeRestartDecision) used by both the file watcher and the config.patch / config.apply RPC write path, so the two write surfaces cannot diverge. Maintainer call-out: this deliberately changes current RPC behavior in hot mode: on main, config-write-flow.ts schedules a direct restart for any restart-required config.patch/config.apply write when mode === "hot"; with this PR, routine restart-required RPC writes return a requiresRestart notice without bouncing the gateway (matching the watcher's warn-and-keep contract), while security-critical writes still direct-restart. If maintainers prefer the RPC surface to keep direct-restarting unconditionally, that is a one-line change in resolveConfigRestartRequirement.

Details

  • src/gateway/config-reload-settings.ts:33: SECURITY_CRITICAL_RESTART_PREFIXES = ["gateway.auth", "auth.profiles", "auth.order", "secrets"]. The auth.profiles / auth.order entries cover the production repro (doctor batch renaming auth.profiles.openai-codex:* with model routes): those paths are unmatched in the reload-plan rules, default to restart-required, and default hot mode dropped them with a warn.
  • Secrets wording (review P2): docs and schema.help now say secrets.providers.*, which is the only secrets.* prefix the reload planner classifies restart-required (src/gateway/config-reload-plan.ts:148); other secrets.* namespaces stay hot/no-op. SECURITY_CRITICAL_RESTART_PREFIXES keeps the broader secrets prefix deliberately: it only ever sees planner-emitted restart reasons, so the conservative superset is inert today and stays correct if more secrets.* paths become restart-required later (documented at the constant).
  • src/gateway/config-reload-settings.ts:55: resolveHotModeRestartDecision(restartReasons) returns "security-critical" | "warn-and-keep" and is the single owner of the hot-mode policy.
  • src/gateway/config-reload.ts:319: the watcher's restart-required hot branch routes through the shared decision; the existing idle-aware restart machinery (queueRestart) remains the only watcher restart path.
  • src/gateway/server-methods/config-write-flow.ts:178: resolveConfigRestartRequirement routes hot-mode RPC writes through the same decision instead of unconditionally direct-restarting.
  • Regression tests pin each branch: warn-and-keep preserved on non-security edits; security-critical auth/secrets changes restart; the doctor-batch auth.profiles/auth.order rename auto-restarts in hot mode (src/gateway/config-reload.test.ts:1835); secrets.providers.* is restart-required in the planner while other secrets.* stays no-op; and the RPC path is pinned both ways in src/gateway/server-methods/config.shared-auth.test.ts:366 (routine write keeps running with requiresRestart: true; auth-token write direct-restarts).
  • Docs updated: docs/gateway/configuration-reference.md, docs/gateway/configuration.md, docs/gateway/index.md describe the hot-mode carve-out (secrets.providers.* wording), that the policy applies to both file edits and config.patch/config.apply writes, and that blanket auto-restart is "hybrid"'s job. The docs/gateway/index.md table is regenerated through scripts/format-docs.mjs, fixing the check-docs failure on the previous head.

Real behavior proof

  • Behavior addressed: in hot reload mode, a config write touching any restart-required key was dropped with a single log.warn while the gateway kept serving from the stale in-memory snapshot. Observed in production as a 4-hour silent outage where the agent kept resolving the legacy openai-codex/gpt-5.5 model id after openclaw doctor --fix had migrated the on-disk config (including auth.profiles.openai-codex:* renames) to openai/gpt-5.5. With this patch, security-critical edits (gateway auth, auth profiles/order, provider secrets) self-heal via restart in hot mode.

  • Real environment tested: live sandbox gateway on macOS (Node 24, loopback port 19777), run from this PR's final-head worktree at b6206ec825 via node --import tsx src/entry.ts gateway run, with isolated OPENCLAW_STATE_DIR + OPENCLAW_CONFIG_PATH and gateway.reload: { mode: "hot", debounceMs: 100 }.

  • Exact steps or command run after this patch: start the sandbox gateway, then per scenario: edit the sandbox openclaw.json on disk and watch the reload log, or drive the RPC path with openclaw gateway call config.get / config.patch:

    (c) file edit: gateway.port 19777 -> 19778                      # routine restart-required
    (d) gateway call config.patch --params '{"raw":"{ gateway: { port: 19779 } }","baseHash":"<config.get hash>"}' --json
    (a) file edit: rename auth.profiles "openai:proofa" -> "openai:proofb" + auth.order  # batch
    (b) file edit: secrets.providers.openai.allowlist rotation
    node scripts/run-vitest.mjs run src/gateway/config-reload.test.ts src/gateway/server-methods/config.shared-auth.test.ts src/gateway/server.config-patch.test.ts
    
  • Evidence after fix: redacted live log capture from the sandbox gateway at b6206ec825:

    (c) routine file edit -> warn-and-keep, no restart:
    [reload] config reload requires gateway restart; hot mode ignoring (gateway.port)
    curl 127.0.0.1:19777 -> HTTP 503 (still serving, not restarted)
    
    (d) routine restart-required config.patch RPC -> requiresRestart notice, no direct restart:
    [gateway] config.patch write actor=cli ... changedPaths=gateway.port restartReason=config.patch
    [reload] config reload requires gateway restart; hot mode ignoring (gateway.port)
    RPC sentinel payload: "stats": { "mode": "config.patch", "requiresRestart": true }
    curl 127.0.0.1:19777 -> HTTP 503 (still serving; same decision as the watcher)
    
    (a) auth.profiles/auth.order batch file edit -> restart scheduled:
    [reload] config reload requires gateway restart; hot mode scheduling restart for security-critical change (gateway.port, auth.profiles.openai:proofa, auth.profiles.openai:proofb, auth.order.openai)
    [reload] config change requires gateway restart (...)
    [gateway] starting HTTP server...   # supervised in-process restart
    [gateway] ready                     # back up on 19777 with new config
    
    (b) secrets.providers rotation file edit -> restart scheduled:
    [reload] config reload requires gateway restart; hot mode scheduling restart for security-critical change (secrets.providers.openai.allowlist)
    [reload] config change requires gateway restart (secrets.providers.openai.allowlist)
    [gateway] ready                     # restarted, rotation propagated
    

    At the same head, locally (macOS, Node 24):

    Test Files  8 passed (8)
         Tests  468 passed (468)
    

    plus tsgo core and core-test lanes clean, oxfmt --check / run-oxlint.mjs clean on touched files, and the docs chain green (format-docs.mjs --check, check-docs-mdx.mjs, docs-link-audit.mjs 0 broken links, generate-docs-map.mjs --check).

  • Observed result after fix: scenario (c) proves existing hot-mode deployments keep the shipped warn-and-keep contract. Scenario (d) proves the RPC write path makes the same decision as the watcher and surfaces requiresRestart: true instead of bouncing the gateway. Scenarios (a) and (b) prove auth-profile batch renames and provider secret rotations propagate by restart in default hot mode, closing the credential-rotation-bypass gap at the exact prefixes that caused the production incident.

  • What was not tested: markdownlint-cli2 was not run locally (network pnpm dlx; covered by CI check-docs). Launchd auto-respawn end-to-end on hosts using KeepAlive: { SuccessfulExit: false } (see operator note below; not a regression, the pre-fix path also required manual intervention); the sandbox exercised the unmanaged in-process restart path shown above.

Operator note: launchd SuccessfulExit=false hosts

Hosts that set KeepAlive: { Crashed=true, SuccessfulExit=false } (to dodge an unrelated respawn cascade) will not auto-respawn after a restart hand-off that exits cleanly. The deployment fork pairs this with a 30s interval watchdog (launchctl print state AND port-binding check, then launchctl kickstart -k). Hosts on default launchd KeepAlive semantics respawn normally and need nothing.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime size: S triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels Jun 2, 2026
@clawsweeper

clawsweeper Bot commented Jun 2, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 20, 2026, 12:56 PM ET / 16:56 UTC.

Summary
The branch adds a shared hot-mode restart decision so gateway-auth and auth-profile/order edits restart while routine restart-required watcher and RPC writes warn and keep the gateway running.

PR surface: Source +81, Tests +267, Docs 0. Total +348 across 10 files.

Reproducibility: yes. from source: current-main hot-mode RPC behavior directly restarts restart-required writes, while this branch changes the same path to warn-and-keep for routine reasons. The reported watcher staleness path is also covered by focused branch tests, but this review did not execute them.

Review metrics: 1 noteworthy metric.

  • Hot-mode decision surfaces: 2 paths changed. One helper now controls both file-watcher and gateway RPC behavior, so the compatibility decision affects disk edits and control-plane writes together.

Merge readiness
Overall: 🦪 silver shellfish
Proof: 🦪 silver shellfish
Patch quality: 🦐 gold shrimp
Result: blocked until stronger real behavior proof is added.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • Restore routine hot-mode RPC direct restart or obtain gateway-owner approval for the new contract.
  • [P1] Add redacted final-head live logs or terminal output for routine RPC, gateway auth, auth-profile/order, and live provider SecretRef rotation.
  • Remove review-specific wording from production comments.

Proof guidance:

  • [P1] Needs stronger real behavior proof before merge: The PR includes credible redacted gateway logs, but the capture is at b6206ec825 and demonstrates provider-secret restarts that the final head explicitly removed; add redacted final-head logs or terminal output for the surviving auth/profile restart and live SecretRef paths. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Risk before merge

  • [P1] Merging as written changes a supported control-plane workflow: routine restart-required config.patch/config.apply writes in hot mode can leave the runtime on the old configuration instead of performing the direct restart current main performs.
  • [P1] The supplied runtime capture predates the final policy change that keeps provider SecretRef rotations live, so merge evidence does not yet cover the exact final behavior.
  • [P1] Restarting for gateway.auth.* and auth-profile/order edits is availability-sensitive and should be confirmed against the final head with the intended supervisor path.

Maintainer options:

  1. Restore routine RPC restart behavior (recommended)
    Preserve current direct-restart behavior for routine hot-mode RPC writes and retain the security-critical watcher carve-out, then capture final-head proof.
  2. Approve the new RPC contract
    Explicitly accept warn-and-keep for routine restart-required RPC writes in hot mode, with clear API and operator documentation plus final-head proof.
  3. Pause the policy change
    Keep the narrow auth/profile restart work separate until gateway owners choose the permanent hot-mode RPC contract.

Next step before merge

  • [P1] A gateway-owner decision is required for the routine hot-mode RPC compatibility contract before an automated repair can safely proceed.

Maintainer decision needed

  • Question: Should routine restart-required config.patch and config.apply writes in gateway.reload.mode: "hot" retain current main’s direct-restart behavior, or intentionally adopt the watcher’s warn-and-keep behavior?
  • Rationale: Both options are plausible, but the branch changes an existing gateway API/operator contract and the security carve-out alone does not determine the intended routine-write policy.
  • Likely owner: amittell — The contributor has documented the exact policy split and can incorporate the chosen gateway-owner direction; formal ownership was not recoverable in this review environment.
  • Options:
    • Preserve direct RPC restart (recommended): Keep the existing direct restart for routine restart-required RPC writes while applying the new security carve-out to watcher and security-critical paths.
    • Adopt watcher parity: Accept routine RPC warn-and-keep behavior in hot mode and document that API writes require an explicit restart or hybrid mode for restart-required edits.

Security
Cleared: The patch changes authentication reload behavior but adds no dependency, permission, secret-exposure, or code-execution surface; the remaining concern is operational compatibility rather than a new security-boundary regression.

Review findings

  • [P1] Preserve routine hot-mode RPC restart behavior — src/gateway/server-methods/config-write-flow.ts:165-179
  • [P3] Remove review-specific production-comment context — src/gateway/config-reload-settings.ts:5-39
Review details

Best possible solution:

Keep direct restart for routine hot-mode RPC writes unless gateway owners explicitly choose parity with watcher warn-and-keep; then add redacted final-head runtime evidence for routine RPC, gateway-auth, auth-profile/order, and live provider-secret rotation behavior.

Do we have a high-confidence way to reproduce the issue?

Yes, from source: current-main hot-mode RPC behavior directly restarts restart-required writes, while this branch changes the same path to warn-and-keep for routine reasons. The reported watcher staleness path is also covered by focused branch tests, but this review did not execute them.

Is this the best way to solve the issue?

Unclear: the shared helper is a maintainable implementation shape, but applying watcher semantics to an explicit RPC write is not proven to be the best product contract. Preserve the current RPC behavior unless gateway owners intentionally approve the change.

Full review comments:

  • [P1] Preserve routine hot-mode RPC restart behavior — src/gateway/server-methods/config-write-flow.ts:165-179
    Routine restart-required config.patch/config.apply writes currently direct-restart in hot mode, but this branch returns a restart notice and leaves the runtime on its prior configuration. The auth/profile security carve-out does not require changing that established API behavior; retain direct restart unless gateway owners explicitly approve the compatibility change.
    Confidence: 0.95
  • [P3] Remove review-specific production-comment context — src/gateway/config-reload-settings.ts:5-39
    The production comments name a ClawSweeper review and item number rather than the enduring runtime contract. Keep the SecretRef and auth-profile rationale, but remove review-specific context so this code remains intelligible after the review record ages out.
    Confidence: 0.98

Overall correctness: patch is incorrect
Overall confidence: 0.91

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against e0206b4967a6.

Label changes

Label changes:

  • add P1: The branch can leave routine restart-required gateway API writes running on stale configuration where current main directly restarts.
  • remove P2: Current review triage priority is P1, so this older priority label is no longer current.

Label justifications:

  • P1: The branch can leave routine restart-required gateway API writes running on stale configuration where current main directly restarts.
  • merge-risk: 🚨 compatibility: It changes the existing hot-mode behavior of config.patch and config.apply for routine restart-required writes.
  • merge-risk: 🚨 auth-provider: The new carve-out changes reload behavior for gateway auth and auth-profile/order routing.
  • merge-risk: 🚨 availability: The branch schedules supervised gateway restarts for selected configuration edits that previously only logged a warning.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦐 gold shrimp.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs stronger real behavior proof before merge: The PR includes credible redacted gateway logs, but the capture is at b6206ec825 and demonstrates provider-secret restarts that the final head explicitly removed; add redacted final-head logs or terminal output for the surviving auth/profile restart and live SecretRef paths. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed

PR surface:

Source +81, Tests +267, Docs 0. Total +348 across 10 files.

View PR surface stats
Area Files Added Removed Net
Source 5 91 10 +81
Tests 2 273 6 +267
Docs 3 13 13 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 10 377 29 +348

What I checked:

  • Routine RPC compatibility change: The branch changes resolveConfigRestartRequirement so routine restart-required RPC writes in hot mode no longer direct-restart; the PR body explicitly identifies this as a deliberate departure from current main behavior. (src/gateway/server-methods/config-write-flow.ts:165, 07989a0b1ad6)
  • Prior blocker remains applicable: The latest completed ClawSweeper cycle identified preserving routine hot-mode RPC restart behavior as a P1; the final PR description still says routine config.patch/config.apply writes return a restart notice instead of restarting. (src/gateway/server-methods/config-write-flow.ts:175, 14d0505f8a89)
  • Final-head proof does not match the final policy: The embedded live capture is from b6206ec825 and demonstrates a provider-secret restart, while the current final-head update says provider SecretRef rotation was returned to the live no-op path. The supplied proof therefore does not demonstrate the final behavior. (src/gateway/config-reload-plan.ts:137, 07989a0b1ad6)
  • Adjacent diagnostics work: The companion health-drift PR tracks observability for stale runtime-versus-disk config rather than this PR's restart-policy change, so it is related but not a replacement. (src/gateway/config-reload.ts:743, 07989a0b1ad6)

Likely related people:

  • amittell: The provided discussion shows repeated revisions of the hot-mode policy, live proof, and the explicit RPC compatibility tradeoff; no current-main feature-history owner could be established from the read-only environment. (role: recent contributor on the proposed gateway-reload policy; confidence: low; commits: 07989a0b1ad6; files: src/gateway/config-reload-settings.ts, src/gateway/server-methods/config-write-flow.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

How this review workflow works
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.
Review history (12 earlier review cycles; latest 8 shown)
  • reviewed 2026-07-08T14:50:25.268Z sha d9ea589545405aefeea091854204ad71f0d9d2b1 :: needs real behavior proof before merge. :: [P1] Remove the duplicate hot-mode restart option | [P2] Narrow the secrets restart wording
  • reviewed 2026-07-08T14:56:48.104Z sha d9ea589545405aefeea091854204ad71f0d9d2b1 :: needs real behavior proof before merge. :: [P1] Remove the duplicate hot-mode restart option | [P2] Narrow the secrets restart wording
  • reviewed 2026-07-09T00:55:18.649Z sha b6206ec825a7cfe1ad539217c22a3bfcfb2cc87e :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-09T01:02:54.756Z sha b6206ec825a7cfe1ad539217c22a3bfcfb2cc87e :: needs maintainer review before merge. :: none
  • reviewed 2026-07-10T09:32:00.231Z sha 093e1e772d8538c88a542965cb0d9671d7c9005c :: needs maintainer review before merge. :: none
  • reviewed 2026-07-10T23:19:02.752Z sha 5a09d6239012687cdc194abb61aa3612c4c2716b :: found issues before merge. :: [P1] Keep provider SecretRefs on the live refresh path
  • reviewed 2026-07-11T02:31:37.999Z sha c1e0ed52988a8e3231ac252da59e2f813f93e211 :: found issues before merge. :: [P1] Keep provider SecretRefs on the live refresh path
  • reviewed 2026-07-20T06:49:54.436Z sha 14d0505f8a89d836c692828dc4e7c44b48583a6d :: needs real behavior proof before merge. :: [P1] Preserve routine hot-mode RPC restart behavior | [P3] Remove review-specific production-comment context

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. labels Jun 2, 2026
@openclaw-barnacle openclaw-barnacle Bot added proof: supplied External PR includes structured after-fix real behavior proof. and removed triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels Jun 2, 2026
@amittell

amittell commented Jun 2, 2026 •

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Added a full ## Real behavior proof section in the PR body. The proof captures the patched runtime from the deployed gateway on gateway-host (ssh user@gateway-host, PID , build 421a97cf2d) plus three historical pre-fix incidents from ~/.openclaw/logs/gateway.err.log including the 2026-06-02T10:10:59Z window that motivated the fix. No live restart of the running gateway was triggered to avoid disrupting production traffic.

@clawsweeper

clawsweeper Bot commented Jun 2, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

@amittell

amittell commented Jun 2, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the pushback. I want to leave a counter-position for the maintainer rather than reshape the PR yet, because the "preserve hot as no-restart" interpretation is at odds with what hot already promises operators.

Why the current PR shape: hot mode never advertised no-automatic-restart.

docs/gateway/configuration.md (the line you cite) reads:

"hot": apply changes in-process without restarting.

That sentence describes the operation hot performs when it can. It does not contract that hot mode will refuse to restart when a change cannot be applied in-process. The implementation already proved this when it logged a warn and silently dropped restart-required changes, leaving the runtime stale; that was the observed-in-production failure (auth.profiles.openai-codex:... rename + agents.defaults.models migration, 4 hour silent outage).

Treating "apply changes in-process" as a strict ban on restart for restart-required edits is what produced the silent staleness. The alternative — "if it can't be done in-process, fall back to the existing restart path" — is what hybrid does today, but operators only see hybrid as "try hot first, restart if required" rather than "hot but with auto-recovery." The semantic distinction between hot and hybrid was never operator-visible; the only practical difference was "does the runtime fix itself when it can't apply a change."

Why I do not want to collapse this into hybrid documentation only.

If hot retains its old "log warn and abandon the plan" behavior even after this clarification, operators on hot mode still have a quiet failure mode for the exact restart-required keys (auth.profiles, gateway.*, plugins.installs, models.pricing, etc.) that doctor and configure routinely touch. The hybrid documentation already says "restart when required"; the only thing preserving hot's old behavior buys is a knob for operators who have opted in to "do not restart me without my consent", which the docs have never explicitly named.

Alternative I will accept: explicit writer restart intent.

The server-methods/config-write-flow.ts:144 seam you flagged (existing writer follow-up restart support) is a reasonable alternative for the doctor / configure / external-write path: have the writers explicitly declare afterWrite: { mode: "restart", reason: "..." } for known restart-required keys. That gives hot a fail-loud contract (the writer says it requires restart) without auto-restart-on-mystery-edit.

If maintainers prefer that direction, I can:

  1. Revert this PR's hot-mode behavior change.
  2. Promote the existing log.warn to log.error with the actionable command inline (this is what my closed fix(gateway): promote hot-mode reload-drop to error with remediation #89578 did).
  3. Make openclaw doctor --fix declare afterWrite: { mode: "restart", reason: "key:auth.profiles" } so its writes route through the explicit-restart seam and hot operators see the restart through the same intent.

Doc alignment. docs/gateway/configuration.md:555 and src/config/schema.help.ts still describe hot as in-process-only. If the PR direction stays as-is, I will update both for parity. If we pivot to the explicit-writer-intent direction, only the gateway doctor write path needs new docs.

Will hold off on either path until a maintainer weighs in on which contract they want hot to formally promise.

@amittell

amittell commented Jun 2, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

PR body now contains the after-fix live capture you asked for: the new hot mode scheduling restart (models.pricing) log line at 2026-06-02T18:11:56.785Z, followed by the SIGUSR1 + clean-shutdown sequence proving the existing restart path is actually called. Same gateway, same dist bundle as before. Also surfaced an honest follow-up about how this interacts with launchd hosts that use KeepAlive: { SuccessfulExit: false } to dodge a separate failure cascade.

@clawsweeper

clawsweeper Bot commented Jun 2, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Command router queued. I will update this comment with the next step.

Re-review progress:

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Jun 2, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Jun 2, 2026
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Jun 2, 2026
@clawsweeper

clawsweeper Bot commented Jun 3, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@clawsweeper clawsweeper Bot added status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. proof: sufficient ClawSweeper judged the real behavior proof convincing. and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Jun 3, 2026
@clawsweeper clawsweeper Bot added the status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. label Jun 11, 2026
@amittell
amittell force-pushed the codex/gateway-restart-required-diagnostics branch from 496b58d to acffef6 Compare June 11, 2026 13:19
@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Jun 11, 2026
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Jun 11, 2026
@amittell
amittell force-pushed the codex/gateway-restart-required-diagnostics branch from acffef6 to 2669153 Compare June 11, 2026 13:28
@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Jun 11, 2026
@clawsweeper clawsweeper Bot added rating: 🌊 off-meta tidepool PR readiness rating does not apply to this item. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Jun 11, 2026
@amittell

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jun 11, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Jun 11, 2026
@amittell

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Rebased onto current main (d4819948f3) and marked ready for review. PR body rewritten to describe the shipped opt-in + security-carve-out design (the previous body still described the superseded unconditional-restart draft and contradicted the diff).

Local verification after rebase: gateway-config shard 360/360 (incl. the three branch-behavior regressions), schema tests 29+51, all passing. The open maintainer question stands: sign-off wanted on the new gateway.reload.autoRestartOnRequired key and the auth/secrets always-restart default split.

@clawsweeper

clawsweeper Bot commented Jun 12, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@amittell

amittell commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto current main and addressed both outstanding review findings. New head: 074e8acf3612c3af71e8f21e00e48ff628f3ab78.

P1 — carve-out missed auth.profiles.* / auth.order.* (the cited production repro: doctor batch renaming auth.profiles.openai-codex:* with model routes still dropped in default hot mode):

  • src/gateway/config-reload-settings.ts:32 — SECURITY_CRITICAL_RESTART_PREFIXES is now ["gateway.auth", "auth.profiles", "auth.order", "secrets"], with a contract comment explaining why deferring a doctor profile rename leaves the runtime authenticating through profiles that no longer exist on disk. auth.profiles.* / auth.order.* are unmatched in the reload-plan rules and default to restart-required, so they now hit the carve-out instead of warn-and-keep.
  • Regression test reproducing the doctor-batch drop: src/gateway/config-reload.test.ts:1878 ("auto-restarts in hot mode when a doctor batch renames auth profiles and order") — default hot mode (autoRestartOnRequired unset), auth.profiles.openai-codex:default renamed to auth.profiles.openai:default plus auth.order rewrite, asserts a queued restart with the security-critical log instead of the previous silent drop.

P2 — config.patch / config.apply direct-restarted in hot mode regardless of autoRestartOnRequired (divergent contract vs the file-watcher path):

  • The hot-mode policy is now a single shared helper, resolveHotModeRestartDecision (src/gateway/config-reload-settings.ts:54), returning "security-critical" | "opt-in" | "warn-and-keep". The watcher branch (src/gateway/config-reload.ts:319) and the RPC write decision (src/gateway/server-methods/config-write-flow.ts:178, inside resolveConfigRestartRequirement) both route through it, so the two write surfaces cannot diverge.
  • Note this deliberately changes today's RPC behavior in hot mode: routine restart-required config.patch/config.apply writes now return a requiresRestart sentinel notice without bouncing the gateway; security-critical and opted-in writes still schedule the direct restart. Pinned in src/gateway/server-methods/config.shared-auth.test.ts:366-421 (routine keeps running, opt-in restarts, gateway.auth.token write restarts regardless of the opt-in).

Rebase: resolved the one conflict in src/gateway/config-reload.ts by composing main's writer-intent followUp.requiresRestart block first, then the hot-mode policy branch, and dropping the re-add of shouldInvalidateSkillsSnapshotForPaths (removed on main in e879a67). Main's noop-snapshot commit (97227bd), watcher health status (e7158a5), and browser-profile hot reload (b82e3c1) behaviors are preserved; the browser-profile RPC test still passes unchanged.

Verification (local, macOS, Node 24, at 074e8acf36): node scripts/run-vitest.mjs run src/gateway/config-reload.test.ts src/gateway/server-methods/config.shared-auth.test.ts src/gateway/server.config-patch.test.ts — 8 files, 474 tests passed. tsgo core + core-test lanes, oxfmt --check, and oxlint on touched files all pass.

Known proof gap (called out in the body): the earlier live sandbox captures (scenarios A/B/C) were taken at d023afb9c4; the secrets.providers.* rotation and the doctor-batch auth.profiles rename are proven at the final head by focused regression tests, not a fresh end-to-end gateway capture. The open maintainer question on the gateway.reload.autoRestartOnRequired key itself (new config surface, no sign-off yet) also remains open in the body.

@amittell

amittell commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 8, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Tightens gateway.reload.mode: "hot" restart behavior by sharing a single hot-mode restart decision across file-watcher reloads and config.patch/config.apply, preserving the existing warn-and-keep default while adding an opt-in for auto-restart and an always-on security-critical restart carve-out.

Changes:

  • Introduces gateway.reload.autoRestartOnRequired (default false) and uses it to optionally escalate routine restart-required hot-mode edits into supervised restarts.
  • Ensures security-critical restart reasons (gateway.auth.*, auth.profiles.*/auth.order.*, secrets.*) trigger restarts in hot mode even without the opt-in, including explicitly classifying secrets.providers.* as restart-required.
  • Adds regression coverage for the three-way hot-mode behavior (warn-and-keep, opt-in restart, security-critical restart) and updates gateway reload docs/help/labels.

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/gateway/server-methods/config.shared-auth.test.ts Adds RPC write-path tests for warn-and-keep vs opt-in restart vs security-critical restart in hot mode.
src/gateway/server-methods/config-write-flow.ts Aligns RPC restart scheduling with the shared hot-mode restart decision.
src/gateway/config-reload.ts Applies the shared hot-mode decision to the file-watcher reload path (warn-and-keep vs scheduling restart).
src/gateway/config-reload.test.ts Adds tests for default hot-mode behavior, opt-in auto-restart, and security-critical restarts (auth + secrets).
src/gateway/config-reload-settings.ts Introduces resolveHotModeRestartDecision and plumbs autoRestartOnRequired into resolved reload settings.
src/gateway/config-reload-plan.ts Marks secrets.providers.* as restart-required to activate the security-critical carve-out for provider secret rotations.
src/config/zod-schema.ts Adds strict-schema support for gateway.reload.autoRestartOnRequired.
src/config/types.gateway.ts Adds the new GatewayReloadConfig.autoRestartOnRequired type + documentation.
src/config/schema.labels.ts Adds label for the new config field.
src/config/schema.help.ts Updates help text for reload mode and documents the new opt-in field.
docs/gateway/index.md Updates the hot reload modes table to mention the opt-in.
docs/gateway/configuration.md Updates reload mode documentation to mention the opt-in behavior.
docs/gateway/configuration-reference.md Updates reference docs to describe warn-and-keep default, opt-in, and security carve-out.

Comment thread docs/gateway/index.md Outdated
| `gateway.reload.mode` | Behavior |
| --------------------- | ----------------------------------------------------------------------------------------------------- |
| `off` | No config reload |
| `hot` | Hot-apply safe changes; warn on restart-required (set `reload.autoRestartOnRequired: true` to opt in) |
Comment thread src/gateway/config-reload-plan.ts Outdated
@@ -137,6 +137,14 @@ const BASE_RELOAD_RULES_TAIL: ReloadRule[] = [
{ prefix: "session", kind: "none" },
{ prefix: "talk", kind: "none" },
{ prefix: "skills", kind: "none" },
// Provider SecretRef storage rotations need a supervised restart so the
// running runtime stops resolving the old credential. The hot-mode
// security carve-out at config-reload.ts:79 relies on this classification
@amittell

amittell commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

Addressed the Copilot review nits (amended into head d9ea589545405aefeea091854204ad71f0d9d2b1):

  • docs/gateway/index.md — the hot-mode table now uses the fully prefixed config key gateway.reload.autoRestartOnRequired.
  • src/gateway/config-reload-plan.ts — the secrets.providers rule comment now references the carve-out by symbol (resolveHotModeRestartDecision / SECURITY_CRITICAL_RESTART_PREFIXES) instead of a hard-coded config-reload.ts:79 line number.

Wording-only change (one doc cell, one comment). Locally verified: node scripts/run-vitest.mjs run src/gateway/config-reload.test.ts — 376/376 passed. CI validates the new head.

@amittell

amittell commented Jul 9, 2026

Copy link
Copy Markdown
Contributor Author

Addressed the review findings; new head is b6206ec825a7cfe1ad539217c22a3bfcfb2cc87e (rebased onto current main d3ff48c51f).

  • [P1] duplicate config key removed: gateway.reload.autoRestartOnRequired is gone entirely; mode: "hybrid" already provides hot-then-restart, so the key duplicated an existing mode (review option 1). Deleted from src/config/types.gateway.ts, src/config/zod-schema.ts, src/config/schema.help.ts, src/config/schema.labels.ts (all four now identical to main except the improved gateway.reload.mode help text), plus docs and tests. The decision union is now "security-critical" | "warn-and-keep" (src/gateway/config-reload-settings.ts:55); the resolved settings shape (mode, debounceMs) matches main again, which also resolves the stored-data-model note on schema.help.ts.
  • [P2] secrets restart wording narrowed: docs (docs/gateway/configuration-reference.md:719, docs/gateway/configuration.md, docs/gateway/index.md) and schema.help now say secrets.providers.*, matching the only secrets.* prefix the planner classifies restart-required (src/gateway/config-reload-plan.ts:148). SECURITY_CRITICAL_RESTART_PREFIXES keeps the conservative broader secrets prefix since it only sees planner-emitted reasons; rationale documented at the constant (src/gateway/config-reload-settings.ts:21).
  • [P1] final-head live proof: fresh sandbox-gateway captures at b6206ec825 are embedded in the rewritten PR body: auth.profiles/auth.order batch edit -> restart scheduled; secrets.providers.openai.allowlist rotation -> restart scheduled; routine gateway.port file edit -> warn-and-keep; routine restart-required config.patch RPC -> requiresRestart: true sentinel with no direct restart (same decision as the watcher).
  • [P1] RPC behavior change: kept as an explicit maintainer call-out in the body (hot-mode routine config.patch/config.apply writes change from direct restart to a requiresRestart notice; one-line change in resolveConfigRestartRequirement if owners prefer the old behavior).
  • check-docs: the failure was format-docs.mjs --check on docs/gateway/index.md table widths; tables now regenerated via scripts/format-docs.mjs, and the local docs chain (format check, MDX, links, docs map) is green.

Local verification at b6206ec825: node scripts/run-vitest.mjs run src/gateway/config-reload.test.ts src/gateway/server-methods/config.shared-auth.test.ts src/gateway/server.config-patch.test.ts -> 8 files / 468 tests passed; tsgo core + core-test lanes clean; oxfmt --check and run-oxlint.mjs clean on touched files.

@amittell

amittell commented Jul 9, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 9, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

@amittell

Copy link
Copy Markdown
Contributor Author

Rebased onto current main (14d0505f8a8) and fixed the durable review's P1:

  • secrets.providers.* stays on the live path: the restart reclassification is reverted — provider SecretRef rotations keep activating through the committed snapshot's live resolution (config-reload-plan.ts keeps secrets as no-op, and secrets is removed from SECURITY_CRITICAL_RESTART_PREFIXES). A regression test pins the live no-op-commit path for secrets.providers.* rotations. Docs updated to match.
  • The security carve-out now covers exactly gateway.auth.* and auth.profiles.*/auth.order.* — the doctor-batch profile-rename scenario that motivated the PR.
  • The separable maintainer question stands: whether routine (non-security) hot-mode config.patch/config.apply writes should keep direct-restart or move to warn-and-keep as in this PR. The shared resolveHotModeRestartDecision makes either choice a one-line policy change.

amittell added 2 commits July 20, 2026 12:49
…t config edits

Hot reload mode (gateway.reload.mode: "hot") kept the shipped warn-and-keep
contract even when gateway.auth.*, auth.profiles.*/auth.order.*, or
secrets.providers.* changed on disk, so a credential rotated in response to a
leak stayed accepted by the running gateway until a manual restart. Hot mode
now schedules a supervised restart for those security-critical prefixes while
routine restart-required edits keep warn-and-keep; blanket auto-restart stays
the hybrid mode's job. The decision is shared between the file watcher and the
config.patch/config.apply RPC write path via resolveHotModeRestartDecision, so
routine restart-required RPC writes in hot mode now return a requiresRestart
notice instead of direct-restarting. secrets.providers.* is now classified
restart-required in the reload planner so provider SecretRef rotations reach
the carve-out.
@clawsweeper

clawsweeper Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper status: review started.

I am starting a fresh review of this pull request: [codex] fix gateway hot-mode restart reloads This is item 1/1 in the current shard. Shard 0/1.

This placeholder means the worker is alive and reading the current context. I will edit this same comment with the actual review when the claws are done clicking.

Crustacean status: shell secured, claws on keyboard, evidence pebbles being sorted.

@amittell

Copy link
Copy Markdown
Contributor Author

Closing as superseded by main.

This PR's premise was refining the hot-mode warn-and-keep contract: keep routine restart-required edits on warn-and-keep, and auto-restart only security-critical ones (gateway.auth.*, auth.profiles.*/auth.order.*). main has since removed that contract entirely in #111527 (config-surface reduction tranche 3, edecdbd05ef): src/gateway/config-reload.ts now takes the strictly stronger path — any restart-required plan goes straight to prepareRestart in every reload mode, with no warn-and-keep branch, no per-prefix decision layer, and no way for a security-critical edit (or any edit) to sit stale on disk. Each piece of this PR is covered or mooted:

Reopen-worthy evidence would be a maintainer decision to bring back a warn-and-keep mode for hot reloads; the shared-decision plumbing in this branch would be the starting point for that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation gateway Gateway runtime merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P1 High-priority user-facing bug, regression, or broken workflow. proof: supplied External PR includes structured after-fix real behavior proof. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: M status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants