Skip to content

perf(infra): name Knowledge workers and trim storage imports - #185169

Merged
steipete merged 3 commits into
mainfrom
steipete/perf-unlabeled-worker-heaps-20261026
Oct 27, 2026
Merged

steipete merged 3 commits into
mainfrom
steipete/perf-unlabeled-worker-heaps-20261026

Conversation

@steipete

@steipete steipete commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Knowledge registry and per-store storage workers were counted as other, hiding their memory footprint. Source and sealed worker entrypoints also missed the diagnostics allowlist when their filenames differed from normal builds.

User Impact

Worker diagnostics identify Knowledge registry/storage workers by bounded script name. Each Knowledge storage worker loads fewer modules and retains less heap. Authorization, storage schema, worker lifetime, and worker heap limits are unchanged.

Why This Change Was Made

Use the existing tracked worker constructor for Knowledge. The transient Bun SQLite close probe and package-update integrity hasher retain their dependency-light native constructors: early-start configuration loading and package-swap recovery require those bootstrap boundaries, so they are explicitly excluded from this attribution change. Derive source/sealed aliases from the runtime entrypoint manifests and map them to canonical built labels; unknown names and eval sources still fold to other.

Knowledge owns native SQLite stores. Its four JSON predicates can use the existing Kysely function builder directly, eliminating the database-engine lifecycle import and its worker resolver entry. The generated runtime assets remain unchanged after preserving those bootstrap boundaries.

The non-test/non-doc diff is +511/−27 lines (net +484), including 464 lines of reproducible benchmark tooling. Runtime source is +20 lines, required to represent canonical manifest labels across launch forms; no cache or lifetime policy is added. Two benchmark scripts provide reproducible owner and real-Gateway evidence, with usage in their headers.

Evidence

Built Node 26.12.1 on macOS, baseline c893f1e59c19d27db2a6b3289ecfc83b980fc7ed versus that production source plus this diff. Two runs per arm, 40 synthetic provisioned stores and 2,000 warm operations per worker per run:

Storage worker metric Base mean Candidate mean
Startup allocation 229.306 MiB 186.893 MiB (−18.50%)
Startup CPU 663.124 ms 1,010.199 ms
Warm allocation, 2,000 operations 523.611 MiB 528.768 MiB (+0.98%)
Warm CPU, 2,000 operations 5,375.398 ms 6,367.825 ms
Retained heap after diagnostic forced GC 32.563 MiB 27.855 MiB (−14.46%)
Natural idle heap 66.289 MiB 68.231 MiB
Loaded scripts 1,301 1,150
Warm total GC 47.954 ms 32.420 ms

The built arms ran B/B/C/C; they are not matched timing pairs. Candidate five-minute host load was roughly 69–70 versus 45–47, and unchanged registry warm CPU also increased 32.19%. Those CPU figures do not establish a regression or CPU neutrality. Module count, startup allocation and post-collection retention improved consistently. The empty mutation journal measures import/owner overhead, not populated-journal throughput.

A closer C/A/A/C source comparison (same workload, source-only baseline overlay) did not reproduce the built CPU increase: warm storage CPU was 4,373.184→4,198.502 ms (−3.99% mean; pairs −11.88%/+4.39%). Warm allocation was 571.873→589.321 MiB (+3.05%; pairs +4.10%/+2.01%). This is a small warm-allocation tradeoff for the measured cold-allocation and retained-module reduction, not a warm-throughput win. Total GC was 25.350→26.275 ms (+0.000462 ms/operation). Loop p99 was 6.814→7.621 ms (+0.807 ms; pair signs mixed), with 2,062/2,061→2,042/2,046 samples. Max GC pauses were 2.498/2.063→1.499/5.590 ms; major collections 0/0→0/1 are context only. The unchanged registry control's CPU moved +6.65%, allocation −0.009%. No adverse timing verdict is drawn from these noisy short windows; no A/A rejection campaign was needed. Source startup heap is not used as packaged-memory evidence.

The isolated built Gateway opened two real Knowledge stores and completed a mock-provider turn. Its diagnostics HTTP endpoint changed from four other workers to one registry-worker.js, two storage-worker.js, and one remaining other, with full 4/4 cohort sampling coverage. The cohort's final natural heap was 141.573→107.057 MiB. Whole-process RSS was 1,778.115→1,811.024 MiB and main heap 271.935→274.784 MiB; these single natural samples are context, not an RSS or throughput improvement claim. No production Gateway was touched. This cold-import/attribution change uses focused owner and Gateway proof rather than a long hot-path stress campaign.

Commands:

node --import ./scripts/tsx.mjs scripts/perf/knowledge-worker-heap-measure.mjs --built --state-dir .local/knowledge-state --output .local/knowledge-result.json --stores 40 --iterations 2000
node --import ./scripts/tsx.mjs scripts/perf/knowledge-worker-diagnostics-measure.mjs --output .local/knowledge-gateway --named

The three source/sealed attribution cases fail on base (20 existing cases pass). The Knowledge import-boundary regression fails on base while its two SDK worker-entry cases pass. All 78 focused candidate assertions passed, including ingestion/history and mid-operation revocation; the first combined wrapper run ended with a source-stamp error because generated assets were refreshed during the invocation. Clean affected-check rerun: 63 tests passed across five files / three shards in 114.76 seconds, including both regression files, the close-probe lifecycle tests, and both import/PR closure guards. The changed Knowledge worker-entry file took 1.74 seconds wall time (about 0.35 seconds of tests).

Validation: runtime build, changed-file formatting/lint, export-name collision guard, and both closure guards passed. Exact-head CI run 40423492141 passed on 2eb95f9800d6b9f1b65e7e8ed9461fd757013c65, including the baseline ratchets and aggregate CI gate. Independent subagent review (autoreview route unavailable): clean after fixing cleanup ownership in the new Gateway probe. The configured Codex autoreview route was refused for an operator-provider mismatch; no operator configuration was changed.

Initial PR CI caught two bootstrap import regressions from converting the close probe and update hasher to tracked constructors. Those conversions were removed, preserving their original contracts. Bare-Node Vite configuration loads for infra, logging, and process now pass; the package-recovery regression plus worker attribution, hasher, and probe tests passed (41 tests across four files, 49.32 seconds). The final correction received a clean independent scoped review.

The initial Linux Bun Knowledge schema run also failed its restored-file index-count assertion. A focused pinned-Bun replay passed all 10 tests, and the corrected-head Linux Knowledge configuration lane passed. The schema/identity owners were unchanged; the initial failure's cause was not established, and no retry-only CI run or schema change was used. GitHub Codex review completed on 0baea64c07d411bbc6887e4b485434f16bcc6dad with no findings.

The next CI run passed every test lane, build, type check, and lint check, but the mock-export ratchet required an isolation explanation on the deliberately throwing engine-import mock. Added that one comment: importing the real lifecycle module is precisely the regression the test rejects. The specific mock-export ratchet and formatting passed locally, and independent review found no issues. No baseline or assertion was relaxed.

The final head initially had no attached pull-request CI run despite being mergeable. The documented close/reopen recovery restored the trigger for this same PR; a delayed superseded run was cancelled, and replacement run 40423492141 passed. The branch was unchanged during recovery. This PR remains ready and unmerged for the lane lead.

@clawsweeper

clawsweeper Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review in progress

ClawSweeper is reviewing this revision. This supersedes any previous blocked status.

View the workflow run.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-26T23:57:16.223115Z 2eb95f9 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime scripts Repository scripts plugin: knowledge size: L labels Oct 26, 2026
@steipete
steipete force-pushed the steipete/perf-unlabeled-worker-heaps-20261026 branch from c38bf97 to 0baea64 Compare October 26, 2026 23:36
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 26, 2026
@steipete
steipete force-pushed the steipete/perf-unlabeled-worker-heaps-20261026 branch from 0baea64 to 2eb95f9 Compare October 26, 2026 23:55
@steipete steipete closed this Oct 26, 2026
@steipete steipete reopened this Oct 26, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:feature Preliminary submission classification; full source review pending. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 27, 2026
@steipete
steipete merged commit f149999 into main Oct 27, 2026
195 of 246 checks passed
@steipete
steipete deleted the steipete/perf-unlabeled-worker-heaps-20261026 branch October 27, 2026 00:11
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 27, 2026
…w#185169)

* perf(infra): name Knowledge workers and trim storage imports

* fix(infra): preserve worker bootstrap import boundaries

* test(knowledge): explain lifecycle import isolation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clawsweeper:intake:feature Preliminary submission classification; full source review pending. docs Improvements or additions to documentation gateway Gateway runtime plugin: knowledge scripts Repository scripts size: L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant