Skip to content

refactor(hooks): await policy preparation through relay lifetime - #145164

Merged
steipete merged 1 commit into
mainfrom
codex/async-native-hook-policy-final
Sep 11, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/async-native-hook-policy-final

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Native hook setup still reads stored MCP approval policy synchronously. Moving that storage work behind an asynchronous API requires a clear boundary: an unavailable direct relay must not hide a pending or failed policy read, and cancellation must not leave the read outside its native owner.

Why This Change Was Made

The relay lifetime owns one prepared policy snapshot. Private startup preparation waits for policy separately from direct publication, then rechecks the live owner. Gateway invocation also waits for policy independently of the locator. Cleanup joins policy, renewal and listener work while preserving errors. Read-only preparation captures the original database and legacy-migration owner before yielding.

MCP callers now await the canonical reader; the unused private synchronous projection is removed. The shared SQLite worker cutover remains separate: SQL still runs on the caller thread in this change. No schema, native hook payload or approval-policy change is included.

User Impact

Registration and command getters remain synchronous. The optional deferMcpToolApprovals field stays undefined until preparation finishes, while native dispatch waits internally. Healthy Gateway fallback remains available after direct transport failure, but failed policy, cancellation and closed ownership cannot produce a late tool decision.

Evidence

Omitting the policy await from the combined implementation reproduced five premature-admission failures. Restoring it passes successful-policy, real legacy-policy failure and held-read cancellation/closure controls. All 487 selected tests, the full changed-code gate, fresh Codex review and the normal build passed.

The unchanged emitted build passed the existing five policy/SQLite modes and three generated cold-CLI modes. A separate real Gateway authentication/dispatch proof verified successful prepared policy after actual listener failure, the specific legacy-policy rejection through a cold CLI, and cancellation reaching the healthy Gateway's rejection without invoking policy. Observed SQLite handles closed and reopened with integrity intact and no locators; all source and artifact hashes remained unchanged.

The real Gateway policy flows took approximately 779 ms, 847 ms and 704 ms. These are instrumented timings, not a speedup claim. Proof used isolated synthetic state and finite failing deadlines; it does not claim native model inference or worker-thread SQL execution.

@clawsweeper

clawsweeper Bot commented Sep 11, 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.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime agents Agent runtime and tooling extensions: codex size: XL maintainer Maintainer-authored PR labels Sep 11, 2026
@steipete
steipete marked this pull request as ready for review September 11, 2026 18:53
@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 Sep 11, 2026
@clawsweeper

clawsweeper Bot commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 11, 2026, 3:00 PM ET / 19:00 UTC.

ClawSweeper review

What this changes

The PR makes stored MCP approval preparation asynchronous and joins it to native-hook startup, invocation, and cleanup while removing an unused private synchronous projection.

Merge readiness

⛔ Blocked before merge - 1 item remains

This remains useful work beyond the merged relay-persistence refactor. Current main still reads MCP grants synchronously, and source review found no blocking defect in the proposed lifecycle integration.

Priority: P2
Reviewed head: e2c789ade8dd334fee976ab47f1337327596188f

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused lifecycle refactor with meaningful boundary coverage and no blocking source-review findings.
Proof confidence 🌊 off-meta tidepool Not applicable: The supplied maintainer-author classification exempts this internal refactor from the external-contributor proof gate. The body reports real Gateway fallback, policy-error, cancellation, and SQLite integrity observations; this review did not independently execute them.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The supplied maintainer-author classification exempts this internal refactor from the external-contributor proof gate. The body reports real Gateway fallback, policy-error, cancellation, and SQLite integrity observations; this review did not independently execute them.
Evidence reviewed 10 items Introduced change and merge identity: Reviewed the pinned merge-base-to-head changes. The recorded test merge has the pinned base followed by the exact PR head as parents; its changed paths match the introduced surface.
Policy readiness and live authority: Startup awaits policy separately from listener publication. Gateway invocation also awaits policy, rejects retired registrations, and preserves the existing authority checks before and after approval-bearing callbacks.
Storage owner remains canonical: The async reader captures the database path and matching legacy-policy directory before yielding, then uses the existing read-only implementation. It introduces no schema or persisted-format change.
Findings None None.
Security None None.

How this fits together

The native-hook relay connects Codex tool events to OpenClaw policy and approval handling. It prepares stored approval settings, receives events through a direct listener or Gateway fallback, and returns decisions under the current run’s authority.

flowchart TD
  A[Stored MCP approvals] --> B[Relay policy preparation]
  C[Codex hook event] --> D[Direct listener or Gateway]
  B --> E[Await policy and check live owner]
  D --> E
  E --> F[Hook decision or rejection]
  B --> G[Relay cleanup drains work]
Loading

Before merge

  • Add data-model compatibility proof - Confirm migration or upgrade compatibility proof before merge.
Agent review details

Security

None.

PR surface

Source +62, Tests +443, Docs +5, Other 0. Total +510 across 20 files.

View PR surface stats
Area Files Added Removed Net
Source 12 184 122 +62
Tests 6 610 167 +443
Docs 1 11 6 +5
Config 0 0 0 0
Generated 0 0 0 0
Other 1 1 1 0
Total 20 806 296 +510

Review metrics

Metric Value Why it matters
Production versus test growth production +62 net lines; tests +443 net lines Production growth implements policy lifetime ownership; most added coverage exercises failure ordering, cancellation, and storage-owner preservation.

Stored data model

Persistent data-model change detected: migration/backfill/repair: src/infra/exec-approvals-migration-gate.ts. Confirm migration or upgrade compatibility proof before merge.

Technical review

Best possible solution:

Keep policy preparation, live admission checks, and cleanup under one relay lifetime while preserving Gateway fallback and existing storage semantics.

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

Not applicable as a current-main bug reproduction: this is preparation for an asynchronous storage boundary. Source confirms the existing synchronous read; the reported premature-admission failures concern an incomplete async cutover.

Is this the best way to solve the issue?

Yes. The patch extends the existing relay and storage owners, preserves awaited runtime callers, and removes an unused private projection instead of maintaining parallel preparation paths.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P2: This is a bounded internal reliability improvement for native-hook policy preparation, with no demonstrated urgent user regression.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The supplied maintainer-author classification exempts this internal refactor from the external-contributor proof gate. The body reports real Gateway fallback, policy-error, cancellation, and SQLite integrity observations; this review did not independently execute them.

Label justifications:

  • P2: This is a bounded internal reliability improvement for native-hook policy preparation, with no demonstrated urgent user regression.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The supplied maintainer-author classification exempts this internal refactor from the external-contributor proof gate. The body reports real Gateway fallback, policy-error, cancellation, and SQLite integrity observations; this review did not independently execute them.

Evidence

What I checked:

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.

@steipete

Copy link
Copy Markdown
Contributor Author

Compatibility disposition: this changes policy preparation and relay lifetime ownership, not the SQLite schema, stored approval format, or native-hook payload. The captured environment keeps the existing legacy-policy refusal, display path and repair hint bound to the original database. Runtime reads neither migrate nor initialize that storage, so this delta needs no new data migration.

The retained proof covers 487 tests, the normal build, SQLite close/reopen integrity, and real Gateway/cold-CLI success, legacy-policy refusal and cancellation. All 19 functional paths remain byte-identical after the recorded rebase, and CI is green at e2c789ade8dd334fee976ab47f1337327596188f. The compiled/live proof belongs to the pre-rebase graph; it does not claim native model inference or worker-thread SQL execution. This addresses the generic data-model compatibility checkbox without weakening an approval or cleanup check.

@steipete
steipete merged commit c0df18e into main Sep 11, 2026
257 checks passed
@steipete
steipete deleted the codex/async-native-hook-policy-final branch September 11, 2026 21:06
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

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 extensions: codex gateway Gateway runtime maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XL 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