Skip to content

fix(settings): preserve concurrent first saves - #134072

Merged
steipete merged 3 commits into
mainfrom
codex/fix-settings-first-write-lock
Aug 31, 2026
Merged

steipete merged 3 commits into
mainfrom
codex/fix-settings-first-write-lock

Conversation

@steipete

@steipete steipete commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

Related: #124471, #133413

What Problem This Solves

Fixes an issue where users saving different settings from concurrent OpenClaw processes could silently lose one setting when its directory did not exist yet. Both processes reported success, but the last writer replaced the other's update.

Why This Change Was Made

Acquire the existing canonical lock before reading settings or invoking the merge callback. The lock implementation already creates its parent directory, so this removes the separate delayed-lock path. Missing-settings reads retain their existing side-effect-free path. No schema, configuration, dependency, or public API changes.

Provenance: the first-write ordering shipped in 2026.8.1 via #124471 and was regressed by #133413 (bec70700e08a09d5719e0acede249d4bcaefcfbf), verified against its raw parent diff. This restores that contract while preserving main's later read-side improvements.

User Impact

Independent global and project settings survive concurrent initial saves. Existing lock ownership, stale-lock handling, and read behavior remain intact.

Evidence

  • Before the fix, two real Node processes both exited successfully but lost the theme update in both scopes; both regression cases failed.
  • After the fix, all 16 storage/manager tests pass, including read races, lock namespaces, nested merges, and first-write concurrency.
  • Separate real-file proof using three simultaneous SettingsManager processes per scope preserved all six updates.
  • Production LOC: +6/-16. Tests: +104/-13. The read-race fixture now releases its writer at the actual lock/file observation instead of depending on a redundant directory probe.
  • Full check:changed passed, including production/test types, lint, and structural guards.
  • Codex autoreview: scoped-clean at the configured P0 threshold. The pinned fs-safe 0.5.6 implementation was inspected directly.

Original contributor credit is retained in the changelog and commit trailers.

Review Follow-through

ClawSweeper's lock-contract concern is resolved by direct inspection of the installed, pinned @openclaw/[email protected] source: dist/file-lock-sync.js:83–90 creates and canonicalizes the parent directory, and acquireFileLockSync calls that owner at line 129 before exclusive lock acquisition. Both first-write scope regressions and the separate six-update SettingsManager proof passed against that exact dependency. No dependency upgrade is part of this change.

The direct no-op callback compatibility finding is also intentionally skipped after checking the stable contract: published 2026.8.1 FileSettingsStorage.withLock explicitly creates the missing directory before locking, reading, or invoking the callback, including callbacks that return undefined. The class was already exported through the agent-sessions SDK in that tag. This repair restores that shipped behavior; the side-effect-free direct callback branch was introduced by the later, unreleased regression in #133413. Read-only callers retain the canonical readSettingsScope absence path, which remains side-effect-free and tested. Running a callback once outside the lock to discover whether it writes would recreate stale input or require duplicate callback execution.

The suggestion to remove the changelog bullet is intentionally skipped: this is maintainer-authorized release repair work with explicitly requested comprehensive release notes, rather than an ordinary contributor PR. The single user-facing bullet records the restored shipped contract and preserves original contributor credit.

CI Repairs

The initial exact-head CI found an unrelated global-session prompt fixture timeout and a workspace-icon test that counted unrelated header SVG fetches. The prompt fixture now includes the model identity supplied by real prepared attempt handles, preserving both sandbox-policy assertions. Its first case failed locally at 138.7 seconds before correction and passed in 199 ms afterward; all 25 prompt/setup tests pass without a timeout increase. Latest main already repaired workspace-icon fetch isolation in #133904 (ca8064f2625), using the shared mockWorkspaceIconFetch helper. The redundant copied UI patch was dropped during rebase; this PR retains main’s canonical UI tests unchanged. No production prompt or UI behavior changes are included. The initial lint job was canceled by runner shutdown with no lint diagnostic; it is not reported as a code failure or a pass.

The interrupted parent lint check passed on a single exact-job retry against unchanged source. A later docs-only relocation of the same settings note resolves a concurrent changelog insertion; text and contributor credit are unchanged. The new commit requires fresh CI independently of that parent result.

@clawsweeper

clawsweeper Bot commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S maintainer Maintainer-authored PR labels Aug 31, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P1 High-priority user-facing bug, regression, or broken workflow. 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 Aug 31, 2026
@clawsweeper

clawsweeper Bot commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: found issues before merge. Reviewed August 31, 2026, 9:35 AM ET / 13:35 UTC.

ClawSweeper review

What this changes

The branch acquires the settings lock before reading or merging first writes, adds cross-process regression coverage, corrects a prompt-test fixture, and adds release-note text.

Regression provenance

Possible regression — probable (reviewed change; known regression link). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 7 items remain

Keep open: the lock-before-read repair addresses a source-reproducible concurrent first-write loss, but the exported storage API’s absent-directory no-op behavior and the release-owned changelog entry remain unresolved merge blockers.

