Skip to content

improve(memory): lower memory-core startup RSS - #119372

Merged
vincentkoc merged 1 commit into
mainfrom
perf/memory-core-lazy-registration-20260804
Aug 5, 2026
Merged

vincentkoc merged 1 commit into
mainfrom
perf/memory-core-lazy-registration-20260804

Conversation

@vincentkoc

@vincentkoc vincentkoc commented Aug 4, 2026 •

Copy link
Copy Markdown
Member

What Problem This Solves

Loading the selected memory-core plugin also loaded the historical session-backfill execution graph, even when operators never used the Control UI backfill methods. Paired profiling of exact CI artifacts from main and this PR shows that graph adds about 141 MB of avoidable peak RSS during the isolated plugin import.

Why This Change Was Made

Gateway method names, scopes, request validation, config lookup, and error mapping remain synchronously registered. The heavy backfill implementation now loads once on the first valid request through a dedicated gateway runtime facade, selection validation lives in a dependency-light leaf, and memory-core uses its focused host facade instead of the deprecated broad agent runtime barrel.

The dedicated facade keeps the gateway's dynamic import separate from the CLI runtime's static imports. Dreaming registration is intentionally unchanged because its timers, generations, and shutdown cleanup need a separate lifecycle-focused change.

Architectural owner: the memory-core gateway adapter. Production delta: +68/-60 lines (net +8); tests: +81 lines.

User Impact

Operators get lower startup memory use with no change to memory tools, prompts, gateway method availability, permissions, request validation, or backfill results.

Evidence

  • Three paired same-host profiles using the exact dist-runtime-build artifacts from successful main CI at fb81d03d8eb2 and exact-head PR CI at af2957ab7f9b:
    • exact main median: 419.97 MB max RSS, 376.33 MB above process baseline
    • exact head median: 278.80 MB max RSS, 235.11 MB above process baseline
    • reduction: 141.17 MB max RSS; 37.5% of the plugin import delta
  • node scripts/run-vitest.mjs extensions/memory-core/src/session-backfill-gateway.lazy.test.ts extensions/memory-core/src/session-backfill-gateway.test.ts extensions/memory-core/src/session-backfill.test.ts extensions/memory-core/index.test.ts
    • 4 files, 50 tests passed
  • Exact-head hosted CI run 30960740376 passed, including build artifacts, production/test types, lint, runtime topology, extension package boundaries, and all selected test shards.
  • Production, full-tree, and script unused-export guards passed.
  • Structured autoreview: clean, no actionable findings, 0.99 confidence.
  • git diff --check passed.

AI-assisted: yes. The implementation and evidence were reviewed before submission.

Punchcard-Session: coral-workshop-workshop-3f

@openclaw-barnacle openclaw-barnacle Bot added extensions: memory-core Extension: memory-core size: M maintainer Maintainer-authored PR labels Aug 4, 2026
@vincentkoc
vincentkoc marked this pull request as ready for review August 4, 2026 23:22
@vincentkoc vincentkoc self-assigned this Aug 4, 2026
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. labels Aug 4, 2026
@clawsweeper

clawsweeper Bot commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 4, 2026, 8:11 PM ET / August 5, 2026, 00:11 UTC.

ClawSweeper review

What this changes

Defers Memory Core session-backfill execution loading until a valid gateway request, reducing plugin-startup memory while retaining synchronous method registration and validation.

Merge readiness

⚠️ Ready for maintainer review - 1 item remains

No blocking findings: current main still eagerly imports the backfill execution graph, while this PR isolates that load behind valid gateway requests. The member-authored, maintainer-labeled change needs ordinary merge judgment; likely related people: Shakker and Peter Steinberger (high confidence).

Priority: P3
Reviewed head: af2957ab7f9b89eab685ea4edb26ef368b0a5d18
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch is a focused, well-covered runtime-boundary improvement with strong supplied exact-head validation evidence.
Proof confidence 🌊 off-meta tidepool Not applicable: This member-authored PR is exempt from the external-contributor proof gate; it nevertheless includes repeated copied artifact-profile output for the after-fix startup measurement.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This member-authored PR is exempt from the external-contributor proof gate; it nevertheless includes repeated copied artifact-profile output for the after-fix startup measurement.
Evidence reviewed 7 items Current-main behavior: Current main statically imports both backfill executors from the gateway adapter, so the execution graph remains part of plugin registration today.
Lazy owner boundary: The PR keeps parsing, agent validation, scopes, and responses eager, then loads the cached execution facade only after a valid request and execution context.
Cached runtime contract: The shared lazy-runtime helper caches the dynamic-import promise, so repeated valid requests share one runtime load.
Findings None None.
Security None None.

How this fits together

Memory Core registers memory and session-backfill gateway methods during plugin startup. Valid backfill requests then read session ingestion state and return preview, apply, or rollback results.

flowchart LR
  A[Memory Core startup] --> B[Gateway method registration]
  B --> C[Backfill request]
  C --> D[Input and agent validation]
  D --> E[Lazy backfill runtime]
  E --> F[Session ingestion state]
  E --> G[Gateway result]
Loading

Decision needed

Question Recommendation
Should maintainers merge this member-authored Memory Core startup-memory optimization after the normal exact-head merge check? Merge the lazy boundary: Accept the focused gateway-owned deferral, which preserves eager validation and the existing CLI execution path.

Why: The PR is authored by a repository member and carries the protected maintainer label, so automated triage must leave the final merge choice to maintainers.

Before merge

None.

Agent review details

Security

None.

PR surface

Source +8, Tests +81. Total +89 across 8 files.

View PR surface stats
Area Files Added Removed Net
Source 7 68 60 +8
Tests 1 81 0 +81
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 8 149 60 +89

Review metrics

Metric Value Why it matters
Production versus test LOC production +68/-60; tests +81 The net +8 production lines establish one dedicated lazy owner boundary and are accompanied by focused regression coverage.

Stored data model

Persistent data-model change detected: migration/backfill/repair: extensions/memory-core/src/session-backfill-gateway.lazy.test.ts, migration/backfill/repair: extensions/memory-core/src/session-backfill-gateway.runtime.ts, migration/backfill/repair: extensions/memory-core/src/session-backfill-gateway.ts, migration/backfill/repair: extensions/memory-core/src/session-backfill.ts, serialized state: extensions/memory-core/src/session-backfill-gateway.lazy.test.ts, serialized state: extensions/memory-core/src/session-backfill-gateway.runtime.ts, and 7 more. Confirm migration or upgrade compatibility proof before merge.

Technical review

Best possible solution:

Merge the dedicated gateway runtime boundary so plugin startup avoids the backfill execution graph while CLI execution keeps its existing static path.

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

Not applicable: this is a measured startup-memory optimization, not a report of broken existing behavior; the PR supplies repeated exact-artifact profile output.

Is this the best way to solve the issue?

Yes: the gateway adapter is the sole non-CLI registration edge, so deferring only its execution graph avoids both eager startup loading and an unnecessary change to CLI behavior.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 9ff9aac71a8b.

Labels

Label justifications:

  • P3: This is a bounded startup-memory improvement with no evidence of an urgent user-facing regression.
  • 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: This member-authored PR is exempt from the external-contributor proof gate; it nevertheless includes repeated copied artifact-profile output for the after-fix startup measurement.

Evidence

What I checked:

Likely related people:

  • Shakker: Blame attributes the eager gateway import and registration path on current main to the commit that introduced this implementation. (role: current gateway-path introducer; confidence: high; commits: 2929dde43e1b; files: extensions/memory-core/src/session-backfill-gateway.ts, src/plugin-sdk/memory-core-host-runtime-core.ts)
  • Peter Steinberger: History shows the original Control UI backfill work and subsequent rollback, draining, and session-ingestion repairs in this area. (role: session-backfill feature-history contributor; confidence: high; commits: ca48f6c0fb5a, 53815217e93f, f216d3cc868e; files: extensions/memory-core/src/session-backfill.ts, extensions/memory-core/src/session-backfill-lifecycle.ts)

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 (2 earlier review cycles)
  • reviewed 2026-08-04T23:28:31.249Z sha 811dbf9 :: needs changes before merge. :: [P2] Keep session backfill behind one runtime boundary
  • reviewed 2026-08-05T00:05:53.720Z sha af2957a :: needs maintainer review before merge. :: none

@vincentkoc
vincentkoc force-pushed the perf/memory-core-lazy-registration-20260804 branch from 811dbf9 to 43ce571 Compare August 4, 2026 23:32
Punchcard-Session: coral-workshop-workshop-3f
@vincentkoc
vincentkoc force-pushed the perf/memory-core-lazy-registration-20260804 branch from 43ce571 to af2957a Compare August 4, 2026 23:39
@vincentkoc

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added 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. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 5, 2026
@vincentkoc

Copy link
Copy Markdown
Member Author

Exact artifact-backed memory profile evidence

Both sides used the same host, Node runtime, dependency tree, profiler command, and restored base package.json expected by the normal built-runtime layout. Inputs were the dist-runtime-build artifacts from successful main CI run 30958313424 at fb81d03d8eb2 and PR CI run 30960740376 at af2957ab7f9b.

main  sample 1: baseline=43.640625 MB maxRSS=419.968750 MB delta=376.328125 MB
main  sample 2: baseline=43.625000 MB maxRSS=420.375000 MB delta=376.750000 MB
main  sample 3: baseline=43.625000 MB maxRSS=419.468750 MB delta=375.843750 MB

head  sample 1: baseline=43.671875 MB maxRSS=279.625000 MB delta=235.953125 MB
head  sample 2: baseline=43.703125 MB maxRSS=278.796875 MB delta=235.093750 MB
head  sample 3: baseline=43.640625 MB maxRSS=278.750000 MB delta=235.109375 MB

median main: maxRSS=419.968750 MB delta=376.328125 MB
median head: maxRSS=278.796875 MB delta=235.109375 MB
reduction:   maxRSS=141.171875 MB delta=141.218750 MB (37.525%)

Command shape:

OPENCLAW_LOCAL_CHECK=0 node scripts/profile-extension-memory.mjs \
  --extension memory-core \
  --skip-combined \
  --concurrency 1 \
  --json <report-path>

@vincentkoc

Copy link
Copy Markdown
Member Author

Maintainer decision: accepted. I reviewed the exact-head owner boundary, exact CI, paired artifact profile, and ClawSweeper recommendation. No repair or rank-up move remains. The latest main drift is CI-only and does not overlap this change, so I am proceeding through the repo-native prepare and squash-merge path.

@vincentkoc
vincentkoc merged commit cbde3c1 into main Aug 5, 2026
130 of 136 checks passed
@vincentkoc
vincentkoc deleted the perf/memory-core-lazy-registration-20260804 branch August 5, 2026 00:16
@vincentkoc

Copy link
Copy Markdown
Member Author

Merged via squash.

vincentkoc added a commit that referenced this pull request Aug 5, 2026
Punchcard-Session: crisp-lantern-orchard-nv

* origin/main:
  perf(memory): defer session backfill runtime (#119372)
  fix(ci): isolate built TUI PTY fixture (#119339)
  fix(commands): restore tool inventory for dynamic models (#119306)
  fix(media): release rejected BytePlus and Runway video downloads under debug capture (#119257)
  docs: add ChromeOS (Crostini) platform install guide (#107663)
  test(msteams): serve JWKS from in-process server in auth coverage (#119354)
  fix(qa): enable OpenAI for stored audio scenario (#119349)
  test(agents): realpath apply-patch temp dir fixture (#119353)
  test(slack): drop redundant .js-suffixed system-event mock (#119352)
  fix(exec): leave safe builtins unrewritten in enforced mode (#119351)
  fix(sessions): keep gateway responsive while large transcript archives are built (#112424)
  fix(tui): restore provider auth in installed local mode (#119283)
vincentkoc added a commit that referenced this pull request Aug 5, 2026
…time

* origin/main:
  fix(ui): clear split-pane questions after answers and cancellations (#118787)
  fix(slack): authorize reaction and message reads before applying limits (#118736)
  fix(ci): isolate cache warmer configs (#119381)
  fix(slack): Fix bad escaping in slack tool commentary (#119373)
  feat(audit): add execution identity inspection (#117034)
  fix(fs): adopt fs-safe 0.5.2 untrusted filename sanitization (#119363)
  fix(ci): preserve release evidence across reruns (#119380)
  fix(telegram): keep commands responsive during Codex login
  perf(memory): defer session backfill runtime (#119372)
  fix(ci): isolate built TUI PTY fixture (#119339)
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 5, 2026
Punchcard-Session: coral-workshop-workshop-3f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extensions: memory-core Extension: memory-core maintainer Maintainer-authored PR P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. 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