Skip to content

refactor(hooks): run bridge storage off the calling thread - #149397

Merged
steipete merged 1 commit into
mainfrom
codex/native-hook-bridge-worker-current
Sep 16, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/native-hook-bridge-worker-current

Conversation

@steipete

@steipete steipete commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Native hook relay registration, renewal, lookup, and cleanup return promises but still execute SQLite on the calling thread.

User Impact

Bridge persistence runs on the shared-state worker while preserving readiness, expiry, stale-owner rejection, and cleanup ordering. No configuration, schema, or retention change is required.

Why This Change Was Made

The store sends typed operations to the canonical worker. Publication and renewal ask the live host to validate the current registration inside the write transaction. Pruning keeps process-liveness planning on the host and compares the complete candidate with the current row before deletion. Accepted bridge operations remain drained before owned removal and listener closure. The cold CLI locator keeps its existing worker; the test-only reset helper retains native cleanup without adding a production worker command.

The shared admission prerequisite, #148623, is now landed in 2fa9fe3825fa6973069e17b298f7d765ac0d646d. This branch carries only the relay change on main containing that commit.

CI on the previous head exposed incomplete test routing: the CLI fixture and aggregate Codex extension runs could still reach the broker from a Vitest thread. These consumers now use the canonical worker inventories. The two redundant Codex leaf owners are removed, the Gateway fixture uses its Gateway worker owner, and the CLI fixture awaits canonical database cleanup.

Evidence

  • Controlled routing regressions reproduced 12 failures before the repair and passed all 13 selected cases afterward, covering direct, aggregate, changed-extension, and Gateway watch selection. The full-suite inventory and root-watch graph audit also passed, with no missing or duplicated tests.
  • The ordinary CLI loopback fixture passed once, asserting exact response and token matching, no Gateway fallback, and zero calls to all six host SQLite methods during the CLI invocation. Registration and cleanup are outside that measurement. Canonical database close, server close, and prepared-worker cleanup completed.
  • The relay facade, kernel, and worker contract/implementation remain byte-identical to the previously qualified candidate. Its source facade lifecycle case and separate normal-build packaged-worker command proof are retained as historical evidence: four write/renew transaction admissions and zero caller-thread SQLite calls after imports through the final read, excluding teardown.
  • The complete scoped changed-file gates passed on the main-based candidate 69bb8f6, including all selected type graphs, lint, storage guards, and import-cycle checks. The composition onto db1d5d2 preserves that feature delta and both relay and subagent commands in the shared worker; fresh core, state/agent test, and root test types and independent P0–P2 review passed. The subsequent carry onto 932846b5 preserves the exact patch and all 23 source-file bindings, incorporating the canonical UI/Goal and planner-fixture fixes from fix(cron): suppress control tokens and retain retry usage #149697 and fix(ci): accept file paths in extension packing fixtures #149726. The unchanged native proofs and complete gate run were not replayed; they remain attributed to their qualified candidates.

No provider, live PID, held-lock, fault, or orphan scenarios were run locally. The facade and packaged-command proofs remain distinct; previous-head CI is not claimed as current-head validation.

CI on a00acecd also recorded Gateway startup-close and Codex side-question close timeouts. Those failures are retained for attribution. Fresh CI run 35061856866 passed on 52b040165188b9fa197642259a6d08061b339817, including every previously failing job. No timeout or assertion was weakened.

@clawsweeper

clawsweeper Bot commented Sep 15, 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 agents Agent runtime and tooling extensions: codex size: L maintainer Maintainer-authored PR labels Sep 15, 2026
@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 15, 2026
@clawsweeper

clawsweeper Bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 16, 2026, 2:41 AM ET / 06:41 UTC (Revision 5).

ClawSweeper review

What this changes

Moves native-hook bridge storage into OpenClaw’s shared database worker and routes affected tests through worker-capable runners.

Merge readiness

✅ Ready for maintainer review

The change remains useful: current main still performs bridge SQLite work on the calling thread. No actionable introduced defect was found, and the maintainer-authored PR is protected from automatic closure.

Priority: P2
Reviewed head: 52b040165188b9fa197642259a6d08061b339817

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A coherent worker migration with useful scoped validation and no blocking correctness findings.
Proof confidence 🌊 off-meta tidepool Not applicable: The ordinary contributor proof gate is exempt for this member-authored PR. Its recorded facade and packaged-worker observations address storage execution; the CLI loopback observation covers lookup and transport only, and no new authority-proof blocker was established.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The ordinary contributor proof gate is exempt for this member-authored PR. Its recorded facade and packaged-worker observations address storage execution; the CLI loopback observation covers lookup and transport only, and no new authority-proof blocker was established.
Evidence reviewed 9 items Current main still needs the change: The fetched main revision retains direct synchronous SQLite reads and write transactions inside the promise-returning bridge store. The related merged project-removal PR supplies admission infrastructure, not this relay migration.
Transaction admission preserves live registration checks: The facade captures database context and record values before waiting. Publication and renewal request host admission inside the worker transaction, immediately before their existing SQL operations.
Cleanup and request authorization remain lifecycle-owned: Unregister removes the live bridge binding, waits for pending operations, performs token-owned removal, and then closes the listener. Request handling checks the token and current registration before invocation; a stored locator alone does not authorize execution.
Findings None None.
Security None None.

How this fits together

The native-hook bridge lets hook CLI processes locate and contact an active OpenClaw relay. Its storage owner publishes, renews, reads, and removes the local endpoint record while the relay lifecycle controls readiness and cleanup.

flowchart TD
  A[Relay registration or renewal] --> B[Shared database worker]
  B --> C[Check current host registration]
  C --> D[Bridge locator database]
  E[Hook CLI] --> F[Read-only locator worker]
  F --> D
  F --> G[Authenticated local relay]
  H[Relay cleanup] --> B
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +148, Tests +50, Docs +13. Total +211 across 23 files.

View PR surface stats
Area Files Added Removed Net
Source 6 412 264 +148
Tests 15 142 92 +50
Docs 2 13 0 +13
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 23 567 356 +211

Review metrics

Metric Value Why it matters
Production versus test growth Net production +148 lines; tests and test support +50 lines Production growth has a stated purpose: separating existing SQL from the host facade and adding typed worker dispatch and admission.

Technical review

Best possible solution:

Keep one shared-worker storage owner while preserving live registration checks, conditional row mutations, and settlement before listener closure.

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

Not applicable as a refactor review; current-main source directly confirms synchronous SQLite inside the asynchronous facade, but this review did not measure runtime blocking.

Is this the best way to solve the issue?

Yes. Reusing the canonical database worker and extracting the existing SQL preserves one storage owner without introducing a parallel implementation or changing persisted contracts.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: This is a bounded operational improvement that removes synchronous bridge storage work from the calling thread.
  • 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 ordinary contributor proof gate is exempt for this member-authored PR. Its recorded facade and packaged-worker observations address storage execution; the CLI loopback observation covers lookup and transport only, and no new authority-proof blocker was established.

Evidence

What I checked:

  • Current main still needs the change: The fetched main revision retains direct synchronous SQLite reads and write transactions inside the promise-returning bridge store. The related merged project-removal PR supplies admission infrastructure, not this relay migration. (src/agents/harness/native-hook-relay-store.ts:88, 199039e7d5ff)
  • Transaction admission preserves live registration checks: The facade captures database context and record values before waiting. Publication and renewal request host admission inside the worker transaction, immediately before their existing SQL operations. (src/agents/harness/native-hook-relay-store.worker.ts:26, 52b040165188)
  • Cleanup and request authorization remain lifecycle-owned: Unregister removes the live bridge binding, waits for pending operations, performs token-owned removal, and then closes the listener. Request handling checks the token and current registration before invocation; a stored locator alone does not authorize execution. (src/agents/harness/native-hook-relay-bridge.ts:232, 52b040165188)
  • Persisted representation and conditional mutations are preserved: The extracted kernel keeps the existing columns, decoding, PID/token ownership predicates, and complete snapshot comparison before pruning. No schema, retention, configuration, or public plugin API change is introduced. (src/agents/harness/native-hook-relay-store.kernel.ts:100, 52b040165188)
  • Affected tests retain executable owners: The core, extension, and Gateway inventories feed fork-based runners. Removed Codex leaf configurations have their tests transferred to the database-worker inventory, with exclusions preventing duplicate ownership. Added routing checks cover direct and changed-extension selection. (test/vitest/vitest.extension-database-workers-paths.mjs:24, 52b040165188)
  • Captured validation and review continuity: The supplied complete PR body reports separate facade lifecycle and normal-build packaged-worker observations, including four write/renew admissions and zero caller-thread SQLite calls within the declared measurement window. It also reports passing CI at the reviewed head: https://github.com/openclaw/openclaw/actions/runs/35061856866. These are contributor-recorded results, not executions performed by this review. The previous completed review examined the same head and retained no findings. (52b040165188)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Vincent Koc: 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 (4 earlier review cycles)
  • reviewed 2026-09-15T20:29:20.773Z sha a5cc31b :: blocked before merge. :: none
  • reviewed 2026-09-15T21:09:35.136Z sha a5cc31b :: blocked before merge. :: none
  • reviewed 2026-09-16T04:35:03.726Z sha a5cc31b :: blocked before merge. :: none
  • reviewed 2026-09-16T06:17:52.892Z sha 52b0401 :: needs maintainer review before merge. :: none

@steipete
steipete marked this pull request as ready for review September 15, 2026 20:43
Base automatically changed from codex/projects-remove-main6a835-20260914 to main September 16, 2026 04:28
@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: XL and removed size: L labels Sep 16, 2026
@steipete
steipete force-pushed the codex/native-hook-bridge-worker-current branch from a5cc31b to a00acec Compare September 16, 2026 05:32
@steipete
steipete force-pushed the codex/native-hook-bridge-worker-current branch from a00acec to 52b0401 Compare September 16, 2026 06:01
@openclaw-barnacle openclaw-barnacle Bot added cli CLI command changes scripts Repository scripts size: L and removed gateway Gateway runtime size: XL labels Sep 16, 2026
@steipete
steipete merged commit 52736da into main Sep 16, 2026
199 of 200 checks passed
@steipete
steipete deleted the codex/native-hook-bridge-worker-current branch September 16, 2026 07:28
@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 cli CLI command changes docs Improvements or additions to documentation extensions: codex maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. scripts Repository scripts size: L 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