Repository navigation
refactor(hooks): await policy preparation through relay lifetime - #145164
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: blocked before merge. Reviewed September 11, 2026, 3:00 PM ET / 19:00 UTC. ClawSweeper reviewWhat this changesThe 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 Review scores
Verification
How this fits togetherThe 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]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +62, Tests +443, Docs +5, Other 0. Total +510 across 20 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Technical reviewBest 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. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
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 |
|
Merged via squash.
|
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
deferMcpToolApprovalsfield 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.