Skip to content

refactor(approvals): carry internal authority into worker dispatch - #166050

Merged
steipete merged 4 commits into
mainfrom
dbasync/w6approval
Oct 6, 2026
Merged

steipete merged 4 commits into
mainfrom
dbasync/w6approval

Conversation

@steipete

@steipete steipete commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Internal channel approval resolution and in-process agent approval requests still selected native compatibility transactions, leaving approval lookups, verdicts, malformed denials, and cron grant minting on the Gateway thread after the WebSocket cutover in #162549.

Why This Change Was Made

Carry the exact first-party live guard through internal dispatch and the request authority owner into the existing approval writer. The guard remains live at transaction and commit admission. The existing writer retains physical database identity, authoritative row rereads, foreign-commit freshness, FIFO, cron authority publication, and accepted-write settlement. No new worker, schema, durable state, configuration, or cache is introduced.

Opaque SDK callbacks and unrecognized transport callbacks retain native execution. The shipped contract is v2026.9.8:src/plugin-sdk/gateway-runtime.ts:46 → src/gateway/server-methods/shared-types.ts:477 (GatewayRequestHandlerOptions.sessionMutationCommitGuard). Its shared SQL kernels remain compatibility debt through the next Plugin SDK major.

User Impact

No user-visible decision, permission, retention, durability, or update-format change. First-party approval persistence leaves the caller thread. Production diff: +81 / −7 / net +74 LOC across five files. Static T1: 846 → 846 (reduction 0); the 16 lane sites remain shared with the released native SDK contract.

Existing other-owner source assertions remain live and may perform their pre-existing indexed session reads: src/agents/harness/native-session/binding-authority.ts:193, src/gateway/session-sharing-source.ts:168, and src/agents/agent-harness-completion-recovery.ts:175. This PR does not claim those authority reads are SQL-free.

Evidence

  • Focused real-entry regressions cover internal channel and agent-tool resolution, malformed denial, atomic cron grant minting, revocation immediately before commit, and opaque callback compatibility. The original internal resolution failed the caller-thread SQL boundary test; the candidate passes it.
  • Six focused suites: 145 tests passed, --maxWorkers=1, 700.86 seconds wall time on the shared local host (638.43 seconds Vitest). The final standalone carrier file passes all seven cases in 88.86 seconds wall / 6.56 seconds test time, including worker startup. This registered-router/worker composition is necessary because store-only tests already passed before the defect was fixed.
  • Shared-registry import gates and indirect caller routing: 16 files / 349 tests passed, --maxWorkers=1, 1,894.30 seconds wall. This includes the runtime-process graph, shared-state and reply import closures, channel/instance dispatch, WebSocket custody, agent-tool routing, and real node auto-review. The new database-backed fixture is routed to the host-owned Gateway project.
  • Committed SDK API diff: no changes, cd060c5fde74 → 345619c72051 (digest ff7b090f). Final follow-up 5ce52b9920fe changes only test braces; all production and API inputs remain unchanged.
  • Complete node scripts/check-changed.mjs --base cd060c5fde7434b5834a46bd5b181047db28c021: passed. The only remaining lint diagnostic is an existing max-lines warning in untouched src/gateway/server-close.agent-databases.test.ts.
  • Published npm driver 2026.9.8 → candidate passed on isolated Linux: update exit 0 in 468.701 seconds, final phase finished, /readyz 200, installed build identity and durable/incognito post-update behavior verified. The tarball was built from the pinned base plus the five content-verified production files; its build metadata retains the base SHA. Tarball SHA-256: 350d2415ef73ff9bba8d1a4aff6eb247700c4ea36c31c2a2257e065a247da873. The owned lease is released. Testbox expired during local source preparation and AWS refused vCPU capacity before this successful Hetzner fallback; neither ran candidate code.
  • Madge: 0 cycles. Database-worker ratchet passed against cd060c5fde7434b5834a46bd5b181047db28c021. No new OPENCLAW_* names.
  • Final independent Codex P2 autoreview: scoped-clean, no actionable P0–P2 findings. The typecheck found a fixture-only generic inference error; the explicit payload type and narrow policy import are fixed, and the carrier tests were rerun. Final lint also caught two missing brace pairs in the new test; both are fixed and the complete changed-code gate was rerun successfully.

Focused real-entry SQL measurements use the shared calibrated native observer on MAIN and workers; prepares are excluded, multi-statement execs are split, and measured failures are zero. Setup and post-request verification are outside the request windows. Resolution rows are identical across three warmed samples per route; malformed denial and first grant mint are single samples.

Flow MAIN before → after All threads before → after
Channel resolution 28 → 0 28 → 26
Agent-tool resolution 16 → 0 16 → 14
Malformed verdict denial 28 → 0 28 → 26
Cron grant mint 36 → 0 36 → 34

These synthetic fixtures isolate the moved approval operations; they do not claim removal of the other-owner source reads listed above or measure uninstrumented latency.

Overlap: B2 #165552; cold admission #165680; incognito P7k/P7l/P7m/P7m2 (#165885, #165895, #165890, #165901); locked-write chain (#165859, #165894, #165904, #165921); concurrent SQL-efficiency and W6 entry/auth lanes. Whoever lands second integrates current main. #162433 is now closed and is only historical incidental overlap.

Landing integration and CI diagnosis

Merged main bcae52b9a85a2207a66b3c9927edc17e56261a58 into the branch with merge commit 42ba88eb4e0b85e91fdfe9e42b9a9b847fd1008d (no rebase). The two dispatch-authority conflicts preserve main's prepared question caller-read wiring alongside the approval carrier. Independent P2 autoreview is scoped-clean, and ClawSweeper's review of this head has no actionable findings.

Integrated-tree validation passed: 11 focused files / 119 tests (--maxWorkers=1, 1,547.13 seconds wall), core production types and all 27 core test-type groups, formatting, and Madge with zero cycles. The focused set includes approval decisions and revocation, opaque callback compatibility, question authority, native approval effects, dispatch, the runtime-process build graph, and the PR wrapper source closure. No additional host-owned routing or wrapper inventory changes were needed.

The committed SDK API report for bcae52b9a85a → 42ba88eb4e0b reports no API changes (digest ff7b090f). The released callback signature was also checked directly in v2026.9.8 and v2026.10.1-beta.1; this PR adds no changed public signature, removed export, or new OPENCLAW_* name.

CI run 37446774421 completed with two PR-caused test failures: ci-node-test-plan.test.ts and vitest-cli-ownership.test.ts compare sorted discovery against the Gateway worker inventory, where this PR had prepended its new test. Their failing CI invocations took 82.56 seconds and 8.95 seconds, respectively. Five full-file runs per file on the PR reproduce the mismatch; five runs per file on the merge base pass (114/114 planner tests and 10/10 CLI ownership tests). The fix belongs in the inventory ordering; no assertion, worker ownership, permission, or runtime behavior needs to change.

The inventory correction is f6044feb22416bc2156beb95bcbf8f907da6af62: it only moves the existing entry into alphabetical position. Both complete failing files now pass all 124 tests (--maxWorkers=1, 219.20 seconds wall; 214.09 seconds Vitest), and a fresh independent P2 autoreview is scoped-clean. All production and SDK inputs are byte-identical to 42ba88eb4e0b, so the integrated runtime/type/import and SDK evidence above remains applicable. No assertions were weakened and no retries or sleeps were added.

Final-head inherited CI failure

CI run 37452119586, attempt 1 tested head f6044feb22416bc2156beb95bcbf8f907da6af62 through merge b352013f3e595c7363db1bb76ffbb841e2261d98, whose main parent is 46ba1d11d1b1f29610f84e87d627550f63a8f3b6. Its sole root failure is job 112231318431, server-rpc-restart-owner.test.ts / records an actual RPC queued reply awaiting final delivery during restart: a 120-second test timeout followed by a 180-second cleanup timeout. The aggregate CI gate also fails; all other selected jobs passed and none were cancelled.

This is inherited from main #165996 (602c0e8ca10ef8e8c1abec2d0c50ce8f86983539): queue admission intentionally stopped emitting terminal chat events, but the unchanged restart fixture awaits queuedRunTerminal.promise before releasing firstGate. The consuming reply cannot finish until that gate is released. The nine fixture, queue, dispatch, and cleanup inputs used to qualify this failure are byte-identical between the CI main parent and tested merge. The request is WebSocket chat.send, which the approval-method predicate excludes; it does not reach this PR's new approval carrier. The operator-authority-loss message occurs only during teardown after the timeout.

Isolated Linux attribution run, Node 24.19.0 / pnpm 12.5.1: the exact PR head passes the original two-file order (6/6, 85.124 seconds wall) and five standalone runs (3/3 each). The merge base bcae52b9a85a2207a66b3c9927edc17e56261a58 also passes five standalone runs (3/3 each). Independently pinned main ba41a183375447849a66538e553e7520328f8428 fails the same case in the original order (1 failed / 5 passed, 358.047 seconds wall), with the same 120-second test and 180-second hook timeouts. The attribution run correctly exits 1; its owned Testbox lease is stopped. This qualifies the authorized inherited-failure admin route and does not claim CI is green.

An earlier local original-order attempt encountered a different prerequisite failure: the imported parent-agent lifecycle case exceeded its 90-second timeout, followed by plugin-metadata-shutdown errors (582.67 seconds total wall). The same unchanged order passes on isolated Linux. Local scheduling/performance remains uncertain; that passing replay is not claimed as a fix for the local timeout.

ClawSweeper completed the exact final head at 2026-10-06T10:52:18.391Z with a ready verdict and no actionable findings (review run). The production and inventory-fix P2 autoreviews are both scoped-clean.

Latest-main source check: fcf275b642608e459130d62b3dc305e215959319 retains all nine causal source blobs from the reproduced main ba41a183375447849a66538e553e7520328f8428; no fix for this failure had landed at that check.

@clawsweeper

clawsweeper Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@github-actions

github-actions Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Security sensitive changes

This maintainer PR changes sensitive security components.

No secops approval is required. This comment is informational because the PR author has Maintain or Admin access.

  • Current SHA: f6044feb22416bc2156beb95bcbf8f907da6af62
  • Maintainer: @steipete
  • Repository role: admin

These security sensitive changes were made:

  • src/gateway/internal-approval-authority.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.

Carefully review these changes before merging.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime agents Agent runtime and tooling size: M labels Oct 6, 2026
@clawsweeper

clawsweeper Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 6, 2026, 6:52 AM ET / 10:52 UTC (Revision 3).

ClawSweeper review

What this changes

The PR carries live internal approval guards into the existing SQLite worker dispatcher, preserves native handling for opaque SDK callbacks, and adds boundary regressions and worker-routing documentation.

Merge readiness

✅ Ready for maintainer review

This remains useful work absent from current main. The pinned patch has no actionable correctness or security findings, and the final inventory correction resolves the documented ordering failure.

Likely related people: steipete (medium-confidence routing candidate from prior merged approval and authority work).

Priority: P2
Reviewed head: f6044feb22416bc2156beb95bcbf8f907da6af62

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused ownership refactor with meaningful real-worker authority coverage and no actionable findings.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The captured execution results and inspected production-boundary harness exercise internal channel and agent-tool dispatch through real approval handlers, worker admission, and SQLite. Successful verdicts and grant minting are observed, while pre-commit caller retirement leaves durable state pending and prevents publication. This review did not execute the harness. No stored-data contract changes, so migration compatibility assessment is not applicable.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The captured execution results and inspected production-boundary harness exercise internal channel and agent-tool dispatch through real approval handlers, worker admission, and SQLite. Successful verdicts and grant minting are observed, while pre-commit caller retirement leaves durable state pending and prevents publication. This review did not execute the harness. No stored-data contract changes, so migration compatibility assessment is not applicable.
Evidence reviewed 9 items Pinned introduction and repository identity: The origin identifies openclaw/openclaw. Reviewed the explicit bcae52b..f6044fe introduction delta; the stale test merge was not used to infer removals or regressions.
Live internal authority: Worker classification requires an internally retained function. The bound assertion checks the original request, client, context, signal, and guard identities before invoking current transport and caller authority; the carrier itself grants no permission.
Existing final commit boundary: The existing approval operation owner requests authority at transaction admission and again immediately before commit. The existing store retains FIFO, physical database admission, receipt publication, and settlement; the PR changes routing rather than the stored model.
Findings None None.
Security None None.

How this fits together

Gateway approvals receive decisions from internal channel runtimes and agent tools, then persist them and publish resolution events. This change selects the existing worker storage path while retaining the caller's live authority through commit.

flowchart TD
  A[Internal channel request] --> C[Gateway approval dispatch]
  B[Agent tool request] --> C
  C --> D{Recognized internal guard?}
  D -->|Yes| E[Existing SQLite worker]
  D -->|No| F[Native compatibility transaction]
  E --> G[Live authority checked before commit]
  F --> G
  G --> H[Persisted verdict and resolution event]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +74, Tests +300, Docs +12. Total +386 across 8 files.

View PR surface stats
Area Files Added Removed Net
Source 5 81 7 +74
Tests 2 300 0 +300
Docs 1 12 0 +12
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 8 393 7 +386

Review metrics

Metric Value Why it matters
Production and regression growth Production net +74 LOC; regression tests +299 LOC Production growth carries existing authority into the worker path; the larger regression harness protects router-to-SQLite behavior that store-only coverage missed.

Technical review

Best possible solution:

Use the existing approval writer for recognized internal callers while preserving live commit checks and the released native callback contract.

Do we have a high-confidence way to reproduce the issue?

Yes, source inspection establishes that current main routes these guarded internal approvals through native compatibility storage. The captured boundary measurements report failing-before and passing-after results; this read-only review did not rerun them.

Is this the best way to solve the issue?

Yes, the patch reuses the existing writer and authority owners instead of adding parallel storage machinery, and preserves opaque callbacks at their established synchronous boundary.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 9eb998b7d1b0.

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. The captured execution results and inspected production-boundary harness exercise internal channel and agent-tool dispatch through real approval handlers, worker admission, and SQLite. Successful verdicts and grant minting are observed, while pre-commit caller retirement leaves durable state pending and prevents publication. This review did not execute the harness. No stored-data contract changes, so migration compatibility assessment is not applicable.

Label justifications:

  • P2: This is a bounded internal approval-storage improvement with no demonstrated urgent user-facing regression.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The captured execution results and inspected production-boundary harness exercise internal channel and agent-tool dispatch through real approval handlers, worker admission, and SQLite. Successful verdicts and grant minting are observed, while pre-commit caller retirement leaves durable state pending and prevents publication. This review did not execute the harness. No stored-data contract changes, so migration compatibility assessment is not applicable.
  • proof: sufficient: Contributor real behavior proof is sufficient. The captured execution results and inspected production-boundary harness exercise internal channel and agent-tool dispatch through real approval handlers, worker admission, and SQLite. Successful verdicts and grant minting are observed, while pre-commit caller retirement leaves durable state pending and prevents publication. This review did not execute the harness. No stored-data contract changes, so migration compatibility assessment is not applicable.

Evidence

What I checked:

  • Pinned introduction and repository identity: The origin identifies openclaw/openclaw. Reviewed the explicit bcae52b..f6044fe introduction delta; the stale test merge was not used to infer removals or regressions. (f6044feb2241)
  • Live internal authority: Worker classification requires an internally retained function. The bound assertion checks the original request, client, context, signal, and guard identities before invoking current transport and caller authority; the carrier itself grants no permission. (src/gateway/server-methods/session-mutation-guards.ts:145, f6044feb2241)
  • Existing final commit boundary: The existing approval operation owner requests authority at transaction admission and again immediately before commit. The existing store retains FIFO, physical database admission, receipt publication, and settlement; the PR changes routing rather than the stored model. (src/gateway/operator-approval-store.operations.ts:51, f6044feb2241)
  • Production-boundary authority coverage: The seven new cases use the real registered Gateway handlers, approval managers, worker admission, and SQLite storage. Channel and tool revocation is injected immediately before commit; assertions require a pending durable row, no resolved timestamp, and no resolution publication. Other cases cover successful resolution, malformed denial, atomic cron grant minting, and opaque callback compatibility. The captured body reports all seven passing, including a failing-before SQL-boundary control; this reviewer inspected the harness but did not execute it. (src/gateway/server-instance-runtime.approvals.test.ts:258, f6044feb2241)
  • Current main still needs this routing: Fetched main retains the native-compatibility fallback and lacks the introduced internal-approval worker binding. The merged refactor(gateway): offload approval grant administration #162549 established related worker infrastructure and grant administration, but does not supersede this internal request cutover. (src/gateway/server-methods/session-mutation-guards.ts:138, 9eb998b7d1b0)
  • Re-review continuity and inventory repair: GitHub's commit endpoint confirms the exact head has parent 42ba88e and only moves the existing approval test entry into alphabetical order. The captured body reports both previously failing complete files passing all 124 tests. The previous completed review had no findings; production inputs are unchanged by this follow-up. (test/vitest/vitest.gateway-server-paths.mjs:125, f6044feb2241)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (2 earlier review cycles)
  • reviewed 2026-10-06T09:34:39.524Z sha 5ce52b9 :: needs changes before merge. :: none
  • reviewed 2026-10-06T10:05:02.380Z sha 42ba88e :: needs maintainer review before merge. :: none

Preserve prepared question caller authority alongside internal approval worker carriers. Integrate current main dependency and session-authority fixes without rebasing. P2 autoreview is scoped-clean; focused approval and dispatch proof passes, with remaining integration gates tracked before landing.
@steipete

steipete commented Oct 6, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 6, 2026
The approval carrier test was prepended to the canonical worker inventory. Sorted discovery then disagreed with the planner and CLI ownership assertions. Keep the same host-owned routing and restore alphabetical order. Both failing files now pass all 124 tests; focused P2 autoreview is clean.
@steipete

steipete commented Oct 6, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Oct 6, 2026
@steipete
steipete merged commit 3a7139a into main Oct 6, 2026
143 of 147 checks passed
@steipete
steipete deleted the dbasync/w6approval branch October 6, 2026 12:21
@steipete

steipete commented Oct 6, 2026

Copy link
Copy Markdown
Contributor Author

Merged via explicitly authorized admin squash with attributed pre-existing CI failures.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 7, 2026
…penclaw#166050)

* refactor(approvals): carry internal authority into worker dispatch

* style(approvals): brace revocation test guards

* fix(test): keep Gateway worker inventory sorted

The approval carrier test was prepended to the canonical worker inventory. Sorted discovery then disagreed with the planner and CLI ownership assertions. Keep the same host-owned routing and restore alphabetical order. Both failing files now pass all 124 tests; focused P2 autoreview is clean.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation gateway Gateway runtime P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. security-sensitive-changed size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant