Repository navigation
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
5410788 to
b9b0cb3
Compare
|
Codex review: blocked before merge. Reviewed September 21, 2026, 7:25 PM ET / 23:25 UTC (Revision 8). ClawSweeper reviewWhat this changesMoves worker inventory reads and mutations into background database workers, publishes committed records into memory, and updates lifecycle callers to await completion. Merge readiness⛔ Blocked before merge - 2 items remain This optimization remains useful: current main and the latest release still execute inventory queries synchronously. No blocking introduced defect was found, and the prior config/default warning is unsupported by the shrink-only baseline changes. Priority: P2 Review scores
Verification
How this fits togetherThe Gateway uses worker inventory to provision remote environments, authorize credentials and transfers, and reconcile cleanup. SQLite remains authoritative; committed in-memory records serve Gateway reads. flowchart TD
A[Gateway inventory requests] --> B[Committed inventory in memory]
B --> C[Lists and authority facts]
D[Environment lifecycle changes] --> E[Live authority checks]
E --> F[SQLite worker]
F --> H[Persistent SQLite state]
F --> B
G[Pairing and placement commits] --> H
G --> B
Before merge
Agent review detailsSecurityNone. PR surfacePR surface statistics unavailable: the file list is incomplete. Review metrics
Stored data modelPersistent data-model change detected: Technical reviewBest possible solution: Keep one committed inventory projection backed by the existing SQLite workers, preserving live authority, atomic parent transactions, and recovery without changing stored contracts. Do we have a high-confidence way to reproduce the issue? Yes, from source: current-main inventory listing directly executes synchronous SQLite queries, and the PR records a matched 5,000-environment benchmark. This review did not rerun it. Is this the best way to solve the issue? Yes. Reusing the existing database workers and publishing through one inventory owner addresses the blocking work while retaining transactional authority and stored compatibility. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 06ce6c415dd2. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (7 earlier review cycles)
|
009a3e9 to
5dea3e0
Compare
|
7418ebf to
ef5d91b
Compare
ef5d91b to
03e284e
Compare
03e284e to
9395367
Compare
9395367 to
e1d6fce
Compare
e1d6fce to
9b868c4
Compare
Serve inventory reads from one committed projection per physical database. Move inventory mutations and durable authority checks into the existing SQLite worker, and publish native placement and pairing updates through the same owner. Preserve cancellation, credential, attachment, and shutdown ordering across the asynchronous cutover, including lost worker replies.
9b868c4 to
33dcf4d
Compare
|
Merged via squash.
|
…w#154804) Serve inventory reads from one committed projection per physical database. Move inventory mutations and durable authority checks into the existing SQLite worker, and publish native placement and pairing updates through the same owner. Preserve cancellation, credential, attachment, and shutdown ordering across the asynchronous cutover, including lost worker replies.
Related: #154318
What Problem This Solves
Large worker inventories occupy the Gateway request thread while list and reconcile queries scan and decode thousands of rows.
User Impact
Worker inventory reads consume committed in-memory facts, and mutations execute through the SQLite worker broker. Main-thread CPU falls by 62.9% for listing 5,000 environments and 56.0% for reconcile selection in the same-lease benchmark. Serialized results are identical. Existing state, configuration, schemas, and retention policy retain their contracts; reopening awaits inventory admission without a data migration. The
config/*edits only shrink static-analysis baselines; operator configuration and durable schemas are unchanged.Why This Change Was Made
A cache around the old synchronous store could not preserve authority: credential, transfer, and pre-commit checks consume its records, and three parent transactions write inventory fields directly. This change gives the store one committed projection, routes every writer through publication, and keeps durable authority checks inside the committing transaction.
Projection lifecycle, authority, and complete cutover
The store owns one projection per physical database. The existing read-only worker scope hydrates it, and hydration shares the mutation publication queue. Broker mutations re-read authoritative environment, credential, and placement rows inside their transaction. The host revalidates live caller authority at transaction entry and commit. A per-environment fence covers commit admission through installation of the acknowledged facts. Keyed record reads continue across diagnostics only when deterministic worker/host digests match every environment and credential field except
lastErrorandupdatedAtMs. Attachment reads retain their separate fence. Transfer-owner reads use their narrower binding equality, so independent workspace capabilities survive RPC credential renewal. This exposes no uncommitted state: live caller and capability checks still run, and changed or unknown bindings remain fenced. RPC credential rotation and expiry retain their existing independent relationship to workspace capability lifetime. Returned records remain detached, and revision changes invalidate sorted inventory and prepared-capacity views. Close drains accepted mutations; physical database lifecycle invalidates the projection.Placement activation and prepared-environment consumption retain their existing synchronous atomic multi-table parent transactions. Node pairing already uses its own write worker: the binding producer now returns the exact environment patch through the retained pairing receipt, and the host installs it before observers, including recovery after a lost result. Across these writers, publications carry only
lastActivatedAtMs,preparation,nodeDeviceId, andupdatedAtMs. Revisions are reserved under the writer lock or at worker commit admission. Bounded field overlays preserve newer publications across delayed full inventory receipts. Publications add no SQL. Fresh projection hydration awaits the inventory initialization transaction before its read snapshot, so it cannot overtake a pairing commit. Migrating the two remaining synchronous parent owners stays separate work.Retention reads bounded 256-row pages in the read worker and evaluates demand in the existing terminal-age order and limit. The write worker compares all observed columns and rechecks placement references before deletion. Live provider demand is checked again at transaction and commit admission. A newly protected row rolls back the best-effort batch and returns zero; arbitrary provider errors propagate unchanged.
Lost replies recover committed facts or reconcile authoritative rows without replaying writes. Permanent revocation notifications settle once across normal completion and recovery. Teardown carries its expected epoch and exact live-owner guard. Cancellation settles durable stop intent before cleanup classification, prepared retirement queues before failure cleanup, and shutdown drains already accepted bootstrap work.
The old synchronous inventory facade, writer/version paths, duplicate read APIs, and obsolete prune wrapper are removed. Callers await mutations. The placement-projection migration in #150270 is incorporated: both worker readers share the row decoder, and attachment conflicts use one constructor across execution, transport, and credential handling.
Inventory sites
The program inventory records 20 direct query calls in the original
store.ts: 12 multi-row/write calls and eight first-row calls. The lane brief's count of 25 predates that inventory. All 20 now execute in worker paths: owner-epoch allocation; environment, credential/hash, and transfer-owner reads; row updates; fallback-port replacement; credential revoke/upsert; inventory listing; intent insertion; node-enrollment predicates/completion; runtime-refresh placement checks and updates; and credential-delivery updates. Prepared reservations, attachments, startup reconciliation, and terminal retention use the same committed owner.No synchronous inventory query remains in the main-thread facade. Only placement activation and prepared-environment consumption retain synchronous main-thread parent transactions, to keep their existing multi-table commits atomic. Pairing is already worker-owned. No new SQL is added to publication paths.
Evidence
Final exact-head CI passed: run 35665715136 completed all 163 jobs successfully for
33dcf4dc067c3ce820bb39425ce0408e97570e4f. The native watcher returnedGREEN; no CI job retry was used.Final lifecycle repairs and rebase proof
The next CI run exposed an asynchronous provisioning race: the provider deadline could fire before the committed
requested→provisioningresult reached its caller. Failure handling now closes attempt authority immediately and joins only that database transition; shutdown still owns outstanding provider work. The deterministic committed-but-undelivered regression fails on the old code with the exact state conflict and passes after repair. Related provider timeout fixtures now advance controlled clocks only after their intended stage begins. Cleanup fixtures clear detached session IDs, and the revocation-recovery case restores a live credential before requiring an authority fence. Pure main passed the affected original suites (32 tests, the 18-test node suite, and 111 provider tests); the candidate failures were reproduced before repair. The old head also had two failures in unchanged Windows files: provider-local-service port cleanup and the SQLite cancellation test's 250ms timing assertion. The corresponding pure-main Windows jobs passed in run 35636756241; no fix is claimed for those transient failures, and no job retry was spent before replacing the head.On Testbox
tbx_01m32mvh1j1613xf7n2e76ch2q, 200 focused tests passed. The final extraction moved the unchanged SSH identity resolver into the existing provider lease owner to meet the line cap; its verified tree2620cb5b67a14e96dfbe4d3e1a4b7d1c4aed9d7apassed changed-file checks, production types, all 25 test type graphs, lint, 65 bootstrap/access/lifetime tests, and the full build (7m18.9s). The 44m36.663s command exited 0.Rebasing incorporated main's conversation-prewarming behavior through the same committed inventory projection. Async attachment classification awaits canonical readiness and includes closed attachments, preserving the post-await owner check. Its redundant read-worker command is removed. Full-candidate review found one further real race: Stop captured creation controllers before awaiting inventory settlement. It now cancels the live registry after the authorized close commits, preserving the internal successor exception. The new regression demonstrates that the old code could allocate an environment after Stop completed; the repaired code refuses before reservation.
On Testbox
tbx_01m32wy50tq7cqgmxck473tm1f, sourcedf7efadd3889b0d922d14ff2f0130726c75702bb, tree0832d2cef0d89ae8e7de44ad73aef111f02279d7, passed 128 focused tests, production types, all 25 test type graphs, targeted lint, export/line-cap guards, and the full build (6m23s). This includes pairing/inference, committed attachment classification, prewarming, owner replacement, and prepared claim/expiry boundaries. The 28m51.092s command exited 0. Both leases are stopped. The previous rebase ontoffcd3adef4f2153bb347a7ab477577c21259adf6preserved main's MCP error cases, worker handlers, and fork routes; range-diff shows only merge-context changes. That published candidate was93953674c346fca0b4dfe6f2872dfca923c4674d. Exact-head GitHub CI remains the landing gate.Published head
93953674c346fca0b4dfe6f2872dfca923c4674dalso passed 98 tests covering committed inventory attachment reads, shared-worker error transport, and worker-turn build/reconnect recovery on Testboxtbx_01m32zw09aey725nzn4z18ynb5. The command exited 0 in 3m33.175s and stopped its lease. Its exact-head CI watcher subsequently stopped for a real conflict with newer main, with no failed CI job observed at that checkpoint.The next rebase onto
f56c75f2a854d43f047367f195e0b09fe288db85integrates main's device-identity worker migration and fixture-lifetime cleanup. Main's exact-path asynchronous shutdown runs before fixture state restoration or directory removal; inventory mutations remain awaited and fixtures publish committed projection updates. The test routing lists are combined. Range-diff confirms only this mechanical integration changed the reviewed patch. Candidatee1d6fce4fda078e823d23dc673f739ab1c7c3b00remains one commit with the original subject.On Testbox
tbx_01m330dd15g7bxvsgjg60g62jh, verified sourcee1d6fce4fda078e823d23dc673f739ab1c7c3b00, treee44b3b5f1a717d48b9fa43a8a52efea834ec305a, passed 80 tests in seven startup, pairing/inference, and executor-lifecycle files (96.17s), both affected Gateway test type graphs, and targeted lint. The 8m9.022s command exited 0; the lease is stopped.Main advanced again during CI:
e1d6fce4fda078e823d23dc673f739ab1c7c3b00reached 158/162 completed jobs with no observed failures, then conflicted with main's desktop descriptor test additions. The mechanical rebase onto32c12d3eba7e78093e41393cbbaf9ff033a651c3retains those additions and awaits the new inventory fixture. Range-diff shows only that fixture adaptation. That candidate was9b868c477aeef82f6ee2448fefeb809bbbfe55cf, still one commit with the original subject.On Testbox
tbx_01m332220dcfrrqgs5stjn5mqm, verified source9b868c477aeef82f6ee2448fefeb809bbbfe55cf, tree975441150e2cad4c02b759b806405761300900f1, passed all 63 tests in the four overlapping desktop, endpoint, inventory round-trip, and remote-handoff files in 100.05s. The 5m20.564s remote command exited 0 and stopped the lease. That head ran CI 35664293032.CI run 35664293032 reported a failure in
checks-node-compact-small-33attest/scripts/package-acceptance-workflow.test.ts→keeps pnpm version selection sourced from packageManager: the pre-existing substring guard rejectedREPLAY_PNPM_VERSIONin the Windows replay workflow. On Testboxtbx_01m3337w7fwp9j42y55f4awdcv, pure main at32c12d3eba7e78093e41393cbbaf9ff033a651c3reproduced that exact failure (one selected test failed; 560 skipped). The proof command verified the expected failure and stopped its lease; it does not claim a passing test. Main already fixed this in 1497878e0bc. Rebasing ontod3e512906b63ca2ba9107aae99cf648ac817deaaincorporates that owner fix with a patch-identical range-diff; no unrelated repair was added here and no CI retry was spent. Published head:33dcf4dc067c3ce820bb39425ce0408e97570e4f. Exact-head CI passed as recorded above.Independent review completed at P0–P2. The accepted shutdown race is fixed. Two later findings were rejected against source and passing boundary tests: the reported await is inside
async deviceTeardown(the synchronousseedEnvironmentcontains no await), and the proposed prepared-expiry claim race is excluded by the pool's guarded retirement, transactional expiry predicate, and synchronous consumption publication. No accepted/actionable finding remains. Peter's explicit direction authorizes the native admin route if an enforced review requirement blocks landing; required CI must still pass.Measured standalone wall time with
pnpm test <file> --maxWorkers=1:src/gateway/worker-environments/service-lifetime.test.tsprovider-provisioning-node.test.tsprovider-bootstrap.test.tsstore-recovery.worker.test.tsplacement-dispatch-cleanup.test.tsprovider-provisioning.test.tsprovider-provisioning.replay.test.tsprovider-provisioning.cancellation.test.tsprovider-allocation-cleanup.test.tssession-attachment-service.test.tsstore-worker.test.tsThese files exercise real broker commits, publication, and lifecycle cleanup; replacing those boundaries with synchronous mocks would hide the races. The two new transition cases took 0.799s and 0.770s within the lifetime suite. No sleeps, timeout increases, serial test configuration, or weakened authority assertions were added.
The benchmark used 5,000 synthetic environments, 50 calls per round, one warm-up and five measured rounds, and median
process.threadCpuUsage()per call on Node 24.19.0. Both variants ran on blacksmith-testbox, profile openclaw-check, leasetbx_01m31fbdfrj5at01j3t8ex19fw.list, 5,000 rowslistForReconcile, 4,001 eligible rowsFull serialized SHA-256 hashes match: list
dc8fe897b3f1531952e5dcf7ac59820fd7d442a6cd1d73fa7b62103cc5020adb; reconcile04f39389262b61ce99433d6ea9f913ac46ab80d11f90687c265135bd13eae6c9. The baseline stages the exact original store/helpers fromd6b6253b965d39a94a23e4d3219c0fcec28008fa. This measures inventory selection, not a full provider reconciliation campaign or live Gateway deployment.Remote validation completed; final exact-head CI is the landing gate. On
tbx_01m32ay8j5d3pkn175ngwxrpsd, the source receipt verified commitf8283c8cf51783c34470bc9da24d6c6223b47766and tree0e9b8f7288261d1a00e20ea0f9dfd7d815cf356c.node scripts/check-changed.mjspassed all selected guards, production/test typechecks, dead-export scans, and lint.node scripts/run-vitest.mjs src/gateway/worker-environments/store-node-enrollment.test.ts src/gateway/worker-environments/worker-turn-rpc.inference-publication.test.ts src/gateway/worker-environments/store-projection.test.ts src/gateway/worker-environments/store-worker.test.ts --maxWorkers=1passed 33 tests in four files in 74.71 seconds.pnpm buildpassed in 284.2 seconds. The complete remote command exited 0 after 3,628.376 seconds. A post-completion Testbox portal-sync warning did not affect the successful command receipt; the lease is stopped.The interrupted rebase was completed and the six original commits were folded into one commit with the original subject. Main advanced during proof; the final rebase onto
6378febad9d74f68c76514e7ac4df5a8d1f7dfe3retained both placement-snapshot and inventory read-worker registrations.git range-diffshows only additive main context around imports/test routing, with no change to the reviewed patch's behavior. That initial published head wasef5d91b5aa9da3ff168f40dfa89fd245206c0ef0; the CI integration repairs below are folded into the current single commit. Formatting andgit diff --checkpassed after conflict resolution. GitHub CI must validate the current exact head before landing.Fresh independent autoreview produced one finding claiming a missing post-handoff error check. It was rejected against the existing
if (handoffError) { throw handoffError; }guard immediately after the awaited handoff inworker-turn-execution.ts; no accepted P0–P2 findings remain. Peter directed native landing and authorized the wrapper's admin route if an enforced review requirement blocks it; required CI remains mandatory.CI integration repairs
CI for the first rebased head caught five generic helper export-name collisions, a missing
session-attachment.tsdependency in the native wrapper inventory, two database-backed test files still assigned to thread projects, and a fixture upsert that ignored explicit null lease/SSH/shared-host values. Four additional wrapper-job failures shared the same missing dependency. These were reproduced against pure mainfbef0baa862c0047c06733ffb137114b499a57c9: main passed the export guard and affected runtime/source-closure/bootstrap tests, while the candidate failed the corresponding boundaries. The fixes give the new internal helpers distinct names, complete the wrapper inventory, use the existing fork projects and awaited fixture shutdown, and preserve omitted fixture fields plus activation history while honoring explicit transport clears. Production authority and shape checks remain unchanged.On
tbx_01m32fc6ydx6bv9cnvsaxe7fs9, verified repaired tree57a6d7aa816e5dedf745cf63646dedef65cff995passed the export-name guard, 134 tests in 11 files across three projects in 164.91 seconds, production and Gateway test typechecks, targeted lint, andpnpm buildin 419.8 seconds. This includes the original pairing/inference files, both re-routed files, resume, the shared-fixture send sibling, activation history, inventory writes, and real wrapper bootstrap. The 15m06.121s command exited 0; the lease is stopped. The single-file cleanup project took 17.87 seconds; the startup authority cases took 1.126 and 0.737 seconds. The main/candidate follow-up initially hit a proof-setup failure because resync replaced a linked baseline's Git metadata; recreating and removing the pure-main baseline inside one invocation resolved it before comparison.Fresh independent autoreview of the complete CI repair diff was clean at P0–P2. The repairs were folded into the original commit and rebased cleanly onto current main. That intermediate head was
03e284eb60a9d7cd5a15f53150f3ad280fe54b52; the original subject is unchanged. Required exact-head CI remains mandatory before merge.The previous lease,
tbx_01m32325psddedpxcn4h6wr13h, passed the 45-case authority suite and all 24 test type graphs at source5dea3e0b8497ec768a3c67082418b14bbc8cd115. After correcting one test cleanup lint error,node scripts/check-changed.mjspassed in 1,030.931 seconds on verified source tree654cfa76f0e64aea75b25e21f7cf27416bdf45ac. The followingpnpm buildwas interrupted when that snapshot was superseded by the publication repairs. These are earlier-source results, not validation of the latest commit.Boundary regressions, measured test cost, and preparation failures
executeSqliteQuerySynccalls. The candidate passes with zero host queries/preparations after hydration. The benchmark lease also passed 252 tests across 18 affected files in 291.85 seconds and a build in 394.73 seconds. Benchmark command wall times were 33.15 seconds before and 13.47 seconds after.tbx_01m31v3p38tqh26cfg1796mtf6, the commit-admission retention regression failed against the pre-fix asynchronous store: two rows were deleted instead of zero (17.63 seconds). Restoring the fix and runningstore-retention.test.ts,store-worker.test.ts,store-recovery.worker.test.ts, andstore-projection.test.tspassed 16 tests in 31.79 seconds. The new case itself took 1.009 seconds and proves real worker rollback, byte-identical retained rows, error identity, and a successful retry.tbx_01m31h4remyx8m4t6ax75fg2r8, both credential ownership regressions failed before the repair and passed afterward (20.65 / 15.48 seconds). They protect a successor credential and a same-epoch owner-state change.tbx_01m31vmyd019vbdknjzc4hhks7, the verified placement-integrated source passed 129 tests in ten files in 82.245 seconds: placement read projection, session row facts and ancestor placement, inventory worker/change events, credential broker, state worker error transport, both read-worker suites, and conversation-binding worker reads. All 24 canonical test type graphs passed in 880.456 seconds.tbx_01m31y3z38hz1wgq78mpcng46y, the rebased source passed 12 fleet/inventory broker tests in 30.488 seconds and all 24 test type graphs in 1,164.636 seconds. The canonical gate then passed structural guards, formatting, documentation, and production/test types before finding five unused exports. Those exports were removed; projection tests now acquire and clean up the real registry owner instead of importing a test-only constructor.tbx_01m320j6px6rpk7tj891rnw5za, the cleaned-up source passed the production and full-tree dead-export scans and all 32 projection/prepared-inventory/worker tests in 53.491 seconds. The remaining batch was stopped to address the confirmed delayed-publication transfer finding and rebase additive read-worker integrations. The repair has a deterministic real-HTTP test that holds committed publication after actual blob verification: diagnostics and same-binding renewal must return exact bytes, while revocation must send no response bytes. On the final lease, the new HTTP regression failed for both diagnostic and renewal publication against the pre-fix modules, while revocation stayed blocked (21.924 seconds). The repair then passed all 45 tests acrossnode-workspace-transfer-credential.test.ts,node-workspace-transfer-revocation.test.ts,store-projection.test.ts,store-worker.test.ts,store-recovery.worker.test.ts, andstore-retention.test.tsin 53.121 seconds. The three new HTTP cases took 1.011, 1.104, and 1.067 seconds. The following aggregate run initially found a test-only Promise-executor lint error; its corrected source passed the aggregate check as recorded above. The final publication repairs are covered by the completed validation above.node scripts/run-vitest.mjs ... --maxWorkers=1for measured cost. Type graphs ran throughnode scripts/run-tsgo-core-test-shards.mjs --stripe 1/1 --concurrency 4. No serial test configuration or worker pin was introduced. Existing fork projects own database-worker tests. The exact-head GitHub workflow supplies the final CI evidence.The latest review findings exposed pairing publication stopping in the worker process and diagnostic publication interrupting inference. Both are repaired in the latest commit. The existing real-bootstrap regression now covers normal publication, lost result recovery, and delayed older inventory replies. A new registered
worker.inference.startdispatch regression requires exact output during diagnostics and aborts on credential replacement/revocation. On the final Testbox proof, normal pairing publication, lost-result recovery, and delayed inventory reply cases took 1.200, 0.974, and 0.935 seconds. The diagnostic, credential replacement, and credential revocation inference cases took 0.804, 0.756, and 0.776 seconds. Earlier HTTP 429 warmup failures are resolved; the resumed warmup succeeded on its first attempt. Independent review of the final repair diff found no actionable P0–P2 findings. No live Gateway was deployed or restarted.