Skip to content

fix(cli): keep backup records and device approvals consistent with the Gateway - #168466

Merged
steipete merged 6 commits into
mainfrom
dbasync/ow3
Oct 10, 2026
Merged

steipete merged 6 commits into
mainfrom
dbasync/ow3

Conversation

@steipete

@steipete steipete commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Final landing proof (2026-10-10)

6273a54dbca8 corrects the administrative SQL observer: canonical schema validation in a fresh in-memory database is not persisted-state access. The observer still checks file-backed statements and custody. The formerly failing Linux pairing case now passes with all 25 administrative-owner process tests (26.93 s Vitest; 41.05 s test-command wall). Focused formatting/lint and independent Codex P0/P1 review passed.

The published-driver 2026.9.9 × candidate 6273a54 update cell passed on Blacksmith Testbox. The package's embedded commit matched the candidate, the update reached finished, and readiness returned HTTP 200 (483.443 s remote command).

CI run 38066676485, attempt 1, completed all 119 jobs with exactly two failed roots and their aggregate, and no cancellations. The untouched cron case “refuses keyless delivery inherited from another conversation's shared main bucket” expected error, received ok; it fails identically on main run 38059964113, job 114236115312. The untouched chat case “chat.send returns in_flight when duplicate attachment send wins parsing race” expected one dispatch but observed zero at line 2396; it fails identically on main run 38068164099, job 114260176569. Both owners are byte-identical between the tested main baseline and the PR merge. The coordinator explicitly authorized native admin admission for independently proven inherited failures; no rerun was requested to obtain green.

CI correction (2026-10-10)

67755c833cede fixes two PR-caused CI failures: the missing-ledger path now explicitly returns undefined for consistent-return lint, and the existing corrupt-database test expects the complete ownership-aware warning. Runtime behavior is unchanged by this correction.

Focused validation: pnpm test src/commands/backup-sqlite.test.ts --maxWorkers=1 passed 8/8 (166.36 s command wall; the original CI shard failed this case in 59.10 s across 49 files). Targeted worker-runtime lint and git diff --check passed. Independent Codex review of the two-line fix found no P0/P1 issues.

Refusal correction (2026-10-10)

The lander found three real byte-preservation failures at 9009852efc36: rejected zero-byte, schema-empty, and wrongly owned global databases changed before the backup outcome writer ran. Runtime configuration loading inside local ownership admission was opening SQLite. A stronger settlement assertion also exposed the outcome writer bootstrapping the rejected zero-byte source afterward.

f73bcfc27f683 makes runtime configuration lazy within the existing local ownership scope. Backup outcome recording does not consume it. The state worker inspects an unopened ledger through the existing artifact-preserving read-only owner check before its writable open; an admitted writer is reused. Missing files remain absent, rejected files retain their bytes, and accepted outcomes still use the existing guarded transaction and settlement. There are no schema or retention changes.

The corrected two-argument outcome assertion is retained, and the test spy now forwards the authority options. The nine managed-source cases assert exact bytes both before the outcome attempt and after settlement. New regressions cover missing/empty files when local admission refuses and a live Gateway refusing a routed outcome without local replay.

Corrective proof Result
Original managed-source regressions Reproduced 3 failures / 9 cases
Missing/empty local refusal regressions with original helper Reproduced 2 failures / 2 cases
Managed-source byte preservation after the fix 9/9 passed; 293.19 s suite time
Local owner, backup outcome, backup ledger, and device CLI suites 73/73 passed; 245.09 s command wall time
Full build at f73bcfc27f683 Passed; 1177.59 s command wall time (macOS, Node v26.11.1)
Formatting and git diff --check Passed

Focused commands: pnpm test src/infra/backup-create.test.ts -t 'rejects a managed' --maxWorkers=1 and pnpm test src/cli/local-state-owner.test.ts src/commands/backup-outcome.test.ts src/state/backup-run-records.test.ts src/cli/devices-cli.test.ts --maxWorkers=1. The three new test bodies took 7.14 s combined locally; CI execution time has not been measured separately, and the existing CI job layout is unchanged. Proof ran locally through the campaign proof slot using the lane's established local fallback (disk above 15 GiB; load below 48).

This follow-up adds a read-only ownership inspection to cold backup ledger admission; already-open writers bypass it. Ordinary chat-turn paths are unchanged. No additional SQL harness run or savings claim is made for this corrective pass. The earlier campaign evidence below remains labeled with its measured heads. The accepted correctness finding is fixed under the three-round review convergence rule.

Corrective diff: production +31/-10 lines, tests +73/-6, docs +2/-0. The requested scope is focused tests plus build, push, and stop; this PR remains ready and unmerged.


What Problem This Solves

CLI backup outcomes and local device-approval fallback could write the same SQLite state as a running Gateway from another process, bypassing its single-owner lifecycle and in-process publications.

User Impact

Backup commands now send outcome records to the local Gateway when it owns the state directory, and otherwise acquire exclusive offline ownership. Recording remains best-effort and never creates an absent state database. A failed or uncertain Gateway call produces the existing warning without replaying locally.

Device approval still uses the existing Gateway RPC. Its direct bootstrap fallback now refuses while a Gateway owns the state, with guidance to stop the Gateway and rerun the exact approval. Offline approval preserves request identity, same-device replacement checks, admin scope semantics, and current approval authority through commit. Explicit remote URLs never fall back to local state.

Why This Change Was Made

Both commands reuse runWithLocalStateOwner. The new admin-only backup.recordOutcome method validates a closed payload, binds the expected physical owner and live requester, and calls the existing worker-backed ledger writer with that authority. Ledger insertion/pruning, retained rows, durability, schema versions, and backup/archive execution ownership are unchanged.

Client bootstrap is deliberately unchanged: client token reads select current rows directly, and device identity bootstrap only inserts an absent key while preserving the first valid winner. The process identity cache retains successful values, never missing rows; no runtime bootstrap path can replace a cached identity. Identity repair remains Doctor-owned under its exclusive migration lock. This is an immutable-bootstrap exemption, not a claim that device identity has no cache.

Evidence

The command boundary regressions use real SQLite writers and physical owner locks with mocked discovery/transport; they are not full WebSocket end-to-end tests. The original implementation failed the foreign-live-owner device approval regression and the missing Gateway-call backup regression. Final device suites pass 60/60 after the mechanical helper extraction; backup outcome tests pass 4/4, and the unchanged owner/ledger/bootstrap siblings passed in the original focused run.

The nine-file focused command is pnpm test src/cli/devices-cli.test.ts src/cli/devices-cli.gateway.test.ts src/infra/device-auth-store.client.test.ts src/infra/device-identity-worker.test.ts src/commands/backup-outcome.test.ts src/commands/backup.create-verify.test.ts src/commands/backup-git.test.ts src/state/backup-run-records.test.ts src/gateway/server-methods/backup.test.ts --maxWorkers=1. Its first run passed 103/104; the closed-payload case exposed TypeBox Omit dropping additional-property rejection. Rebuilding that payload through closedObject fixed it. A later device run hit compiled-worker preparation inside a test; moving preparation to file setup fixed the timeout/spillover. The final backup/device unit command passed 54/54 in 335.79 s wall time; the final extracted-device command passed 60/60 in 314.38 s, including worker preparation. CI seconds are not yet available.

The final 29 remaining canonical checks ran on an isolated 9009852efc36 checkout: 27 passed, with only the two inherited failures below. They included formatting, config/plugin boundaries, production and test typechecks, typed lint, scripts, schema parity, database/media/sidecar guards, and import cycles. Summed command wall time was 915.97 seconds. The earlier six changed-check guards, including the database-worker/T1 ratchet, passed; the exact two-row mock-baseline shrink now passes its final check. Madge also passed. The aggregate changed-check/Knip result is not claimed green. Full Knip reports only two inherited exports on the exact base: isTelegramReadOnlyControlLaneText and resolveContextTokens. The same base failure was independently recorded; upstream commit afb4f0ff366b already removes them. This branch does not touch those files or integrate unrelated main changes. The final deprecated-API guard also reports internal-config-api in untouched src/gateway/server-methods/agents.ts. Its blob matches the baseline exactly (ffa3cffaad743); main commit 959197ba0923f removes the reported direct config mutation and states the guard fix. This inherited failure is recorded without an unrelated integration.

Full pnpm build passed on final head 9009852efc36 in 346.88 seconds on macOS / Node 26.11.1. The final checks and build used the authorized static-proof fallback through the campaign proof slot after capacity waits and the earlier Testbox job expiration. The source checkout remained clean.

Plugin SDK API diff completed for 427f926e7c2d → b2825e4bebc5: no entrypoints added or removed, four changed reachable declarations from the additive backup RPC, with 152 transitively affected exports. Acknowledgement: 8032bf73. The later commit only extracts existing internal device-fallback helpers and prunes two stale mock-ratchet entries.

Three Codex P2 review rounds completed. The first two were scoped-clean. The third reported a P2 follow-up: append backup.recordOutcome at the end of the method table to preserve advertised method indices. It remains recorded under the campaign's three-round convergence rule; this is not a clean-review claim. No accepted P0/P1 finding remains. Post-review changes are the mechanical device helper extraction required by the file-size gate and the exact two-row mock-baseline shrink, with device regressions rerun.

Scope: production +254/−143 lines; tests +260/−13; docs/config +6/−3. The added code supplies the narrow ownership adapter and RPC, plus regression coverage. Existing fallback helpers moved to keep the runtime module within its established size ratchet.

SQL and worker-request report

Six runs alternated baseline 427f926e7c2d and candidate 13959252b2d6 on the same host. Cells are medians [minimum–maximum]. Warmed counts are per-turn means over ten turns; other rows are phase totals. All-thread includes MAIN, workers, and helper processes. No phase-median duration ratio exceeds 1.5.

The initial raw general SQL gate does not pass: warmed SQL rises by 15.8/turn (+1.43%), and first-turn SQL rises by 490 (+24.65%). The designated additional whole-workload pair completed with lower statement and request totals, but its detailed attribution files were lost during subsequent proof setup. A separate Testbox observation and the remaining evidence limitations are reported below. No removed statements or requests, and no performance saving, are claimed. The fixed workload never invokes the changed CLI operations or backup.recordOutcome; the worker command and its SQL remain unchanged.

Phase Base all-thread SQL Candidate all-thread SQL Base MAIN SQL Candidate MAIN SQL Base requests Candidate requests Duration C/M
01.boot 3347 [3325–3351] 3348 [3345–3349] 1988 [1986–1988] 1988 [1984–1988] 69 [66–70] 69 [69–70] 0.845
01.connect 379 [314–462] 345 [290–484] 61 [61–63] 61 [61–65] 45 [37–46] 42 [36–50] 1.140
02.first-turn 1988 [1875–2497] 2478 [1833–2497] 77 [56–105] 98 [70–105] 291 [290–346] 341 [288–346] 1.072
03.warmed 1105.7 [1087.7–1189] 1121.5 [1058.4–1142.5] 13 [11–19] 12.1 [9.8–13.9] 204.4 [200.1–213.2] 204.8 [199.8–209.1] 1.020
04.second-session 4270 [4108–4347] 4286 [4272–4340] 134 [126–156] 147 [137–148] 709 [688–729] 732 [719–736] 0.804
05.control-plane 86 [33–100] 121 [35–126] 13 [0–23] 35 [0–35] 11 [5–20] 24 [5–25] 0.951
06.cron 1327 [1257–1403] 1318 [1241–1320] 44 [40–46] 32 [9–74] 202 [190–213] 198 [188–201] 1.168
07.compaction 422 [408–526] 465 [407–536] 25 [25–53] 48 [25–48] 85 [84–102] 92 [84–104] 1.098
08.shutdown 201 [197–205] 204 [199–207] 133 [130–133] 133 [128–136] 15 [15–15] 15 [15–15] 0.357

The exact warmed median-run difference is database.prepareWrite +11.4 SQL/+0.3 requests per turn, session.entry.read +2.7 SQL, session-entry-read +1.1 SQL, session-maintenance-read +1.1 SQL/+0.1 requests, and other unchanged owners net −0.5 SQL. Remaining request movements are plugins.catalogSnapshot.write +0.1 and session.maintenance.read −0.1. No new logical request type appears.

The first-turn difference is existing database.prepareWrite +196 SQL, domain binding +49, MAIN/unassigned +42, domain execution +35, tombstones +27, plugin-state compare/delete +26, session entry +25, memory source replacement +21, and other unchanged owners net +69. Lost async origins prevent claiming every extra execution is background work; the conservative origin verdict remains indeterminate. Boot+connect+first medians rise 5692→6135; control+cron falls 1427→1367; compaction+shutdown rises 619→669. These are recorded rather than described as passing exceptions.

All 78 top-level turns, six children, cron runs, compactions, RPC receipts, and graceful shutdowns passed; every warmed request completed. Native/request count conservation and MAIN/worker calibration passed. Three failed BEGIN IMMEDIATE executions are excluded from successful totals and preserved as diagnostics: one baseline deferred-plugin lease release and two candidate shutdown idle-agent lease releases, all in unchanged owners. The workload passed despite those warnings.

Measurement source is pinned to 13959252b2d6; the later implementation delta corrects release-train metadata/test setup and mechanically extracts existing internal fallback helpers, with no SQL-path change. The shared workload is unchanged; the private invocation disables evidence archives and reuses the established request observer. No raw traces or fixture databases are retained.

Designated additional pair: retained evidence and limitation

A separate Hetzner pair ran baseline 427f926e7c2d then candidate b2825e4bebc5, with all 13 turns passing on each side. Retained command output records whole-workload statements 22,583 → 22,437, requests 3,396 → 3,391, and wall time 52.239 → 52.149 seconds (ratio 0.9983). These are single-run observations, not a new multi-run median.

Retained phase Base all-thread SQL Candidate all-thread SQL Base MAIN SQL Candidate MAIN SQL Base requests Candidate requests
First turn 1904 1808 43 34 285 265
Warmed, per turn 1079.4 1069.3 10.4 10.7 201.1 200.6

The subsequent final-check checkout failed while writing files under /tmp. Automatic lease cleanup preceded detailed JSON export, so the full phase and per-operation tables from this pair are unavailable. The totals above remain valid retained output; they are not presented as complete attribution evidence. The separate Testbox pair used persistent storage and independent run/copy/inspection checkpoints. It supplies another observation and retained operation vectors; it does not replace this observation or reconstruct the missing Hetzner vectors.

Independent Testbox observation and count attribution

This supplements the original M,C,M,C,M,C macOS series; it does not replace or pool those observations. The original warmed medians remain 1,105.7 → 1,121.5 SQL/turn and 204.4 → 204.8 requests/turn, with first-turn SQL 1,988 → 2,478.

The designated additional Hetzner M,C pair at 427f926e7c2d / b2825e4bebc5 recorded 22,583 → 22,437 all-thread statements (−146) and 3,396 → 3,391 requests (−5) from startup through shutdown; wall time was 52.239 → 52.149 s. Its whole-total criterion passed. First-turn SQL was 1,904 → 1,808 and warmed SQL/turn 1,079.4 → 1,069.3. A subsequent checkout exhausted the original /tmp storage and automatic cleanup ran before granular files were exported. That pair’s per-operation breakdown and complete phase table remain an explicit evidence gap. The terminal lease is deleted; its native failure archive contains only logs/config/timing metadata, no SQL or request datasets. Testbox data below does not reconstruct that missing breakdown.

The separate Testbox recovery M,C pair uses the same exact source pins, one sample per side, after restoring the byte-unchanged observer’s expected census-helper path. Each source had its own clean worktree in an independent Git repository outside native sync. No SQL saving is claimed: removed statements/requests attributable to this PR are 0 / 0.

Each cell is median [min–max] for this one-pair recovery sample. Warmed counts are per turn across ten turns; other counts are per phase. All-thread includes MAIN, worker threads, and helper processes. MAIN is the Gateway’s process/thread 0.

Phase All-thread SQL M → C MAIN SQL M → C Requests M → C C/M wall time
01.boot 3320.0 [3320.0–3320.0] → 3319.0 [3319.0–3319.0] 1984.0 [1984.0–1984.0] → 1984.0 [1984.0–1984.0] 67.0 [67.0–67.0] → 67.0 [67.0–67.0] 0.9831
01.connect 484.0 [484.0–484.0] → 490.0 [490.0–490.0] 69.0 [69.0–69.0] → 69.0 [69.0–69.0] 72.0 [72.0–72.0] → 73.0 [73.0–73.0] 1.0333
02.first-turn 1813.0 [1813.0–1813.0] → 1816.0 [1816.0–1816.0] 59.0 [59.0–59.0] → 59.0 [59.0–59.0] 264.0 [264.0–264.0] → 263.0 [263.0–263.0] 0.9859
03.warmed 1023.9 [1023.9–1023.9] → 1023.4 [1023.4–1023.4] 7.8 [7.8–7.8] → 7.8 [7.8–7.8] 195.0 [195.0–195.0] → 195.0 [195.0–195.0] 0.9959
04.second-session 3944.0 [3944.0–3944.0] → 3948.0 [3948.0–3948.0] 118.0 [118.0–118.0] → 118.0 [118.0–118.0] 684.0 [684.0–684.0] → 686.0 [686.0–686.0] 1.0055
05.control-plane 34.0 [34.0–34.0] → 34.0 [34.0–34.0] 0.0 [0.0–0.0] → 0.0 [0.0–0.0] 5.0 [5.0–5.0] → 5.0 [5.0–5.0] 1.0131
06.cron 1210.0 [1210.0–1210.0] → 1211.0 [1211.0–1211.0] 44.0 [44.0–44.0] → 44.0 [44.0–44.0] 175.0 [175.0–175.0] → 175.0 [175.0–175.0] 0.9987
07.compaction 406.0 [406.0–406.0] → 405.0 [405.0–405.0] 25.0 [25.0–25.0] → 25.0 [25.0–25.0] 84.0 [84.0–84.0] → 84.0 [84.0–84.0] 1.0600
08.shutdown 195.0 [195.0–195.0] → 195.0 [195.0–195.0] 129.0 [129.0–129.0] → 129.0 [129.0–129.0] 14.0 [14.0–14.0] → 14.0 [14.0–14.0] 1.0252

Whole workload: all-thread SQL 21,645 → 21,652 (+7; +0.0323%); requests 3,315 → 3,317 (+2; +0.0603%); wall time 41.840 → 41.774 s (ratio 0.9984). No phase has duration skew above 1.5. First-turn SQL rises by 3 (+0.1655%); warmed SQL/turn falls by 0.5 with requests unchanged. These exact increases are retained, not rounded to a pass or replaced by the earlier pair.

Varying whole-workload operation SQL M → C Δ SQL Requests M → C Δ requests
task-worker/session-exact-entries 2350 → 2342 -8 385 → 385 +0
task-worker/session-row-facts 562 → 567 +5 85 → 86 +1
task-worker/workers.placementProjection 237 → 241 +4 98 → 98 +0
task-worker/lifecycle-artifact-plan 12 → 15 +3 1 → 1 +0
task-worker/mentions.snapshot 139 → 142 +3 57 → 57 +0
task-worker/session-entry-read 400 → 403 +3 105 → 105 +0
task-worker/session-pending-archives 6 → 9 +3 2 → 2 +0
task-worker/sessionRows.sharedFacts 189 → 186 -3 94 → 95 +1
task-worker/session-activity-summary-source 276 → 278 +2 15 → 15 +0
task-worker/session-row-backfill 141 → 139 -2 21 → 21 +0
task-worker/skillLibrary.read 141 → 139 -2 28 → 28 +0
task-worker/deliveryQueue.outbound 27 → 26 -1 8 → 8 +0
task-worker/restartSentinel.snapshot 6 → 7 +1 1 → 1 +0
sqlite-broker/session.entry.read 906 → 905 -1 256 → 256 +0
sqlite-broker/session.maintenance.read 101 → 102 +1 20 → 20 +0
task-worker/transcript-message-presence 15 → 14 -1 2 → 2 +0

Other previously implicated owners are unchanged in this recovery pair: database.domain.bind 400 SQL / 74 requests on each side; database.domain.execute 733 SQL / 98 requests on each side; database.prepareWrite 268 SQL / 7 requests on each side; pluginState.compareDelete 169 SQL / 26 requests on each side; plugins.catalogSnapshot.write 8 SQL / 1 requests on each side; session-entry 63 SQL / 7 requests on each side; session-tombstones 81 SQL / 9 requests on each side.

Phase reconciliation, in boot/connect/first/warmed-ten-turns/second-session/control/cron/compaction/shutdown order: SQL −1 +6 +3 −5 +4 +0 +1 −1 +0 = +7; requests 0 +1 −1 +0 +2 +0 +0 +0 +0 = +2. The complete per-phase operation/caller vector is retained in phase-operation-caller-attribution.json; it conserves both totals exactly.

First-turn operation SQL M → C Δ SQL Observed statement class
lifecycle-artifact-plan 12 → 15 +3 One existing admission trio: schema_version, user_version, sqlite_schema SELECT
session-pending-archives 3 → 6 +3 The same existing admission trio
mentions.snapshot 12 → 13 +1 One config_machine_state SELECT
restartSentinel.snapshot 6 → 7 +1 One config_machine_state SELECT
workers.placementProjection 19 → 20 +1 One config_machine_state SELECT
session-exact-entries 215 → 214 -1 Five existing read-class changes, net −1
catalog 8 → 3 -5 user_version −1, sqlite_master SELECT −2, auth_profile_store SELECT −2
session-row-facts 33 → 33 +0 No SQL-vector change; caller attribution shifts +6 unknown / −6 named

The first-turn identity is +3 +3 +1 +1 +1 −1 −5 = +3 SQL. session-row-facts has an identical complete normalized SQL vector; its +6/−6 change is only movement between unknown and named caller buckets. A pluginCatalog.read send is absent from the first-turn request window while its SQL remains 14 on both sides; its whole-workload request total is unchanged. Full SQL text/count vectors are retained in the request-statements CSVs.

Named varying callers are session-transcript-worker-runtime.ts:257, openclaw-state-read-worker.ts:407, the auth/catalog readonly-process adapter, and the existing session/state worker clients. Every named varying caller file is byte-identical between the two pins. Unknown caller labels are preserved rather than invented; no retained native SQL stack names any of the 9 changed operational source files. The harness does not invoke the device CLI fallback or backup.recordOutcome.

Validation: all 26 top-level turns, both native children, cron runs, compactions, RPC receipts, and graceful shutdowns passed. MAIN and worker calibration each observed 8 calls / 2 prepares / 7 successful statements / 0 errors. Reduction recorded exact equality by phase, thread and normalized SQL, zero missing contexts and zero duplicate sends. The two known boot-only unknown-target links per run remain disclosed. Failed native executions in these samples: two BEGIN IMMEDIATE attempts, one per side during connect-time plugin lifecycle lease release (database is locked); successful statement totals exclude them. Both stacks are unchanged, and all product receipts passed.

Limits: raw per-event streams were removed after verified reduction under disk-hygiene policy. Phase boundaries, aggregate transport/request counts, normalized SQL, and unique native stacks remain; arbitrary new reconstruction of worker/timestamp/async-origin chains is therefore unavailable. This is complete count attribution for the retained Testbox sample, not proof that every unknown origin was scheduled background work, and not a reconstruction of the lost Hetzner per-operation data. All original observations remain in the evidence record; there was no rerun to obtain lower numbers.

The designated additional whole-workload totals check passed. The independent Testbox count vectors and source comparison identify no reproducible PR-caused statement or request increase. This supports publication under RAW TURN INCREASE together with TARGETS ARE AIMS; it is not a standalone noise-floor pass, a reconstruction of lost event origins, or a claim of SQL savings.

Published-driver × candidate update cell: passed at final head 6273a54, as recorded above. This change has no SQLite schema migration.

@clawsweeper

clawsweeper Bot commented Oct 10, 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.

@github-actions

github-actions Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Security sensitive changes

This maintainer PR changes sensitive security components.

No secops approval is required. This comment is informational because the PR author has Maintain or Admin access.

  • Current SHA: 6273a54dbca8d8bf23e5395a185ac762f109f957
  • Maintainer: @steipete
  • Repository role: admin

These security sensitive changes were made:

  • src/gateway/methods/core-descriptors.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.

Carefully review these changes before merging.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation app: web-ui App: web-ui gateway Gateway runtime cli CLI command changes commands Command implementations size: L labels Oct 10, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. 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. labels Oct 10, 2026
@clawsweeper

clawsweeper Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

What this changes

Routes CLI backup records through the Gateway owner and requires exclusive offline ownership for device-approval fallback.

Example: Run openclaw backup record --status ok --target host-restic --bytes 42 while the local Gateway owns the state directory.

  • Before: The CLI records the outcome through its own SQLite worker.
  • After: The CLI submits the outcome to the owning Gateway without replaying an uncertain response locally.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) Useful ownership repair with meaningful real-SQLite regressions, but an unfixed authorization defect and missing production authority proof prevent merge readiness.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is necessary before merge. See Before merge.
Patch quality 🦪 silver shellfish (2/6) Security review found an item that needs attention.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: CLI administrative writes can bypass the running Gateway's state ownership and publications.
Reason: The maintainer-authored change repairs an owned consistency defect and explicitly accepts the live-Gateway fallback restriction.

Merge readiness

⛔ Blocked before merge - 4 items remain

Keep open: this maintainer-authored PR addresses a current ownership defect, but backup recording still lacks requester revalidation at worker commit.

Priority: P2
Reviewed head: 6273a54dbca8d8bf23e5395a185ac762f109f957

Before merge

  • Add real behavior proof - Authority-chain proof required: supplied changed-path coverage uses mocked transport, while update readiness and workload measurements do not exercise these operations; provide redacted terminal output or logs showing an authorized Gateway backup record, operator.write-only rejection through production authorization, requester revocation after dispatch preventing ledger commit, and exclusive offline device approval through settlement, removing credentials, IPs, phone numbers, and non-public endpoints. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Revalidate requester authority at the backup worker commit (P2) - The previously reported guard gap remains. With an already-admitted worker, an admin request can lose current authority after native dispatch but before its ledger transaction commits. Passing assertCurrent here checks host admission and dispatch, but supplies no write-admission factory; the worker's backup branch calls write, which requests neither transaction nor commit authorization. Physical database custody can remain valid while requester authority has ended, so insertion and retention pruning still commit. Bind the existing write-admission mechanism to assertCurrent and request its transaction and pre-commit grants from the backup worker, with a regression proving revocation rolls the write back.
  • Resolve security concern: Revoked authority can alter retained backup history - The affected kernel performs retention pruning as well as insertion, so the unauthorized effect can change existing operational history rather than only add a record.
  • Complete next step - Classify the exact-head chat-test assertion before treating all remaining CI failures as inherited.

Findings

  • [P2] Revalidate requester authority at the backup worker commit — src/state/backup-run-records.ts:60-63
  • [medium] Revoked authority can alter retained backup history — src/state/openclaw-state-worker-runtime.ts:144

Tests

  • Missing end-to-end proof: Missing changed-path proof covers authorized backup recording, production operator.write-only rejection, revocation after dispatch preventing commit, and offline device-approval custody through settlement.
Agent review details

How this fits together

CLI administrative commands select the live Gateway or exclusive offline owner; those owners authorize worker-backed writes to shared SQLite state.

flowchart TD
  A[CLI command] --> B[Local state owner]
  B --> C[Live Gateway RPC]
  B --> D[Exclusive offline custody]
  C --> E[SQLite worker]
  D --> E
  E --> F[Backup ledger or device approvals]
Loading

Technical review

Best possible solution:

Keep the existing ownership routing and bind the backup worker's transaction and commit admission to the captured requester guard.

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

Current main directly dispatches CLI ledger writes and permits local approval fallback without the shared ownership adapter; supplied regressions report failures on the original implementation, but this review ran no target code.

Is this the best way to solve the issue?

Reusing the existing local-state owner is appropriate, and device approval already carries its guard through worker admission, but backup recording needs the same effect-boundary protection.

Full review comments:

  • [P2] Revalidate requester authority at the backup worker commit — src/state/backup-run-records.ts:60-63
    The previously reported guard gap remains. With an already-admitted worker, an admin request can lose current authority after native dispatch but before its ledger transaction commits. Passing assertCurrent here checks host admission and dispatch, but supplies no write-admission factory; the worker's backup branch calls write, which requests neither transaction nor commit authorization. Physical database custody can remain valid while requester authority has ended, so insertion and retention pruning still commit. Bind the existing write-admission mechanism to assertCurrent and request its transaction and pre-commit grants from the backup worker, with a regression proving revocation rolls the write back.
    Confidence: 0.97

Overall correctness: patch is incorrect
Overall confidence: 0.95

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 7517981b5e67.

Provenance checked

  • Backup outcome recording keeps the original intent (bd07ce6: Offload ledger insertion and pruning while retaining awaited settlement, best-effort warnings, and absent-database behavior.)
  • Device replacement approval keeps the original intent (6ea907c: Recover superseded approvals only for matching device identity, role/client metadata, and compatible scopes.)
  • Local-state ownership admission changes intended behavior with a stated reason (1b08795: Route same-root mutations to the authenticated physical owner and retain exclusive offline custody through settlement; lazy config access prevents refused backup outcomes from opening storage.)
  • Administrative SQL observer keeps the original intent (a899211: Observe persisted administrative SQL and physical custody across process and worker execution; excluding the transient in-memory schema reference preserves that contract.)

Testing

Proof path: in-process harness.

Security

Needs attention: Backup requester authority is not fenced at the durable worker effect.

Evidence

Security concerns:

  • [medium] Revoked authority can alter retained backup history — src/state/openclaw-state-worker-runtime.ts:144
    The affected kernel performs retention pruning as well as insertion, so the unauthorized effect can change existing operational history rather than only add a record.
    Confidence: 0.96

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 1b08795 adds src/cli/local-state-owner.ts:37 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 1b08795ae494; files: src/cli/local-state-owner.ts)
  • Vincent Koc: Raw commit fe25ed2 adds src/cli/devices-cli.runtime.ts:191 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: fe25ed214ef5; files: src/cli/devices-cli.runtime.ts)

PR surface

Source +132, Tests +319, Docs +7, Other -2. Total +456 across 24 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 12 285 153 +132
Tests 9 342 23 +319
Docs 2 8 1 +7
Config 0 0 0 0
Generated 0 0 0 0
Other 1 0 2 -2
Total 24 635 179 +456

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This is a focused administrative-state repair with a remaining authorization defect affecting backup-ledger writes.
  • merge-risk: 🚨 security-boundary: A dispatched backup write can commit after requester authority ends because no worker pre-commit grant checks that authority.
  • merge-risk: 🚨 compatibility: The maintainer-approved fallback change requires authorized Gateway access or exclusive offline operation; mixed-version backup recording can warn instead of writing directly.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦪 silver shellfish.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only; repair and merge need explicit maintainer commands such as @clawsweeper autofix or @clawsweeper automerge.

History

Review history (4 earlier review cycles)
  • reviewed 2026-10-10T14:01:20.610Z sha 9009852 :: needs real behavior proof before merge. :: [P2] Revalidate backup requester authority at worker commit | [P2] Append the new RPC to preserve advertised method positions
  • reviewed 2026-10-10T15:09:23.181Z sha f73bcfc :: needs real behavior proof before merge. :: [P2] Revalidate requester authority at the backup worker commit | [P2] Append the RPC to preserve advertised method positions | [P2] Update the corrupt-database warning regression assertion
  • reviewed 2026-10-10T15:25:21.190Z sha 67755c8 :: needs real behavior proof before merge. :: [P2] Revalidate requester authority at the backup worker commit | [P2] Append the RPC to preserve advertised method positions
  • reviewed 2026-10-10T16:19:32.543Z sha 6273a54 :: needs real behavior proof before merge. :: [P2] Revalidate requester authority at the backup worker commit | [P2] Append the RPC to preserve advertised method positions

Reviewed October 10, 2026, 12:41 PM ET / 16:41 UTC (Revision 5).

Keep the missing-ledger early return explicit for consistent-return lint and update the corrupt-database assertion to the owner-aware refusal warning.

Validation: backup-sqlite.test.ts passes 8 tests (166.36s command wall); targeted worker lint passes. Codex fix-diff review: no P0/P1 findings.
The schema validator builds a transient reference database. Keep the administrative owner assertions focused on persisted state while continuing to observe file-backed statements.

Validation: administrative owner process tests 25/25 on Testbox; focused formatting and lint; independent P0/P1 review.
@steipete
steipete merged commit 9c37dbf into main Oct 10, 2026
184 of 188 checks passed
@steipete
steipete deleted the dbasync/ow3 branch October 10, 2026 16:51
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via explicitly authorized admin squash with attributed pre-existing CI failures.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 11, 2026
…e Gateway (openclaw#168466)

* fix(cli): keep device approval and backup writes with the state owner

* fix(gateway): validate backup recording on the current protocol train

* refactor(cli): isolate device fallback validation

* fix(backup): preserve database bytes on refused outcomes

* fix(backup): align refusal return and warning expectations

Keep the missing-ledger early return explicit for consistent-return lint and update the corrupt-database assertion to the owner-aware refusal warning.

Validation: backup-sqlite.test.ts passes 8 tests (166.36s command wall); targeted worker lint passes. Codex fix-diff review: no P0/P1 findings.

* test(cli): exclude in-memory schema SQL from owner observation

The schema validator builds a transient reference database. Keep the administrative owner assertions focused on persisted state while continuing to observe file-backed statements.

Validation: administrative owner process tests 25/25 on Testbox; focused formatting and lint; independent P0/P1 review.
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 cli CLI command changes commands Command implementations docs Improvements or additions to documentation gateway Gateway runtime merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. security-sensitive-changed size: L 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