Repository navigation
refactor(gateway): offload approval grant administration - #162549
Conversation
Infer shared-state worker command contracts from lazy per-domain handler tables. Migrate Web Push, APNs, worktree registry operations, and fleet registry while preserving the existing broker and transaction owners.
|
🦞👀 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: blocked before merge. Reviewed October 1, 2026, 8:30 AM ET / 12:30 UTC (Revision 13). ClawSweeper reviewWhat this changesThe branch moves approval-grant listing and revocation into existing database workers, consolidates approval dispatch, and prepares Discord capture workers before testing. Merge readiness⛔ Blocked before merge - 1 item remains This remains useful, unmerged work. The prior conflict blocker is resolved, and the reviewed diff has no actionable correctness or security findings. Priority: P2 Review scores
Verification
How this fits togetherOpenClaw’s approval subsystem stores operator decisions and reusable grants for scheduled commands. CLI and UI requests inspect or revoke those grants, while command launch independently checks whether execution remains authorized. flowchart TD
A[CLI and approval UI] --> B[Gateway approval requests]
B --> C[Live requester authority]
C --> D[Read-only worker]
C --> E[Guarded write worker]
D --> F[Approval database]
E --> F
F --> G[Grant ledger or revocation result]
F --> H[Native command launch checks]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +9, Tests +139, Other +2. Total +150 across 36 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Technical reviewBest possible solution: Keep grant administration with the existing worker owners while preserving native launch checks, live requester authority, and established stored-state semantics. Do we have a high-confidence way to reproduce the issue? Not applicable to an internal refactor; the original synchronous administration path and proposed worker boundary are directly identifiable in source. Is this the best way to solve the issue? Yes. Reusing the existing read transport, guarded writer, and typed registry avoids a competing storage or authorization owner. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against a9074f2454c3. 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 (12 earlier review cycles; latest 8 shown)
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
Resolve the shared worker registry conflict by retaining every main domain alongside operatorApprovals and execApprovals. Preserve the existing synchronous cron launch boundary.
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
Preserve all registered worker domains and retain the completed exec facade retirement while resolving conflicts. Approval authority, cron launch, and stored-state contracts remain unchanged.
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
Apply the lockfile-only fix from main 4b32b40. The CI build prunes the duplicate @pnpm/exe environment entry and leaves the checkout dirty, causing prebuilt real-Gateway UI setup to refuse it. Application dependency bytes and pinned versions are unchanged.
Dependency graph guard clearedThis PR no longer has dependency changes awaiting review. A future dependency graph change from an external contributor requires a maintainer's
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
Retain userProfiles alongside both approval registry domains. Preserve the normalized pnpm lockfile and all main domain registrations.
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Merged via squash.
|
…2549) * refactor(state): register worker operations once per domain Infer shared-state worker command contracts from lazy per-domain handler tables. Migrate Web Push, APNs, worktree registry operations, and fleet registry while preserving the existing broker and transaction owners. * refactor(gateway): run operator approval grants in workers * test(agents): retain cron grant worker test routing * fix(gateway): break approval worker type-import cycles * refactor(gateway): keep cron grants at the launch boundary * fix(test): prepare Discord capture workers before test admission * fix(deps): drop stale package-manager lock metadata Apply the lockfile-only fix from main 359ebb7. The CI build prunes the duplicate @pnpm/exe environment entry and leaves the checkout dirty, causing prebuilt real-Gateway UI setup to refuse it. Application dependency bytes and pinned versions are unchanged.
What Problem This Solves
Standing-grant list/revoke administration still performs SQLite work on the Gateway thread, and approval worker commands duplicate dispatch and type declarations outside the shared typed registry.
User Impact
Grant administration runs through the existing SQLite workers with live requester-authority checks. Cron exec grant validation and consumption retain current main's synchronous native-launch behavior. The Gateway exec implementation and launch tests match integrated main
b9c7034d1bcdfcb19fbd82e4526a366b4aa54fb4byte-for-byte; the cron validation/consumption transaction remains native.No schema, stored-state, retention, durability, permission, configuration, or updater/Doctor behavior changes. The shipped v2026.9.4
sessionMutationCommitGuardnative-compatibility path and boot-only approval cleanup/pruning remain intact.Deferred launch-authority work:
Why This Change Was Made
Register OperatorApproval operations and
execApprovals.commitAuthorizationsthrough the typed handler registry, sharing transaction admission and resolution receipts with the retained native SDK path. Shared DTOs stay in leaf modules so worker-derived contracts do not create static import cycles. Related to #162446.The Discord capture E2E now uses the existing runner admission helper to compile its workers before Vitest starts. This prevents cold compilation from consuming the case deadline without changing timeouts, assertions, or Gateway behavior.
Only grant list/revoke RPC storage is offloaded in this grant cutover: listing uses the existing read-only worker transport; revocation uses the registered guarded writer. RPCs recheck authority after settlement, and revocation rechecks it at transaction admission and commit. Allow-once approval consumption stays with its existing transaction owner.
The cron validate/consume worker commands and async facades were removed, along with the cron validation read command, extracted exec helper, and worker-only cron tests. Current main's native path is restored without a compatibility layer. The test API registration in
exec-approvals-sqlite.tsuses typedObject.assigninstead of the undocumented assertion; the obsolete old-store assertion exemption was removed without adding exceptions.Production diff against integrated main
b9c7034d1bcdfcb19fbd82e4526a366b4aa54fb4: +415 / −406 / net +9, within the +90 ceiling. Production means non-test/non-test-support.tsundersrc/,extensions/, andpackages/. The shared-state changes are registry wiring and existing read transport integration; the broker lifecycle is unchanged.Evidence
139 tests in 8 focused files passed. Each row ran
pnpm test <file> --maxWorkers=1withOPENCLAW_VITEST_NO_OUTPUT_TIMEOUT_MS=1800000; wall times include wrapper/compiler setup.src/agents/bash-tools.exec-host-gateway.test.tssrc/gateway/operator-approval-standing-grants.test.tssrc/gateway/server-methods/approval.legacy-authority.test.tssrc/gateway/operator-approval-store.worker.test.tssrc/gateway/operator-approval-store.test.tssrc/infra/exec-approvals-store.read-worker.test.tssrc/infra/exec-approvals-authorization.worker.test.tssrc/state/openclaw-state-worker-registry.test.tsThe restored launch tests cover standing-grant execution without prompting, consumption at the pre-spawn boundary, and denial when the parent approval is revoked after consultation. Admin grant tests prove no SQLite statements execute on the calling thread for list/revoke, rejected commit authority rolls revocation back, and RPC authority is checked after storage settlement. Real worker/SQLite and native-compatibility coverage justify the longer integration files.
pnpm tsgo:core: passed.node scripts/run-oxlint.mjs --tsconfig tsconfig.core.json <changed files>: passed.pnpm check:assertion-safety --base 347b627f9c0c63b439a080087dbe5d9752ca3fce: passed; baseline change is the exact deletion of the obsoletesrc/infra/exec-approvals-store.tsentry.pnpm check:madge-import-cycles: passed, 0 cycles, with configuration and exceptions unchanged.pnpm check:database-worker-ratchet --base e2e4a34c9828f1230d906567c0eacb7b1e1fe185: passed.git diff --check: passed.The description uses the current PR template headings, including
What Problem This Solves. CI timing will come from the normal updated-head run; no workflow reruns were dispatched for proof.Main
9ced5fc07daee9af43fa2a7542f7543bdd651648is integrated through merge commit6ecb2c21b3c7d5d394846799f5cab0a4096ff7f8; the registry retains all main domains plusoperatorApprovalsandexecApprovals. The 139 focused tests also passed on that merged source in a combined 238.13s, with core typecheck, ratchet, madge (0 cycles), and P2 autoreview clean.Capture E2E admission repair
The two hosted attempts timed out in
test/e2e/gateway-transcripts-discord-capture.e2e.test.ts > Gateway admitted Discord transcript capture > fences late STT and preserves the admitted owner's history after a room route changes. The second failed job compiled 11,889 worker inputs for 33.820s inside the test's first dynamic import. The first turn was submitted at 115.785s and completed at 122.780s, past the unchanged 120s deadline.The runner already prepares known worker users before Vitest starts, but its selection omitted this E2E. Add that file to
shouldPrepareVitestCoreWorkers. Both direct-runner andpnpm testregression cases failed before the change withprepared: falseat Vitest spawn; the existing suite now passes all 51 cases. This is a shared harness omission, not a two-minute approval transaction wait. No authority or timeout workaround was added.A paired cold-cache reproduction used Blacksmith Testbox
tbx_01m3vj1d8pjxe2hazdkd88x0p1, run 36852794722, Node 24.19.0 on 8 vCPUs. The capture test ran first on both revisions, matching the failed shard order; disposable phase/CPU instrumentation and Gateway startup tracing were the only source modifications. Both completed successfully on this faster host, while both reproduced compilation inside the test. This does not claim a main timeout was reproduced.6ecb2c21b3c70ac1c241fba8b46efef77afbRepair validation:
Fixed capture E2E on the same Testbox: passed, 61.70s command wall, including cold worker compilation before Vitest starts. The capture source was verified unchanged; the final run used fresh filesystem/module caches and disabled compiler-cache reuse. Command:
CI=1 OPENCLAW_VITEST_NO_OUTPUT_TIMEOUT_MS=1800000 OPENCLAW_E2E_USE_PREBUILT_DIST=1 OPENCLAW_VITEST_WORKER_CACHE=0 OPENCLAW_VITEST_FS_MODULE_CACHE_PATH=/tmp/operator-approvals-discord-fixed-fs NODE_COMPILE_CACHE=/tmp/operator-approvals-discord-fixed-compile pnpm test test/e2e/gateway-transcripts-discord-capture.e2e.test.ts --maxWorkers=1.pnpm test test/scripts/vitest-worker-artifacts.batch.test.ts --maxWorkers=1: 51 passed, 53.33s wall. The two added cases take the existing controlled-compiler path and prove compile-before-spawn ordering through both public runners. The file's existing real subprocess lifecycle, failure, and cancellation coverage accounts for its cost.pnpm test src/gateway/operator-approval-standing-grants.test.ts src/gateway/operator-approval-store.worker.test.ts src/infra/exec-approvals-authorization.worker.test.ts --maxWorkers=1: 44 passed, 100.22s runner wall.node scripts/check-changed.mjs --base 9ced5fc07daee9af43fa2a7542f7543bdd651648 -- scripts/lib/vitest-runtime-selection.mts test/scripts/vitest-worker-artifacts.batch.test.ts: passed, including script/root-test typechecks and targeted lint.pnpm check:madge-import-cycles: 0 cycles.pnpm check:database-worker-ratchet --base e2e4a34c9828f1230d906567c0eacb7b1e1fe185: passed.Fresh Codex autoreview through P2: scoped-clean.
This repair adds 0 production LOC, 3 tooling LOC, and 9 net test LOC. At the original repaired head, production was +510 / −496 / net +14; the current integrated-head totals above account for main’s completed facade retirement. No further hosted workflow reruns or merge submissions were requested for the repair.
Previous integrated candidate
Merged main
b9c7034d1bcdfcb19fbd82e4526a366b4aa54fb4through merge commitebda96c2fd816422e41bb39cde69e550fe133ebdto resolve actual conflicts. All main worker registry domains coexist withoperatorApprovalsandexecApprovals; superseded dispatch and type declarations remain removed. The resolution also preserves main’s completed exec facade retirement from #162333, so moved helpers do not resurrect retired APIs. The exec launch implementation and tests match integrated main. No schema, durability, retention, permission, or update contract changed.Validation on the resolved tree:
node scripts/run-vitest.mjs <files> --maxWorkers=1.test/scripts/vitest-worker-artifacts.batch.test.ts: 51 passed, 30.03s runner wall, including both Discord capture compile-before-spawn cases.git diff --check: passed. Direct repository Node wrappers reused the existing installation without dependency reconciliation. The ratchet compared against the original common base9ced5fc07daee9af43fa2a7542f7543bdd651648while the merge was staged.b46efef77afbwith no actionable source or security findings and accepted the documented capture harness repair. Its conflict blocker is resolved here; its generic data-model checklist is unsupported by a stored-contract delta, and the focused previous-schema-reader/candidate-reopen case passed again.The earlier capture timeout and its cold-cache repair evidence above remain recorded. Current-head GitHub CI is tracked separately; these local results do not claim hosted CI success.
UI prebuilt source-state repair
Prior-head CI run 36858008070 failed both real-Gateway UI shards before tests, in
assertPrebuiltUiE2eRuntimeattest/vitest/vitest.ui-e2e-prebuilt.global-setup.ts:57. That gate runsgit status --porcelain --untracked-files=alland refuses nonempty output or Git failure. The gate is unchanged.Root cause: dependency-refresh commit
2918779dbf3c, included by the merge, added a stale duplicate@pnpm/[email protected]entry to the lockfile's package-manager environment document.pnpm buildprunes that entry and its package/snapshot records, dirtyingpnpm-lock.yaml. Main fixed this in4b32b401503d, just after this branch's conflict-resolution merge. This classifies the failure as inherited stale generated metadata, rather than an approval/worker behavior regression.Commit
384bf1fbeac9commits the normalized lockfile. Its blob7c44ac974c7fb1f0515c50589c5267684306fb3eis byte-identical to main's lockfile-only fix. The application dependency document and pinned versions are unchanged. The repair deletes 25 metadata lines and changes no source or harness checks.Validation:
OPENCLAW_BUILD_PRIVATE_QA=1 OPENCLAW_RUN_NODE_SKIP_DTS_BUILD=1 pnpm buildpassed in 115.52s but changed onlypnpm-lock.yaml; invoking the unchanged prebuilt-UI guard reproduced source state is dirty or unavailable.OPENCLAW_BUILD_PRIVATE_QA=1 OPENCLAW_RUN_NODE_SKIP_DTS_BUILD=1 OPENCLAW_BUILD_ALL_NO_PNPM=1 pnpm buildpassed in 135.90s andgit status --porcelain --untracked-files=allwas empty.node --import ./scripts/tsx.mjs --input-type=module -e 'import {assertPrebuiltUiE2eRuntime} from "./test/vitest/vitest.ui-e2e-prebuilt.global-setup.ts"; console.log(assertPrebuiltUiE2eRuntime(process.cwd()))'.OPENCLAW_VITEST_NO_OUTPUT_TIMEOUT_MS=1800000 pnpm test test/vitest-ui-e2e-prebuilt.test.ts src/gateway/operator-approval-standing-grants.test.ts src/gateway/operator-approval-store.worker.test.ts src/infra/exec-approvals-authorization.worker.test.ts --maxWorkers=1: 57 passed, 98.87s wall, including all 13 prebuilt-UI admission tests.pnpm check:madge-import-cycles: 0 cycles.pnpm check:database-worker-ratchet --base e2e4a34c9828f1230d906567c0eacb7b1e1fe185: passed.git diff --checkand fresh Codex autoreview through P2: clean.This repair adds 0 production LOC; the full PR remains +415 / −406 / net +9. These are local preparation and focused-test results, not a claim of a new hosted UI run. No workflow retry, admin exception, merge request, or auto-merge was submitted for this repair.
Current landing candidate and UI E2E setup repair
The prior run
36858008070failed both real-Gateway UI E2E shards before test admission with “source state is dirty or unavailable.” The coordinator traced this to stale@pnpm/exepackage-manager metadata:pnpm buildpruned it frompnpm-lock.yaml, leaving a dirty checkout. Commit384bf1fbeac947155060a20cf693fb9ae23f28aeapplies main's exact normalization from4b32b401503d63edd0162b84072bd0deb2574cb0; application dependency versions and bytes are unchanged. This supersedes the earlier unresolved-attribution stop.Final candidate
d6b581d6fbc678129d9975c38373fba4c794ca88merges mainab1b93295ad0f0c093563585bbc76f2e6ce39686to resolve the new registry conflict.userProfiles,operatorApprovals, andexecApprovalsall remain registered, and the lockfile matches integrated main exactly. No schema, stored-state, permission, retention, durability, or updater behavior changed.On this resolved source, all 139 focused tests passed in 122.66s runner wall. Core typecheck, the database-worker ratchet (effective common base
b9c7034d1bcdfcb19fbd82e4526a366b4aa54fb4while staged), formatting, and diff checks passed; Madge reports zero cycles. Fresh Codex autoreview of the complete candidate against integrated main through P2 is scoped-clean. The earlier 51 passing runner regression cases remain applicable because their source and owning implementation are unchanged. Current-head CI and ClawSweeper completion remain separate landing gates.