Repository navigation
perf(agents): carry prepared exec policy into delegate tool construction - #165012
Conversation
Prepare delegate exec policy through the existing async readers for each construction and permission refresh. Carry the captured source and recheck live authority before publishing tools; unavailable approval policy remains fail-closed. Migrate bundled harness, Gateway, inventory, skill, cron, compaction, and placement callers. Add awaited SDK factories while retaining deprecated synchronous signatures through the next Plugin SDK major. Schemas, stored bytes, retention, and update behavior are unchanged.
|
🦞👀 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:
|
|
Codex review: blocked before merge. Reviewed October 4, 2026, 4:10 PM ET / 20:10 UTC (Revision 8). ClawSweeper reviewWhat this changesThe PR moves delegate approval-policy reads into existing database workers, migrates bundled tool construction to awaited factories, and preserves released synchronous plugin SDK factories. Merge readiness⛔ Blocked before merge - 2 items remain Keep open with no actionable findings. The integrated-head SDK report resolves the previous checkpoint, and current main still lacks this optimization. Priority: P2 Review scores
Verification
How this fits togetherAgent tool construction combines session permissions, execution policy, and available capabilities into the tools an agent can call. Delegate tools use those prepared policies while existing runtime owners enforce live execution authority. flowchart TD
A[Session and execution settings] --> B[Tool construction]
B --> C[Existing database readers]
C --> D[Fresh approval policy]
D --> E[Live authority check]
E --> F[Bound agent tools]
F --> G[Authorized tool dispatch]
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: Use awaited construction for bundled runtimes while retaining released synchronous factories through their documented SDK migration window. Do we have a high-confidence way to reproduce the issue? Yes: current-main source still resolves delegate policy synchronously, and the captured Gateway workload measures those reads before and after. This read-only review did not execute the workload or tests. Is this the best way to solve the issue? Yes: the patch reuses existing worker readers and one shared assembler, while retaining the released synchronous SDK contracts. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against a2697c13548d. 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 (7 earlier review cycles)
|
Fix stale factory mocks and two existing call assertions exposed by CI. Keep the behavior assertions and prune only obsolete mock-baseline entries. Validation: 127 focused cases passed; targeted lint, formatting, mock ratchet, and P2 review are clean.
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
Document conservative deny defaults for ordinary approval-read errors while retaining rejection for migration errors and lost authority. Match the existing reader and delegate regression, addressing the ClawSweeper documentation finding.
Merge main at 90c4d9a without rebasing. Preserve its asynchronous auth-profile source preparation while keeping the awaited delegate construction paths and live authority checks. Route cron through the internal async factory and exclude the private auth source hint from both public SDK factory signatures.
Merge main at 3071b14 without rebasing. Keep both catalog and delegate worker-flow descriptions, and place delegate preparation beside the related skill-library flow. The code and test patch against main is unchanged from the previously reviewed candidate. This also incorporates the main fix for queued setup inputs in 7ecc80a.
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Merged via explicitly authorized admin squash with attributed pre-existing CI failures.
|
…ion (openclaw#165012) * perf(agents): carry prepared exec policy into delegate construction Prepare delegate exec policy through the existing async readers for each construction and permission refresh. Carry the captured source and recheck live authority before publishing tools; unavailable approval policy remains fail-closed. Migrate bundled harness, Gateway, inventory, skill, cron, compaction, and placement callers. Add awaited SDK factories while retaining deprecated synchronous signatures through the next Plugin SDK major. Schemas, stored bytes, retention, and update behavior are unchanged. * test(agents): validate async tool construction callers * test(agents): finish async tool factory fixture migration Fix stale factory mocks and two existing call assertions exposed by CI. Keep the behavior assertions and prune only obsolete mock-baseline entries. Validation: 127 focused cases passed; targeted lint, formatting, mock ratchet, and P2 review are clean. * docs(sdk): clarify failed exec approval reads Document conservative deny defaults for ordinary approval-read errors while retaining rejection for migration errors and lost authority. Match the existing reader and delegate regression, addressing the ClawSweeper documentation finding.
What Problem This Solves
Delegate tool construction still resolves exec approvals synchronously on the Gateway thread. This performs five approval-related SQL statements per warmed turn, even though the existing owner already has an asynchronous reader.
Why This Change Was Made
Prepare fresh, source-bound exec defaults immediately before each construction and permission-mode refresh, then carry those facts into delegate construction. Reuse the preparation and read-only worker owners from #164648; preserve live host/grant checks after awaited work and before dispatch, and fail closed when the approval read fails.
Add
createOpenClawCodingToolsAsyncandhostCapabilities.createToolSurfaceAsync, and migrate every bundled runtime caller: embedded turns and refreshes, compaction, Gateway/MCP/HTTP, inventory, placement, skill/cron dispatch, system-prompt inspection, and the Codex, Copilot, and AgentsAPI harnesses. The released synchronous factories retain their signatures and completion timing, with@deprecatedguidance, a compatibility record, migration docs, and a signature test. Doctor retains its synchronous one-shot contract (src/flows/doctor-tool-schema-projection.ts:132).User Impact
No intended user-visible policy change. Each construction still observes a fresh approvals read; there is no run-wide snapshot. Physical store identity is captured before yielding, and prepared facts do not grant execution authority. MCP cancellation remains scoped to construction, while cached tools keep their live invocation checks. Worker execution rechecks its receipt after preparation.
No new service, cache, schema, retention, durability, transport, or database-admission implementation. No new
OPENCLAW_*names. Update behavior and existing close/settlement ownership are unchanged, so a published-driver update cell is not required for this lane.The async SDK addition is explicitly approved; the sync paths remain until the next Plugin SDK major and explicit breaking-release approval. Indirect SDK reachability was checked against v2026.9.8: the released factories remain intact; the changed worker tool callback fields were absent from that release.
Original reviewed candidate production diff: +522 / −211 / net +311 (733 changed lines) in
src/andextensions/, excluding tests/support. The factory shares one assembler between the async runtime and deprecated sync entrypoints.Evidence
Local sqlmeasure3 workload on Node 24.21.0, pinned baseline
82adb7a49d36versus the measured implementation ind476ce11c4cd. Both runs completed 13 top-level turns, successful delegated child and cron work, committed compaction, and graceful Gateway exit[0, null].Warmed MAIN counts: before
[223,223,227,221,223,223,223,223,223,223]; after[215,212,215,222,243,248,210,215,215,215]. The after run has 58 more non-delegate statements in its warmed windows (including admission, ownership, and recovery work), so the raw mean is reported alongside the exact caller-attributed cohort. Counts excludeprepareand failed executions; multi-statementexeccalls are split. The static inventory stays unchanged because the synchronous SDK/Doctor contracts retain the shared kernels.Removed warmed caller stacks:
openclaw-delegate-tool.ts→ shared-state admission (3.0/turn), ownership (1.0), andexec-defaults.tsapprovals (1.0), plus agent read-version/session-entry/session-participant classification (3.0). All six underlying site groups have zero MAIN statements attributed to delegate construction afterward. Build wall time: 134.1 → 285.8 s; workload wall time: 102.2 → 180.4 s on the loaded shared host. The later lint correction restores a synchronous MCP inventory projection return; the workload does not calltools.effective, and none of its measured construction paths changed afterward.SDK diff: local committed refs
82adb7a49d36→d476ce11c4cd, physical private TMPDIR, 588.99 s. 0 entrypoints added/removed, 1 export added, 0 removed; 161 exports affected by reachability, 13 distinct changed declarations. Ack digest:8102b1bb. Subsequent changes are test routing/fixtures, the exact approved SDK surface budget, and removal of a redundant await from the synchronous MCP inventory projection; public declarations are unchanged.Focused tests used
pnpm test <files> --maxWorkers=1: 56 files, 989 passing cases, one Linux-only SDK-report case skipped on macOS. These are cumulative results across scoped batches, including the exact successful replays described below. No requested focused file remains unrun.The three new delegate boundary test bodies total 2.722 s locally. CI seconds are not inferred from local wall time. Shared-registry/runtime/import-closure gates passed 4 files / 30 tests, including
runtime-process-build-graph,openclaw-state.worker.imports,get-reply.imports, and all 17 eager-import-closure cases (that shard: 67.86 s). Madge: 0 cycles, 61.04 s. Database-worker ratchet passed against the pinned base. New environment names: 0.Fixture repairs: broker-backed policy tests now use the existing forked owners; async mocks/callers await construction; MCP's legacy-session assertion accepts the new live-authority callback argument. Full inventory, MCP, cron, and loopback replays passed. The local full changed-file run reached core lint after passing types and export scans; its duplicate type import and unnecessary await were fixed and the exact files passed type-aware lint in 24.29 s. The final root-fixture scoped check passed in 1,117.60 s.
Two timing failures remain disclosed: the full-watch graph hit its existing 120-second subprocess deadline, then passed the same case unchanged in 43.51 s wall time; AgentsAPI PDF steering hit its existing five-second attempt budget, then passed the same case unchanged in 66.17 s. The PDF fixture disables tools. Neither replay is claimed as a code fix, and neither timeout was increased.
Final full
node scripts/check-changed.mjs --base 82adb7a49d36e844e4ea1989bc5d865abac916f0passed throughscripts/crabbox-wrapper.mjson Blacksmith Testbox: command 40m 26.148s, provider run 40m 33.734s, exit 0. The receiver and payload verified the exact candidate tree1bc7f7ff50b55c6a890d8e4af5d0b317240b1872, all 98 changed-file hashes, and the physical checkout before checks. Final commit8a3cf3e35d314dhas that exact tree. Leasetbx_01m43srz3k4kv5ghe90nk4mrjcstopped automatically after success. Testbox workflow; its backing workflow can show cancellation from the completed lease cleanup, so the wrapper's exit-0 receipt is the gate result.An earlier Testbox attempt stopped before validation because my probe compared HEAD with the local commit; this transport uses a verified carrier commit. The final probe checks the candidate tree and bytes, retaining the receiver's source guards.
P2 autoreview of the final staged candidate: scoped-clean, no accepted/actionable P0–P2 findings; base pinned to
82adb7a49d36e844e4ea1989bc5d865abac916f0, private TMPDIR, Codex. A preceding pass caught an index-only missing await in a cron fixture. The already typed working-tree correction was staged and the complete candidate was re-reviewed successfully. No additional production/security finding remained.CI follow-up
Commit
dd1b5668c7b176repairs the eight stale test fixtures exposed by initial CI: six mocked synchronous factory exports and two old embedded-attempt argument assertions. Existing behavior assertions remain intact; seven obsolete mock-baseline entries were removed. The corrected files pass 127 cases in 386.62 s withnode scripts/run-vitest.mjs <files> --maxWorkers=1; type-aware lint, formatting, the mock ratchet, and P2 autoreview passed.The original attribution matrix completed 90 isolated runs on Node 24.21.0: each of nine files ran five times at original head
8a3cf3e35d314and five times at base82adb7a49d36. All eight stale-fixture files failed 5/5 on the PR and passed 5/5 on the base. The memory reindex fixture failed 5/5 on both. Main fixed that resource-close/readmission ordering in83f4c296109bf(#164962); mergefd7686d391d0incorporated it. Post-merge delegate/memory proof passed 27 cases in 353.19 s and MCP public-catalog readiness passed 7 cases in 263.02 s. CI on that head passed. Full-context P2 review was clean; the proposed stale-MCP-catalog finding was rejected because both public return paths revalidate and retry after construction.ClawSweeper identified one P3 documentation issue, corrected in
8b003dcec9ba: ordinary exec-approval read errors use conservative deny defaults; migration-required errors and lost admitted authority reject construction. Formatting and P3 review passed. Trusted reviews subsequently completed8b003dcec9baand06a63457328dafwith no actionable correctness or security findings. Released v2026.9.8 signatures, the compatibility record/type test, and unchanged storage/update contracts address the generic compatibility checklist.CI on
8b003dcec9bafinished all 107 jobs with two independently attributed main failures, their downstream aggregate gate, and no cancellations. The transcript-presence fixture intercepted host SQLite after main0816aa1b57dc(#164989) moved that query to a worker. Its presence result stayed correct; only the obsolete host-spy classification assertion failed. Fifteen causal files were byte-identical between that CI main baseline and tested merge. Five isolated local macOS runs at each revision gave PR 5/5 pass, merge base 5/5 pass, main 5/5 the same failure.The initial-setup UI case likewise failed on main run 37208571327 at
2851e89750f5, withSession setup-proof-session placement authority changedpreceding its expected-two/observed-one launch assertion. Ten isolated Linux browser controls at old PR8b003dcec9baand basebca3c49262e58gave PR 5/5 pass; base 2/5 identical failures and 3/5 pass. Controls used Node 24.21.0 versus CI's 24.19.0. The exact invalidating publication was not identified, and passing repetitions were not claimed as a fix. Main then repaired queued setup runtime reads in7ecc80a4573660; the current branch includes that fix.Main advances created real conflicts. Merge
06a63457328dafcombined main's auth-profile reader preparation with awaited tool construction: cron uses the internal async factory, and both public factories exclude the private auth-source hint. 220 cases across 12 focused files passed in 988.86 s, along with production types, SDK test types, lint, formatting, both ratchets, and full P2 autoreview. Merge5d28f9a120f9d159e44da861f534659ec17113adincorporates main3071b147cce7, including the UI fix, and retains both worker-flow documentation additions. The code/test patch against main has the same stable patch ID as06a6345. Additional current-context proof passed: 3 delegate cases in 283.90 s, production types 44.32 s, SDK test types 135.60 s, docs formatting, and fresh full P2 review. Both integrations are merge commits; no rebase or CI rerun was used.The completed local SDK report for
bca3c49262e58→fd7686d391d0took 1337.18 s and showed one added export, zero removals, zero entrypoint changes, with 161 reachable affected exports (digestbfd1e383d6e5c72962a3a3f3ec69d8bb9235327e55e1e074fbcb8ecd01f92433). The refreshed local SDK comparison3071b147cce7→5d28f9a120f9completed exit 0 in 1095.79 s, including native cleanup: one added export, zero removals, zero entrypoint changes, and 161 reachable affected exports. Final report digest:69e474b2019107034bb87fcb59a553333acc455defe83d9c6386968ace3a347c; acknowledgment69e474b2. The released synchronous signatures remain supported, and both public factories exclude the private auth-source hint.Final-head CI, attempt 1, completed 83 successful jobs, 22 skipped jobs, and the one inherited presence-fixture failure plus its downstream gate; zero cancellations. Both real-Gateway UI shards and
security-fastpassed. The tested merge is8aa3d2fe49e64d47ba5e2be51c65d79750eb0116, with ordered parents maina0c1b065b5b2and reviewed head5d28f9a120f9. Refreshed source comparisons confirm all 15 primary causal files and 13 supporting files match the independently reproduced main implementation; broader main changes were inspected rather than assumed identical. The original controls retain their original refs. The owner has explicitly authorized the native admin route for this independently proven pre-existing failure; the failed fixture is not represented as fixed or green.Trusted ClawSweeper completed the final head at 2026-10-04 19:45:16 UTC, with no actionable correctness or security finding. Its remaining integrated-SDK checkpoint is now fulfilled by the report above. Configuration and storage contracts remain unchanged, with the additive SDK compatibility boundary documented and type-checked. Reported local wall times are not CI seconds.
Overlaps and follow-up
Related: #138596 (delegated approval-authority repair, same function); this change carries policy preparation and preserves the existing authority semantics. Related: #162433 (ownership design draft); this change keeps focused caller/constructor hunks and does not restructure its design. The current base also overlaps shared docs/test lists/wrapper inventory changed by #164891, #164906, #164846, and #164682. This lane reconciles shared-file conflicts through merge commits. Later overlap with #164992, #165034, and #164922 was integrated the same way.
Unrelated synchronous eligibility reads remain follow-up debt:
src/gateway/tool-resolution.ts:247,src/gateway/tool-resolution.ts:479, andsrc/auto-reply/reply/commands-system-prompt.ts:200. No new host SQL is added inside worker grants. The boundary regression asserts zero caller-thread SQL for the moved delegate preparation, including fresh policy changes, captured-store retention, read failure, and revoked construction authority.