Repository navigation
perf(agents): read worktree publication and tool availability through the worktree reader - #164685
Conversation
Refresh freshness at read admission and after BEGIN while reusing handle-owned facts for runtime schema checks. Validate canonical triggers before exposing agent readers and classify shared-state failures only after failed admission. Focused runtime checks execute zero SQL statements, versus 30 with the baseline owner. Preserve foreign-commit and snapshot semantics. Full workload measurement and remote integration checks remain merge preconditions after remote runner and fleet-capacity admission failed.
Route audited writer claims, live-model-switch bookkeeping, and pending-final preparation, settlement, and cleanup through the existing agent executor. Preserve native opaque SDK callbacks and the excluded lifecycle and cron paths. The paired isolated Gateway workload reduces native patch transactions from 8 to 2 per warmed turn and target-site SQL from 48 to 12. Overall main-thread SQL averages 648.5 to 493.4 statements per warmed turn. Lifecycle persistence remains follow-up work after #142236; cron preparation remains with #161105. Local caller, settlement, error identity, import-boundary, cycle, and database ratchet proof passes. Full build, changed checks, and released SDK diff remain explicit merge preconditions under the maintainer's validation instruction.
Integrate the pinned measurement baseline and retain main-key facts through the existing connection and reader-admission owners. Preserve raw writes, foreign commits, transaction snapshots, authorizers, and continuation authority.
Create and read producer-recovery sessions under the same explicit shared-state root as their delivery queue. Worker-backed pending-final settlement correctly rejects the previous fixture ownership mismatch. Preserve durable payloads and all existing assertions.
Use the existing worker generation claim for maintenance metadata instead of retaining a host read handle. Keep both live ownership checks around the required transaction-entry freshness probe. Consolidate shared-state cache initialization, refresh, and terminal failures in its admission sibling and update the compiled-wrapper inventory. This keeps the cache within the existing module-size limit without changing stored schema or quarantine semantics. Focused maintenance, ownership, schema, worker, wrapper, and quarantine proof passed. Independent Codex review is clean through P2. Full landing validation remains required before merge.
Keep the accounting persistence suite within its line cap by moving fixture construction into a dedicated test-support module. Preserve suite-owned state, immediate operation registration, and every test case and assertion.
Refresh canonical readiness when it consumes schema facts. Retention only holds native lifetime, so cold restore and other worker handoffs no longer execute host SQLite before dispatch. Protect foreign schema invalidation at the warm readiness fast path. Tighten retained-reader budgets to the optimized counts, and require early missing-table diagnosis before callbacks while preserving handle-cleanup assertions. Validation: 93 focused tests, production types, state/config test types, and independent review clean through P2.
Integrate the released-SDK diff tooling fix and the inherited child-coordination fixture correction. The merge preserves every authored source, test, and documentation blob; the wrapper inventory combines both branches.
…7aaf51b0f897b4e94dafe02184fee6e77e3f' into dbasync/wtlookup
Move publication preparation and per-turn tool availability through the existing worktree reader. Capture the physical store and session lifecycle before yielding, refresh availability facts, and preserve live effect guards and branch identity semantics.
|
🦞👀 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. |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
Integrate schema-facts admission and current main before landing the publication lookup lane. Preserve main's separate template worker registry while retaining the owner lookup operation and type import. The resulting main-relative diff is the original 18-file lane. Independent Codex P2 autoreview is scoped-clean. Focused integration proof is running; the prior exact-head CI run remains historical evidence.
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Codex review: needs maintainer review before merge. Reviewed October 4, 2026, 6:31 AM ET / 10:31 UTC (Revision 6). ClawSweeper reviewWhat this changesMove worktree lookups for GitHub publication preparation and agent tool availability into the existing database worker while preserving live execution guards. Merge readiness✅ Ready for maintainer review The PR remains useful: current main and the latest release retain synchronous worktree preparation reads. The pinned patch has no actionable correctness or security findings. Priority: P2 Review scores
Verification
How this fits togetherThe worktree registry connects agent sessions to their repository checkouts. Publication preparation uses those records to select available tools and GitHub publishing inputs, while execution separately checks current authority before writes. flowchart TD
A[Agent session] --> B[Capture store and lifecycle]
B --> C[Worktree database worker]
C --> D[Validate selected workspace]
D --> E[Tool availability]
D --> F[Live publication guards]
F --> G[Git and GitHub effects]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +121, Tests +178, Docs +9. Total +308 across 18 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep preparation reads in the existing worktree worker, with one shared lookup kernel and live transaction and Git-effect authority checks. Do we have a high-confidence way to reproduce the issue? Yes: current-main preparation reaches the native registry query, and the supplied paired Gateway workload measures that hotspot. This review inspected source and existing evidence without rerunning target code. Is this the best way to solve the issue? Yes: reusing the existing worker and lookup kernel is a focused solution, and final-effect guards remain with their current owners. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against c190df12716a. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (5 earlier review cycles)
|
Keep the SQL boundary fixture isolated from session storage, managed-worktree services, configuration, and credential state. Document those boundaries for the new first-party mock-export check. No executable test code, assertions, timeouts, or production behavior changes. The mock-export check, formatter, reader tests, and scoped P2 review pass.
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
Preserve main's provisioned-snapshot fixture and asynchronous chunk reader alongside the publication owner-lookup reader import. The main-relative authored production patch remains byte-for-byte identical across all eleven production files. The affected registry reader, runtime build graph, and worker import checks pass. Fresh scoped P2 review is clean. CI passed on the prior head 1b25053 before this conflict repair.
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Merged via squash.
|
… the worktree reader (openclaw#164685) * perf(state): carry admitted schema facts with database handles Refresh freshness at read admission and after BEGIN while reusing handle-owned facts for runtime schema checks. Validate canonical triggers before exposing agent readers and classify shared-state failures only after failed admission. Focused runtime checks execute zero SQL statements, versus 30 with the baseline owner. Preserve foreign-commit and snapshot semantics. Full workload measurement and remote integration checks remain merge preconditions after remote runner and fleet-capacity admission failed. * perf(agents): run per-turn session-entry patches through the worker Route audited writer claims, live-model-switch bookkeeping, and pending-final preparation, settlement, and cleanup through the existing agent executor. Preserve native opaque SDK callbacks and the excluded lifecycle and cron paths. The paired isolated Gateway workload reduces native patch transactions from 8 to 2 per warmed turn and target-site SQL from 48 to 12. Overall main-thread SQL averages 648.5 to 493.4 statements per warmed turn. Lifecycle persistence remains follow-up work after openclaw#142236; cron preparation remains with openclaw#161105. Local caller, settlement, error identity, import-boundary, cycle, and database ratchet proof passes. Full build, changed checks, and released SDK diff remain explicit merge preconditions under the maintainer's validation instruction. * test(outbound): align recovery fixtures with queue state Create and read producer-recovery sessions under the same explicit shared-state root as their delivery queue. Worker-backed pending-final settlement correctly rejects the previous fixture ownership mismatch. Preserve durable payloads and all existing assertions. * fix(state): preserve worker handoffs during schema admission Use the existing worker generation claim for maintenance metadata instead of retaining a host read handle. Keep both live ownership checks around the required transaction-entry freshness probe. Consolidate shared-state cache initialization, refresh, and terminal failures in its admission sibling and update the compiled-wrapper inventory. This keeps the cache within the existing module-size limit without changing stored schema or quarantine semantics. Focused maintenance, ownership, schema, worker, wrapper, and quarantine proof passed. Independent Codex review is clean through P2. Full landing validation remains required before merge. * test(agents): extract accounting persistence fixture Keep the accounting persistence suite within its line cap by moving fixture construction into a dedicated test-support module. Preserve suite-owned state, immediate operation registration, and every test case and assertion. * fix(state): keep retained handles free of schema probes Refresh canonical readiness when it consumes schema facts. Retention only holds native lifetime, so cold restore and other worker handoffs no longer execute host SQLite before dispatch. Protect foreign schema invalidation at the warm readiness fast path. Tighten retained-reader budgets to the optimized counts, and require early missing-table diagnosis before callbacks while preserving handle-cleanup assertions. Validation: 93 focused tests, production types, state/config test types, and independent review clean through P2. * perf(agents): read worktree publication lookups in worker Move publication preparation and per-turn tool availability through the existing worktree reader. Capture the physical store and session lifecycle before yielding, refresh availability facts, and preserve live effect guards and branch identity semantics. * test(gateway): document publication reader mock isolation Keep the SQL boundary fixture isolated from session storage, managed-worktree services, configuration, and credential state. Document those boundaries for the new first-party mock-export check. No executable test code, assertions, timeouts, or production behavior changes. The mock-export check, formatter, reader tests, and scoped P2 review pass.
What Problem This Solves
Publication and tool-availability preparation synchronously query the worktree registry on the Gateway thread. The measured path performs five main-thread statements per warmed turn, including shared-state admission and ownership checks, even when no managed worktree exists.
Why This Change Was Made
Reuse the existing worktree reader and shared-state worker for owner lookup, preserving the query and row codec in one kernel. Capture the physical store and session lifecycle before yielding, carry the initial session facts, and refresh worktree selection after credential or repository preparation. Migrate ordinary shared/personal publication and executor preparation reads together. Recheck the selected publisher after the new await before recording a claim request.
Live transaction and Git-effect guards retain their current synchronous authority checks. Prepared lookup results never authorize an effect. No new worker service, policy cache, schema, retention, durability, or branch-identity change is introduced. Existing coordinator SDK method signatures and update behavior remain unchanged.
The prerequisite #164490 merged as
c828f7ed1d560295f78166a98fb54687dc162b28. The branch includes main througha0a1f184a3867aa4dd3493a743e0c59a4ebfbecd, using merge commits. The main-relative diff remains this 18-file lane. Integration preserves #164706's separate template dispatcher, #164320's provisioned-snapshot fixture and asynchronous chunk reader, and #164779's worker-based initial session reads. The latter introduces an earlier await, so both availability and target discovery now capture the physical worktree store before session preparation and recheck its admission afterward. Live effect guards remain synchronous.Overlap: #131582 covers publication branch naming; the small request/executor hunks preserve its branch-identity design space. #164779 shares availability preparation; its session-reader implementation is retained unchanged. The broader #162433 turn/queue/stop design and GC/allocation work remain untouched. Workload measurements below belong to original head
53c46a6fff7f5744c6f0630f23a711b64a00cca3, not a new latency benchmark.User Impact
Worktree-attributed Gateway-thread SQL falls 5 → 0 per warmed turn, 50 → 0 across ten turns, and 86 → 0 across the full workload. All main-thread SQL is 344.1 → 338.3 per warmed turn and 9,498 → 9,405 overall. Across all threads/processes, the workload executes 37,935 → 38,348 statements, including worker admission and background work.
At the measured heads, the static inventory stayed T1 921 → 921 (T2 377, T3 272, W 971). The shared lookup kernel remains conservatively T1 because live guards and creation/placement callers still use its native path; no inventory reclassification claims that debt is gone.
Evidence
The unchanged sqlmeasure harness, observer, and analyzer ran locally with Node v24.21.0 and source-map builds, fresh synthetic state, a local streaming provider, and the normal loopback device challenge/pairing flow. Before:
cfb80c638c72d82371e65ffad61a2e7acd6b238d(main plus the two prerequisites). After:53c46a6fff7f5744c6f0630f23a711b64a00cca3. Both completed all 13 parent turns, the child turn, a successful cron run, committed compaction, and clean shutdown. Counts exclude statement preparation.Phase windows include concurrent maintenance. Memory cold setup shifted between compaction and shutdown (combined main-thread count 601 → 611), and the warmed outlier moved between turns; phase deltas are not independent patch effects. Instrumented workload wall time/RSS: 159.36 s / 2.53 GiB → 252.18 s / 2.36 GiB on the loaded host. These timings are not a latency benchmark.
Validation at the original measured head:
pnpm test <files> --maxWorkers=1. Broader publication/worker-binding run: 149 existing cases passed in an 843.46 s command; the two new-suite failures were an incorrect Vitest thread-pool route, corrected to the existing database-worker pool. The subsequent run passed the four boundary cases and existing admission/binding cases (44 passes, 848.44 s command); a new revocation fixture initially failed to intercept the mocked reader and was corrected. Final targeted run: publisher revocation plus both registry-reader cases, 3 passed, 892.45 s including cold worker compilation/imports. Registry tests also cover latest-live selection, owner-kind filtering, and captured environment without host SQL. No test uses an added timer/sleep/poll.node scripts/check-changed.mjs --base cfb80c638c72d82371e65ffad61a2e7acd6b238d: passed, 3,701.57 s, including core and all selected test typechecks, dead exports, lint, and guards. Existing unrelated max-lines warnings remain; no ratchet growth or new environment names.v2026.9.8with a real-path temporary directory: passed, 2,375.98 s, digest39769e7e. The report includes main's existing changes since that release. The indirectGatewayRequestHandlerOptions.context.githubPublicationServicecontract was inspected; this lane preserves the coordinator method signatures.58b544712d0349f85a06fda6a249f872012582a1: scoped-clean, no accepted actionable findings.The first after-measurement attempt lost its WebSocket with code
1006after one successful turn. The Gateway remained alive until harness cleanup. A diagnostic replay completed every phase with regular protocol pings, followed by the successful unchanged-harness run reported above. The original disconnect remains unexplained and is excluded from the comparison. An initial regression collection attempt also raced the setup build's generated namespace; serializing those phases resolved that tooling failure. Neither event is presented as a product fix. The wall times above include the heavily loaded host and cold compilation; current-head CI is recorded below.Remaining host-read debt: the native lookup in
src/gateway/github-publication-availability.ts:166is retained for live transaction/Git-effect checks, with callers ingithub-publication.ts,github-publication-coordinator-methods.ts,github-publication-executor.ts, andgithub-personal-publication.ts. The service's creation and placement callers remain outside this lane. Session, publication-lifecycle, placement, and lease reads are separate owners.Integration validation
Current head:
bf604ea2b8c671023dad4646a8a338fe32afc0bd. Exact-head CI passed (run 37194419557: 60 jobs successful, 23 intentionally skipped). Dependency/security statuses briefly reported review incomplete before completing successfully; no failed CI job or rerun was involved. ClawSweeper completed trusted review of this head at 2026-10-04 10:13 UTC with no correctness/security findings and Before merge: None. Native landing is in progress. Prior-head CI 37191021566 at53cd06dremains historical evidence.The PR-caused CI failure at
c9407abwas main's new first-party mock-export check. Commit1b25053added six explicit mock-isolation comments without changing executable tests, assertions or timeouts; CI then passed at1b25053and53cd06d. The additional synthetic session-reader mock required by #164779 has its own isolation explanation. The current mock-export ratchet, targeted lint, formatting and whitespace checks pass.The third merge's two new captured-store cases were first run with store capture deliberately left after session preparation: availability returned false and target discovery rejected the missing worktree in the retargeted store, while the four existing cases passed. Moving capture before the await repairs that integration defect. The corrected focused run passed all 47 cases across publication admission, worker binding and all six real worker-boundary cases:
pnpm test src/gateway/github-publication-availability.worker.test.ts src/gateway/github-publication-admission.test.ts src/gateway/worker-environments/worker-github-binding.test.ts --maxWorkers=1, 394.92 seconds wall time on the loaded Mac (Node 26.10.0). Fresh P2 autoreview of the full main-relative candidate completed scoped-clean, with no accepted actionable findings.Reusable earlier proof:
v2026.9.8completed on53cd06din 1,451.32 seconds, digest3eedc257ab6716b4065cf2cb910b8f5a2ddf5d92d75da5354dab6ccf0bf0b7a8. It includes main's accumulated SDK changes. The final integration changes internal preparation composition only; direct inspection reconfirmed unchanged released coordinator signatures reachable throughGatewayRequestHandlerOptions.context.githubPublicationService, with no new or removed SDK export. The report is reused for that unchanged lane contract, not presented as a new whole-main compatibility report.The broader Mac publication run recorded 170 passes and four failures in 1,827.01 seconds. Three failures stop at the unchanged fixture's initial
git init, before publication behavior; its stderr-only error loses the exact termination cause. The real-reset case exceeded its existing 120-second timeout, with the stalled await unidentified. These remain investigated failures, not claimed fixes.The isolated AWS comparison completed 20 of 20 complete file runs, five runs of each of
github-personal-publication.test.tsandgithub-publication-boundaries.test.tson bothc9407ab34edf1a092f3a7a15e30bba5342864471and main baseline06d4475d6079aaa875a9b477ac0935d1459b1023, singly with--maxWorkers=1. All 860 cases passed on Linux/Node 24.21.0 in a 2,035.937-second command; the lease is released. That comparison did not reproduce or explain the Mac failures. The third merge changes initial publication session preparation and its fixture mocks, so this earlier comparison is not represented as exact-head integration coverage; the final focused tests and current-head CI provide that coverage separately.