Skip to content

fix(ui): persist Control UI settings across reconnects via gateway-owned LWW prefs writes - #114286

Merged
steipete merged 6 commits into
mainfrom
fix/ui-prefs-lww-reconnect-sync
Jul 27, 2026
Merged

steipete merged 6 commits into
mainfrom
fix/ui-prefs-lww-reconnect-sync

Conversation

@steipete

@steipete steipete commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Control UI settings (theme, language, chat preferences, sidebar sessions) sync
into gateway config ui.prefs through config.patch guarded by a
whole-document CAS baseHash. Two tabs or a Gateway reconnect lose writes:
the browser-side queue fetches config.get, patches with that hash, retries
once, then silently drops the edit. Edits made while disconnected never
replay, and a tab that loses a CAS race to a sibling tab never persists its
preference. This is the issue PR #114170 attempted to fix client-side; its
own live two-tab reconnect proof failed twice (on head 049e0ea and on the
stronger unpublished candidate 85adc15), so that PR is closed in favor of
this boundary-correct replacement.

Why This Change Was Made

Only the gateway can serialize concurrent preference writers; per-tab module
state categorically cannot fence a sibling tab. This PR therefore fixes the
issue at the ownership boundary:

  • Gateway: config.patch now accepts a hash-free patch iff every changed
    path is inside the documented last-writer-wins preference subtree
    (ui.prefs) AND the patch is a leaf-level operation (container replacement
    or deletion at/above ui.prefs still requires the document CAS, so a stale
    client cannot wipe concurrently added keys). The server already owns the
    merge, validation, destructive-array guard, and a lock-time CAS inside
    replaceConfigFile. A lost commit race deliberately surfaces to the client
    instead of retrying server-side: a server retry would replay frozen stale
    intent over the winner, while the client's retry replays current intent.
    Every other path keeps the strict document CAS unchanged, baseHash was
    already optional in the wire schema, and no protocol or config surface
    changes.
  • Control UI: the CAS queue, config.get-before-patch, and stale-hash
    suppression set are deleted. Local edits become per-key pending intent that
    shadows server reconciliation until the gateway acks, persists per gateway
    scope in localStorage, and replays on reconnect (flushServerUiPrefs fires
    on the connected transition even when the reconnect reuses the client
    object). Commit-race conflicts retry once, then reschedule a bounded
    delayed drain — conflicts imply another writer made progress, so this
    converges. After each ack the runtime config capability refreshes, and its
    existing request-version fencing discards stale in-flight config.get
    responses, closing the echo flip-flop window.
  • Capability hardening (settings editor shares the reconnect symptom): a
    dead prior-connection flight no longer blocks the explicit-op FIFO after
    reconnect, and set() captures its connection epoch at enqueue so a
    pre-reconnect submission cannot commit into the new connection.

User Impact

Settings changes persist across Gateway restarts, reconnects, and multiple
concurrent tabs/devices. Edits made while disconnected are retained and
written once the connection returns. Concurrent writers on disjoint
preferences no longer conflict; same-key writers converge last-writer-wins,
matching user expectation for UI preferences. Viewer-scope clients keep the
existing silent device-local degrade. No config or protocol surface changes.

Evidence

  • Focused suites: src/gateway/server-methods/config.test.ts (hash-free LWW
    gate, mixed-path rejection, destructive-array guard, noop, stale-hash
    strict-mode preservation, commit-race retry), ui/src/app/server-prefs.test.ts
    (pending-intent model incl. offline retention + reconnect flush, shadowed
    reconciliation, retained-snapshot memo, cross-tab pending merge, conflict
    retry vs validation drop), ui/src/lib/config/index.test.ts (FIFO release +
    epoch-captured set). 126 tests green via
    node scripts/run-vitest.mjs (20 gateway + 103 ui + 3 e2e); expanded
    check-changed (formatting, core/UI typechecks, lint, architecture,
    storage guards) passed remotely on Blacksmith Testbox, exit 0.
  • End-to-end regression ui/src/e2e/settings-prefs-reconnect.e2e.test.ts
    (real Chromium executed, no skips): offline edit replays after a
    same-client reconnect as a hash-free config.patch (asserted: no
    baseHash, no CAS config.get, zero patches escape while disconnected);
    two pages with disjoint keys both persist; a server delta applies without
    reverting a pending local key.
  • Iterative structured review (gpt-5.6-sol, xhigh): four accepted P2s were
    fixed in-branch (server-side retry replaying frozen stale intent over a
    race winner; container-level hashless ops; retained-snapshot
    re-reconciliation reverting acked prefs; cross-tab persisted-pending
    clobber). Two findings consciously rejected with code proof: post-backoff
    epoch recheck (the guard is the first statement of every attempt
    iteration) and retain-on-transient-error (retention would permanently
    stick the pending shadow for viewer-scope clients; drop releases the
    shadow and matches the documented device-local degrade). Final delta
    review clean: patch is correct (0.91).
  • Live real-gateway proof on Blacksmith Testbox tbx_01kygyxbpxr8awqaxdd5j73qkn
    (Actions run 30238422165): production build, isolated loopback gateway
    (port 43019, dedicated state dir, real /readyz), two authenticated real
    Chromium pages (/settings/appearance, /settings/general). Online
    theme=knot persisted; SIGTERM; both pages reached reconnecting; offline
    theme=dash + locale=fr with zero patches escaping while down; gateway
    restart; after reconnect the gateway's openclaw.json physically ended as
    {"locale":"fr","theme":"dash"} — and the dash replay survived a live
    stale-config rejection through the client retry, the exact point where
    both fix(ui): preserve settings across concurrent Gateway writes #114170 candidates failed. Artifact SHA-256:
    initial.png 692e41aa…187c78, pre-reconnect.png 839df5f2…450c63,
    disconnected.png 63688719…bfca08, final pages e63d0790…694e77 /
    ddb7a013…8d0ad3, result.json bad03705…27a076,
    gateway.log c08625fd…9741f4, structured-stdout.log e8b4c270…12da1e.
    One honest residual: the page that selected French offline kept English
    chrome until reload because i18n.setLocale never retries a lazy bundle
    fetch that failed while the gateway was down — a pre-existing main bug
    independent of this PR (the sibling page rendered French correctly via the
    server delta); follow-up task filed.
  • Hosted CI: first run failed one pre-existing app-host.test.ts fixture
    that predated the new reconcile identity fence (fake context without
    runtimeConfig); fixed in f50600b. Full CI green on that head: Actions
    run 30238640504.
  • AI-assisted (Codex implementation from a frozen spec; design, review, and
    verification by maintainer session).

@openclaw-barnacle openclaw-barnacle Bot added app: web-ui App: web-ui gateway Gateway runtime size: XL maintainer Maintainer-authored PR labels Jul 27, 2026
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. labels Jul 27, 2026
@clawsweeper

clawsweeper Bot commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 27, 2026, 1:07 AM ET / 05:07 UTC.

ClawSweeper review

What this changes

The branch lets the gateway accept narrowly constrained hash-free last-writer-wins writes for ui.prefs and makes the Control UI retain, reconcile, and replay pending settings edits after reconnects.

Merge readiness

⛔ Blocked until stronger real behavior proof is added - 5 items remain

Keep this PR open. It addresses a plausible P1 regression at the correct gateway/UI ownership boundary, but the proposed hash-free config.patch exception needs maintainer acceptance and the PR still lacks inspectable after-fix real-gateway evidence.

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

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The patch has substantive focused coverage, but the required inspectable after-fix real behavior proof is still absent.
Proof confidence 🧂 unranked krab (1/6) Needs stronger real behavior proof before merge: The PR describes a live gateway and Chromium run, but the cited Testbox/run/artifact fields are still placeholders; add redacted after-fix live output, logs, recording, or a linked artifact, then update the PR body for automatic re-review (or ask a maintainer to comment @clawsweeper re-review).
Patch quality 🦐 gold shrimp (3/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Needs proof Needs stronger real behavior proof before merge: The PR describes a live gateway and Chromium run, but the cited Testbox/run/artifact fields are still placeholders; add redacted after-fix live output, logs, recording, or a linked artifact, then update the PR body for automatic re-review (or ask a maintainer to comment @clawsweeper re-review).
Evidence reviewed 5 items Gateway ownership change: The branch introduces a documented-in-code hash-free LWW exception limited to ui.prefs, while retaining strict document CAS for other configuration paths and for unsafe container-level operations.
Reconnect and pending-intent path: The Control UI changes pending preference handling and explicitly flushes those pending writes when a gateway client reconnects, with runtime configuration refreshed after acknowledgement.
Regression coverage added: The branch adds a Chromium-oriented reconnect regression suite and focused gateway/UI tests covering offline retention, replay, concurrent disjoint preferences, and reconciliation.
Findings None None.
Security None None.

How this fits together

Control UI settings are mirrored locally in the browser and synchronized to gateway configuration. Browser edits pass through the gateway’s configuration write path, then flow back through runtime configuration snapshots to update connected tabs and devices.

flowchart LR
  A[Control UI settings edit] --> B[Pending browser preference intent]
  B --> C[Gateway config.patch request]
  C --> D{ui.prefs leaf-only write?}
  D -->|Yes| E[Gateway LWW config write]
  D -->|No| F[Strict whole-config CAS]
  E --> G[Gateway config snapshot]
  F --> G
  G --> H[UI reconciliation and refresh]
Loading

Decision needed

Question Recommendation
Should OpenClaw make ui.prefs a gateway-enforced leaf-level last-writer-wins exception to the normal whole-document config.patch CAS contract? Approve bounded LWW contract: Accept hash-free leaf writes only under ui.prefs, subject to current-head real-gateway proof and normal merge refresh.

Why: This is a deliberate compatibility and concurrency-policy change, not only a local UI repair; the gateway boundary determines its long-term behavior for all callers.

Before merge

  • Add real behavior proof - Needs stronger real behavior proof before merge: The PR describes a live gateway and Chromium run, but the cited Testbox/run/artifact fields are still placeholders; add redacted after-fix live output, logs, recording, or a linked artifact, then update the PR body for automatic re-review (or ask a maintainer to comment @clawsweeper re-review).
  • Resolve merge risk (P1) - Merging changes the effective config.patch concurrency contract: eligible ui.prefs leaf writes may now omit document CAS, so maintainers should explicitly accept the bounded LWW exception and its future compatibility boundary.
  • Resolve merge risk (P1) - The patch carries pending preference state across reconnects and tabs; tests are useful but do not substitute for a redacted real gateway run that demonstrates offline edits persist after reconnect without regressing snapshot reconciliation.
  • Resolve merge risk (P1) - The PR is behind current main; refresh the merge review against the resulting three-way merge before landing.
Agent review details

Security

None.

PR surface

Source +189, Tests +898. Total +1087 across 9 files.

View PR surface stats
Area Files Added Removed Net
Source 4 341 152 +189
Tests 5 1024 126 +898
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 9 1365 278 +1087

Review metrics

Metric Value Why it matters
Configuration write contract 1 narrowed hash-free exception The PR changes one generic configuration-write rule by allowing hash-free leaf updates under ui.prefs, which needs explicit compatibility ownership.

Stored data model

Persistent data-model change detected: serialized state: ui/src/app/server-prefs.test.ts, serialized state: ui/src/e2e/settings-prefs-reconnect.e2e.test.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Add inspectable live gateway proof (recommended)
    Before merge, attach a redacted terminal transcript, recording, logs, or artifact from the stated two-page reconnect run that shows the persisted ui.prefs result after gateway restart.
  2. Accept the contract with explicit ownership
    A gateway/config owner may accept the leaf-only LWW exception after confirming that relaxing CAS inside ui.prefs is the intended permanent compatibility policy.
  3. Pause for a narrower write API
    Pause this branch if maintainers do not want a path-sensitive exception in the generic configuration patch protocol.

Technical review

Best possible solution:

Keep strict whole-document CAS as the default, accept the leaf-only ui.prefs LWW exception only with explicit gateway/config ownership approval, and attach redacted live gateway evidence showing two-page and offline-reconnect persistence on the current head.

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

Unclear for a high-confidence live reproduction from the available evidence. The new focused tests and detailed failure model make the source path reproducible, but the claimed real gateway run has no inspectable artifact or transcript.

Is this the best way to solve the issue?

Unclear. Moving concurrent-write serialization to the gateway is a stronger boundary than the closed client-only predecessor, but maintainers must first decide whether the generic configuration patch protocol should carry this permanent leaf-level LWW exception.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 16d2b7e46784.

Labels

Label justifications:

  • P1: The reported regression can silently lose Control UI settings during reconnects or concurrent browser writes, affecting an active user workflow.
  • merge-risk: 🚨 compatibility: The gateway changes when callers may omit whole-document CAS for a configuration subtree.
  • merge-risk: 🚨 session-state: Pending browser preference intent now survives reconnects and is merged with returned gateway snapshots.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦐 gold shrimp.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs stronger real behavior proof before merge: The PR describes a live gateway and Chromium run, but the cited Testbox/run/artifact fields are still placeholders; add redacted after-fix live output, logs, recording, or a linked artifact, then update the PR body for automatic re-review (or ask a maintainer to comment @clawsweeper re-review).

Evidence

What I checked:

  • Gateway ownership change: The branch introduces a documented-in-code hash-free LWW exception limited to ui.prefs, while retaining strict document CAS for other configuration paths and for unsafe container-level operations. (src/gateway/server-methods/config.ts:86, f50600b51af8)
  • Reconnect and pending-intent path: The Control UI changes pending preference handling and explicitly flushes those pending writes when a gateway client reconnects, with runtime configuration refreshed after acknowledgement. (ui/src/app/app-host.ts:1541, f50600b51af8)
  • Regression coverage added: The branch adds a Chromium-oriented reconnect regression suite and focused gateway/UI tests covering offline retention, replay, concurrent disjoint preferences, and reconciliation. (ui/src/e2e/settings-prefs-reconnect.e2e.test.ts:1, f50600b51af8)
  • Related branch is not a viable replacement: The earlier related implementation at fix(ui): preserve settings across concurrent Gateway writes #114170 was closed unmerged, and this PR explicitly replaces its client-only approach; it is not evidence that the current work is obsolete.
  • Real-behavior proof remains uninspectable: The PR body describes a Testbox gateway-and-Chromium run but leaves the Testbox ID, run ID, artifacts, and hosted-CI evidence as placeholder comments; the prior ClawSweeper proof request therefore remains unresolved.

Likely related people:

  • steipete: The available history shows six commits on this replacement and the earlier related Control UI settings-write PR, making this the strongest available routing signal for the proposed gateway/UI design. (role: recent area contributor; confidence: medium; commits: 6b5d573e3de6, 173f9084b506, 98ea21655825; files: src/gateway/server-methods/config.ts, ui/src/app/server-prefs.ts, ui/src/lib/config/index.ts)

Rank-up moves

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

  • Attach redacted evidence from the claimed real gateway two-page reconnect run, including the persisted post-reconnect result.
  • Obtain explicit gateway/config owner approval for the path-limited LWW configuration-write contract.
  • Refresh the merge review after rebasing or otherwise updating the branch against current main.

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 (1 earlier review cycle)
  • reviewed 2026-07-27T04:42:06.724Z sha 98ea216 :: needs real behavior proof before merge. :: none

@steipete
steipete marked this pull request as ready for review July 27, 2026 04:55
@steipete

Copy link
Copy Markdown
Contributor Author

Addressing the review's decision item and rank-up moves:

  • Owner decision — accepted. As gateway/config owner I accept the path-limited LWW configuration-write contract: config.patch without baseHash is valid iff every changed path is a leaf operation strictly inside ui.prefs (the documented cross-device preference surface); container-level replacement/deletion and every other config path keep the strict document CAS. Rationale is in the PR body: only the Gateway can serialize concurrent preference writers, and a lost commit race must surface to the client whose retry replays fresh intent.
  • Real-gateway evidence attached. Runtime logs and the machine-readable result of the two-page reconnect run on Blacksmith Testbox tbx_01kygyxbpxr8awqaxdd5j73qkn (isolated loopback gateway, production build, real Chromium): https://gist.github.com/steipete/5a27cf801d3d3dbe44b60bbd59d4306a — post-reconnect openclaw.json ended {"locale":"fr","theme":"dash"} with both offline edits physically acknowledged; the dash replay survived a live stale-config rejection via the client retry. SHA-256 for every artifact (including screenshots) is in the PR body.
  • The one residual named in the body (offline-selected locale keeps English chrome until reload) is a pre-existing main bug in i18n.setLocale lazy-bundle retry, filed as a follow-up and independent of this change.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Command router queued. I will update this comment with the next step.

@steipete
steipete merged commit e0eed25 into main Jul 27, 2026
124 checks passed
@steipete
steipete deleted the fix/ui-prefs-lww-reconnect-sync branch July 27, 2026 05:17
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 27, 2026
…ned LWW prefs writes (openclaw#114286)

* fix(ui): sync Control UI prefs via hash-free LWW config.patch

* test(ui): prove prefs reconnect replay end to end

* fix(gateway): surface hash-free prefs commit races instead of replaying stale intent

* fix(ui): never re-reconcile a retained config snapshot over acked prefs

* fix(ui): merge persisted pending prefs across tabs instead of clobbering

* test(ui): pass current runtime config through sidebar prefs reconcile fixture
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: web-ui App: web-ui gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: XL status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant