Skip to content

fix: reread config on in-process gateway restart#80161

Merged
scoootscooob merged 2 commits into
openclaw:mainfrom
scoootscooob:codex/79947-gateway-restart-config-reread
May 10, 2026
Merged

fix: reread config on in-process gateway restart#80161
scoootscooob merged 2 commits into
openclaw:mainfrom
scoootscooob:codex/79947-gateway-restart-config-reread

Conversation

@scoootscooob

@scoootscooob scoootscooob commented May 10, 2026

Copy link
Copy Markdown
Member

Summary

Real behavior proof

  • Behavior or issue addressed: In-process gateway run restarts must not reuse the first startup config snapshot after the config file changes on disk.
  • Real environment tested: macOS local OpenClaw worktree, Node v25.2.1, pnpm 10.33.2, temp OPENCLAW_HOME/OPENCLAW_STATE_DIR/OPENCLAW_CONFIG_PATH, real gateway process on 127.0.0.1:19661.
  • Exact steps or command run after this patch: Started pnpm --silent openclaw gateway run --port 19661 with OPENCLAW_NO_RESPAWN=1, temp config token token-before, verified gateway health, rewrote the temp config token to token-after, sent SIGUSR1, then verified gateway health with token-after.
  • Evidence after fix: Terminal output from the after-fix live gateway smoke:
real gateway pid=72130 port=19661
before restart with token-before: {"ok":true,"rpcOk":null,"status":null}
after SIGUSR1 restart with token-after: {"ok":true,"rpcOk":null,"status":null}
restart log lines:
1:2026-05-10T03:40:16.767-04:00 [gateway] loading configuration…
4:2026-05-10T03:40:16.827-04:00 [gateway] starting...
9:2026-05-10T03:40:20.024-04:00 [gateway] http server listening (9 plugins: acpx, bonjour, browser, canvas, device-pair, file-transfer, memory-core, phone-control, talk-voice; 3.2s)
21:2026-05-10T03:40:22.715-04:00 [gateway] signal SIGUSR1 received
22:2026-05-10T03:40:22.720-04:00 [gateway] received SIGUSR1; restarting
26:2026-05-10T03:40:22.785-04:00 [gateway] restart mode: in-process restart (OPENCLAW_NO_RESPAWN)
30:2026-05-10T03:40:22.990-04:00 [gateway] http server listening (9 plugins: acpx, bonjour, browser, canvas, device-pair, file-transfer, memory-core, phone-control, talk-voice; 0.2s)
  • Observed result after fix: The restarted real gateway accepted the post-rewrite token-after config after SIGUSR1, showing the second in-process start reread disk config instead of reusing the first startup snapshot.
  • What was not tested: No additional gaps.

Verification

  • OPENCLAW_VITEST_FS_MODULE_CACHE_PATH=/tmp/openclaw-vitest-cache-79947 pnpm test src/cli/gateway-cli/run.option-collisions.test.ts
  • pnpm check:changed
  • pnpm exec oxfmt --check --threads=1 src/cli/gateway-cli/run.ts src/cli/gateway-cli/run.option-collisions.test.ts CHANGELOG.md
  • git diff --check

@openclaw-barnacle openclaw-barnacle Bot added cli CLI command changes size: S maintainer Maintainer-authored PR labels May 10, 2026
@clawsweeper

clawsweeper Bot commented May 10, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

Summary
The PR consumes the gateway CLI's pre-read startup config snapshot only for the first restart-loop start, adds a regression test, updates the changelog, and refreshes one Swift protocol model field.

Reproducibility: yes. Current main's source path shows the stale pre-read snapshot is passed into every in-process restart start, and the linked bug plus PR proof describe a concrete SIGUSR1/config-write path; I did not run an independent live container repro in this read-only pass.

Real behavior proof
Sufficient (terminal): The PR body includes copied terminal output from an after-fix real gateway run using temp config, a live process, and SIGUSR1 restart, which exercises the changed runtime path.

Next step before merge
Protected maintainer label and duplicate open fix PR require normal maintainer selection/review, not a ClawSweeper repair lane.

Security
Cleared: No concrete security or supply-chain regression was found; the diff does not add dependencies, CI execution, permissions, or secret exposure paths.

Review details

Best possible solution:

Land one narrow consume-once startup snapshot fix with the regression test, then close the linked bug after merge and close the duplicate fix PR as superseded.

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

Yes. Current main's source path shows the stale pre-read snapshot is passed into every in-process restart start, and the linked bug plus PR proof describe a concrete SIGUSR1/config-write path; I did not run an independent live container repro in this read-only pass.

Is this the best way to solve the issue?

Yes. Consuming the CLI pre-read snapshot once is the narrow owner-boundary fix: first boot keeps the startup optimization, later in-process restarts omit initialSnapshotRead and force the gateway startup loader to read disk again.

What I checked:

  • Protected label: Live PR metadata shows this PR is open, non-draft, mergeable, and labeled maintainer, which blocks conservative cleanup closure even when the change looks correct. (fcc6ebc2bb94)
  • Current-main root cause: Current main captures startupConfigSnapshotRead before runGatewayLoop and passes it into every startGatewayServer call made by the run loop, so the same pre-read snapshot is available on later in-process starts. (src/cli/gateway-cli/run.ts:790, 35ceba0e4e6a)
  • Snapshot contract: loadGatewayStartupConfigSnapshot uses initialSnapshotRead when supplied and only reads openclaw.json from disk when it is absent, matching the linked bug's stale-snapshot failure mode. (src/gateway/server-startup-config.ts:66, 35ceba0e4e6a)
  • In-process restart path: The run loop falls back to in-process restart and resolves the restart loop instead of spawning a fresh process when respawn is unavailable, so later iterations reuse the same closure from runGatewayCommand. (src/cli/gateway-cli/run-loop.ts:253, 35ceba0e4e6a)
  • Patch behavior: The PR changes the run-loop closure to move startupConfigSnapshotRead through a consume-once variable and adds a regression test asserting the first start receives the snapshot while the second does not. (src/cli/gateway-cli/run.ts:787, fcc6ebc2bb94)
  • Related work: Search found the linked open bug, this PR, the earlier closed unmerged attempt, and another open PR with the same central fix at fix(gateway): re-read config on in-process restart instead of replaying stale snapshot #80041.

Likely related people:

  • steipete: The startup snapshot handoff was introduced in commit 5980040, and recent path history shows repeated gateway startup/config work by this author. (role: introduced behavior and frequent adjacent contributor; confidence: high; commits: 598004089454, 0ee52e940547, e651809084a1; files: src/cli/gateway-cli/run.ts, src/gateway/server-startup-config.ts, src/cli/gateway-cli/run.option-collisions.test.ts)
  • vincentkoc: Recent commits on src/cli/gateway-cli/run.ts cover CLI/gateway startup guidance and the current shallow blame attributes the surrounding run-loop block to this author in the checked-out main snapshot. (role: recent area contributor; confidence: medium; commits: be1c38e692f2, 346e327586ee, ad943ec30c74; files: src/cli/gateway-cli/run.ts)
  • shakkernerd: Recent history on server-startup-config.ts includes plugin metadata and config snapshot work directly adjacent to the snapshot reuse contract. (role: adjacent startup-config contributor; confidence: medium; commits: 5a72378b2797, d62cc59388b5, fd6c9fc7f5f6; files: src/gateway/server-startup-config.ts)

Remaining risk / open question:

Codex review notes: model gpt-5.5, reasoning high; reviewed against 35ceba0e4e6a.

@scoootscooob
scoootscooob marked this pull request as ready for review May 10, 2026 07:42
@scoootscooob
scoootscooob force-pushed the codex/79947-gateway-restart-config-reread branch from 4ad1ac9 to fcc6ebc Compare May 10, 2026 07:53
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 10, 2026
@scoootscooob
scoootscooob merged commit e5fe9bd into openclaw:main May 10, 2026
113 checks passed
steipete pushed a commit that referenced this pull request May 10, 2026
* fix: reread config on in-process gateway restart

* fix: refresh swift protocol model
steipete pushed a commit that referenced this pull request May 11, 2026
* fix: reread config on in-process gateway restart

* fix: refresh swift protocol model
steipete pushed a commit that referenced this pull request May 11, 2026
* fix: reread config on in-process gateway restart

* fix: refresh swift protocol model
steipete pushed a commit that referenced this pull request May 11, 2026
* fix: reread config on in-process gateway restart

* fix: refresh swift protocol model
steipete pushed a commit that referenced this pull request May 12, 2026
* fix: reread config on in-process gateway restart

* fix: refresh swift protocol model

(cherry picked from commit 537bcad)
longstoryscott pushed a commit to longstoryscott/openclaw that referenced this pull request May 13, 2026
* fix: reread config on in-process gateway restart

* fix: refresh swift protocol model
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 24, 2026
* fix: reread config on in-process gateway restart

* fix: refresh swift protocol model
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 24, 2026
* fix: reread config on in-process gateway restart

* fix: refresh swift protocol model

(cherry picked from commit 537bcad)
jameslcowan pushed a commit to jameslcowan/openclaw that referenced this pull request Jun 2, 2026
* fix: reread config on in-process gateway restart

* fix: refresh swift protocol model
jameslcowan pushed a commit to jameslcowan/openclaw that referenced this pull request Jun 2, 2026
* fix: reread config on in-process gateway restart

* fix: refresh swift protocol model

(cherry picked from commit 537bcad)
sablehead pushed a commit to sablehead/openclaw that referenced this pull request Jun 10, 2026
* fix: reread config on in-process gateway restart

* fix: refresh swift protocol model
sablehead pushed a commit to sablehead/openclaw that referenced this pull request Jun 10, 2026
* fix: reread config on in-process gateway restart

* fix: refresh swift protocol model

(cherry picked from commit 537bcad)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes maintainer Maintainer-authored PR proof: sufficient ClawSweeper judged the real behavior proof convincing. size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: in-process gateway restart silently drops user config (stale startupConfigSnapshotRead reuse)

1 participant