Repository navigation
perf(exec): prepare exec defaults and approvals through the async readers - #164648
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.
…dad14cf0e74a246c18c001341577ae6b5d8a' into dbasync/execprep
|
🦞👀 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:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Codex review: needs maintainer review before merge. Reviewed October 4, 2026, 4:54 AM ET / 08:54 UTC (Revision 3). ClawSweeper reviewWhat this changesThe PR moves approval-policy reads during reply skill preparation to existing asynchronous readers and reuses the prepared execution settings when selecting node skills. Merge readiness✅ Ready for maintainer review The optimization remains useful on current main. No blocking correctness or security finding remains, and the prior mock-export ratchet finding is resolved. Priority: P2 Review scores
Verification
How this fits togetherReply skill preparation combines configuration, session settings, and stored execution policy to decide which skills appear in the agent’s context. Command execution separately checks current approval policy before dispatch. flowchart TD
A[Configuration and session settings] --> C[Prepare execution defaults]
B[Stored approval policy] --> D[Existing async policy reader]
D --> C
C --> E[Check node skill eligibility]
E --> F[Reusable skill snapshot]
F --> G[Agent reply context]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +11, Tests +97, Other -1. Total +107 across 5 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Use the existing worker-backed approval reader for reply preparation while preserving the synchronous compatibility callers and execution-time policy owner. Do we have a high-confidence way to reproduce the issue? Not applicable as a functional bug reproduction; source confirms the synchronous caller, and the reported paired Gateway workload measures its SQL before and after. Is this the best way to solve the issue? Yes. Reusing the existing async reader and policy resolver is a narrow cutover that preserves policy ownership and synchronous callers. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against bced15851945. 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
History |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Merged via squash.
|
…ders (openclaw#164648) * 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(exec): prepare reply skill approval defaults asynchronously * test: document exec preparation mock isolation
What Problem This Solves
Reply skill preparation synchronously reads exec approval policy on every turn, including shared-state admission and ownership checks on the Gateway thread.
Why This Change Was Made
ensureSkillSnapshotnow uses the existingresolvePreparedExecDefaultsAsyncandloadExecApprovalsReadOnlyAsyncreaders, then carries the resolved defaults into the existing node-eligibility calculation. Policy precedence, sandbox/full-session short circuits, node bindings, and thesystem.rundeny check stay with their current owners. Read failures retain the existing deny/refusal behavior; there is no native retry.Scope is limited to reply skill preparation:
createOpenClawDelegateToolsForRunis excluded and remains owned by #138596's delegated approval-authority repair. Its measured warmed direct reads remain 10 → 10. Other synchronous callers remain outside this lane; this does not retire the shared primitive or reclassify it as worker-only.Prerequisites #164490 and #164514 are merged. This branch now targets main and integrates
06d4475d6079aaa875a9b477ac0935d1459b1023through merge commit41836cc9f6baf8f3231da18d774c24ca9a3fe468, without rebasing. The production delta remains unchanged. The diff contains the four exec-preparation files plus a one-line shrink of the mock-export baseline required by the integrated main guard; the history has one merge base. The original before/after measurements below used integrated base4b27b04c2c8348528dbbef7bace70700be16f3be.User Impact
No user-visible policy change, new worker service, cache, schema, retention/durability change, migration, or new environment name. Prepared skill availability is not execution authority; existing execution-time approval checks and session publication guards remain in place.
Lane production LOC: +23 / −12 / net +11 (35 changed lines), excluding prerequisite commits. Production files:
src/agents/exec-defaults.tsandsrc/auto-reply/reply/session-updates.ts; tests: the existing session-updates suite plus its new exec-preparation boundary suite.Evidence
The unchanged local sqlmeasure harness ran before and after with Node 24.21.0 / SQLite 3.53.4, source maps, isolated synthetic state, and the same local streaming model fixture. Both runs completed 13/13 top-level chat receipts, child completion, cron, compaction, and graceful shutdown. All observed on-disk database locations stayed inside their synthetic fixtures.
Selected caller: 3.2 → 0 main-thread statements per warmed turn, 32 → 0 over ten turns, and 41 → 0 across the whole workload. The 32 warmed statements were 10 direct approval reads, 12 admission checks, and 10 ownership checks. Static T1 remains 921 → 921, since the shared primitive retains other callers.
Overall warmed mean: 343.9 → 342.4; median 338 → 335. Whole-workload main-thread totals: 9,504 → 9,436. Phase windows include concurrent maintenance, so the overall delta is not all credited to this patch. This is one run per revision and not a latency benchmark. Failed statements are separate: baseline had two main-thread and two off-main errors; after had none.
Successful main-thread SQL by phase and turn
Counts exclude prepares and failed statements; trigger internals are outside the observer contract.
Final-head validation (
a99909f3484eccde4d5ec11146ed21e5d2be122e):pnpm test src/auto-reply/reply/session-updates.exec-preparation.test.ts src/auto-reply/reply/session-updates.test.ts --maxWorkers=1: 9 passed, 83.11 s wall. This confirms zero caller-thread approval SQL, captured-store routing, worker-read failure denial, and session deletion/rebound/rename/unpin handling on the final head.node --import ./scripts/tsx.mjs scripts/check-test-mock-exports.mts --base 06d4475d6079aaa875a9b477ac0935d1459b1023: passed, 10,848 grandfathered factories. The canonical pruning command removed exactly the obsolete exec-defaults mock entry; no baseline allowance was added.git diff --checkpass.a99909f3484eccde4d5ec11146ed21e5d2be122edocuments their isolation and prunes the removed factory. Production code, assertions, and factory behavior are unchanged. Final-head CI passed with no rerun or admin exception.Integrated-head proof (
41836cc9f6baf8f3231da18d774c24ca9a3fe468):Original-head validation (
c481aed2180845ffc8d191252d725a6cb716aa99):pnpm test src/auto-reply/reply/session-updates.exec-preparation.test.ts src/auto-reply/reply/session-updates.test.ts src/agents/exec-defaults.test.ts src/infra/exec-approvals-store.read-worker.test.ts --maxWorkers=1: 56 tests passed, 349.32 s wall including cold worker compilation. The two changed reply files shared a 42.77 s shard; their test execution was approximately 0.079 s (existing suite) and 3.325 s (new boundary suite).pnpm test test/scripts/runtime-process-build-graph.test.ts test/scripts/eager-import-closure.test.ts src/auto-reply/reply/get-reply.imports.test.ts src/state/openclaw-state.worker.imports.test.ts --maxWorkers=1: 30 tests passed, 419.93 s wall.pnpm check:madge-import-cycles: 0 cycles, 42.28 s.pnpm check:database-worker-ratchet --base 58b544712d0349f85a06fda6a249f872012582a1: passed, 17.82 s.Tooling recovery: the interrupted initial setup retained its own build lock; it was released using the documented recovery after verifying its processes had exited. An initial regression invocation failed before running tests because the concurrent Gateway build changed the compiled namespace. Builds and tests were then serialized; the stable original-code run failed for the intended regression, and the candidate passed. These tooling failures are not counted as product regressions.
Released SDK comparison generated against
v2026.9.8(digest890cdcee): 8 entrypoints removed, 1 added, and 2,307 affected exports across the full branch history. The lane adds an optionalpreparedDefaultsargument to an indirectly reachable declaration; existing one-argument synchronous calls and their return type remain supported. This lane removes no entrypoint or export. The report is not a zero-diff compatibility assertion for all changes since the release. The SDK command exited successfully after cleanup (2,245.35 s wall).node scripts/check-changed.mjs --base 58b544712d0349f85a06fda6a249f872012582a1 -- <the four lane files>passed (2,591.15 s wall), including production types, all 27 test type graphs, formatting, lint, dead exports, and the selected guards. No required local gate remains unrun. CI seconds are not yet available at publication.