Skip to content

fix(memory): avoid session rendering during index scans - #181594

Draft
vincentkoc wants to merge 5 commits into
mainfrom
fix/memory-index-worker-imports-20261022
Draft

vincentkoc wants to merge 5 commits into
mainfrom
fix/memory-index-worker-imports-20261022

Conversation

@vincentkoc

@vincentkoc vincentkoc commented Oct 23, 2026 •

Copy link
Copy Markdown
Member

HOLD — draft; do not land. Completed A/B qualification failed the frozen performance gate. No merge or deployment.

What Problem This Solves

Session-index statistics load the broad session inventory and rendering runtime into a retained indexing worker, even though the scan only needs grouped transcript statistics.

User Impact

The candidate removes those unused imports while preserving results, incognito checks, cancellation authority, and worker lifecycle. The completed comparison observed lower median sampled Gateway RSS, but failed the frozen CPU/latency acceptance gate. This PR is held; these benchmark observations do not establish that the code change caused every observed slowdown.

Why This Change Was Made

The memory host SDK owns a narrow guarded statistics reader. The indexing worker loads it lazily; the existing session facade re-exports the same operation for current callers. The SQLite query kernel, configuration, scheduling, and public SDK contract are unchanged.

Evidence

  • Linux / Node 24.22.1: 16 focused tests across worker reads, dispatch, and streamed session preparation passed. Restoring the old broad import makes the isolation regression fail; restoring the fix passes.
  • Full builds and package integrity checks passed. Targeted type-aware lint, memory-core type checking, SDK surface compatibility, formatting, and line-cap validation passed for the production change.
  • Independent production and benchmark reviews found no remaining scoped P0–P2 issue. Subsequent harness changes preserve both command and cleanup errors, retain native worker identity, and use a compiled observer against the installed Gateway's existing registry.
  • Unscored packaged activation profiling observed the guarded statistics reader and its SQL kernel executing in the indexing worker. Profiled RSS is diagnostic only and will not be used for the comparison.
  • CI exposed missing private-SDK documentation, a missing core-bridge inventory entry, and a closed benchmark mock. These are corrected and covered by focused contract tests. The remaining Telegram callback-drain, hooks error-formatting, and subagent completion failures from run 39948209888 remain unresolved until matching evidence establishes their cause.
  • Benchmark instrumentation: net +316 lines; benchmark tests: +285 lines. This supplies missing workload, worker identity, and input evidence without adding product configuration.
  • Runtime change: +57/-47 (net +10); production regression tests: +30/-4; SDK registration: +13/-1. The positive runtime delta creates one private import boundary while moving the existing guard implementation.

Performance acceptance — frozen before scored runs

Baseline package: 9827935108e185e3f290d622dcccec07ff3814ae. Candidate package: 5826994e5e33ec25f48c5c3fff77c5656bb9684e. Common harness: 387e559d45cc95bde5394481a11bbcaddfe0bd87. Later changes relative to the candidate package concern benchmark evidence and a test inventory only; runtime source and dependencies are identical.

Both packages run on macOS arm64 / Node 24.22.1 with the same committed harness and byte-identical compiled worker sampler. This is the trusted local fallback after the requested Testbox allocation remained queued and was stopped before executing its payload. Linux correctness/build evidence above remains separate.

Seed 32 SQLite-backed sessions with 20 messages of 1,024 characters each. Run the existing owner-routed memory search after seeding; require owner RPC observations, successful indexing-worker tasks, and retained native worker identity. Pool telemetry does not identify individual task kinds: separate, unscored activation profiles establish execution of transcript statistics.

Then run two concurrent sessions, one warmup turn and two measured turns each, 20 fixed probe rounds, two history clients with burst one, one subscriber, and control-plane probes. Compare one and five synthetic plugins with five serial, interleaved A/B pairs per plugin count. Alternate pair order. Keep cold readiness and memory-scan timing separate from warm load. Disable CPU and heap profiling for scored runs.

Require successful behavior and clean teardown, measurable process RSS reduction with attributable removal of unused worker imports, and user-facing CPU/latency/count metrics that hold or improve. Report median, p95, spread, host load, all failed attempts, and work counts. Any worsening requires explicit maintainer acceptance; a 20% regression in any cell stops landing. Worker heaps are attribution only, not additive RSS.

The harness records embedding input ordinals, counts, character lengths, and exact ordered SHA-256 digests before fixture cleanup. Clipped or unparseable input evidence stays unknown and cannot establish matched work. Informational memory-index rebuild notices are preserved; stale/unavailable results fail qualification.

Full-corpus activation passed on both installed packages: four verified turns each, 33 successful indexing tasks, and the guarded reader plus SQL kernel observed in each indexing-worker CPU profile. All 109 ordered embedding request payloads matched exactly (651 inputs, 816,449 characters); raw arrival ordinals remain recorded separately. Both fixtures shut down cleanly. These profiled runs are unscored.

Completed performance qualification — HOLD / DO NOT LAND

All 20 scored attempts completed with exit 0: five serial, alternating-order A/B pairs for each of one and five plugins, with no exclusions. The observed median RSS reduction is modest: one plugin, 2,904.078 → 2,840.281 MiB (-2.20%); five plugins, 3,096.172 → 3,065.719 MiB (-0.98%). The indexing worker's stable post-load heap fell approximately 35.4%, with the same sampled worker counts (30 / 34). Worker heap is attribution, not additive process RSS.

The frozen acceptance gate FAILED. Stop conditions include:

Plugins Metric Baseline → candidate Change
1 Scan main CPU total, run p95 294.194 → 356.784 ms +21.28%
1 Scan main CPU user, run p95 252.619 → 310.227 ms +22.80%
5 Agent warmup, run p95 2,869.293 → 4,465.807 ms +55.64%
1 Median of per-run history p95 13.950 → 18.305 ms +31.22%
5 Median of per-run cron.list p50 1.861 → 2.281 ms +22.62%
5 Median of per-run cron.status p50 1.867 → 2.304 ms +23.44%

The history p95 run ranges were 11.435–19.133 → 12.031–21.447 ms. The cron.list run-p50 ranges were 1.804–2.074 → 2.010–3.039 ms; cron.status, 1.819–2.073 → 2.017–3.049 ms. Their paired median p50 changes were +26.46% and +24.06%. Pooled request percentiles below do not erase these run-level regressions.

Additional worsening of at least 20% appears in readiness-window utilization/CPU-core ratios below, and in one-plugin pre-scan main-heap p95 (+20.39%), pre-scan array-buffer p95 (+35.11%), and post-load main array-buffer median (5.983 → 7.483 MiB, +25.06%). Array buffers are not RSS. Candidate five-plugin pair 05 also recorded five degraded readiness samples, versus zero elsewhere; all remained HTTP 200 with ok=true.

This is an observed benchmark acceptance failure, not proof of a product regression or a causal explanation for each slowdown. Host noise, lower medians elsewhere, and successful exits do not waive the predeclared stop condition. The candidate remains draft/held. No merge or deployment.

Run-level memory, CPU, and phase results

Each variant/cohort has five independent runs. Entries show median [minimum, maximum]; with five runs, nearest-rank p95 equals the maximum. Percentage changes compare the marginal medians or p95 values, not paired deltas. CPU values are milliseconds. Harness setup includes preparation; it is not isolated listener-startup latency.

Plugins Metric Baseline median [min, max] Candidate median [min, max] Median change p95 change
1 RSS before load (MiB) 2848.969 [2652.922, 2867.312] 2772.031 [2007.734, 2811.016] -2.70% -1.96%
1 RSS after load / sampled peak (MiB) 2904.078 [2721.031, 2933.688] 2840.281 [2132.234, 2878.109] -2.20% -1.89%
1 RSS after scan (MiB) 2584.078 [2407.953, 2618.438] 2487.219 [1532.297, 2568.172] -3.75% -1.92%
1 Index-worker heap after load (MiB) 75.576 [75.575, 75.578] 48.841 [48.836, 48.842] -35.37% -35.38%
1 Harness setup (ms) 10248.152 [9869.828, 10371.342] 9971.715 [9672.369, 10537.325] -2.70% +1.60%
1 Memory scan (ms) 3897.002 [3815.259, 4012.425] 3694.092 [3572.895, 4073.737] -5.21% +1.53%
1 Agent warmup (ms) 2780.808 [2770.808, 2950.980] 2786.744 [2730.959, 2813.900] +0.21% -4.65%
1 Turn batch (ms) 2472.426 [2443.727, 2477.825] 2451.645 [2440.005, 2489.925] -0.84% +0.49%
1 Load process CPU total (ms) 1289.399 [1217.690, 1512.870] 1229.194 [1164.779, 1477.430] -4.67% -2.34%
1 Load main CPU total (ms) 538.889 [525.630, 582.558] 525.735 [516.191, 560.692] -2.44% -3.75%
1 Load process CPU user (ms) 1178.142 [1113.836, 1400.373] 1129.056 [1058.216, 1375.271] -4.17% -1.79%
1 Load main CPU user (ms) 487.334 [474.560, 527.765] 473.075 [466.859, 508.523] -2.93% -3.65%
1 Scan process CPU total (ms) 3193.456 [3170.150, 3263.192] 2916.931 [2851.136, 3505.962] -8.66% +7.44%
1 Scan main CPU total (ms) 279.855 [274.680, 294.194] 276.789 [265.422, 356.784] -1.10% +21.28%
1 Scan main CPU user (ms) 242.776 [238.748, 252.619] 239.793 [230.563, 310.227] -1.23% +22.80%
5 RSS before load (MiB) 3019.422 [2944.062, 3100.062] 2990.797 [2612.266, 3010.984] -0.95% -2.87%
5 RSS after load (MiB) 3096.172 [2919.438, 3163.062] 3065.719 [2731.359, 3085.094] -0.98% -2.46%
5 Sampled peak RSS (MiB) 3096.172 [2960.094, 3163.062] 3065.719 [2731.359, 3085.094] -0.98% -2.46%
5 RSS after scan (MiB) 2822.578 [2749.156, 2867.422] 2702.797 [2211.328, 2783.484] -4.24% -2.93%
5 Index-worker heap after load (MiB) 75.577 [75.576, 75.578] 48.843 [48.842, 48.843] -35.37% -35.37%
5 Harness setup (ms) 11591.543 [11293.685, 11702.971] 11078.216 [10910.411, 12935.335] -4.43% +10.53%
5 Memory scan (ms) 5081.124 [5048.325, 5272.519] 4807.214 [4644.176, 5059.521] -5.39% -4.04%
5 Agent warmup (ms) 2842.109 [2758.699, 2869.293] 2770.585 [2748.493, 4465.807] -2.52% +55.64%
5 Turn batch (ms) 2486.611 [2457.744, 2575.496] 2466.825 [2455.734, 2511.742] -0.80% -2.48%
5 Load process CPU total (ms) 1343.349 [1233.482, 1406.508] 1304.687 [1252.299, 1496.076] -2.88% +6.37%
5 Load main CPU total (ms) 541.762 [525.655, 633.437] 546.013 [538.175, 591.163] +0.78% -6.67%
5 Load process CPU user (ms) 1234.783 [1137.358, 1290.795] 1190.176 [1150.931, 1378.891] -3.61% +6.82%
5 Load main CPU user (ms) 490.785 [473.792, 575.436] 492.681 [486.311, 534.444] +0.39% -7.12%
5 Scan process CPU total (ms) 3330.880 [3155.818, 3398.281] 3019.229 [2953.133, 3195.642] -9.36% -5.96%
5 Scan main CPU total (ms) 303.228 [281.541, 320.228] 295.797 [277.323, 297.610] -2.45% -7.06%
5 Scan main CPU user (ms) 261.314 [242.517, 270.880] 250.813 [241.239, 258.127] -4.02% -4.71%

Paired RSS-after-load changes differ from ratios of marginal medians:

  • One plugin: median -1.254% [-26.917%, +4.380%], median absolute change -36.406 MiB.
  • Five plugins: median -2.753% [-11.029%, +5.674%], median absolute change -86.141 MiB.
  • Paired load process-CPU changes: one plugin +0.888% [-23.009%, +10.489%]; five plugins +2.627% [-7.379%, +11.369%]. Lower marginal CPU medians therefore do not establish consistent paired improvement.
  • Paired setup changes: -1.998% [-5.618%, +1.600%] / -2.431% [-6.285%, +14.536%] for one/five plugins. Paired scan changes: -6.341% [-7.934%, +2.796%] / -4.873% [-10.313%, -4.040%].

Retained residency anomalies: one-plugin candidate pair 05 ended at 2,132.234 MiB versus baseline 2,917.547 MiB, with 30 workers; five-plugin candidate pair 02 ended at 2,731.359 MiB versus baseline 3,069.953 MiB, with 34 workers. Neither sample was excluded or assigned a cause. Index-worker heap samples are complete and stable; some aggregate worker snapshots have pending workspace-memory-worker samples, so aggregate heap must not be summed as process RSS.

Request latency and readiness-window telemetry

Pooled request samples are descriptive, not independent run replicates. Per variant/cohort: history has 200 samples; readiness, sessionsList, Control UI, load subscriptions, and each cron method have 100; initial subscriptions and fresh connections have five.

Plugins Request Baseline median / p95 / min / max (ms) Candidate median / p95 / min / max (ms)
1 readyz 1.639 / 7.131 / 0.705 / 23.758 1.612 / 4.827 / 0.649 / 17.413
1 history 3.593 / 19.133 / 2.061 / 35.165 3.706 / 19.249 / 1.909 / 28.514
1 sessionsList 1.296 / 7.831 / 0.900 / 16.345 1.301 / 7.327 / 0.837 / 8.099
1 Control UI 3.314 / 11.984 / 2.506 / 28.706 3.423 / 12.528 / 2.498 / 23.156
1 initial subscription 1.096 / 1.256 / 1.041 / 1.256 1.083 / 1.159 / 1.068 / 1.159
1 subscription during load 1.974 / 8.230 / 0.884 / 16.760 2.019 / 7.892 / 0.958 / 9.933
1 fresh connection 1.729 / 2.099 / 1.567 / 2.099 1.741 / 1.778 / 1.605 / 1.778
1 cron.list 2.015 / 9.600 / 1.193 / 19.870 2.104 / 10.030 / 1.206 / 11.372
1 cron.status 2.022 / 9.606 / 1.440 / 19.632 2.110 / 10.044 / 1.440 / 11.169
5 readyz 1.617 / 13.396 / 0.639 / 21.397 1.706 / 6.169 / 0.712 / 17.530
5 history 3.167 / 20.338 / 2.167 / 38.546 3.549 / 19.062 / 1.911 / 31.293
5 sessionsList 1.233 / 9.480 / 0.819 / 15.566 1.356 / 7.522 / 0.869 / 9.577
5 Control UI 3.230 / 17.857 / 2.362 / 25.585 3.567 / 15.163 / 2.469 / 22.995
5 initial subscription 1.237 / 1.455 / 1.157 / 1.455 1.126 / 1.180 / 0.987 / 1.180
5 subscription during load 1.875 / 9.836 / 0.843 / 16.007 2.104 / 7.658 / 0.891 / 9.559
5 fresh connection 1.803 / 1.970 / 1.577 / 1.970 1.773 / 1.825 / 1.715 / 1.825
5 cron.list 1.956 / 12.447 / 1.208 / 19.181 2.189 / 9.612 / 1.417 / 11.621
5 cron.status 1.965 / 12.414 / 1.352 / 18.944 2.191 / 9.565 / 1.421 / 11.387

Readiness-window utilization and CPU-core ratio are separate from integrated load CPU:

Plugins Telemetry Baseline median / p95 Candidate median / p95 Median / p95 change
1 Utilization 0.140 / 0.302 0.188 / 0.446 +34.29% / +47.68%
1 CPU-core ratio 0.577 / 1.299 0.789 / 1.502 +36.74% / +15.63%
5 Utilization 0.272 / 0.343 0.323 / 0.450 +18.53% / +31.20%
5 CPU-core ratio 0.800 / 1.174 1.114 / 1.541 +39.25% / +31.26%
1 Delay-p99 observation (ms) 25.8 / 39.5 24.0 / 42.2 —
5 Delay-p99 observation (ms) 32.2 / 48.6 0 / 41.3 —

Zero histogram observations are retained literally and do not establish zero latency. The five degraded readiness samples in candidate five-plugin pair 05 reported delay p99/max 45.7 ms, utilization 0.195, and CPU-core ratio 1.099.

Work equivalence, behavior, and attribution

All 20 runs used the same corpus and matched the ordered embedding evidence after dropping only the separately recorded global arrival ordinal: 109 requests, 651 inputs, 816,449 characters per run, with no unknown hashes/counts/lengths.

  • Every run seeded 32 sessions; launched, terminally completed, and verified four measured turns and two warmup turns; observed the owner route, 33 indexing tasks, and one search result.
  • Provider work matched: 44 response requests and 109 embedding requests. Setup: 32 responses / 108 embeddings; warmup: four responses; load: eight responses / one embedding; post-load: zero. Load purposes were four benchmark turns and four activity recaps. The four unbound inference records are matching activity-recap work, not missing turn verification; no session-observer or unknown inference occurred.
  • Every run made 20 readiness, 20 UI, 20 sessionsList, 20 load-subscription, 40 history, and 40 control-plane calls, plus one initial subscription and one fresh connection. Session updates and plugin metadata scans were zero.
  • All Gateway processes exited cleanly with both exit/close receipts and no early exit. Failed request samples and budget violations were zero. The five degraded readiness samples above remain a separate behavioral anomaly.
  • Scan diagnostics recorded zero dropped events, collection errors, or dropped histogram samples. The same informational automatic-index-repair warning occurred in all 20 runs.
  • Separate unscored profiles observed the guarded transcript-statistics reader and shared SQL kernel in both builds: eight/nine inclusive reader samples, respectively. They establish execution of the intended import boundary; they are not scored RSS or CPU evidence.

Reproducibility identities:

  • Common compiled sampler SHA-256: 25a55faab541747521e70a7c8efb3b8941be952b703b8d594f18c757738198d5.
  • Common corpus SHA-256: 34d2e393372aa46b8a27397d7591a1f65360af850547dc355d587b6ddf42e667.
  • Canonical ordered embedding evidence SHA-256: f984fafc7704736e5d21e9b3090d24412c04a74bf392c6ff0c219bd1f5c41138.
Host conditions and interpretation limits

The host was macOS arm64, Node 24.22.1, 18 available CPUs, 48 GiB RAM. Load averages below are load1 snapshots, shown as median [min, max].

Plugins / variant Before After Free memory before (MiB range)
1 / baseline 5.311 [4.450, 5.638] 4.580 [3.914, 5.638] 735–4,421
1 / candidate 4.507 [3.914, 5.626] 5.311 [4.087, 5.626] 3,834–5,580
5 / baseline 5.182 [4.087, 5.827] 4.901 [4.669, 5.827] 3,293–4,702
5 / candidate 5.159 [4.669, 5.455] 5.182 [4.766, 5.455] 3,882–5,077

These snapshots do not identify a causative competing process, memory pressure/compression, or thermal state. No sample was removed and no causal explanation is assigned to the outliers or slowdowns.

Separate CI / merge status

At exact head 387e559d45cc95bde5394481a11bbcaddfe0bd87, GitHub reports a merge conflict (mergeable=false, mergeable_state=dirty, no merge SHA), and no current-head ci.yml run exists. Security Review 39951492021 completed, but its combined openclaw/ci-gate status is pending, waiting for CI. This is separate from the failed performance gate. No rebase, close/reopen, CI dispatch, or additional review round is requested while this candidate is held.

The three older Bun failures (Telegram callback drain, hooks error formatting, subagent completion) remain UNKNOWN in attribution. The corrected mock, SDK documentation, and bridge inventory do not establish that those unrelated failures are inherited or repaired.

@vincentkoc vincentkoc self-assigned this Oct 23, 2026
@clawsweeper

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

@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 23, 2026
@vincentkoc
vincentkoc marked this pull request as ready for review October 23, 2026 11:44
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. 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 23, 2026
@clawsweeper

clawsweeper Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: stale review; fresh review needed.

Summary
The latest durable ClawSweeper review was for head 7d9b93608a8fd4ed293d230d2a64f6c7ef5e2fc7, but the PR head is now 387e559d45cc95bde5394481a11bbcaddfe0bd87. Its old verdict and PR readiness labels are no longer current.

Next step
Comment @clawsweeper re-review when the current head is ready; pushes after the first review are not reviewed automatically.

Review history (1 earlier review cycle)
  • reviewed 2026-10-23T12:01:43.271Z sha 7d9b936 :: needs changes before merge. :: [P2] Document the new private SDK subpath | [P2] Register the extracted memory-host core bridge | [P2] Preserve exports in the managed-process mock

@openclaw-barnacle openclaw-barnacle Bot added the docs Improvements or additions to documentation label Oct 23, 2026
@vincentkoc
vincentkoc marked this pull request as draft October 23, 2026 12:20
@clawsweeper clawsweeper Bot removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 27, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation extensions: memory-core Extension: memory-core extensions: xai P2 Normal backlog priority with limited blast radius. scripts Repository scripts size: L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant