Repository navigation
fix(config): settle Gateway writes after invalid canonical rereads - #161868
Conversation
Fail runtime application receipts for missing or invalid committed snapshots while preserving valid-candidate retries and restart intent. Preserve config.set persistence acknowledgements and cover the authenticated config.patch failure response. Keep reload admission with its existing contracts, share no-watcher fixtures, and extract the reread cases to satisfy line caps. Prune one stale max-lines entry with the canonical guard. Disk writes, updater behavior, config schemas, and rollback are unchanged.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. Reviewed September 30, 2026, 8:38 AM ET / 12:38 UTC. ClawSweeper reviewWhat this changesThe branch makes Gateway config reload treat missing or invalid post-write snapshots as application failures, documents recovery, and adds authenticated RPC regression coverage. Merge readiness✅ Ready for maintainer review Keep open. Current main can classify an invalid post-write reread as superseded, leaving a waiting config request without a settled application result. The PR addresses that failure through the existing receipt path, and the review found no concrete introduced defect. Priority: P2 Review scores
Verification
How this fits togetherGateway config requests persist a file and publish its committed snapshot to the reload owner. That owner checks the reread, applies valid runtime changes, and settles the request's response. flowchart LR
A[Gateway config request] --> B[Persist config file]
B --> C[Canonical reread]
C --> D{Usable snapshot?}
D -- Yes --> E[Apply runtime config]
D -- No --> F[Fail application receipt]
E --> G[Client response]
F --> G
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +6, Tests +41, Docs +6, Other -1. Total +52 across 7 files. View PR surface stats
Review metricsNone. Technical reviewBest possible solution: Keep reread classification in the reload owner and let config RPCs consume its settled result, while preserving the last good runtime and existing watcher retry behavior. Do we have a high-confidence way to reproduce the issue? Yes. The captured negative-control Gateway RPC case timed out after an injected post-write invalid edit, and current main retains the same classification path; this read-only review did not rerun it. Is this the best way to solve the issue? Yes. The repair changes the reload owner's error classification and reuses the existing RPC failure response without adding another config-write policy. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 1de9a42f114e. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
…161868) When an external edit left openclaw.json missing or invalid while a Gateway config write was waiting for runtime application, the final canonical reread fell into the same branch that skips application. The pending write then waited for another file event that never came, so config.patch and config.apply hung until the client timed out. The write snapshot is now checked through the reload contracts: a missing or invalid reread fails the accepted transaction, and the request returns UNAVAILABLE with the committed config details. The runtime does not adopt the change, and the Gateway still never overwrites the external edit. The hot-reload docs describe the recovery: repair the file, run config.get, then reapply. A deterministic regression injects an incomplete external edit mid-write for config.set, config.patch and config.apply. It passed 42 executions under stress-ng CPU load. The earlier CI "JSON5 parse failed" log line came from an intentional corrupt-file fixture, not a torn write; disk write atomicity is unchanged. Release note: config.patch and config.apply no longer hang when the config file is edited into an invalid state during a Gateway write; they return UNAVAILABLE.
Main 6b2afbf conflicted in eight files. Resolution notes: - config-reload.ts: main moved source observation into src/config/source.ts (openclaw#157372) and write notifications now carry the writer's canonical reread (openclaw#161868). The observation tracker keys on source.observation.revision, the accepted-echo marker lives in config-reload-observed.ts, and the pending-write path records the notification's snapshot because it no longer rereads. config-reload-watcher.ts is removed: main dropped the polling resolver it held. - snapshot.ts: runtimeConfig sits beside main's childRuntime (openclaw#157190). - server-methods/health.ts: the capability projection wraps main's inlined cached-health object and its live childRuntime read. - server-connection-state.ts: the health event projection returns main's { payload } projection shape. - health.ts: the runtime-config line joins main's formatter loop. - connect-hello.update-scope.test.ts: makeContext takes { caps, client }. - config-reload.observation.test.ts: writes use makeWrite; the reread cases now drive the notification's snapshot, and the read-failure case is gone with the reread it covered.
What Problem This Solves
A concurrent external edit can leave the canonical reread missing or invalid immediately after a Gateway config write. The reload owner classified that unusable snapshot as superseded and retained its application receipt without scheduling another observation. An authenticated
config.patchcould persist its config and then end inCLIENT_TIMEOUTinstead of returning the existingUNAVAILABLEresponse with the committed config details.Why This Change Was Made
Classify an unusable committed snapshot as an ordinary reload failure. The existing catch path settles the caller's receipt as
failedwhile retaining retry and restart intent. Valid-snapshot supersession and watcher retries keep their existing behavior. Snapshot admission lives with the existing reload contracts; the reread regressions have a focused sibling file and share a no-watcher Gateway fixture. Every existing behavioral case is retained.The warning in job 109827485028 was intentional: an earlier passing test wrote
{ external editor incomplete\n, producing the exact JSON5eat column 12. That test passed in 288 ms; the numeric-key test timed out about 72 seconds later. The original numeric-key timeout remains unattributed and is not claimed fixed here; it passed 21 stress executions during this investigation.History inspection found no publication, lock, or reread-order regression in f5e5f75 or b4d93d2. c35b657 began publishing the canonical snapshot to the reload owner, exposing this receipt failure. b36eb3e changes updater admission reads, not config publication.
User Impact
Waiting
config.patchandconfig.applycallers receive the existing application-failure response when the canonical reread cannot be applied. The last good managed runtime stays active, committed config details remain available, and the external edit is not overwritten.config.setstill acknowledges persistence. No schema, public SDK, protocol, runtime floor, or dependency change.Update behavior: disk writes, config format, backups, rollback, updater admission, Doctor, and migrations are unchanged. Existing configs and concurrent updater saves retain their behavior. Normal writes already stage a same-directory file and rename it under the config lock, which covers finalization. The older EPERM/EEXIST copy fallback can expose partial bytes to unlocked cross-process readers; it is deliberately unchanged because removing it would alter supported permission-error behavior, and there is no evidence that it caused this CI warning. Root-write fsync policy is unchanged as well. A published-driver × candidate cell was not run because these updater and disk-write contracts are unchanged.
Evidence
Remote commands used
node scripts/crabbox-wrapper.mjs run --id <id> --timing-json -- .... Primary lease:tbx_01m3rvvqh2w4zvxdwv9smbhwrf. Recovery lease:tbx_01m3s1r91kg5pat4g8yavvjq8n, backing run. Source base:7f122b9e69fca7bfeb91fcf8d2418f07726adc6f; final source capsule tree:191bad0fc3b771c4f6996d006626962e2aff8df1.GatewayClientRequestTimeoutError,CLIENT_TIMEOUT,config.patch,timeoutMs: 10000, andrequestSent: true. The preservedconfig.setcase passed. This usednode scripts/run-vitest.mjs src/gateway/server.config-patch.test.ts -t 'settles when an external edit invalidates'before the cases were extracted; the same command passed after the production fix.node scripts/run-vitest.mjs src/gateway/server.config-patch.test.ts src/gateway/config-reload.test.ts src/config --maxWorkers=1passed 6,050 tests / 474 files. Existing configuration skipped 10 tests / 3 files. Command wall: 2,266.109 s.node scripts/run-vitest.mjs src/gateway/config-reload.test.ts src/gateway/server.config-patch.test.ts src/gateway/server.config-write-reread.test.ts --maxWorkers=1passed 214 tests / 3 files. Wrapper test wall: 270.78 s.pnpm check:architecturepassed.node scripts/run-vitest.mjs src/gateway/server.config-write-reread.test.ts --repeats 20 --maxWorkers=1passed 21 executions per case / 42 total, with eightstress-ngCPU workers targeting 75% load for 148.33 s. Vitest wall: 141.95 s. Before extraction, both reread cases plus the numeric-key case also passed 21 executions each under the same contention level (63 total).node scripts/run-vitest.mjs src/gateway/server.config-write-reread.test.ts --maxWorkers=1passed in 64.17 s wrapper wall / 61.96 s Vitest wall. The cases took 413 ms and 315 ms; cold transformation and shared Gateway startup dominate. This real authenticated-RPC and persistence boundary catches a request that a helper-only assertion could leave hanging. The pre-extraction 82-case config-patch file took 91.74 s with one worker. CI seconds remain pending; no CI wait or rerun was requested.env OPENCLAW_CHECK_CHANGED_REMOTE_CHILD=1 OPENCLAW_CHANGED_LANES_RAW_SYNC=1 node scripts/check-changed.mjspassed on the recovery lease. The standalone timing run plus gate took 2,323.964 s. Core lint had zero errors and two pre-existing max-lines warnings in untouched base files (src/agents/embedded-agent-runner/run/terminal-resolution.test.ts: 1,056 counted lines, andui/src/pages/chat/components/chat-transcript-projection.ts: 701); root test-helper lint had zero warnings/errors. A non-gating runner-portal sync warning did not change the native command exit code of 0.config-reload.ts1,412 → 1,415 counted lines (cap 700) andserver.config-patch.test.ts1,899 → 1,922 (cap 1,000). The coherent extractions remove that growth. The guard's own--prunecommand removed one pre-existing staleworker-environments/bootstrap.tsbaseline entry: 696 → 695, copied byte-for-byte from Testbox. Environment-variable budget stayed 476/476. No rule, budget, cap, snapshot, or inventory was expanded.Release-note context: Gateway config writes now return their existing application-failure response when an external edit invalidates the canonical reread, instead of leaving the request waiting for another file event.