Priority: P1
Reviewed head: 98b333fe84c50fa9509bd288299d967cf31f5109
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The core race repair is well targeted, but unresolved exported-behavior and release-ownership questions prevent a higher readiness rating.
Proof confidence 🌊 off-meta tidepool Not applicable: Repository state identifies this as a MEMBER-authored PR, so the external-contributor proof gate does not apply; the body describes real process evidence, but this read-only review did not execute it.
Patch quality 🦐 gold shrimp (3/6) 2 actionable review findings remain.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: Repository state identifies this as a MEMBER-authored PR, so the external-contributor proof gate does not apply; the body describes real process evidence, but this read-only review did not execute it.
Evidence reviewed 8 items Current main leaves the first-write race open: Current main reads an absent settings file and invokes the callback before creating/acquiring a lock when the parent directory is absent; two processes can therefore derive independent replacements from the same empty state.
Introduced repair serializes the merge: The PR obtains the settings-file lock before observing the file or invoking the merge callback, which is the correct owner boundary for concurrent read-modify-write operations.
Caller merges under the storage callback: SettingsManager reads the current serialized settings, merges only modified fields, and returns the next JSON from within withLock; this is the caller whose atomicity the change repairs.
Findings 2 actionable findings [P2] Verify no-op settings-storage compatibility
[P2] Remove the release-owned changelog entry
Security None None.

How this fits together

SettingsManager persists global and project preferences through FileSettingsStorage. The storage callback merges a current settings file under a file lock before writing it back, so lock ordering determines whether independent processes preserve each other’s changes.

flowchart LR
  A[Settings update] --> B[Settings manager]
  B --> C[File settings storage]
  C --> D[File lock]
  D --> E[Merge callback]
  E --> F[Global or project settings file]
Loading

Decision needed

Question Recommendation
Should direct FileSettingsStorage no-op callbacks gain absent-directory creation, and should this PR retain its release-owned changelog entry? Narrow the public behavior change: Retain lock-before-read for writes while preserving no-op callback behavior unless an independently verified released contract requires directory creation.

Why: The current branch changes an exported behavior whose claimed stable provenance is contradicted by the inspected commit graph, while the release-owned file has no independently visible exception.

Before merge

  • Verify no-op settings-storage compatibility (P2) - This moves lock acquisition ahead of fn, so an absent direct FileSettingsStorage.withLock(scope, () => undefined) call gains the lock owner’s parent-directory side effect. The class is exported through the agent-sessions SDK, while the stated v2026.8.1 provenance is contradicted by the inspected ancestry. Verify the released contract or preserve the current no-op behavior before merging.
  • Remove the release-owned changelog entry (P2) - CHANGELOG.md is release-owned under the applicable repository policy. Keep the release-note context in the PR body or squash message unless a release owner records an explicit exception for this entry.
  • Resolve merge risk (P1) - Acquiring the lock before a callback that returns undefined can create an absent parent directory for direct exported FileSettingsStorage callers; the claimed stable-release justification is not supported by the inspected release ancestry.
  • Resolve merge risk (P1) - The repair relies on @openclaw/fs-safe creating a lock parent before acquisition, but its installed 0.5.6 source was unavailable in this read-only checkout for independent contract verification.
  • Resolve merge risk (P1) - The manually added CHANGELOG.md bullet needs explicit release-owner approval or relocation to the PR’s release-note context.
  • Complete next step (P2) - A maintainer must resolve the exported no-op compatibility contract and release-owned changelog exception before a repair direction is safe.

Findings

  • [P2] Verify no-op settings-storage compatibility — src/agents/sessions/settings-storage.ts:164
  • [P2] Remove the release-owned changelog entry — CHANGELOG.md:75
Agent review details

Security

None.

PR surface

Source -10, Tests +91, Docs +1. Total +82 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 1 6 16 -10
Tests 2 105 14 +91
Docs 1 1 0 +1
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 112 30 +82

Review metrics

Metric Value Why it matters
Production versus test delta production -10 net; tests +91 net; release metadata +1 The repair simplifies production storage logic while adding process-contention coverage; the remaining release-owned metadata needs a release decision.
Exported behavior affected 1 exported storage class FileSettingsStorage is exposed through the agent-sessions SDK, so no-op callback semantics require compatibility review.

Merge-risk options

Maintainer options:

  1. Verify and preserve the direct-call contract (recommended)
    Confirm the stable-release behavior from source, then either preserve side-effect-free absent no-op callbacks or make the compatibility decision explicit before merge.
  2. Accept an intentional API behavior change
    Release and session owners may accept parent-directory creation for no-op direct callers after documenting the upgrade effect and correcting provenance.
  3. Pause the release-note addition
    Keep the repair under review but remove the manually maintained changelog entry until release ownership chooses its inclusion.

Technical review

Best possible solution:

Keep the lock-before-read repair, but establish the released direct-callback contract before merging; preserve side-effect-free no-op callers if that is the contract, and keep release-note context out of CHANGELOG.md unless release ownership explicitly approves it.

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

Yes, source-reproducible: current main invokes the first-write merge callback before lock acquisition when the directory is absent. The introduced test encodes the two-process interleaving for both scopes, but read-only review rules prohibit running it.

Is this the best way to solve the issue?

Unclear: locking before the read-modify-write callback is the correct repair boundary, but the direct no-op callback compatibility contract and release provenance need verification before this is the best complete solution.

Full review comments:

  • [P2] Verify no-op settings-storage compatibility — src/agents/sessions/settings-storage.ts:164
    This moves lock acquisition ahead of fn, so an absent direct FileSettingsStorage.withLock(scope, () => undefined) call gains the lock owner’s parent-directory side effect. The class is exported through the agent-sessions SDK, while the stated v2026.8.1 provenance is contradicted by the inspected ancestry. Verify the released contract or preserve the current no-op behavior before merging.
    Confidence: 0.88
  • [P2] Remove the release-owned changelog entry — CHANGELOG.md:75
    CHANGELOG.md is release-owned under the applicable repository policy. Keep the release-note context in the PR body or squash message unless a release owner records an explicit exception for this entry.
    Confidence: 0.97

Overall correctness: patch is incorrect
Overall confidence: 0.9

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P1: The PR repairs a current-main path where concurrent first saves can silently lose an independently saved setting.
  • merge-risk: 🚨 compatibility: Lock acquisition timing can change filesystem side effects for direct exported storage callers and depends on an unverified release contract.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: Repository state identifies this as a MEMBER-authored PR, so the external-contributor proof gate does not apply; the body describes real process evidence, but this read-only review did not execute it.

Evidence

What I checked:

  • Current main leaves the first-write race open: Current main reads an absent settings file and invokes the callback before creating/acquiring a lock when the parent directory is absent; two processes can therefore derive independent replacements from the same empty state. (src/agents/sessions/settings-storage.ts:166, 87dba63ec9c5)
  • Introduced repair serializes the merge: The PR obtains the settings-file lock before observing the file or invoking the merge callback, which is the correct owner boundary for concurrent read-modify-write operations. (src/agents/sessions/settings-storage.ts:164, 98b333fe84c5)
  • Caller merges under the storage callback: SettingsManager reads the current serialized settings, merges only modified fields, and returns the next JSON from within withLock; this is the caller whose atomicity the change repairs. (src/agents/sessions/settings-manager.ts:253, 98b333fe84c5)
  • Process-level regression coverage: The new table-driven test starts independent Node processes for global and project paths and asserts that both independently written fields survive after contention. (src/agents/sessions/settings-storage.test.ts:196, 98b333fe84c5)
  • Public SDK surface: FileSettingsStorage is exported through the extension-safe agent-sessions SDK, so direct callers can observe its no-op callback filesystem behavior independently of SettingsManager’s pure read path. (src/agents/sessions/extension-sdk.ts:22, 98b333fe84c5)
  • History and release provenance need correction: The original fix and later refactor are merged commits, but neither merge commit is an ancestor of the supplied v2026.8.1 release commit; that contradicts the PR body’s claim that the original PR shipped in that release. (0b2f6880e79a)

Likely related people:

  • Swagat Rathod: 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)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Verify the stable-release source contract for absent direct no-op callbacks.
  • Remove the changelog addition or record release-owner approval and correct the provenance.

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.

History

Review history (2 earlier review cycles)
  • reviewed 2026-08-31T11:32:20.441Z sha 88b285d26440b1a531bb8a081d8db0dc2222534e :: needs changes before merge. :: [P2] Remove the release-owned changelog entry
  • reviewed 2026-08-31T12:13:15.786Z sha 4fdee64 :: found issues before merge. :: [P2] Preserve no-op settings-storage behavior | [P2] Remove the release-owned changelog entry

@steipete steipete self-assigned this Aug 31, 2026
steipete and others added 2 commits August 31, 2026 05:00
Acquire the canonical settings lock before reading or deriving updates, including absent directories. Keep missing reads lazy and verify both settings scopes with independent processes.

Co-authored-by: Swagat Rathod <[email protected]>

Co-authored-by: Ayaan Zaidi <[email protected]>
@steipete
steipete force-pushed the codex/fix-settings-first-write-lock branch from fd3363d to 4fdee64 Compare August 31, 2026 12:01
@steipete
steipete merged commit ee06699 into main Aug 31, 2026
469 of 472 checks passed
@steipete
steipete deleted the codex/fix-settings-first-write-lock branch August 31, 2026 14:51
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 1, 2026
* fix(settings): preserve concurrent first saves

Acquire the canonical settings lock before reading or deriving updates, including absent directories. Keep missing reads lazy and verify both settings scopes with independent processes.

Co-authored-by: Swagat Rathod <[email protected]>

Co-authored-by: Ayaan Zaidi <[email protected]>

* test(agents): prepare the model identity in prompt fixture

* docs(changelog): avoid concurrent release note conflict

---------

Co-authored-by: Ayaan Zaidi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: S status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant