Skip to content

fix(config): settle Gateway writes after invalid canonical rereads - #161868

Merged
steipete merged 1 commit into
mainfrom
steipete/config-write-atomicity
Sep 30, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/config-write-atomicity

Conversation

@steipete

Copy link
Copy Markdown
Contributor

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.patch could persist its config and then end in CLIENT_TIMEOUT instead of returning the existing UNAVAILABLE response 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 failed while 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 JSON5 e at 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.patch and config.apply callers 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.set still 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.

  • Negative control: the added RPC case failed on unchanged production code with GatewayClientRequestTimeoutError, CLIENT_TIMEOUT, config.patch, timeoutMs: 10000, and requestSent: true. The preserved config.set case passed. This used node 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.
  • Broad proof before the mechanical extraction: node scripts/run-vitest.mjs src/gateway/server.config-patch.test.ts src/gateway/config-reload.test.ts src/config --maxWorkers=1 passed 6,050 tests / 474 files. Existing configuration skipped 10 tests / 3 files. Command wall: 2,266.109 s.
  • Final affected proof: 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=1 passed 214 tests / 3 files. Wrapper test wall: 270.78 s. pnpm check:architecture passed.
  • Final regression stress: node scripts/run-vitest.mjs src/gateway/server.config-write-reread.test.ts --repeats 20 --maxWorkers=1 passed 21 executions per case / 42 total, with eight stress-ng CPU 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).
  • Measured standalone cost: node scripts/run-vitest.mjs src/gateway/server.config-write-reread.test.ts --maxWorkers=1 passed 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.
  • Full changed-lanes gate: env OPENCLAW_CHECK_CHANGED_REMOTE_CHILD=1 OPENCLAW_CHANGED_LANES_RAW_SYNC=1 node scripts/check-changed.mjs passed 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, and ui/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.
  • Deslop: scoped diff inspected, no further cleanup needed. Final contextual Codex autoreview: P2 scoped-clean, no actionable findings.
  • Guards: the initial line-cap failures were config-reload.ts 1,412 → 1,415 counted lines (cap 700) and server.config-patch.test.ts 1,899 → 1,922 (cap 1,000). The coherent extractions remove that growth. The guard's own --prune command removed one pre-existing stale worker-environments/bootstrap.ts baseline entry: 696 → 695, copied byte-for-byte from Testbox. Environment-variable budget stayed 476/476. No rule, budget, cap, snapshot, or inventory was expanded.
  • Infrastructure: the first full changed-lanes run lost its Testbox during core lint, exit 255, after all typechecks and unused-export scans passed. The provider then reported that lease absent. Recovery used a fresh lease with a 90-minute idle timeout; this was not treated as a source-code failure or a completed gate.
  • Numstat: production/non-test +14 / -3 (net +11), comprising runtime code +8 / -2, docs +6 / -0, and the canonical baseline shrink +0 / -1. Tests and test support +84 / -43 (net +41). Lane F's bug-fix exception applies; no STOP condition required a loosened guard.

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.

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.
@clawsweeper

clawsweeper Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime size: S labels Sep 30, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 30, 2026
@clawsweeper

clawsweeper Bot commented Sep 30, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 30, 2026, 8:38 AM ET / 12:38 UTC.

ClawSweeper review

What this changes

The 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
Reviewed head: 075ab8bd94ab96e2403b5db8ed08a32a86d8ebed

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A narrow owner-level fix has a failing negative control, authenticated Gateway boundary coverage, and substantial focused validation.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The changed reload owner is exercised through an authenticated GatewayClient config.patch request with an injected post-write invalid edit. The PR records a pre-fix timeout and an after-fix pass; the case asserts UNAVAILABLE with committed details, unchanged runtime state, and preserved config.set behavior. No stored-data contract changes.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The changed reload owner is exercised through an authenticated GatewayClient config.patch request with an injected post-write invalid edit. The PR records a pre-fix timeout and an after-fix pass; the case asserts UNAVAILABLE with committed details, unchanged runtime state, and preserved config.set behavior. No stored-data contract changes.
Evidence reviewed 8 items Current main retains the failure condition: The main-branch reload path places missing and invalid snapshots inside its supersession check.
Introduced reload classification: The PR rejects unusable write snapshots before the separate valid-snapshot supersession checks; the reload catch settles ordinary errors as failed.
Existing RPC response contract: A non-applied config.patch or config.apply receipt produces UNAVAILABLE with redacted committed config details.
Findings None None.
Security None None.

How this fits together

Gateway 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
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +6, Tests +41, Docs +6, Other -1. Total +52 across 7 files.

View PR surface stats
Area Files Added Removed Net
Source 2 8 2 +6
Tests 3 84 43 +41
Docs 1 6 0 +6
Config 0 0 0 0
Generated 0 0 0 0
Other 1 0 1 -1
Total 7 98 46 +52

Review metrics

None.

Technical review

Best 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.

Labels

Label changes:

  • add P2: A concurrent invalid edit can make a Gateway config write wait until client timeout, but the trigger is limited.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The changed reload owner is exercised through an authenticated GatewayClient config.patch request with an injected post-write invalid edit. The PR records a pre-fix timeout and an after-fix pass; the case asserts UNAVAILABLE with committed details, unchanged runtime state, and preserved config.set behavior. No stored-data contract changes.
  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The changed reload owner is exercised through an authenticated GatewayClient config.patch request with an injected post-write invalid edit. The PR records a pre-fix timeout and an after-fix pass; the case asserts UNAVAILABLE with committed details, unchanged runtime state, and preserved config.set behavior. No stored-data contract changes.

Label justifications:

  • P2: A concurrent invalid edit can make a Gateway config write wait until client timeout, but the trigger is limited.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The changed reload owner is exercised through an authenticated GatewayClient config.patch request with an injected post-write invalid edit. The PR records a pre-fix timeout and an after-fix pass; the case asserts UNAVAILABLE with committed details, unchanged runtime state, and preserved config.set behavior. No stored-data contract changes.
  • proof: sufficient: Contributor real behavior proof is sufficient. The changed reload owner is exercised through an authenticated GatewayClient config.patch request with an injected post-write invalid edit. The PR records a pre-fix timeout and an after-fix pass; the case asserts UNAVAILABLE with committed details, unchanged runtime state, and preserved config.set behavior. No stored-data contract changes.

Evidence

What I checked:

  • Current main retains the failure condition: The main-branch reload path places missing and invalid snapshots inside its supersession check. (src/gateway/config-reload.ts:986, 1de9a42f114e)
  • Introduced reload classification: The PR rejects unusable write snapshots before the separate valid-snapshot supersession checks; the reload catch settles ordinary errors as failed. (src/gateway/config-reload.ts:986, 075ab8bd94ab)
  • Existing RPC response contract: A non-applied config.patch or config.apply receipt produces UNAVAILABLE with redacted committed config details. (src/gateway/server-methods/config.ts:675, 075ab8bd94ab)
  • Production-boundary regression: The new case injects an invalid external edit after persistence, then checks the config.patch failure response, preserved runtime, disk contents, and config.set acknowledgment through a Gateway RPC client. (src/gateway/server.config-write-reread.test.ts:20, 075ab8bd94ab)
  • Authenticated test entry point: The shared fixture starts a Gateway server and connects a token-authenticated GatewayClient with operator.admin scope. (test/helpers/gateway/config-rpc-gateway.ts:149, 075ab8bd94ab)
  • Reported before-and-after proof: The captured PR body reports a pre-fix authenticated config.patch CLIENT_TIMEOUT on unchanged production code, a pass after the fix, focused Gateway runs, and a measured standalone cost for the new test. This review did not execute the tests.

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Ayaan Zaidi: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Vincent Koc: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
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.

Workflow

  • 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.

@steipete
steipete merged commit cd59fe8 into main Sep 30, 2026
214 of 215 checks passed
@steipete
steipete deleted the steipete/config-write-atomicity branch September 30, 2026 12:52
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 1, 2026
…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.
amittell added a commit to amittell/openclaw that referenced this pull request Oct 9, 2026
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.
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 P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant