Repository navigation
perf(hooks): reduce native relay startup memory and latency - #120340
Conversation
|
Codex review: blocked before merge. Reviewed September 7, 2026, 5:06 PM ET / 21:06 UTC. ClawSweeper reviewWhat this changesThe PR gives native hook subprocesses a lightweight executable, narrows startup imports, and shares existing output-draining and database-version logic. Warning SQLite table change This PR modifies persisted SQLite tables in Merge readiness⛔ Blocked before merge - 1 item remains Keep open as useful, well-supported performance work with no introduced blocking defect found. The previous migration blocker does not apply: the storage change preserves the existing reader’s behavior. Priority: P2 Review scores
Verification
How this fits togetherNative provider hooks launch short-lived processes that send events to OpenClaw’s owning runtime. The relay reads its SQLite locator, invokes the existing bridge or Gateway fallback, and returns the policy result through process output and exit status. flowchart LR
A[Native provider hook] --> B[Executable selection]
B --> C[Dedicated relay]
B --> D[Explicit override or older CLI]
C --> E[Existing relay client]
D --> E
E --> F[SQLite locator and owner bridge]
E --> G[Gateway fallback]
F --> H[Policy output and bounded exit]
G --> H
Before merge
Agent review detailsSecurityNone. PR surfaceSource +33, Tests +201, Other +79. Total +313 across 22 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Technical reviewBest possible solution: Keep the dedicated executable within the shared runtime build while preserving the canonical relay policy, fallback, and state-admission owners. Do we have a high-confidence way to reproduce the issue? Not applicable as a newly claimed incident fix: this PR is scoped to performance improvement, supported by a pinned before/after relay comparison rather than a current-main reproduction of host exhaustion. Is this the best way to solve the issue? Yes. Reusing the existing relay implementation and unified build removes startup overhead without introducing competing policy or persistence logic. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 0bec2710f683. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (18 earlier review cycles; latest 8 shown)
|
|
I independently validated this architecture on a 16 GiB Apple Silicon Mac and inspected the exact Codex hook-execution contract used by the affected deployment ( Codex process contract
The practical lifecycle consequence is that the generated POSIX command should use Compatible runtime resultI adapted the dedicated-entry architecture to an older stable branch's generation-authenticated registry and exercised the emitted relay binary directly. This is supporting evidence rather than an exact-head artifact for this PR. An isolated 18-concurrent-cold-relay run reached 60.66 MiB maximum individual RSS and 1,086.73 MiB maximum aggregate RSS, with zero failures and zero survivors. Separate success, malformed-input, timeout, stale-registration, replacement, owner-shutdown, and cancellation cases also left zero survivors. A 15-minute production observation after deployment found no idle relays and no memory-pressure regression. These results support the dedicated executable as the right ownership boundary. They also reproduce the relevant Codex concurrency, timeout, stdio, and process-tree assumptions from source rather than inferring them from OpenClaw alone. I can provide a redacted test procedure or rerun the bounded test against a rebased exact head if that would help the contributor satisfy the remaining acceptance gate. |
Use a dedicated cold-process entry and exact lightweight imports for native hook relays. Preserve executable overrides and older package resolution, and check the emitted static import boundary during normal runtime builds. Share the existing bounded output drain with the general CLI so both paths retain callback ordering and the five-second missing-callback backstop. Keep current main's SQLite owners unchanged; the prior classifier extraction and unrelated cleanup diagnostics are no longer needed for this path. Preserve contributor ancestry. This source snapshot is for isolated runtime qualification; it does not claim that the reported memory incident is fixed. Co-authored-by: Mr. Stellar <[email protected]> Co-authored-by: Tak Hoffman <[email protected]>
Inline the canonical state and agent schemas in the standalone relay graph. Its emitted lazy modules referenced missing SQL assets and failed to load in qualification run 34104346187; the comparison correctly did not proceed. Record the command exit code before the unref'd output drain so natural exit retains failures. Extend the existing build-owner and child-process fixtures without adding another schema-copy or fallback path. Co-authored-by: Mr. Stellar <[email protected]> Co-authored-by: Tak Hoffman <[email protected]>
Build the existing dedicated relay entry inside the canonical runtime graph so lazy Gateway dependencies and schema inlining have one build owner. Remove the separate graph that emitted 3,336 additional runtime files. Retain the cold static graph budget, server exclusions and external package allowlist while permitting shared chunks inside dist. Keep declaration partitions and the executable path unchanged; validate the resulting cold closure and runtime benefit before updating the contributor PR. Co-authored-by: Mr. Stellar <[email protected]> Co-authored-by: Tak Hoffman <[email protected]>
Integrate pinned main 5f66166 for the current fs-safe dependency and shared state admission owner before comparing the native relay entry. Preserve the reviewed relay patch, canonical CLI watchdog, shared output drain, and 512 KiB cold static graph budget. Runtime comparison remains pending. Co-authored-by: Mr. Stellar <[email protected]> Co-authored-by: Tak Hoffman <[email protected]>
Move the existing content-version reader and its per-database query cache into the schema admission owner. Publication imports the shared key and internal readers use the admission module, keeping updater-only semver out of the native relay cold graph without changing stored data or policy. The actual qualification build rejected the semver import before this repair. Keep the external import guard and 512 KiB budget unchanged; rerun the built-artifact, schema, and ordinary relay proofs on the exact head. Co-authored-by: Mr. Stellar <[email protected]> Co-authored-by: Tak Hoffman <[email protected]>
Assert the executable exists in the unified runtime graph while retaining exact declaration-entry equality for every other entry. Preserve the existing declaration-only and package output contracts. The previous exact-head CI failed this stale equality assertion. Runtime source and the qualified native-relay build remain unchanged. Co-authored-by: Mr. Stellar <[email protected]> Co-authored-by: Tak Hoffman <[email protected]>
Merge pinned main 79dcb09, including the canonical Markdown test split that repairs the observed max-lines CI failure. Preserve the reviewed native-relay patch and contributor history. Retain the existing bounded live proof as historical 5f/4a evidence. Current emitted-graph guards and exact-head CI remain required. Co-authored-by: Mr. Stellar <[email protected]> Co-authored-by: Tak Hoffman <[email protected]>
|
Merged via squash.
|
…#120340) Reduce repeated native-hook subprocess startup work with a dedicated entry in the existing unified runtime graph. Reuse the relay handler and bounded output drain, narrow cold imports, and keep schema-version admission independent of updater publication policy. Preserve executable overrides, deadlines, output/status and contributor history; no storage semantics or configuration changes. Pinned same-host 2e5016f/4a87fd3c qualification completed 203 matching ordinary relay callbacks, clean child/listener teardown and 170 focused tests. Across three 20-child cohorts per arm, median sampled aggregate RSS fell 30.67% and median child latency fell 50.43%; these historical measurements are not refreshed-main timings or unique-memory measurements. The shared qaRuntime build added one regular file and 221 net bytes rather than a duplicate runtime graph. Exact final-head CI34159221537 passed, including the current 512 KiB bootstrap guard. Earlier packaging/import and declaration-test failures were repaired without relaxing the guard. The prior ACP cleanup assertion passed on the subsequent normal CI run without ACP changes; no cause or fix is claimed for that observation. Related: openclaw#119565, openclaw#91009. Incident-scale exhaustion remains outside this scoped startup improvement; neither issue is closed. Co-authored-by: Mr. Stellar <[email protected]> Co-authored-by: Tak Hoffman <[email protected]> Co-authored-by: Peter Steinberger <[email protected]> Co-authored-by: sightingsstellar-beep <[email protected]> Co-authored-by: Takhoffman <[email protected]>
Related: #119565, #91009. These incidents remain open; this PR makes a measured startup improvement without claiming to resolve incident-scale exhaustion.
What Problem This Solves
Concurrent Codex native hooks pay for the general OpenClaw CLI startup graph in each short-lived relay process. This change reduces that repeated startup work while keeping ordinary hook delivery, output, deadlines and process cleanup intact.
Why This Change Was Made
Prefer a dedicated relay executable built inside the existing unified runtime graph. This shares lazy Gateway dependencies and canonical SQL-schema inlining instead of emitting a second runtime graph. Use the existing lightweight error and scope owners, share the unchanged bounded output drain, and keep the existing state-version reader independent of updater publication policy.
Explicit executable/CLI overrides and older-package entry selection remain supported. The 512 KiB cold static graph budget, server exclusions and external-package allowance stay enforced. No schema, stored representation, publication policy, configuration or dependency version is changed by this PR.
User Impact
Native hook subprocesses start with less memory and latency. No setup change is required. The existing general CLI path also benefits from the narrower imports.
Evidence
Secretless paired qualification: baseline
5f661669b2c2979f2a61e23d4addb3bdd4545469, candidate4a87fd3ce171f824fc04fcdf5b91f0dfb150fe98, tooling6a0013f2dc48b8bcc56c9651c444cc39e3bc41cc. Both used Node 24.20.0, integrity-verified pnpm 12.3.4 and the canonicalqaRuntimebuild.The table reports the median of three alternating 20-child cohort measurements per arm. Each latency measurement is that cohort's median child latency; these are not pooled 60-child medians:
The complete candidate reduced sampled aggregate RSS by 30.67% and latency by 50.43% against baseline. The dedicated entry improved another 6.19% RSS and 8.12% latency compared with the same candidate's general CLI. These are bounded same-host observations, not unique/private-memory measurements, statistical guarantees or incident-scale Gateway responsiveness proof.
All 203 real registered
post_tool_usenotifications produced exactly one matching callback, expected output and exit status, with no surviving owned children or TCP servers. The emitted cold closure is 64 files / 328,258 bytes, below the unchanged 524,288-byte limit. Its actual reachable lazy Gateway module loaded successfully; this is module-load proof, not a claim of a live legacy Gateway RPC or model session.The complete
distcontains 8,846 regular files / 153,634,294 bytes, versus 8,845 / 153,634,073 at baseline: one additional file and 221 net bytes. The dedicated entry itself is 624 bytes. Both build stamps and all recorded runtime/source hashes were verified again after the cohorts.All 170 focused tests across eight files passed, including resolver, source-process/finalizer, relay CLI, build graph, state-publication and database-preflight coverage. Earlier actual qualification failures exposed missing SQL assets in the separate graph and an updater-only
semverimport in cold admission; both are repaired, and neither guard was weakened. The new natural-exit status case passes; its pre-fix failure was source-predicted rather than separately executed.Direct dependency inspection used Codex
rust-v0.153.4(3d2ee51ca2d5db578f328aa75e20aa22c0197c9a),codex-rs/hooks/src/engine/command_runner.rs:205-329, matching the pinned dependency's piped output, completion and process cleanup contract. Source and proof reviews found no actionable P0–P2 findings. The test-only declaration-contract follow-up passed its exact CI test, and the earlier ACP cleanup assertion did not recur without any ACP source change; its original cause is not claimed fixed. Current main is integrated at79dcb093e50d521e5cdd5d0cfe967a9ef2d66698, including the canonical Markdown test split from #141466 that repairs the observed max-lines CI failure. The candidate patch is unchanged. The size and timing figures above remain measurements of the explicitly pinned5f/4acomparison, not of this main integration. Exact-head CI for2bc6c2037f40096b5349225cd784463894f47489passed, including the current emitted bootstrap guard. The build job exercised merge1d77074fc665a8eadceedd9feba006dbbc0f7345with main5180c4569c5d7ada2864cafffe511b116935148a; no refreshed absolute size or timing measurement is claimed.ClawSweeper follow-through: maintainers accepted the isolated startup-improvement scope; incident-scale MCP/Gateway proof is deferred and no linked incident is closed. The generic data-model checkbox does not apply to this reader relocation: SQL, value validation, query-cache lifetime and publication behavior are unchanged, and existing state suites pass. The latest exact-head technical review also explicitly found no introduced defect and confirmed the migration blocker is inapplicable. The refreshed head carries this revised scope and evidence.
Runtime production +113/-80; build tooling +81/-2; tests +261/-60. Runtime growth supplies the dedicated executable and shared drain; the schema-reader work relocates existing behavior. Original contributor ancestry is preserved. Thanks @sightingsstellar-beep and @Takhoffman.