Skip to content

perf(plugins): release retired knowledge link parses - #185368

Merged
steipete merged 1 commit into
mainfrom
steipete/perf-knowledge-storage-worker-heap-20261026
Oct 27, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/perf-knowledge-storage-worker-heap-20261026

Conversation

@steipete

@steipete steipete commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Knowledge workers retain obsolete document bodies after edits because the global Markdown-link cache keeps up to 20,000 full body strings.

User Impact

Knowledge uses less retained heap as documents change. Link resolution, merged-page references, filesystem validation, and store access rules remain unchanged. No configuration or migration is required.

Why This Change Was Made

Tie extracted links to the existing parsed-record lifetime with weak keys, replacing the global body-keyed FIFO. Shallow scan copies and merged projections share that owner. Recently modified files still undergo the complete guarded reread and validation; identical freshly read bytes can reuse their link parse without admitting a cached record read.

Production code is net +14 lines across three files. The additional ownership handoff preserves reuse for merged projections and unsettled files; the old FIFO and eviction policy are removed. The remaining changes add synthetic Knowledge coverage to the existing performance tools and regressions.

Evidence

The baseline includes the earlier worker import reduction in #185169. A fresh isolated Gateway ran 10,800 synthetic sessions, 65 WebSocket clients, 40 default plugins plus Knowledge, concurrent mock-provider turns with tool calls and native subagents, and sidebar/list/search churn. Its Knowledge store contained 256 synthetic pages of approximately 14 KiB, with 25 edits per round. After 10.5 minutes, its storage worker retained 38.9 MiB after GC; the body-keyed cache held 531 document versions (7.1 MiB of key strings). The snapshot analysis is aggregate-only and ephemeron-aware; key-string bytes are a census, not an exclusive dominator claim.

Built storage-worker protocol, 256 pages, 3,000 catalog operations per side with one document edited every 10 operations:

Metric Base Candidate Change
Post-GC worker heap 38.59 MiB 35.03 MiB −3.56 MiB (−9.2%)
Worker CPU 81,298.962 ms 83,981.755 ms +3.3%
Allocated bytes 11,077,469,072 11,127,260,080 +0.45%
Catalog p95 (3,000 samples/side) 896.16 ms 580.37 ms context under host contention
Total GC per 3,000 operations 1,879.54 ms 1,423.61 ms −24.3%
Maximum GC pause 152.80 ms 127.51 ms context

This is a small retained-heap improvement, not a CPU or allocation improvement. Host load varied substantially (1-minute load at arm start/end: base 78.70→77.54, candidate 76.03→88.00), so wall-time changes are not claimed as speedups. Minor collections were 394→395 and major collections 22→22; major pause tails are context-only. GC/min changed 275.56→306.36 ms because the same work finished sooner, an absolute +30.79 ms/min. Owner GC by kind: minor total 1,241.39→1,027.39 ms, maximum 152.80→92.13 ms; major total 500.16→390.79 ms, maximum 129.47→127.51 ms. Worker loop p99 was 44.24→26.31 ms (117,863/113,050 samples).

The full Gateway runs also confirm the retention reduction: Knowledge post-GC heap 38.885→35.469 MiB (−3.416 MiB, −8.78%), and snapshot heap 38.856→35.434 MiB. Both completed 40 mock turns and 40 tool calls/results. The candidate snapshot has no full-body string keys in the link cache, versus 531 in the baseline. Total string shallow bytes fell 23,082,372→18,818,996.

Whole-Gateway timing is inconclusive as a causal comparison: mean 1-minute host load was 18.319→94.548 (candidate range 77.264–125.075). The numbers below are reported, not hidden, but do not establish a regression or speedup; no adverse verdict is made without A/A controls. No A/A controls were run, so these host-contended timing samples do not support an adverse or favorable whole-Gateway verdict.

Untraced Gateway metric Base Candidate
Measured seconds 630.740 631.283
Main-thread CPU 7.940% 11.042%
Main GC, seconds/minute 0.184864 1.063386
Event-loop p99 30.556 ms (n=30,266) 162.136 ms (n=22,038)
sessions.list client p99 71.249 ms (n=1,189) 888.605 ms (n=1,202)
Server handler mean 10.810 ms 64.952 ms
Server handler estimated p99 66.35 ms 563.50 ms
Final process RSS 2,793.006 MiB 2,876.995 MiB
Final main heap 687.549 MiB 810.014 MiB
Knowledge allocation counter 24.481 MiB/s 21.922 MiB/s

