Repository navigation
fix(settings): take the settings file lock before the first-write read - #124471
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: found issues before merge. Reviewed August 30, 2026, 9:49 AM ET / 13:49 UTC. ClawSweeper reviewWhat this changesThe PR serializes file-backed first writes before reading settings and adds a two-process regression test for preserving concurrent settings fields. Regression provenancePossible regression — probable (reviewed change; known regression link). No predecessor PR is attributed. Merge readinessThe lock-first repair addresses the reported first-write race, but it regresses the exported FileSettingsStorage contract: a no-op direct withLock call now creates the settings directory. Keep this PR open for a compatibility-preserving update-path design. Priority: P1 Review scores
Verification
How this fits togetherSettingsManager loads and persists agent preferences through SettingsStorage. FileSettingsStorage coordinates global and project settings files, which supply preferences to future agent sessions. flowchart LR
A[Preference change] --> B[Settings manager]
B --> C[Settings storage]
C --> D{Load or save}
D --> E[Read settings]
D --> F[Lock, read, merge]
F --> G[Settings file]
E --> H[Agent session]
G --> H
Decision needed
Why: This class and its storage interface are exposed through the extension-safe SDK; the repair needs a maintainer choice between preserving that contract and intentionally changing it. Before merge
Findings
Agent review detailsSecurityNone. PR surfaceSource +11, Tests +111. Total +122 across 3 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep direct no-write withLock calls lazy, and route SettingsManager persistence through a dedicated lock-before-read update path while retaining the race regression coverage. Do we have a high-confidence way to reproduce the issue? Yes: current main reads a missing file before taking the lock, while SettingsManager merges fields inside that callback; the added two-process test encodes the same storage race. Is this the best way to solve the issue? No: locking before the read is the right owner boundary, but the current implementation also changes the supported direct no-write storage behavior. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against ab989f0d3c79. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (4 earlier review cycles)
|
ab46902 to
ec3d2dd
Compare
Two processes could read an absent settings file before either acquired its lock. Each process then merged from an empty object, and the later write silently discarded the other process's setting. Keep missing-file reads lazy, but acquire the file lock before every read-modify-write callback. Existing custom settings stores keep using their shipped lock-based read contract.
ec3d2dd to
22f9230
Compare
|
Thanks @MrSwagatRathod! Proof: Two real Node processes wrote
Example
|
Remove the unshipped optional settings-read branch and synthetic process test added by #124471. Keep missing-directory reads side-effect free, lock before reads when the directory exists, and document unsupported concurrent external first creation. Co-authored-by: Ayaan Zaidi <[email protected]>
Prevent concurrent OpenClaw processes from silently discarding distinct settings when they create the same settings file. Keep missing-file loads lazy, and acquire the canonical file lock before each read-modify-write operation. Co-authored-by: Ayaan Zaidi <[email protected]>
Remove the unshipped optional settings-read branch and synthetic process test added by openclaw#124471. Keep missing-directory reads side-effect free, lock before reads when the directory exists, and document unsupported concurrent external first creation. Co-authored-by: Ayaan Zaidi <[email protected]>
What Problem This Solves
Two OpenClaw processes can write distinct settings to the same absent
settings.json. Both calls report success, but the second write can silently discard the first setting.Fixes #124394.
Root cause
FileSettingsStorage.withLockread a missing file before it acquired the file lock. Both processes could therefore merge their changes from the same empty object.Fix
readSettingsScope.SettingsStorage.withLockpath for custom storage implementations.Evidence
The proof started two real Node processes against one absent settings file. One process wrote
defaultModel; the other wrotetheme.f46f9b5aa39f{"theme":"dark"};defaultModelwas lost22f9230dd6f{"defaultModel":"provider/model","theme":"dark"}Current main
b4f85100f72dhas no later changes to the settings owner files.Focused validation:
node scripts/run-vitest.mjs src/agents/sessions/settings-storage.test.ts src/agents/sessions/settings-manager.test.tspasses 7 tests.