Repository navigation
refactor: move exec policy writes off the Gateway thread - #167115
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
|
Codex review: needs maintainer review before merge. Reviewed October 8, 2026, 2:40 PM ET / 18:40 UTC (Revision 6). ClawSweeper reviewWhat this changesMoves execution-policy mutations and agent-policy cleanup to the shared database writer while retaining synchronous current-policy checks before command execution. Review scores
ProductKind: Refactor · Worth it: Yes Merge readiness✅ Ready for maintainer review This PR remains useful and has no actionable blocking finding at the pinned head. Earlier test-routing and merge-conflict concerns are resolved, and the maintainer-authored work should remain open for landing. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherExecution policy controls which commands agents and plugins may launch. Gateway, CLI, and node requests update the shared SQLite policy; launch guards consume current policy immediately before execution. flowchart TD
A[Gateway and CLI policy requests] --> B[Captured requester and database authority]
B --> C[Shared database writer]
C --> D[Current policy and deletion checks]
D --> E[Persisted execution policy]
E --> F[Prepared live policy reader]
F --> G[Final launch authorization]
G --> H[Execute or refuse command]
Technical reviewBest possible solution: Keep policy mutations in the existing writer owner and preserve the live synchronous launch guard until the documented SDK retirement conditions are met. Do we have a high-confidence way to reproduce the issue? Not applicable as a standalone bug report; current-main source confirms synchronous policy writes, and supplied production-owner measurements demonstrate the scheduling change. Is this the best way to solve the issue? Yes. The patch reuses the shared writer and reader lifecycle owners, migrates internal callers together, and retains the released synchronous policy boundary. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against b3b40e1615d5. Provenance checked
TestingProof path: in-process harness. Added test files: 18. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +513, Tests +618, Docs +27, Other +1. Total +1159 across 48 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: LabelsLabel changes: No label changes. Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (5 earlier review cycles)
|
|
@clawsweeper re-review Integrated main in b64be50. The only manual source resolution combined both test imports; main's newer-schema admission diagnostics are preserved. The generated worker inventory was regenerated. Fresh Codex P2 review is clean, core production types and import-cycle checks passed, and all 143 focused reader, policy, authorization, plugin, and cron-grant tests passed on the integrated tree. |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review Current head: 5731460. Both reported consumers now use the existing host-owned fork project. Administrative CLI Bun coverage is preserved and all 25 Bun cases pass. Node proof passes the socket no-replay case and offline owner cases; socket cleanup awaits worker settlement. The CLI observation now permits worker-only SQL while continuing to verify every observed native owner's PID, missing custody, persisted state, and no replay. Fresh P2 review is clean. |
|
🦞👀 Re-review progress:
|
|
Merged via squash.
|
…7115) * refactor: move exec policy mutations to the shared writer * test: complete exec policy worker fixtures * perf: reduce final exec policy authority checks to one read * test: admit the exec authority reader before measuring writes * test: retain host ownership for exec policy consumers * test: align Bun qualification coverage for policy CLI
What Problem This Solves
Exec-policy edits, allowlist usage recording, and agent removal perform synchronous SQLite work on the Gateway thread, while plugin launch guards open write transactions just to check current policy.
User Impact
Policy mutations and agent-policy cleanup use the shared-state writer. Policy revocation still blocks execution immediately before launch or retry, including changes made through a foreign connection. Released synchronous Plugin SDK contracts remain supported.
There are no schema, stored-data, durability, retention, permission, or update-migration changes. The retained final SELECT intentionally makes steady usage plus its guard cost 9 statements instead of 8, while MAIN falls from 8 to 1. Cold authorization also pays once-per-handle reader admission (557→560 total). These explicitly permitted authority costs are counted, not claimed as savings.
Why This Change Was Made
Typed mutations capture their physical source before yielding, share the existing writer FIFO, and reread policy and deletion authority inside synchronous transactions. Host authority is rechecked at transaction and commit admission. Policy edits end the preceding authorization batch; independent cancellation scopes cannot share its failure. Cron uses are fenced before commit, and failed or uncertain work cannot revive revoked uses. Gateway policy RPCs retain requester authority even when clients omit
expectedOwnerId.Preparation admits a read-only handle through the existing reader pool. The final guard runs one indexed current-policy SELECT without a transaction or per-call freshness/schema PRAGMAs. Physical identity, lifetime, integrity, and transaction exclusion still apply; retired readers require fresh preparation. Raw native and foreign writers prevent substituting cached policy facts. The v2026.9.8 synchronous pre-spawn guard and policy readers remain T1; retirement requires the next Plugin SDK major, removal of raw synchronous writers, and complete revocation publication. Doctor retains its native migration adapter; released opaque approval guards retain their named native kernels.
Landing validation
Landing head:
d90e5d7312a6ac71e695c31144c92b08df16f486. Main was integrated in merge commitsb64be50807ac,62189a4dd1dd,51e60184ef749, anda6e5fd509defb. Resolutions retained both reader test groups and worker-access documentation sections, regenerated the inventory, preserved the renamed Gateway media-test route, and adopted main's shared all-thread administrative SQL observer from #167239. Main's newer-schema admission diagnostics remain intact. No SQL-path implementation changed during conflict resolution; the paired SQL and published-driver proof below remains applicable.Fresh P2 review of the integrated policy change and a separate P2 review of the final test repair are clean. The released SDK audit was also checked against
v2026.9.9andv2026.10.1-beta.1: changed mutation callables remain internal, while synchronous policy readers andprepareExecAuthorization(source): () => voidretain their signatures. The original formal SDK report and its explained transitive fingerprints are retained below.Local validation:
onCopytype error; refreshing this checkout's frozen dependencies resolved it. Focused type checks and formatting passed again for the test repair.CI run 37816488133 on
62189a4dd1ddexposed two real test-owner gaps: the administrative CLI fixture and node socket-policy fixture invoked the new worker owner from threaded projects. Commit57314601865bdroutes both through the existing host-owned fork project, preserves administrative CLI Bun coverage, and awaits socket worker cleanup. The final shared observer verifies worker SQL and valid offline custody for every pairing and policy operation, alongside persisted-state and no-replay checks. The same run'schat-outbox-recovery.e2e.test.tsfailure was a 30-second screenshot timeout in an unchanged mocked-Gateway UI flow, unrelated to exec policy. ClawSweeper's earlier routing findings are addressed. A later CI run ona6e5fd509defbfound the expected Bun qualification list had not included the newly qualified CLI suite. Commitd90e5d7312a6aadds that one expected entry; its focused qualification case passed in 5.20 s. Current required CI is tracked separately; older runs are not claimed as current-head success.Evidence
Original paired/package proof head:
63d8523e65f09eca17bbd6da5d80fd51cdad8e3c; comparison base:d327a36593da472032d1d7349b0e62652da815d0. Measurements use643a199eb9847c95b0cd42755960401f2df8b488; the final commit adds only four fixture lines, and production equivalence is verified.Static inventory: T1 797→794, targeted sites 6→3, total counted primitive sites 2,531→2,527. Retained synchronous authority/SDK sites remain T1. Fresh Codex P2 reviews are clean for production and the final fixture correction.
Validation ran on an isolated Hetzner ccx33 host with
CI=1. Times below are measured remote command wall seconds, not a claim about GitHub billed seconds.pnpm test <files> --maxWorkers=1pnpm test test/scripts/worker-deploy-build-plugin.test.ts --maxWorkers=1 -t 'reads exec environment and commits authorization through SQLite workers in a relocated archive'node scripts/check-changed.mjs --base d327a36593da472032d1d7349b0e62652da815d0pnpm check:madge-import-cycles/pnpm deadcode:fullpnpm check:database-worker-ratchet --base d327a36593da472032d1d7349b0e62652da815d0/ inventory on both refspnpm plugin-sdk:api:diff --base d327a36593da472032d1d7349b0e62652da815d0 --head 63d8523e65f09eca17bbd6da5d80fd51cdad8e3c2026.9.8driver × candidate update cellThe focused suites cover foreign-connection denial immediately before spawn, physical-source replacement, FIFO, transaction-local deletion guards, rollback, independent cancellation, maintenance ownership, cron revocation and accepted/unknown work settlement. The sole focused failure included five permitted one-time reader-admission reads inside a zero-SQL observer. The four-line fixture correction admits that reader before observation, leaving writer startup and the original three-operation ordering test intact.
SDK comparison: 0 entrypoint additions/removals and 0 direct exported declaration changes; 131 reachable fingerprints changed across five whole-module fallback sections. This is not an empty diff. The renderer conservatively retains whole transitive modules for unindexable declarations; the changes include private mutation/store/config declarations. Inspection of current and v2026.9.8 SDK barrels, runtime fields, root exports and package subpaths found no changed mutation callable exposed publicly. The synchronous policy readers and
(source) => () => voidprepareExecAuthorizationcontract remain intact. Review digest:02fd5b751352089655b35e8f002ff551e2696432835c808afd7087616d2ac5f2.The 104,161,138-byte candidate tarball has SHA-256
b289ae6bfe48cd8468108010765550cf732bea74a95965393a424064ca8c5bfc. The published-driver cell verified candidate commit63d8523e65f09eca17bbd6da5d80fd51cdad8e3cand build ID2026.9.8-63d8523e65f0-2026-10-08T09-11-20.660Z, readiness 200, durable/incognito post-update checks and service stop. Every cell step exited 0. Both package versions are 2026.9.8, so the commit/build ID supplies the candidate identity.Remote admission took about 73 minutes, with backed-off fleet-limit retries after one AWS provisioning failure. Missing
rg, Corepack activation, Buildx and refreshed Docker group membership were repaired on the isolated host; early environment failures did not run the update workload. No product exception or baseline expansion was added. The census limitations and measurement scope are explicit below; no completed GitHub CI result is claimed before PR publication.Current-base shared-workload sanity pair
One alternating M,C pair on the same Hetzner ccx33 host, Node 24.21.0, using the shared workload unchanged. This is the acceleration-rule sanity check after the retained three-pair series below; the only integration conflict was generated inventory, which was regenerated; executable owner files had no conflicts. Values are one-run phase samples with degenerate ranges; warmed values average ten turns. Every phase passes and wall ratios are 0.970–1.026. No full paired rerun is required.
These decreases are observed background variation, not claimed exec-policy savings: the shared workload does not exercise policy edits, removal/restore, usage writes or exec launches. Native SQL errors are zero; SQL census conservation is exact, with no missing contexts or duplicate sends. Both sides retain two unresolved boot transport targets (
workerEnvironments.snapshot,userProfiles.catalog) and two unmatched sends/receives, still counted. Warmed request linkage has no such gap.Current-base direct owner operations and exact attribution
One alternating M,C owner pair. Warm rows are within-process medians [min–max] over three operations; cold and foreign-deny rows are single observations. These are owner-entry-point measurements, not complete Gateway/CLI turn timings. The APIs and returned final guards execute for real, and persisted usage/denial are checked. All threads and helper processes are counted; native SQL errors are zero. Database requests include actual broker open/command sends. Cold raw IPC totals 1,652→1,656 contain 1,650→1,654 esbuild/tsx messages; every excluded loader stack was verified. Actual cold database transports are 2→2.
data_versionprobe. Net +3; not claimed as a cold saving.data_versionper operation. The latter two baseline repetitions also execute workerschema_versionanduser_version; candidate avoids those two probes. Thus per-operation reductions are 2, 4, 4, median4.data_version, machine-state coordination SELECT, policy SELECT, policy UPSERT. DB transports0→1.data_version,schema_version,user_version; retain current policy SELECT and deny result.data_version, one machine-state coordination SELECT, one policy SELECT, one full deletion-journal SELECT, and onetable_info(agent_deletion_journal)(−6); add workerschema_version+user_versionafter the foreign seed (+2). Net−4. Two individual operation-id guards become two batched agent-id/operation-id guards, no single-agent count saving. MAIN22→0; DB transports0→2.schema_version,user_version) after the preceding foreign seed; later operations9,9. No final-read PRAGMAs. DB transports0→1.data_version, one machine-state coordination SELECT (−5); addschema_versionanduser_version(+2), net−3.data_version, one machine-state coordination SELECT; keep exactly one indexed current-policy SELECT.data_version,schema_version,user_version, one machine-state coordination SELECT; keep indexed current-policy SELECT, which still refuses execution.The five cold MAIN admission reads are exactly
PRAGMA data_version,PRAGMA schema_version,PRAGMA user_version,SELECT type, name, tbl_name, sql FROM main.sqlite_schema WHERE type IN ('table', 'index', 'trigger'), andselect "value_json" from "config_machine_state" where "state_key" = ?. The removed worker coordination query isSELECT value_json FROM config_machine_state WHERE state_key = ? LIMIT 1. The retained final read isselect "raw_json" from "exec_approvals_config" where "config_key" = ?.A separate local M,C pair on the same production bytes measured complete usage plus guard at 8 [8–8]→9 [9–9], MAIN 8→1, worker requests 0→1, with zero native SQL errors. Instrumented operation medians were 3.389 ms [2.367–5.169]→34.028 ms [21.583–186.118]. The earlier six-pair single-operation comparison on the prior revision was 8.698×. These async-worker versus in-thread microbenchmark timings are informational, explicitly not duration gates or latency-improvement claims.
Historical three-pair whole-workload measurements and attribution — earlier source
These retained results are historical regression evidence, not final-head proof. Baseline
9ef85029b0d270b57838c84c612ea4f70d145249; candidate evidence carrierce533a3eb9e2cce64b63008f06a3ebb9709becc4, tree7de4989e8704025e2eee6857a7445ed4636df50c, source-patch SHA-256b45b8bd1dbffe95389b56e48d1f142ef33d200a1a24fa9b10cae72e7d8db6b8f. Three alternating M,C pairs on one AWS c7a.2xlarge host, Node 24.21.0 / SQLite 3.53.4, using the unchanged shared workload with a private census observer copy. All six runs passed; native SQL errors were zero.Values are medians [min–max] across three runs. Each warmed sample first averages the ten warmed turns. All-thread counts include helper processes and workers; request counts include open/close transport sends. Every phase duration ratio is ≤1.5.
Combined-window counts retain all work; each median is computed from per-run sums:
Boot+connect+first turn increases by 13, so a decreasing deferred-startup combined window is not claimed. First-turn attribution uses the narrower noise-floor allowance. Compaction/shutdown increases each remain within the ≤10-statement non-turn allowance. No statement relocation is presented as a reduction.
Census conservation is exact, with zero missing SQL-context rows or duplicate sends. Each run retains two unresolved boot transport targets (
workerEnvironments.snapshot,userProfiles.catalog) and two unmatched sends/receives. They remain counted; their originating caller is not claimed fully resolved. Catalog observations are attributed to unchanged owners, not assumed to be timers.The shared workload does not execute policy edits, deletion rollback, usage writes, or exec launches. Its warmed −0.9 statement/−0.2 request difference is not claimed as an exec-policy saving. The current-base sanity pair is reported above.
Focused test commands
The corresponding remote
CI=1wall times are 78.6 s, 28.9 s and 145.1 s. GitHub CI will attach after publication; no completed hosted run is claimed.