Main GC detail (base→candidate): minor 633→536 collections, 1,136.88→7,690.56 ms total, maximum 11.17→322.80 ms; major 34→18 collections, 774.41→3,430.28 ms total, maximum 45.22→592.30 ms; incremental 34→18 collections, 32.06→67.45 ms total, maximum 1.33→43.16 ms. These full-Gateway GC figures share the host-load confound above. Knowledge status p95 was 238.14→4,530.94 ms with only 11 samples/side (including warmup), so it is context only; the fixed-work owner comparison has 3,000 operations/side.

Handler histograms contain 1,173 observations per side; interpolated p99 lies in the 60–80 ms and 500–600 ms buckets. Storage-worker evidence is complete; the broader diagnostic census is incomplete because Git workers retired and were replaced. A separate canonical allocation pair completed on fresh fixtures (inclusive V8 sampling at 512 KiB; GC/latency in this mode are diagnostic only):

Main allocation pass Base Candidate
Sampled JS allocation 22.590 MiB/s 23.534 MiB/s
Total sampled bytes 14,212,527,576 14,817,226,400
Measured seconds 600.011 600.446
Turns / tool calls / results 40 / 40 / 40 40 / 40 / 40
sessions.list calls 1,192 1,193
Committed writes 104 103
Mean host load, 1 minute 44.799 30.414

Sampled main allocation rose 0.944 MiB/s (+4.18%); this is not a main-thread allocation win. The single serial pair also ran under different host loads. The measured benefit is lower retained Knowledge-worker heap, with no CPU or allocation-saving claim.

Artifacts compare ce069f9f837471069b3a35df1e7c05953ea792ab against the same build inputs plus this production patch. The branch was subsequently rebased cleanly onto current main; exact-head CI passed on 97f9785ddfd00a3e0d96789c9943d1f3fec03360. Earlier candidate measurements exposed excess parsing for unsettled files; that version was superseded by the reviewed ownership handoff above.

Validation completed: 33 focused Knowledge tests passed (markdown-links, real-vault, source-descriptor-integration); the earlier merged-reference sibling run passed all 20 tests; canonical stress-controller tests passed all 26 tests. Both eager-import and PR-wrapper source closure guards passed (29 tests), export-name collision checks passed, changed-file type-aware lint and formatting passed, and the full runtime artifact build completed successfully. PR CI supplies broad validation.

The focused live-record churn regression fails on the baseline because unrelated documents evict a still-live record's parse. Additional coverage checks merged projections, changed bodies, and guarded rereads of unsettled files.

Independent subagent review (autoreview route unavailable): the configured Codex helper refused its route preflight; the authorized isolated reviewer found no actionable P0–P2 findings, including in the subsequent unsettled-file ownership fix. The reviewer also checked the final rebased head and found no actionable integration findings. No operator configuration was changed.

RSS is process-wide and cannot be honestly assigned to an individual worker. This proof uses synthetic local state, never a live deployment or production data.

Keep Markdown link extraction with the current parsed document instead of retaining obsolete body strings in a global FIFO. Preserve merged projections and guarded rereads of unsettled files. Add focused regressions and synthetic Knowledge worker coverage to the existing performance harness.
@clawsweeper

clawsweeper Bot commented Oct 27, 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.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 27, 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-27T03:10:12.978321Z 97f9785 PR opened
ℹ️ 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.

@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. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. 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
@clawsweeper

clawsweeper Bot commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR ties Markdown-link parses to live Knowledge records and extends existing performance tools to measure document churn.

Example: A Knowledge store contains 256 pages and repeatedly edits documents.

  • Before: The global FIFO retains obsolete document bodies; the reported worker benchmark retained 38.59 MiB after GC.
  • After: Retired record owners can release their link parses; the reported candidate retained 35.03 MiB after GC.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The focused patch appears correct and has green exact-head checks, while the reported worker comparison provides limited performance confidence under substantial host contention.
Proof confidence 🦐 gold shrimp (3/6) The ordinary contributor proof gate does not apply to this maintainer-authored PR; its reported built storage-worker comparison exercises catalog scans and document edits through the real worker protocol, with broader candidate Gateway measurements unfinished.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Knowledge workers keep obsolete document bodies reachable as users edit their vaults.
Reason: A small lifetime correction removes unnecessary retention without changing link results or persisted formats, and the maintainer-authored direction explicitly discloses the measured CPU and allocation tradeoff.

Merge readiness

✅ Ready for maintainer review

Keep open: this maintainer-authored PR addresses retained Knowledge document bodies that current main still caches; no actionable correctness or security defects were found.

Priority: P2
Reviewed head: 97f9785ddfd00a3e0d96789c9943d1f3fec03360

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: The supplied Gateway census establishes baseline retention; candidate Gateway timing and main-allocation results are still described as pending.
Agent review details

How this fits together

Knowledge scans guarded vault files into validated records, extracts document links, and resolves them against eligible records for navigation, connections, and diagnostics.

flowchart LR
  A[Vault files] --> B[Guarded scan and validation]
  B --> C[Parsed record owners]
  C --> D[Merged record projections]
  C --> E[Weak link parse cache]
  D --> E
  E --> F[Scoped link resolution]
  F --> G[Navigation and diagnostics]
Loading

Technical review

Best possible solution:

Keep link extraction with the existing parsed-record lifetime while preserving merged-projection reuse and complete file validation.

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

Current main demonstrably retains complete obsolete body strings as global cache keys until FIFO eviction; the PR additionally reports a baseline Gateway heap census, but no target code was executed during this review.

Is this the best way to solve the issue?

The change fixes the retaining owner directly, removes the superseded FIFO, and keeps necessary reuse through existing record copies; its new flags configure diagnostic scripts only.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Markdown-link extraction cache changes intended behavior with a stated reason (65ad180: The bundled implementation reused body parses across scans that copy records and bounded edit-driven growth with FIFO eviction.)
  • Merged-reference projections keeps the original intent (65ad180: Effective records redirect metadata references to surviving pages while retaining authored document bodies.)
  • Settled-file scan admission keeps the original intent (65ad180: Only settled file and descriptor stamps admit cached record reads; failed reads must be retried.)
  • Worker heap measurement and stress tooling keeps the original intent (f149999: Existing tools measure real Knowledge worker protocols and distinguish worker heap diagnostics from whole-process RSS.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

  • Pinned production change: The introduced diff replaces the string-keyed FIFO with a WeakMap, carries ownership through merged projections, and preserves guarded rereads for unsettled files. (extensions/knowledge/src/markdown-links.ts:42, 97f9785ddfd0)
  • Current main still retains body keys: Fetched main retains the global Map keyed by complete body strings with a 20,000-entry FIFO limit. (extensions/knowledge/src/markdown-links.ts:42, ef1df2f79516)
  • Validation remains before ownership reuse: The new handoff occurs after guarded reading, scope validation, descriptor hydration, and envelope validation; it requires identical raw bytes and current source descriptors. (extensions/knowledge/src/vault-scan.ts:329, 97f9785ddfd0)
  • Reported performance evidence and tradeoff: The full PR body reports 3,000 built-worker catalog operations per arm: retained heap decreases 3.56 MiB, while CPU increases 3.3% and allocation increases 0.45%; the maintainer explicitly frames this as a retained-heap improvement and declines a speedup claim. (97f9785ddfd0)
  • Original cache purpose and feature history: The bundled Knowledge history records cross-scan parse reuse as the FIFO's purpose; feat(knowledge): bundle the Knowledge memory plugin #180139 brought the plugin into this repository. History before that import remains unknown: the follow search ended at an unavailable creation-parent object. (extensions/knowledge/src/markdown-links.ts:40, 65ad18005286)
  • Exact-head checks: The reviewed head has successful CI, dependency-review, and security-sensitive-review statuses; paginated check inspection found only two cancelled auto-response jobs outside successful, skipped, or neutral checks. (97f9785ddfd0)

Likely related people:

  • Peter Steinberger: Raw commit f149999 adds scripts/perf/knowledge-worker-heap-measure.mjs:89 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: f149999a3504; files: scripts/perf/knowledge-worker-heap-measure.mjs)

PR surface

Source +14, Tests +77, Docs +11, Other +125. Total +227 across 9 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 3 37 23 +14
Tests 1 78 1 +77
Docs 1 11 0 +11
Config 0 0 0 0
Generated 0 0 0 0
Other 4 131 6 +125
Total 9 257 30 +227

Review metrics

Metric Value Why it matters
Runtime versus regression-test delta Runtime +37/-23; tests +78/-1 The net 14 runtime lines preserve ownership across merged projections and guarded rereads while removing FIFO eviction machinery.

Labels

Label changes:

  • add P2: This reduces bounded retained memory in the optional Knowledge plugin without evidence of an urgent outage or broken core workflow.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: This reduces bounded retained memory in the optional Knowledge plugin without evidence of an urgent outage or broken core workflow.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Complete the already-running candidate Gateway comparison to establish whole-Gateway timing and allocation effects.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed October 26, 2026, 11:21 PM ET / October 27, 2026, 03:21 UTC.

@steipete
steipete merged commit 6338c20 into main Oct 27, 2026
149 of 151 checks passed
@steipete
steipete deleted the steipete/perf-knowledge-storage-worker-heap-20261026 branch October 27, 2026 04:06
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 27, 2026
Keep Markdown link extraction with the current parsed document instead of retaining obsolete body strings in a global FIFO. Preserve merged projections and guarded rereads of unsettled files. Add focused regressions and synthetic Knowledge worker coverage to the existing performance harness.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal backlog priority with limited blast radius. plugin: knowledge rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. scripts Repository scripts size: M 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