Repository navigation
fix(config): serialize concurrent config mutations - #76601
Conversation
|
Codex review: needs maintainer review before merge. Summary Reproducibility: yes. Current main prepares non-interactive Real behavior proof Next step before merge Security Review detailsBest possible solution: Land this centralized config mutation fix, then keep any remaining multi-agent orchestration failures tracked in the linked broader issues as separate work. Do we have a high-confidence way to reproduce the issue? Yes. Current main prepares non-interactive Is this the best way to solve the issue? Yes. Moving read/transform/write into a central config-layer lock and retry helper is the narrow maintainable fix for this race, and it avoids a command-local retry loop while preserving broader follow-up scope separately. What I checked:
Likely related people:
Remaining risk / open question:
Codex review notes: model gpt-5.5, reasoning high; reviewed against 1ae9d8227ae0. |
f086923 to
842c8c2
Compare
4385ae9 to
8a60c43
Compare
|
bump ^? |
a1442fd to
1cd93cf
Compare
1cd93cf to
d5f204d
Compare
0bfdf24 to
2404582
Compare
|
Landing proof for PR #76601.
|
|
thanks for merging. |
Summary
Centralizes config-file mutation behind reusable transform/write helpers so concurrent writers re-read, rebase, and commit against the latest persisted config instead of clobbering each other or surfacing avoidable
ConfigMutationConflictErrors.This is intentionally generic:
agents addis one caller of the shared config mutation API, and gateway/runtime/plugin writers now use the same semantic mutation path where they previously rewrote a prepared full config object.Related: #43367
Problem
Config updates were spread across read/modify/write call sites. A caller could read a snapshot, prepare a new config, then lose the race when another command or gateway request wrote first. Cross-process locking alone was not enough because same-process callers could overlap, and command-specific retry loops would leave the same stale-snapshot bug available to the next config writer.
The visible case was concurrent
openclaw agents add --non-interactivecalls: one process could crash on a conflict or overwrite from a stale snapshot, leaving only part of the requested agent set in the config.What Changed
src/config/mutate.ts:transformConfigFile/mutateConfigFilebaseHashcontract for stale prepared snapshots and made prepared writes carry their originalbaseSnapshotthrough the config writer.agents addto express the desired addition as a config transform, so retries reapply intent to the latest config snapshot.agents.create,agents.update,agents.delete, andskills.config.set/config,/plugins enable|disable, and/allowlistconfig editsmutateConfigFilewhere production code now does.agents addbehavior.Why This Shape
The important invariant is now owned by the config layer: when code reads config in order to write config, it should do that through one mutation path that owns locking, base-hash checks, retry semantics, include-file writes, runtime snapshot refresh, and after-write follow-up behavior.
That avoids duplicating conflict loops at each command boundary and keeps future config writers from accidentally reintroducing stale-snapshot writes.
Real behavior proof
openclaw agents add --non-interactivecalls should preserve all requested agents when they mutate the same config file at the same time.f5ab8e8d78, macOS, Node viapnpm openclaw, isolated tempOPENCLAW_HOME,OPENCLAW_STATE_DIR, andOPENCLAW_CONFIG_PATH.pnpm openclaw agents addcommands concurrently against/tmp/openclaw-pr76601-proof.lG9g45/openclaw.json, waited for all three, then ranpnpm openclaw agents listand inspected the final config.main,race-one,race-two, andrace-three. NoConfigMutationConflictErrorescaped to the user, and no agent entry was lost.Verification
Rebased on current
origin/mainand pushed latest head494f7531eb.Commands run on latest head:
Results: