Skip to content

perf(pairing): run channel mutations in the SQLite worker - #167239

Merged
steipete merged 9 commits into
mainfrom
dbasync/w6pairing
Oct 8, 2026
Merged

steipete merged 9 commits into
mainfrom
dbasync/w6pairing

Conversation

@steipete

@steipete steipete commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Channel pairing APIs returned promises while still executing their SQLite mutations on the Gateway thread. Each request refresh, prune, approval, or allowlist edit also replaced the entire channel snapshot, including unchanged accounts and entries.

User Impact

Pairing mutations use the existing shared-state SQLite worker. Removing an approval now also matches legacy whitespace-padded entries by their canonical sender ID. The released synchronous allowlist reader remains supported and reads only its own table.

There are no schema, durability, retention, configuration, or permission-policy changes, and no new migration is required.

Why This Change Was Made

One semantic worker operation retains the captured physical store and writer ordering. Preparation reads requests through existing read-only admission. The transaction reads requests and allowlist rows in one statement; a fresh no-match result with nothing to prune retains native write admission and final host authority without an empty transaction. Channel-specific approval callbacks prepare their result on the host outside SQL; the worker then rereads the exact selected request before consuming it and adding an approval. Live host authority is checked at transaction entry and immediately before commit. The commit grant linearizes the accepted mutation: a later revocation cannot turn its committed result into a reported failure. Unknown write outcomes are not replayed.

The writer preserves canonical account normalization, request expiry/caps, code uniqueness, approval burn behavior, and allowlist ordering. It compares authoritative rows with the normalized result and writes only changed rows, with bounded batches. Doctor keeps its existing offline snapshot migration; the obsolete runtime full-state reader is removed.

The existing SQLite worker also returns its completed native capability fact on one successful reply. The native runtime owner validates process/library identity and the current WAL safety floor before making that fact available to later sibling workers. This avoids an extra first-reader probe without another request, caller-thread SQL, or any change to reader permissions; malformed hints never replace an accepted write outcome.

Production TypeScript grows by 479 net lines (857 added, 378 removed). The added worker owns differential writes and the approval preparation/reselection handshake; the host facade and shared pure model replace the former monolithic runtime path. Native capability propagation adds 66 net production lines in the existing admission/transport owner; removing the post-commit rejection simplifies the facade. Tests, routing, documentation, and inventory accounting comprise the remaining changes.

Evidence

Comparison base: 2095264a927102e6ff70b68afd3c1477861e7249; candidate: 56c5ba4072a3ecc7ba8b046ef244b10360dfb41e. A conflict in the database-worker test-routing list required integrating this base; the resolution retains both sets of consumers. The final diff contains 22 lane files.

node scripts/database-worker-inventory.mjs --json reports repository T1 799 → 790 and pairing T1 10 → 1. The remaining site serves the released synchronous allowlist reader. Static site retirement is separate from runtime statement savings.

Measurements use one AWS c7a.2xlarge host in eu-west-1, Linux x64, Node 24.21.0, and SQLite 3.53.4. Base and candidate have separate exact-commit checkouts, runtime builds, and isolated state. Frozen pnpm installs share immutable dependency files through supported hardlinks; all 253 workspace dependency links per side resolve to their own checkout. The final benchmark runtimes were built with the canonical qaRuntime profile and source maps, then checked against HEAD, build-info, file hashes, and all nine compiled pairing entrypoints.

The shared workload and statement counter are unchanged from the campaign harness (run.mts SHA-256 1de5109a7b89eaf8c10ef943bde724a89bd44772b7d70419bd344caf18d92cd1). The task-owned observer adds request/authority/timestamp attribution. Counts below retain scheduled maintenance, and all ranges are medians [min–max]. Database requests and native authority requests are summed within each run before taking the median; continuation frames and settlement notices are reported separately.

Direct pairing owner

Three alternating base/candidate pairs completed. Each counted operation includes its predefined one-second settling window; background SQL remains in the totals. These are instrumented execution-count measurements. The full fixture includes the listed operations, four request seeds, one seed read, foreign-row aging, and cleanup. All six native/census/CSV joins reconcile exactly; failed native executions, fork IPC requests, and continuation frames are zero.

Operation + settle All SQL M All SQL C MAIN M → C Seconds M → C C/M time
01.cold-request 1630 [1630–1630] 1623 [1623–1623] 1630 [1630–1630] → 0 [0–0] 1.386 [1.369–1.389] → 2.038 [2.035–2.044] 1.471
02.refresh 10 [10–10] 7 [7–7] 10 [10–10] → 0 [0–0] 1.006 [1.006–1.006] → 1.009 [1.008–1.009] 1.003
03.list 7 [7–7] 6 [6–6] 7 [7–7] → 0 [0–0] 1.004 [1.004–1.004] → 1.007 [1.007–1.007] 1.003
04.allow-add 11 [11–11] 7 [7–7] 11 [11–11] → 0 [0–0] 1.005 [1.005–1.005] → 1.008 [1.008–1.008] 1.003
05.allow-noop 7 [7–7] 6 [6–6] 7 [7–7] → 0 [0–0] 1.003 [1.002–1.004] → 1.007 [1.006–1.007] 1.003
06.allow-read 6 [6–6] 6 [6–6] 0 [0–0] → 0 [0–0] 1.750 [1.749–1.758] → 1.750 [1.749–1.752] 1.000
07.approve 11 [11–11] 8 [8–8] 11 [11–11] → 0 [0–0] 1.005 [1.005–1.005] → 1.006 [1.006–1.007] 1.001
08.burned-approve 7 [7–7] 6 [6–6] 7 [7–7] → 0 [0–0] 1.002 [1.002–1.003] → 1.006 [1.005–1.006] 1.004
09.allow-remove 10 [10–10] 9 [9–9] 10 [10–10] → 0 [0–0] 1.003 [1.002–1.004] → 1.007 [1.007–1.007] 1.004
10.remove-noop 7 [7–7] 6 [6–6] 7 [7–7] → 0 [0–0] 1.003 [1.003–1.003] → 1.006 [1.006–1.006] 1.003
11.dismiss 10 [10–10] 7 [7–7] 10 [10–10] → 0 [0–0] 1.004 [1.004–1.004] → 1.007 [1.006–1.007] 1.003
12.prune 10 [10–10] 7 [7–7] 10 [10–10] → 0 [0–0] 1.003 [1.003–1.004] → 1.006 [1.006–1.007] 1.003
13.list-empty 7 [7–7] 6 [6–6] 7 [7–7] → 0 [0–0] 1.003 [1.003–1.003] → 1.006 [1.006–1.006] 1.003
14.host-empty-approve 10 [10–10] 11 [11–11] 10 [10–10] → 0 [0–0] 1.002 [1.002–1.002] → 1.010 [1.010–1.010] 1.007
15.host-empty-burned-approve 7 [7–7] 4 [4–4] 7 [7–7] → 0 [0–0] 1.003 [1.003–1.003] → 1.005 [1.005–1.005] 1.002
16.host-existing-approve 11 [11–11] 10 [10–10] 11 [11–11] → 0 [0–0] 1.004 [1.004–1.004] → 1.008 [1.008–1.010] 1.004
17.host-existing-burned-approve 7 [7–7] 4 [4–4] 7 [7–7] → 0 [0–0] 1.003 [1.003–1.003] → 1.004 [1.004–1.005] 1.001
18.close 5 [5–5] 1 [1–1] 5 [5–5] → 0 [0–0] 1.024 [1.023–1.024] → 1.026 [1.026–1.026] 1.002
Whole fixture 1825 [1825–1825] 1770 [1770–1770] 1819 [1819–1819] → 2 [2–2] 25.243 [25.226–25.254] → 25.964 [25.956–25.964] 1.029

All migrated mutation operations execute zero MAIN SQL. The two candidate MAIN statements in the complete fixture belong to its symmetric raw foreign-row aging setup. Actual SQL falls 1825 → 1770 (−55); moving SQL to a worker is accounted for separately.

Operation + settle Database requests M → C Authority requests M → C Combined request sends M → C
01.cold-request 0 [0–0] → 2 [2–2] 0 [0–0] → 4 [4–4] 0 [0–0] → 6 [6–6]
02.refresh 0 [0–0] → 1 [1–1] 0 [0–0] → 2 [2–2] 0 [0–0] → 3 [3–3]
03.list 0 [0–0] → 1 [1–1] 0 [0–0] → 2 [2–2] 0 [0–0] → 3 [3–3]
04.allow-add 0 [0–0] → 1 [1–1] 0 [0–0] → 2 [2–2] 0 [0–0] → 3 [3–3]
05.allow-noop 0 [0–0] → 1 [1–1] 0 [0–0] → 2 [2–2] 0 [0–0] → 3 [3–3]
06.allow-read 1 [1–1] → 1 [1–1] 0 [0–0] → 0 [0–0] 1 [1–1] → 1 [1–1]
07.approve 0 [0–0] → 1 [1–1] 0 [0–0] → 2 [2–2] 0 [0–0] → 3 [3–3]
08.burned-approve 0 [0–0] → 1 [1–1] 0 [0–0] → 2 [2–2] 0 [0–0] → 3 [3–3]
09.allow-remove 0 [0–0] → 1 [1–1] 0 [0–0] → 2 [2–2] 0 [0–0] → 3 [3–3]
10.remove-noop 0 [0–0] → 1 [1–1] 0 [0–0] → 2 [2–2] 0 [0–0] → 3 [3–3]
11.dismiss 0 [0–0] → 1 [1–1] 0 [0–0] → 2 [2–2] 0 [0–0] → 3 [3–3]
12.prune 0 [0–0] → 1 [1–1] 0 [0–0] → 2 [2–2] 0 [0–0] → 3 [3–3]
13.list-empty 0 [0–0] → 1 [1–1] 0 [0–0] → 2 [2–2] 0 [0–0] → 3 [3–3]
14.host-empty-approve 0 [0–0] → 1 [1–1] 0 [0–0] → 3 [3–3] 0 [0–0] → 4 [4–4]
15.host-empty-burned-approve 0 [0–0] → 1 [1–1] 0 [0–0] → 1 [1–1] 0 [0–0] → 2 [2–2]
16.host-existing-approve 0 [0–0] → 1 [1–1] 0 [0–0] → 3 [3–3] 0 [0–0] → 4 [4–4]
17.host-existing-burned-approve 0 [0–0] → 1 [1–1] 0 [0–0] → 1 [1–1] 0 [0–0] → 2 [2–2]
18.close 1 [1–1] → 2 [2–2] 0 [0–0] → 0 [0–0] 1 [1–1] → 2 [2–2]
Whole fixture 2 [2–2] → 25 [25–25] 0 [0–0] → 44 [44–44] 2 [2–2] → 69 [69–69]

The request cost is explicit: 21 mutation commands + one actor open + one close add 23 database requests. Live authority adds 19 transaction grants + 21 commit grants + two host-approval preparations + two schema-maintenance preparations. Baseline checks ran in-process. The unchanged async reader remains one request. Separately, settlement notifications are 0 → 21 and other observed controls are 1 → 2 per fixture; those controls are not counted as additional database operations.

The host-empty approval is 10 → 10 for operation SQL and 10 → 11 including settling: the extra statement is PRAGMA wal_checkpoint(PASSIVE) from the unchanged WAL scheduler. The same timer also contributes one statement to allow-remove settling. No database or authority request is sent in either settling window. The timer retains its original actor-open context; it is not a second approval command. The +1 phase increase uses the documented non-turn tolerance, with all raw work retained.

For visibility into cold handoff cost, API-only instrumented time is 0.385 [0.369–0.387] → 1.037 [1.034–1.044] seconds. The counted operation-plus-settle duration ratio is 1.470503, below 1.5; all other numbered operation windows are below 1.008.

Shared workload

Three alternating base/candidate pairs completed all 13 top-level turns, the native child, control RPCs, cron, committed compaction, and graceful shutdown. All six runs exited 0 with no remaining fixture children or failed native SQL executions. Host idle admission was 99.875–100%. The warmed gate uses the median of each run’s ten-turn mean, as specified by the shared harness; individual turn rows remain visible.

Phase All SQL M All SQL C MAIN M → C Seconds M → C C/M time
01.boot 2684 [2684–2684] 2684 [2684–2685] 1820 [1820–1820] → 1820 [1820–1820] 10.241 [10.209–10.763] → 10.209 [10.197–10.254] 0.997
01.connect 383 [383–383] 370 [370–378] 60 [60–60] → 60 [60–60] 1.165 [1.163–1.169] → 1.165 [1.164–1.169] 1.000
02.first-turn 3540 [3540–3541] 3556 [3545–3557] 74 [74–74] → 74 [74–74] 8.138 [8.113–8.284] → 8.107 [8.064–8.134] 0.996
03.turn-01 1362 [1360–1366] 1362 [1360–1371] 0 [0–0] → 0 [0–0] 2.004 [2.001–2.028] → 2.011 [1.996–2.014] 1.003
03.turn-02 1353 [1352–1354] 1353 [1348–1357] 0 [0–0] → 0 [0–0] 1.961 [1.941–1.966] → 1.970 [1.965–1.973] 1.005
03.turn-03 1350 [1350–1351] 1350 [1350–1350] 0 [0–0] → 0 [0–0] 1.921 [1.921–1.923] → 1.914 [1.913–1.931] 0.996
03.turn-04 1343 [1343–1343] 1344 [1343–1345] 0 [0–0] → 0 [0–0] 1.921 [1.914–1.922] → 1.907 [1.907–1.922] 0.993
03.turn-05 1343 [1343–1344] 1343 [1343–1344] 0 [0–0] → 0 [0–0] 1.899 [1.894–1.970] → 1.886 [1.879–1.887] 0.993
03.turn-06 1368 [1364–1370] 1368 [1360–1368] 0 [0–0] → 0 [0–0] 1.901 [1.900–1.963] → 1.892 [1.892–1.895] 0.995
03.turn-07 1356 [1346–1357] 1352 [1352–1357] 0 [0–0] → 0 [0–0] 1.898 [1.887–1.898] → 1.948 [1.891–1.954] 1.026
03.turn-08 1338 [1338–1346] 1338 [1337–1338] 0 [0–0] → 0 [0–0] 1.918 [1.914–1.919] → 1.926 [1.915–1.988] 1.004
03.turn-09 1340 [1340–1347] 1347 [1340–1347] 0 [0–0] → 0 [0–0] 1.890 [1.881–1.969] → 1.883 [1.880–1.893] 0.996
03.turn-10 1343 [1336–1343] 1343 [1336–1343] 0 [0–0] → 0 [0–0] 1.873 [1.870–1.886] → 1.869 [1.863–1.869] 0.998
03.warmed mean / turn 1349.7 [1349.1–1350.1] 1350.2 [1348.3–1350.4] 0 [0–0] → 0 [0–0] 1.925 [1.922–1.928] → 1.919 [1.919–1.926] 0.997
04.second-session 4591 [4582–4605] 4601 [4586–4609] 71 [71–71] → 71 [71–71] 7.668 [7.642–7.729] → 7.633 [7.633–7.720] 0.995
05.control-plane 40 [40–40] 40 [40–40] 0 [0–0] → 0 [0–0] 1.087 [1.086–1.088] → 1.086 [1.086–1.087] 0.999
06.cron 1860 [1842–1861] 1860 [1860–1860] 44 [30–44] → 44 [44–44] 5.475 [5.466–5.488] → 5.468 [5.465–5.470] 0.999
07.compaction 754 [754–754] 754 [754–754] 42 [42–42] → 42 [42–42] 1.492 [1.492–1.511] → 1.497 [1.488–1.510] 1.003
08.shutdown 1048 [1047–1049] 1047 [1047–1059] 393 [393–393] → 393 [393–393] 1.128 [1.103–1.154] → 1.100 [1.098–1.116] 0.975
Phase Database requests M → C Authority requests M → C Combined request sends M → C
01.boot 60 [60–60] → 60 [60–60] 14 [14–14] → 14 [14–14] 74 [74–74] → 74 [74–74]
01.connect 56 [56–56] → 56 [55–56] 34 [34–34] → 32 [32–33] 90 [90–90] → 88 [87–89]
02.first-turn 376 [376–376] → 376 [376–377] 253 [253–253] → 255 [254–255] 629 [629–629] → 631 [630–632]
03.turn-01 304 [304–304] → 304 [304–304] 184 [184–184] → 184 [184–184] 488 [488–488] → 488 [488–488]
03.turn-02 301 [299–301] → 301 [299–301] 184 [184–184] → 184 [184–184] 485 [483–485] → 485 [483–485]
03.turn-03 303 [303–303] → 303 [303–303] 184 [184–184] → 184 [184–184] 487 [487–487] → 487 [487–487]
03.turn-04 301 [301–301] → 301 [301–301] 184 [184–184] → 184 [184–184] 485 [485–485] → 485 [485–485]
03.turn-05 301 [301–301] → 301 [301–301] 184 [184–184] → 184 [184–184] 485 [485–485] → 485 [485–485]
03.turn-06 305 [305–305] → 305 [305–305] 184 [184–184] → 184 [184–184] 489 [489–489] → 489 [489–489]
03.turn-07 301 [299–301] → 299 [299–301] 184 [184–184] → 184 [184–184] 485 [483–485] → 483 [483–485]
03.turn-08 299 [299–301] → 299 [299–299] 184 [184–184] → 184 [184–184] 483 [483–485] → 483 [483–483]
03.turn-09 300 [300–302] → 302 [300–302] 184 [184–184] → 184 [184–184] 484 [484–486] → 486 [484–486]
03.turn-10 301 [299–301] → 301 [299–301] 184 [184–184] → 184 [184–184] 485 [483–485] → 485 [483–485]
03.warmed mean / turn 301.6 [301.4–301.6] → 301.6 [301.2–301.6] 184 [184–184] → 184 [184–184] 485.6 [485.4–485.6] → 485.6 [485.2–485.6]
04.second-session 886 [885–888] → 887 [885–888] 613 [613–613] → 613 [613–613] 1499 [1498–1501] → 1500 [1498–1501]
05.control-plane 5 [5–5] → 5 [5–5] 2 [2–2] → 2 [2–2] 7 [7–7] → 7 [7–7]
06.cron 209 [206–209] → 209 [209–209] 192 [192–192] → 192 [192–192] 401 [398–401] → 401 [401–401]
07.compaction 91 [91–91] → 91 [91–91] 27 [27–27] → 27 [27–27] 118 [118–118] → 118 [118–118]
08.shutdown 105 [105–105] → 105 [105–107] 119 [119–119] → 119 [119–119] 224 [224–224] → 224 [224–226]

Fork IPC request counts are zero throughout. Other transport observations, shown separately from request sends:

Phase Continuation frames M → C Settlement notices M → C Other observed controls M → C
01.boot 0 [0–0] → 0 [0–0] 18 [18–18] → 18 [18–18] 8 [8–8] → 8 [8–8]
01.connect 6 [6–6] → 6 [6–6] 30 [29–30] → 29 [29–29] 15 [15–15] → 14 [13–14]
02.first-turn 26 [26–26] → 26 [26–26] 105 [105–106] → 106 [106–106] 122 [122–122] → 123 [123–124]
03.warmed mean / turn 9 [9–9] → 9 [9–9] 78.6 [78.6–78.6] → 78.6 [78.6–78.6] 89 [89–89] → 89 [89–89]
04.second-session 28 [25–28] → 25 [25–28] 260 [260–260] → 260 [260–260] 294 [294–294] → 294 [294–294]
05.control-plane 0 [0–0] → 0 [0–0] 1 [1–1] → 1 [1–1] 1 [1–1] → 1 [1–1]
06.cron 9 [9–9] → 9 [9–9] 91 [88–91] → 91 [91–91] 99 [99–99] → 99 [99–99]
07.compaction 11 [11–11] → 11 [11–11] 16 [16–16] → 16 [16–16] 13 [13–13] → 13 [13–13]
08.shutdown 0 [0–0] → 0 [0–0] 86 [86–86] → 86 [86–86] 39 [39–39] → 39 [39–39]

Gate disposition: first-turn +16 / 3540 = 0.452% and warmed +0.5 / 1349.7 = 0.037% pass the documented ≤0.5% noise allowance after the untouched-owner attribution below. MAIN is unchanged. The warmed combined request median is unchanged at 485.6 per turn (301.6 database + 184 authority). Channel-pairing mutation requests are absent from this workload; no shared-turn saving is credited to this PR. Native runtime capability probes are six per complete run on both sides, at most one per process. Separate WAL-policy version queries remain counted.

Attribution uses the actual median-SQL runs: first M3/C1, warmed M3/C2, second-session M1/C2. The native event sequence is joined exactly to the corresponding process/thread census; request medians above are computed independently and are not reconstructed by summing category medians.

Window / unchanged owner SQL M SQL C Delta Evidence
First: cron mutation 0 13 +13 The same startup mutation moves from connect to first-turn. Worker 5, request 49; identical cron runtime/receipt-authority caller.
First: agent-deletion snapshot 23 28 +5 Same request count; repeated table/schema/config/cursor validation in the unchanged snapshot reader.
First: skill-library read 15 14 −1 Unchanged reader/cache work.
First: placement projection 37 36 −1 Unchanged reader/cache work.
First total difference +16
Warmed ten turns: session row facts 651 660 +9 One additional queued row-facts read in the unchanged projection drain.
Warmed ten turns: shared row facts 148 151 +3 Paired projection refresh; caller resolves through session-row-projection-read/refresh and session-projection-work.
Warmed ten turns: device-pairing list 67 72 +5 One additional materialized read transaction within the same request count; unchanged device-pairing reader.
Warmed ten turns: placement projection 289 291 +2 Unchanged freshness/cache work.
Warmed ten turns: auth-profile rows 344 336 −8 Unchanged auth reader/cache work.
Warmed ten turns: ACP metadata 22 20 −2 Unchanged reader/cache work.
Warmed ten turns: exec approvals 62 60 −2 Unchanged reader/cache work.
Warmed ten turns: outbound delivery 13 12 −1 Unchanged reader/cache work.
Warmed ten turns: runtime target 180 179 −1 Unchanged reader/cache work.
Warmed total difference +5 / 10 = +0.5 per turn

The cron boundary is directly witnessed: M3 process 12808/worker 5 executes request 49 during connect, 1791462895984–1791462896002 ms; first-turn starts at 1791462896004. C1 process 12266/worker 5 executes the same request type at 1791462706761–1791462706877; first-turn starts at 1791462706756. Its 13 successful statements move with the request. SQL events are bounded by timestamped request/phase events; no unrecorded per-statement timestamp is invented.

The five extra snapshot statements are a second table_info(agent_databases), table_info(session_watch_cursors), sqlite_master lookup for operator approvals, config-machine-state read, and watcher-cursor read. Warmed row reads occur on worker 9, shared projection reads on worker 7; the extra shared read’s stack reaches withSessionRowDatabaseFacts → refreshBatch → drain. The paired queued history read retains its transport stack rather than an invented missing upstream frame. These business/scheduler/reader paths are unchanged from the base; the modified native-capability path introduces no extra capability probe or channel mutation request.

Second-session +10 uses the non-turn tolerance: row facts +10, shared facts +1, transcript anchors +2, message presence +1, mentions +1, offset by auth rows −2, entry preparation −2, and domain publication −1. These are unchanged projection/read/cache owners. Connect’s −13 is the cron relocation, and shutdown’s −1 is unchanged maintenance timing; neither is counted as a PR saving.

Adjacent-window sums remain visible for context; the first/warmed gate above uses the noise rule, not a combined-window waiver:

Window M1 / M2 / M3 SQL C1 / C2 / C3 SQL Median M → C
startup 6607 / 6608 / 6607 6610 / 6608 / 6611 6607 → 6610
control+cron 1882 / 1901 / 1900 1900 / 1900 / 1900 1900 → 1900
compaction+shutdown 1803 / 1801 / 1802 1801 / 1813 / 1801 1802 → 1801

Statement attribution

Every changed statement class is included below, including replacement writes and additional freshness/maintenance work. Group counts are summed within each full fixture before taking medians.

Statement group M C Delta
Separate request/allowlist reads plus replacement UNION 43 24 -19
Full-channel deletes/inserts plus replacement differential DML 45 17 -28
BEGIN / COMMIT 46 42 -4
Busy-timeout reads/sets 9 6 -3
WAL autocheckpoint policy reads/sets 7 1 -6
Combined data/schema/user-version observations 42 45 +3
Periodic WAL checkpoints 0 2 +2
Unchanged statement classes 1633 1633 0
Total 1825 1770 −55

The UNION replaces two authoritative table reads. Differential DML replaces full-channel rewrites while retaining foreign rows and canonical account ordering. Fresh host-side absence can avoid two empty transactions after current native admission and the final grant. The existing private worker connection owns its busy-timeout/WAL policy, avoiding temporary policy save/restore work. Three additional freshness observations are retained for correctness; two periodic checkpoints remain counted. Native runtime capability probes are one per process on both sides: propagation prevents a regression and earns no probe-saving credit.

Regressions cover foreign commits/account aliases and scoped rows (read fusion/differential DML), expiry/caps/code reuse and collision handling, native supervision plus revoked transaction/commit grants (including missing approvals), callback metadata/selection/expiry races, null/error burns, accepted-write settlement, and current native-library/WAL-floor validation. The released synchronous reader stays separate.

Validation on the final implementation:

  • Pairing store, worker, SDK consumer, native SQLite admission, broker reply, and reply-cleanup suites: 107 passed, wrapper 68.12 s, Vitest 27.43 s. Pairing/SDK accounts for 29 tests; native admission/reply/settlement accounts for 78. CI execution seconds are not yet available.
  • Integrated foreign-freshness and read-connection cache suites: 61 passed, wrapper 30.18 s. These cover the updated base's fused schema observations and newer-catalog handling.
  • Actual worker producer regression: 1 passed, wrapper 59.93 s, Vitest 42.55 s, including transforms. It proves the native fact reaches the opening caller, is sent once, and adds no request. The framed-reply tests independently retain publication until final delivery. No added sleeps or per-test Gateway boots.
  • CI=1 node scripts/check-changed.mjs --base 2095264a927102e6ff70b68afd3c1477861e7249 --timed: passed on the committed candidate in 1,307.46 s, including all ratchets, formatting, production and all 27 core-test typecheck graphs, three zero-entry export scans, lint, and authorization/ownership guards. An earlier invocation during the pending merge selected the old merge-base and unrelated upstream changes; it is superseded by this correctly scoped run.
  • pnpm check:madge-import-cycles: zero cycles; pnpm deadcode:knip: passed on the merged candidate.
  • Fresh Codex P2 autoreview against the integrated base: scoped-clean.

The legacy padded-entry removal regression failed before the bounded owner fix (changed: false, entry retained), then passed. The accepted-approval regression also failed before removing the facade's post-commit rejection, then passed while the transaction/commit revocation tests continued passing. Other owner tests protect physical store capture, FIFO, foreign rows and account aliases, native supervision for selected and missing requests, adapter errors/null burns, and metadata/selection/expiry races. Native admission tests preserve current WAL safety and process/library matching; invalid hints cannot alter a completed database outcome.

The canonical SDK diff completed successfully for the exact base and candidate (619.14 s, exit 0; digest 6ba670aa2ebb20018561a34a726269cab75bfeed1bf8e5a18e2efaceef3f491b). It reports 131 reachable-type closure changes across 24 entrypoints, zero entrypoints added/removed, and zero visible export declarations or signatures changed. Its sole detailed declaration delta is the optional internal successful-reply field nativeRuntimeAdmission?: unknown on SqliteWorkerReply.

Compatibility disposition: this is an additive, backward-compatible internal transport change. Existing replies without the field remain valid; the broker validates and consumes the optional metadata without exposing it as a domain result. No public operation, required parameter, authority, trust, or persistence contract changes. The diff is explicitly acknowledged here as hasChanges: true. An additional proof-wrapper assertion expecting an empty diff exited 1; that overstrict expectation is recorded, not represented as a canonical SDK failure or an empty API diff.

Remote proof used Blacksmith Testbox lease tbx_01m4dfbzs1barcdz9q0d3kz25h (run), pinned to the exact base and candidate above. Package build/validation and both canonical qaRuntime builds passed. The published 2026.9.8 driver × candidate update cell passed: run 75259e00-032e-4f0d-87ef-b4b3ccb22086 finished, readiness returned 200, the service PID changed, and the running server reported the exact candidate build ID 2026.9.8-56c5ba4072a3-2026-10-08T10-04-07.212Z. The identity probe was scope-limited but included the server build identity; installed-file equality alone was not used as running-version proof.

The focused Doctor discovery test passed on both revisions at its unchanged 120-second timeout: base test 14.019 s / command 46.64 s, candidate test 19.078 s / command 64.62 s. Both runtime archives were verified against source SHA, role, file hashes, source maps, relative symlinks, and build-info before the lease stopped successfully; terminal status was completed, with zero active leases. Source fingerprints were unchanged.

This Testbox validation run waited 60 s for an ordinary proof slot; source capture took 18.725 s, and provider/setup before the payload took 148.794 s (the provider does not expose a separate queue-only duration). Earlier attempts encountered the shared AWS fleet cap without obtaining a lease, and one recorded slot wait lasted 1,220.303 s before pausing for the native-admission fix. Other historical wait durations are unavailable. No fleet limit was bypassed. The aggregate remote helper exited 1 solely for the extra SDK zero-diff assertion described above; the package, update, Doctor, SDK comparison, and runtime build commands themselves exited 0.

The first local compiled probe could not start because the dist-only runtime archive omitted workspace package outputs; that failed setup is retained outside the measurement series. A bounded package supplement used one later Testbox lease, tbx_01m4dj9byvsj40da9gmbp1gt4q (run), after 420 s waiting for an ordinary slot and 16.827 s source capture. Both canonical package builds passed. Its initial export smoke used the wrong resolution owner and failed; after that command settled, a sequential package-owned export check and archive recovery passed in 5.277 s without rebuilding or changing product source. Both revisions resolved and imported 163 exports across 17 packages. All 415 package output files were byte-identical across the independently built revisions; source/input/output manifests and archive hashes were verified before cleanup. The lease is completed, with zero active leases. Local installation replaced only generated package outputs and preserved the original verified Gateway runtimes and build IDs. No SQL result from the failed setup is included in the tables.

The existing Telegram paired-DM consumer passed after routing through the established fork-based database-worker project. Its earlier thread-project refusal (Shared-state admission requires the host broker) and the routing fix remain recorded. A loaded local Doctor run timed out before a later successful replay; the replay is not represented as a timeout fix or proof of an inherited failure. The final remote Doctor comparison above passed on both revisions; it does not establish a fix for the earlier loaded-host timeout.

The retained synchronous SDK reader is a separate compatibility boundary. A mixed worker-first mutation followed by its first synchronous read opens and admits a distinct MAIN handle; worker publication does not transfer that handle. MAIN also retains its own native capability probe. That source-level +1 probe is part of an otherwise unmeasured cold-admission path, including ownership, schema, connection policy, and WAL setup. The async mutation performance claim does not cover this mixed sequence, and no total or tolerance pass is claimed for it. The released synchronous contract remains isolated until its documented next-major retirement.

Final measurement proof used AWS lease cbx_c3b99228147d, run run_5d2c1c3740e4967d67a267d31782c854, on the exact heads above. Both three-pair batches exited 0. All 1,413 raw evidence files and source/build/binding/load/cleanup receipts were verified before release (archive SHA-256 7f11886b5918af1d216d1e2eef3e1d3b0f974ef9d2c5c19205db1501ea735c70). The lease is released, with no host or active owned lease; the ordinary proof slot and native SSH resources were released too.

Measurement recovery is preserved: six earlier alternating macOS pairs had cold duration ratio 2.122775 and are diagnostic-only, never pooled with AWS. A later Testbox attempt waited 780 s for an ordinary slot, then timed out after 914.302 s without a payload; it was stopped before AWS. The first AWS setup hit the /tmp quota before measurements. The successful retry used the workspace filesystem and supported pnpm hardlinks (installs 44.5 s / 5 s); no disk-size increase or dependency change. Native archive transfer was too slow (13.55 MB in about five minutes), so the owned transfer was stopped and canonical same-lease runtime builds replaced that transport step. Earlier source, update, Doctor, and SDK evidence remained valid because the reviewed source stayed unchanged. All attempts retained at most one lease, and all are stopped.

Landing follow-through

The reviewed pairing implementation was integrated with main fc1b2e66564e80ee567c5af844420572ef02671b in merge commit 5bc73079f0ae7442e6eb781d6f216845e966129d, without conflicts. The existing alternating-pair SQL, released-driver update, and canonical SDK comparison evidence above remains valid; landing reuses it under the maintainer's proof-reuse direction.

CI run https://github.com/openclaw/openclaw/actions/runs/37781150278 exposed two fixture adaptations caused by the worker cutover. The administrative CLI routing fixture ran its Gateway handler inside a Vitest thread and observed only main-thread SQL; it now uses the established host-owned project and observes native SQL on both the CLI thread and workers while retaining custody, no-replay, and durable-state assertions. The worker-registration fixture's closed native SQLite mock lacked the optional capability-capture function, preventing its synthetic reply from settling; the mock now explicitly returns no capability fact while keeping native database creation forbidden. No production fallback or weaker assertion was added.

The same run's unrelated typecheck/package-boundary failure (clearFailedSystemAgentSessionState missing in src/system-agent/agent-turn.ts) was fixed on main by 19f37f076862830f9b8953287f94a4725e3b8908. UI active-run/display-tail failures were fixed on main by e8e341ecebf70a0d3802b3f52deecb4d53ec1ebb and d0194c3401f9c225dfd24d232715011e7dbf3f5d. Those fixes are included in this integration.

Released SDK surface was checked against v2026.10.1-beta.1 and stable v2026.9.9: public pairing operations retain their parameter shapes and return types. The synchronous reader remains covered by its existing compatibility record and type test; removed full-state SQLite readers and the relocated account helper are internal. No new environment-variable names are introduced.

Focused landing validation passed 49 tests across the administrative CLI custody suite, worker registration, shared-state imports, and runtime process build graph. The CLI suite passed all 25 cases in 264.70 s on this loaded host; it retains real process/RPC routing, offline lock custody, and lost-acknowledgement settlement, which an in-process mock cannot prove. The complete three-shard command took 745.73 s, including a 326.64 s cold compiled-worker preparation. The wrapper dependency inventory passed separately (28.32 s command, 25.18 s Vitest). Production typechecking and Madge passed with zero cycles. The first post-integration test-type invocation found an installed pre-integration ghostty declaration; refreshing this task-owned checkout to its frozen lockfile resolved that mismatch. No source workaround was made for it.

The fixture repair is commit 1858e96a5a3f; fresh Codex P2 autoreview of the integrated implementation and fixes is scoped-clean. Its earlier index-only finding was resolved by staging the already-reviewed fixture repair. The test-mock allowance inventory was regenerated and shrank by one exact legacy entry.

Keep adapter preparation outside SQL, reread the exact request before approval, and retain live transaction and commit grants. Preserve normalized account scope and update changed rows without rewriting the channel snapshot. Keep the released synchronous allowlist reader isolated.

Also fix removal of legacy whitespace-padded allow entries, with a failing-then-passing owner regression. Runtime statement budgets and package/update proof remain pending before publication.
Route the real Telegram pairing writer test through the existing fork-based database-worker project, preserving the broker host boundary. Resolve the worker cutover lint findings without changing SQL or mutation behavior.
@clawsweeper

clawsweeper Bot commented Oct 8, 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 8, 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: 1858e96a5a3f0b25172774feae3efe02692284a4
  • Maintainer: @steipete
  • Repository role: admin

These security sensitive changes were made:

  • src/pairing/pairing-store-keys.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.
  • src/pairing/pairing-store-model.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.
  • src/pairing/pairing-store-sqlite.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.
  • src/pairing/pairing-store.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.
  • src/pairing/pairing-store.worker-contract.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.
  • src/pairing/pairing-store.worker.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 scripts Repository scripts size: XL labels Oct 8, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 8, 2026
@clawsweeper

clawsweeper Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 8, 2026, 1:33 PM ET / 17:33 UTC (Revision 2).

ClawSweeper review

What this changes

Moves channel pairing mutations into the existing SQLite worker, updates only changed rows, and propagates validated native SQLite capability facts.

Example: Remove sender foreign from account alpha

  • Before: A stored entry containing ' foreign ' remains approved and removal returns changed: false.
  • After: Removal returns changed: true, leaves alpha with ['keep'], and preserves beta's approval.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A useful, coherent worker cutover with real runtime proof, explicit compatibility accounting, and no blocking finding.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): The supplied compiled-runtime measurements exercise the pairing owner and real SQLite worker, while real CLI custody runs verify worker SQL, durable approvals, refusal, and lost-acknowledgement behavior. Revocation and foreign-selection regressions exercise the production admission/transport boundary and inspect persisted results. Pairing production bytes remain unchanged from the measured candidate; the current head adds fixture adaptations. Existing tables and serialized contracts are preserved, with released-driver update and SDK compatibility evidence.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes
User problem: Pairing administration can occupy the Gateway thread and rewrite unrelated account rows while handling requests and approvals.
Reason: The measured work has a clear runtime benefit and follows the established worker architecture. Prior merged history establishes the author's ownership of the affected direction.

Merge readiness

✅ Ready for maintainer review

This PR remains useful and review-ready: current main still has the central performance problem, the supplied runtime evidence covers the change, and no actionable introduced defect was found.

Priority: P2
Reviewed head: 1858e96a5a3f0b25172774feae3efe02692284a4

Before merge

None.

Findings

None.

Agent review details

How this fits together

Channel pairing stores pending requests and approved senders in shared SQLite state. The Gateway and CLI submit account-scoped operations, and the storage owner returns requests, approval results, and updated allowlists.

flowchart TD
  A[Gateway or CLI pairing request] --> B[Capture store and caller authority]
  B --> C[Existing SQLite worker]
  C --> D[Prepare channel approval on host]
  D --> E[Reread selected request]
  C --> E
  E --> F[Check transaction and commit authority]
  F --> G[Write changed rows and return result]
Loading

Technical review

Best possible solution:

Keep pairing mutations with the existing shared-state worker while preserving channel policy, released SDK behavior, and acknowledged write settlement.

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

Yes: current-main source performs pairing mutations synchronously, and the supplied matched runtime measurements establish their Gateway-thread SQL cost; the padded-entry removal regression is also reported failing before the fix.

Is this the best way to solve the issue?

Yes: the patch uses the existing storage and transport owners, preserves approval policy and public operations, and replaces snapshot rewrites with bounded differential writes.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 56c033e8267a.

Provenance checked

Testing

Proof path: shipped entry point. Added test files: 8.

Security

None.

Evidence

What I checked:

  • Current main still uses synchronous mutations: The pinned current-main source still calls runOpenClawStateWriteTransaction directly and removes allowlist entries by exact string equality; it does not contain this mutation-worker cutover. (src/pairing/pairing-store.ts:129, 56c033e8267a)
  • Live authority remains with the host: The host checks captured database and caller authority for admission requests and again after channel approval preparation; the worker requests transaction and commit grants and rereads the selected request before consuming it. (src/pairing/pairing-store.ts:80, 1858e96a5a3f)
  • Forbidden and revoked mutations are covered: Production worker-boundary regressions verify rollback on transaction/commit revocation, refusal after external supervision takes custody, account isolation, callback races, and successful settlement after an accepted commit grant. The body reports these suites passed; this read-only review did not execute them. (src/pairing/pairing-store.worker.test.ts:59, 1858e96a5a3f)
  • Real runtime and upgrade evidence: The full PR body was retrieved through REST, extending the captured body identity 62cb6a26cf9edcedcdb25c344ddb09f6c6630fa88007c0c3e9ed2738a668eed8. It records three alternating Linux runtime pairs, zero MAIN SQL for migrated mutations, 1825→1770 total statements, and a published 2026.9.8 updater run reaching readiness 200 with the candidate serving build identity. Supporting runs: https://github.com/openclaw/openclaw/actions/runs/37760703795 and https://github.com/openclaw/openclaw/actions/runs/37766347441. (56c5ba4072a3)
  • Re-review continuity and current-head validation: The pairing production files are unchanged since the prior reviewed head. The intervening native SQLite changes add inherited main's WAL NOOP capability handling; the current head repairs CLI SQL observation and a closed registration mock. The body reports 49 focused landing tests passed, including all 25 real CLI custody cases. The previous review had no findings. (src/cli/admin-state-owner.process.test.ts:272, 1858e96a5a3f)
  • Accepted compatibility scope: The area owner's body explicitly acknowledges the additive optional nativeRuntimeAdmission reply field and reachable SDK declaration changes. Old replies remain valid, public pairing parameters and return types remain unchanged, and the released synchronous reader remains supported through the next Plugin SDK major. (src/infra/sqlite-worker-contract.ts:96, 1858e96a5a3f)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Vincent Koc: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

PR surface

Source +479, Tests +578, Docs +14, Other +4. Total +1075 across 27 files.

View PR surface stats
Area Files Added Removed Net
Source 11 857 378 +479
Tests 13 740 162 +578
Docs 1 18 4 +14
Config 0 0 0 0
Generated 0 0 0 0
Other 2 7 3 +4
Total 27 1622 547 +1075

Review metrics

Metric Value Why it matters
Measured SQL and transport cost 1825→1770 SQL statements; 2→69 combined request sends The measured improvement removes Gateway-thread mutations while explicitly accounting for the worker and live-authority handoff cost.

Stored data model

Persistent data-model change detected: migration/backfill/repair: scripts/database-worker-inventory.mjs. Migration or upgrade compatibility proof is recorded; maintainers should verify it before merge.

Labels

Label changes:

  • add merge-risk: 🚨 compatibility: The optional worker-reply field changes reachable SDK declarations; the area owner explicitly accepts this backward-compatible addition and retains existing public pairing contracts.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.

Label justifications:

  • P2: This is a bounded runtime performance improvement with a focused legacy-entry removal repair.
  • merge-risk: 🚨 compatibility: The optional worker-reply field changes reachable SDK declarations; the area owner explicitly accepts this backward-compatible addition and retains existing public pairing contracts.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

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 (1 earlier review cycle)
  • reviewed 2026-10-08T13:08:04.816Z sha 56c5ba4 :: needs maintainer review before merge. :: none

@openclaw-barnacle openclaw-barnacle Bot added the cli CLI command changes label Oct 8, 2026
@steipete

steipete commented Oct 8, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Oct 8, 2026
@steipete
steipete merged commit a899211 into main Oct 8, 2026
178 checks passed
@steipete
steipete deleted the dbasync/w6pairing branch October 8, 2026 17:40
@steipete

steipete commented Oct 8, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 9, 2026
…67239)

* refactor(pairing): move channel mutations to the shared-state worker

Keep adapter preparation outside SQL, reread the exact request before approval, and retain live transaction and commit grants. Preserve normalized account scope and update changed rows without rewriting the channel snapshot. Keep the released synchronous allowlist reader isolated.

Also fix removal of legacy whitespace-padded allow entries, with a failing-then-passing owner regression. Runtime statement budgets and package/update proof remain pending before publication.

* fix(pairing): align worker transport and test ownership

Route the real Telegram pairing writer test through the existing fork-based database-worker project, preserving the broker host boundary. Resolve the worker cutover lint findings without changing SQL or mutation behavior.

* perf(pairing): remove redundant approval preparation queries

* style(pairing): normalize supervision fixture formatting

* fix(pairing): preserve worker admission and committed results

* test(pairing): cover worker custody in CLI and registration fixtures
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes docs Improvements or additions to documentation merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. scripts Repository scripts security-sensitive-changed size: XL status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant