Skip to content

perf(gateway): move worker inventory SQL off the main thread - #154804

Merged
steipete merged 1 commit into
mainfrom
steipete/perf-micro-worker-migrate-environment-inventory-20260919
Sep 21, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/perf-micro-worker-migrate-environment-inventory-20260919

Conversation

@steipete

@steipete steipete commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

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 lastError and updatedAtMs. 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, and updatedAtMs. 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 returned GREEN; 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 → provisioning result 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 tree 2620cb5b67a14e96dfbe4d3e1a4b7d1c4aed9d7a passed 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, source df7efadd3889b0d922d14ff2f0130726c75702bb, tree 0832d2cef0d89ae8e7de44ad73aef111f02279d7, 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 onto ffcd3adef4f2153bb347a7ab477577c21259adf6 preserved main's MCP error cases, worker handlers, and fork routes; range-diff shows only merge-context changes. That published candidate was 93953674c346fca0b4dfe6f2872dfca923c4674d. Exact-head GitHub CI remains the landing gate.

Published head 93953674c346fca0b4dfe6f2872dfca923c4674d also passed 98 tests covering committed inventory attachment reads, shared-worker error transport, and worker-turn build/reconnect recovery on Testbox tbx_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 f56c75f2a854d43f047367f195e0b09fe288db85 integrates 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. Candidate e1d6fce4fda078e823d23dc673f739ab1c7c3b00 remains one commit with the original subject.

On Testbox tbx_01m330dd15g7bxvsgjg60g62jh, verified source e1d6fce4fda078e823d23dc673f739ab1c7c3b00, tree e44b3b5f1a717d48b9fa43a8a52efea834ec305a, 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: e1d6fce4fda078e823d23dc673f739ab1c7c3b00 reached 158/162 completed jobs with no observed failures, then conflicted with main's desktop descriptor test additions. The mechanical rebase onto 32c12d3eba7e78093e41393cbbaf9ff033a651c3 retains those additions and awaits the new inventory fixture. Range-diff shows only that fixture adaptation. That candidate was 9b868c477aeef82f6ee2448fefeb809bbbfe55cf, still one commit with the original subject.

On Testbox tbx_01m332220dcfrrqgs5stjn5mqm, verified source 9b868c477aeef82f6ee2448fefeb809bbbfe55cf, tree 975441150e2cad4c02b759b806405761300900f1, 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-33 at test/scripts/package-acceptance-workflow.test.ts → keeps pnpm version selection sourced from packageManager: the pre-existing substring guard rejected REPLAY_PNPM_VERSION in the Windows replay workflow. On Testbox tbx_01m3337w7fwp9j42y55f4awdcv, pure main at 32c12d3eba7e78093e41393cbbaf9ff033a651c3 reproduced 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 onto d3e512906b63ca2ba9107aae99cf648ac817deaa incorporates 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 synchronous seedEnvironment contains 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:

File under src/gateway/worker-environments/ Seconds
service-lifetime.test.ts 34.582
provider-provisioning-node.test.ts 38.854
provider-bootstrap.test.ts 36.706
store-recovery.worker.test.ts 19.214
placement-dispatch-cleanup.test.ts 20.382
provider-provisioning.test.ts 62.080
provider-provisioning.replay.test.ts 64.958
provider-provisioning.cancellation.test.ts 49.263
provider-allocation-cleanup.test.ts 41.850
session-attachment-service.test.ts 29.461
store-worker.test.ts 27.106

These 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, lease tbx_01m31fbdfrj5at01j3t8ex19fw.

Operation Original main-thread CPU Candidate main-thread CPU Reduction
list, 5,000 rows 25.625 ms 9.517 ms 62.9%
listForReconcile, 4,001 eligible rows 20.355 ms 8.957 ms 56.0%

Full serialized SHA-256 hashes match: list dc8fe897b3f1531952e5dcf7ac59820fd7d442a6cd1d73fa7b62103cc5020adb; reconcile 04f39389262b61ce99433d6ea9f913ac46ab80d11f90687c265135bd13eae6c9. The baseline stages the exact original store/helpers from d6b6253b965d39a94a23e4d3219c0fcec28008fa. 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 commit f8283c8cf51783c34470bc9da24d6c6223b47766 and tree 0e9b8f7288261d1a00e20ea0f9dfd7d815cf356c. node scripts/check-changed.mjs passed 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=1 passed 33 tests in four files in 74.71 seconds. pnpm build passed 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 6378febad9d74f68c76514e7ac4df5a8d1f7dfe3 retained both placement-snapshot and inventory read-worker registrations. git range-diff shows only additive main context around imports/test routing, with no change to the reviewed patch's behavior. That initial published head was ef5d91b5aa9da3ff168f40dfa89fd245206c0ef0; the CI integration repairs below are folded into the current single commit. Formatting and git diff --check passed 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 in worker-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.ts dependency 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 main fbef0baa862c0047c06733ffb137114b499a57c9: 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 tree 57a6d7aa816e5dedf745cf63646dedef65cff995 passed the export-name guard, 134 tests in 11 files across three projects in 164.91 seconds, production and Gateway test typechecks, targeted lint, and pnpm build in 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 source 5dea3e0b8497ec768a3c67082418b14bbc8cd115. After correcting one test cleanup lint error, node scripts/check-changed.mjs passed in 1,030.931 seconds on verified source tree 654cfa76f0e64aea75b25e21f7cf27416bdf45ac. The following pnpm build was 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
  • The original entry point fails the no-host-SQL regression on five cached executeSqliteQuerySync calls. 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.
  • On 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 running store-retention.test.ts, store-worker.test.ts, store-recovery.worker.test.ts, and store-projection.test.ts passed 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.
  • On 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.
  • On 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.
  • On 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.
  • On 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 across node-workspace-transfer-credential.test.ts, node-workspace-transfer-revocation.test.ts, store-projection.test.ts, store-worker.test.ts, store-recovery.worker.test.ts, and store-retention.test.ts in 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.
  • Focused tests ran through node scripts/run-vitest.mjs ... --maxWorkers=1 for measured cost. Type graphs ran through node 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.
  • Initial fixture failures exposed missing awaits, wrong thread routing, cancellation/retirement/shutdown ordering, and SDK/UI acknowledgement fakes; those were repaired and covered by subsequent passing runs. The complete changed gate exposed the shared dispatcher's 703/700 line-cap violation, resolved by rebasing on fix(cron): keep healthy active runs from delaying job lists #154421, which owns the fleet extraction; no duplicate fleet implementation remains in this PR. Blacksmith native full sync timed out on reused leases before validation; those leases were stopped and replaced. Seeding fresh leases from the published topic branch reduced the verified source handoff to a targeted one-file sync (20.362 seconds). Source receipt verification uses the maintained source capsule's source/tree/base identities rather than hydrated Git HEAD.

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.start dispatch 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.

@clawsweeper

clawsweeper Bot commented Sep 21, 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.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation app: web-ui App: web-ui gateway Gateway runtime agents Agent runtime and tooling fleet size: XL maintainer Maintainer-authored PR labels Sep 21, 2026
@steipete
steipete force-pushed the steipete/perf-micro-worker-migrate-environment-inventory-20260919 branch from 5410788 to b9b0cb3 Compare September 21, 2026 12:12
@openclaw-barnacle openclaw-barnacle Bot removed the fleet label Sep 21, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 21, 2026
@clawsweeper

clawsweeper Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 21, 2026, 7:25 PM ET / 23:25 UTC (Revision 8).

ClawSweeper review

What this changes

Moves 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
Reviewed head: 33dcf4dc067c3ce820bb39425ce0408e97570e4f

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A coherent optimization with measured gains, meaningful boundary proof, and no remaining actionable finding.
Proof confidence 🦞 diamond lobster (5/6) ✨ media proof bonus Sufficient (linked_artifact): Recorded Testbox proof exercises the real inventory broker and HTTP transfer path across delayed committed publication: valid transfers return exact bytes and revocation prevents response headers. Pairing recovery and registered inference checks cover the related authority consumers; no live deployment is claimed.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (linked_artifact): Recorded Testbox proof exercises the real inventory broker and HTTP transfer path across delayed committed publication: valid transfers return exact bytes and revocation prevents response headers. Pairing recovery and registered inference checks cover the related authority consumers; no live deployment is claimed.
Evidence reviewed 10 items Pinned introduction and merge ownership: Reviewed the introduced delta from d3e5129 to 33dcf4d. Raw test-merge metadata confirms b9421f4 followed by the pinned head as its parents; base-only workflow changes were not attributed to this PR.
Still necessary on main: At the fetched main revision, list and listForReconcile still call listRows through the synchronous SQLite reader. The inventory store is unchanged between the pinned merge base and fetched main.
Latest release retains the original path: GitHub contents inspection of v2026.9.5 confirms synchronous inventory queries and listForReconcile calling listRows; release metadata reports publication on September 19, 2026.
Findings None None.
Security None None.

How this fits together

The 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
Loading

Before merge

  • Review config compatibility - Confirm compatibility and upgrade impact for the changed config or default surface before merge.
  • Add data-model compatibility proof - Confirm migration or upgrade compatibility proof before merge.
Agent review details

Security

None.

PR surface

PR surface statistics unavailable: the file list is incomplete.

Review metrics

Metric Value Why it matters
Production versus test growth Production net +1,989 lines; tests and support net +2,685 lines The growth has a concrete justification: committed projection ownership, asynchronous publication and recovery, and boundary regressions.
Recorded inventory benchmark 5,000 environments: list CPU −62.9%; reconcile-selection CPU −56.0% The same-lease comparison reports identical serialized results and measures the intended main-thread reduction.

Stored data model

Persistent data-model change detected: unknown-truncated-pull-files. Confirm migration or upgrade compatibility proof before merge.

Technical review

Best 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.

Labels

Label justifications:

  • P2: A measured Gateway responsiveness improvement for large worker inventories, without evidence of an urgent user-facing outage.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (linked_artifact): Recorded Testbox proof exercises the real inventory broker and HTTP transfer path across delayed committed publication: valid transfers return exact bytes and revocation prevents response headers. Pairing recovery and registered inference checks cover the related authority consumers; no live deployment is claimed.
  • proof: sufficient: Contributor real behavior proof is sufficient. Recorded Testbox proof exercises the real inventory broker and HTTP transfer path across delayed committed publication: valid transfers return exact bytes and revocation prevents response headers. Pairing recovery and registered inference checks cover the related authority consumers; no live deployment is claimed.

Evidence

What I checked:

  • Pinned introduction and merge ownership: Reviewed the introduced delta from d3e5129 to 33dcf4d. Raw test-merge metadata confirms b9421f4 followed by the pinned head as its parents; base-only workflow changes were not attributed to this PR. (33dcf4dc067c)
  • Still necessary on main: At the fetched main revision, list and listForReconcile still call listRows through the synchronous SQLite reader. The inventory store is unchanged between the pinned merge base and fetched main. (src/gateway/worker-environments/store.ts:939, 06ce6c415dd2)
  • Latest release retains the original path: GitHub contents inspection of v2026.9.5 confirms synchronous inventory queries and listForReconcile calling listRows; release metadata reports publication on September 19, 2026. (src/gateway/worker-environments/store.ts:972, ec9c1a13db89)
  • Authority and publication ordering: Mutations serialize through the projection owner, recheck caller authority at transaction and commit admission, fence changed bindings, and install acknowledged facts before notifications. Lost outcomes recover receipts or reconcile rows without replaying writes. (src/gateway/worker-environments/store.ts:159, 33dcf4dc067c)
  • Earlier functional findings addressed: Record-authority digests exclude only diagnostic fields; transfer equality preserves the existing independent capability lifetime. Pairing receipts publish environment bindings on the host before observers, including lost-result recovery. Extracted inventory helpers use distinct names. (src/gateway/worker-environments/store-commit-authority.ts:9, 33dcf4dc067c)
  • Config and upgrade warning resolved: The two config changes remove obsolete static-analysis exemptions. No operator setting, default, durable schema, or serialized record format changes. Store schema edits make initialization bookkeeping rollback-aware; documented reopening waits for inventory admission. Public docs: docs/reference/database-schemas/storage-changes.md. (docs/reference/database-schemas/storage-changes.md:36, 33dcf4dc067c)

Likely related people:

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

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (7 earlier review cycles)
  • reviewed 2026-09-21T12:23:01.834Z sha b9b0cb3 :: blocked before merge. :: [P2] Preserve valid transfers during non-authority inventory writes
  • reviewed 2026-09-21T13:05:01.503Z sha 009a3e9 :: blocked before merge. :: [P2] Preserve valid transfers during non-authority inventory writes
  • reviewed 2026-09-21T13:56:59.021Z sha 5dea3e0 :: blocked before merge. :: [P1] Publish pairing completion back to the Gateway inventory | [P2] Preserve active inference during diagnostic publication
  • reviewed 2026-09-21T17:15:55.809Z sha ef5d91b5aa9da3ff168f40dfa89fd245206c0ef0 :: blocked before merge. :: [P2] Give extracted inventory helpers unique exported names
  • reviewed 2026-09-21T18:17:56.393Z sha 03e284e :: blocked before merge. :: none
  • reviewed 2026-09-21T22:06:39.919Z sha 93953674c346fca0b4dfe6f2872dfca923c4674d :: blocked before merge. :: none
  • reviewed 2026-09-21T22:33:55.062Z sha e1d6fce4fda078e823d23dc673f739ab1c7c3b00 :: blocked before merge. :: none

@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Sep 21, 2026
@steipete
steipete force-pushed the steipete/perf-micro-worker-migrate-environment-inventory-20260919 branch from 009a3e9 to 5dea3e0 Compare September 21, 2026 13:38
@steipete
steipete marked this pull request as ready for review September 21, 2026 14:52
@steipete
steipete enabled auto-merge (squash) September 21, 2026 14:52
@github-actions

github-actions Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Security sensitive changes

This maintainer PR changes sensitive security components. This comment is informational because the PR author has repository Maintain or Admin access.

  • Current SHA: 33dcf4dc067c3ce820bb39425ce0408e97570e4f
  • Maintainer: @steipete
  • Repository role: admin

These security sensitive changes were made:

  • src/gateway/worker-environments/credential-broker.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/gateway/worker-environments/store-commit-authority.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.
  • src/infra/device-bootstrap.worker-kernel.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.
  • src/infra/device-pairing-cloud-worker.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.
  • src/infra/device-pairing-dispatch.worker.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.
  • src/infra/device-pairing-read.types.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.
  • src/infra/device-pairing-store.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.
  • src/infra/device-pairing-worker.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.

Carefully review these changes before merging.

@steipete
steipete force-pushed the steipete/perf-micro-worker-migrate-environment-inventory-20260919 branch from 7418ebf to ef5d91b Compare September 21, 2026 17:04
@clawsweeper clawsweeper Bot removed the merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. label Sep 21, 2026
@steipete
steipete force-pushed the steipete/perf-micro-worker-migrate-environment-inventory-20260919 branch from ef5d91b to 03e284e Compare September 21, 2026 18:09
@steipete
steipete disabled auto-merge September 21, 2026 18:09
@openclaw-barnacle openclaw-barnacle Bot added the scripts Repository scripts label Sep 21, 2026
@steipete
steipete enabled auto-merge (squash) September 21, 2026 18:10
@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Sep 21, 2026
@steipete
steipete force-pushed the steipete/perf-micro-worker-migrate-environment-inventory-20260919 branch from 03e284e to 9395367 Compare September 21, 2026 21:56
@steipete
steipete disabled auto-merge September 21, 2026 21:58
@steipete
steipete force-pushed the steipete/perf-micro-worker-migrate-environment-inventory-20260919 branch from 9395367 to e1d6fce Compare September 21, 2026 22:24
@steipete
steipete enabled auto-merge (squash) September 21, 2026 22:24
@steipete
steipete disabled auto-merge September 21, 2026 22:24
@steipete
steipete force-pushed the steipete/perf-micro-worker-migrate-environment-inventory-20260919 branch from e1d6fce to 9b868c4 Compare September 21, 2026 22:45
@steipete
steipete enabled auto-merge (squash) September 21, 2026 22:45
@steipete
steipete disabled auto-merge September 21, 2026 22:45
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.
@steipete
steipete force-pushed the steipete/perf-micro-worker-migrate-environment-inventory-20260919 branch from 9b868c4 to 33dcf4d Compare September 21, 2026 23:02
@steipete
steipete enabled auto-merge (squash) September 21, 2026 23:03
@steipete
steipete disabled auto-merge September 21, 2026 23:03
@steipete
steipete merged commit c768bd1 into main Sep 21, 2026
229 checks passed
@steipete
steipete deleted the steipete/perf-micro-worker-migrate-environment-inventory-20260919 branch September 21, 2026 23:32
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 22, 2026
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling app: web-ui App: web-ui docs Improvements or additions to documentation gateway Gateway runtime maintainer Maintainer-authored PR 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