Skip to content

fix(memory): reduce memory retained by retrieval workers - #167327

Closed
RomneyDa wants to merge 1 commit into
mainfrom
fix/memory-search-session-identity-imports
Closed

RomneyDa wants to merge 1 commit into
mainfrom
fix/memory-search-session-identity-imports

Conversation

@RomneyDa

@RomneyDa RomneyDa commented Oct 8, 2026 •

Copy link
Copy Markdown
Member

What Problem This Solves

The read-only memory retrieval worker eagerly loads the session-store runtime through two pure helpers: session-key classification and transcript filename parsing. Prewarming consequently retains unrelated session, configuration, and agent module graphs.

User Impact

Memory retrieval retains less unrelated runtime state. Prewarming, privacy-forget selection, session grammar, and installed plugin compatibility remain unchanged; no operator migration or new setting is required.

Why This Change Was Made

  • Reuse the existing private-local session-key-runtime SDK subpath for these pure identity helpers.
  • Move the dreaming classifier unchanged to the existing session-key owner; retain the established memory-session exports for installed plugin compatibility.
  • Migrate both bundled memory readers together. Keep prewarming, privacy-forget selection, cron/dreaming/archive grammar, and main's incognito bindings unchanged.
  • No new subpath, dependency, config option, schema, permission, or update migration. No tests added or changed.

Evidence

  • Canonical Linux build passed. Built retrieval-worker imports decreased from 2,173 to 784 URLs; the session runtime is no longer reachable.
  • Isolated worker retained heap: 57.9 → 24.5 MiB; process RSS: 141.9 → 98.0 MiB.
  • Real isolated Linux Gateway completed both samples and cleanup. Settled RSS: 927.7 → 893.2 MiB; the earlier sample increased from 994.3 to 1,054.7 MiB. This is directional local ARM64 evidence, not strict CI peak-RSS qualification.
  • Existing session-state/cron/forget tests: 46 passed on release and 46 on this main source. Main focused command wall time: 136.02 s. No additional test CI cost introduced.
  • Fresh release and main reviews: scoped-clean P0–P2.
  • Native main pnpm build: passed (5m32.2s). Required main changed gate: passed in full.
  • Isolated Matrix cold-import profiler passed at 104.25 MiB. This dirty-tree local screening is not strict release qualification.

Exact-source strict release performance finished: three cells passed, one CPU interval was inconclusive, and the many-plugin cell failed unchanged RSS budgets (Gateway 1,250.1/1,177 MiB; status CLI 954.9/900 MiB). The retained-worker improvement does not establish a peak-RSS or CPU pass. Publication is not part of this PR.

@clawsweeper

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

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation extensions: memory-core Extension: memory-core size: S labels Oct 8, 2026
@RomneyDa
RomneyDa marked this pull request as ready for review October 8, 2026 16:38
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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. labels Oct 8, 2026
@clawsweeper

clawsweeper Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 8, 2026, 1:15 PM ET / 17:15 UTC (Revision 2).

ClawSweeper review

What this changes

The branch routes memory retrieval workers through lightweight session identity helpers while preserving existing memory-session exports.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, behavior-preserving improvement with real setup measurements and no actionable finding; broader performance qualification remains explicitly separate.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): Supplied built-worker measurements exercise the changed retrieval-worker import boundary and show lower retained heap and RSS; the real isolated Linux Gateway run also shows lower settled RSS. The earlier Gateway sample increased, so this supports the scoped retention improvement without establishing peak-RSS or CPU qualification. No stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes
User problem: The Gateway retains unnecessary memory when retrieval workers load unrelated session and agent runtime modules.
Reason: The measured retained-memory reduction justifies this small import-boundary change. Existing session classification, privacy-forget behavior, and operator settings remain intact.

Merge readiness

✅ Ready for maintainer review

This PR remains useful and has no concrete review blocker. Current main retains the broad imports, the patch preserves existing behavior and compatibility, and the supplied measurements support its scoped memory improvement.

Priority: P2
Reviewed head: b563b167c42ed428f5b373a5b2cde1a029f1daf7

Before merge

None.

Findings

None.

Provenance

  • packages/memory-host-sdk/src/host/openclaw-runtime-session.ts dreaming classifier: original intent not found (unknown: Host evidence identifies a consolidation edit, but the local string-history search encountered an unavailable promisor blob and HTTP 403; exact classifier introduction was not established.)
Agent review details

How this fits together

Memory retrieval workers search indexed notes and prepare privacy-forget selections outside the Gateway thread. They need session identity helpers, but importing those through the session runtime also retains unrelated configuration and agent modules.

flowchart TD
  A[Gateway memory requests] --> B[Retrieval worker]
  B --> C[Search notes or prepare forget selection]
  C --> D[Lightweight session identity helpers]
  D --> E[Classify session keys and transcript names]
  C --> F[Return results to Gateway]
Loading

Technical review

Best possible solution:

Keep pure session identity helpers with their lightweight owner while preserving installed-plugin exports and the existing worker lifecycle.

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

Not applicable to a functional bug: source confirms the eager import path, and the supplied before/after measurements demonstrate the retention cost; this review did not execute target code.

Is this the best way to solve the issue?

Yes: reusing the existing lightweight entry point removes the import cause without duplicating session grammar or changing supported call signatures.

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: shipped entry point. Added test files: 0.

Security

None.

Evidence

What I checked:

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Hannes Rudolph: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

PR surface

Source +12, Docs +5. Total +17 across 6 files.

View PR surface stats
Area Files Added Removed Net
Source 5 35 23 +12
Tests 0 0 0 0
Docs 1 5 0 +5
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 40 23 +17

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This is a bounded runtime memory improvement supported by concrete local measurements.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

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 need explicit maintainer commands such as @clawsweeper autofix or @clawsweeper automerge.

History

Review history (1 earlier review cycle)
  • reviewed 2026-10-08T16:44:12.870Z sha b563b16 :: needs maintainer review before merge. :: none

@steipete

Copy link
Copy Markdown
Contributor

Thanks @RomneyDa for the import-boundary fix and the original measurements. I opened #172392 as a maintainer replacement because edits to this branch are disabled, with Dallin Romney's co-author credit preserved.

It adapts the session-identity move to current main and also removes a newer keyword-expansion import through the same heavy facade. The Mac worker comparison now shows 66.47 → 24.92 MiB settled heap and 2,293 → 738 loaded URLs, with identical search rows and Forget plans. The Ollama embedding-index control shows the same reduction. The final local-model repeat passed, and the replacement is ready for review; it has not been merged.

steipete added a commit that referenced this pull request Oct 15, 2026
* fix(memory): reduce memory retained by retrieval workers

Route indexing and Forget identity helpers through session-key-runtime so
retrieval workers do not retain the unrelated session-store module graph.
Move dreaming identity classification to its session-key owner, preserving
the existing memory host facades and installed-plugin exports. Cover the
lightweight import boundary with a regression and document the SDK seam.

Continues #167327 with its contributor's credit on current main.

Co-authored-by: Dallin Romney <[email protected]>

* fix(memory): keep query expansion off the session-store facade

The current keyword planner added another pure helper import through the
session facade after the original worker-retention patch. Mac measurements
showed that retaining this edge erased the benefit of moving the two
identity consumers. Reuse the existing lightweight retrieval SDK facade and
extend the import regression to cover query expansion as well.

Query tokenization and installed-plugin exports remain unchanged.

* fix(memory): keep transcript identity parsing free of codecs

Move transcript filename grammar into an import-free leaf shared by artifact helpers and compression. Keep session-key runtime off the artifact and native codec import graph, with an SDK import regression.

* fix(tooling): include transcript names in PR wrapper sources

---------

Co-authored-by: Dallin Romney <[email protected]>
@steipete

Copy link
Copy Markdown
Contributor

Thank you @RomneyDa for identifying and fixing the retrieval-worker import boundary, and for the memory measurements. The credited maintainer replacement is now merged in #172392 as 9d8180f.

Dallin Romney's Co-authored-by credit is preserved in the merge commit. Closing this original PR now that the replacement has landed.

@steipete steipete closed this Oct 15, 2026
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 16, 2026
…2392)

* fix(memory): reduce memory retained by retrieval workers

Route indexing and Forget identity helpers through session-key-runtime so
retrieval workers do not retain the unrelated session-store module graph.
Move dreaming identity classification to its session-key owner, preserving
the existing memory host facades and installed-plugin exports. Cover the
lightweight import boundary with a regression and document the SDK seam.

Continues openclaw#167327 with its contributor's credit on current main.

Co-authored-by: Dallin Romney <[email protected]>

* fix(memory): keep query expansion off the session-store facade

The current keyword planner added another pure helper import through the
session facade after the original worker-retention patch. Mac measurements
showed that retaining this edge erased the benefit of moving the two
identity consumers. Reuse the existing lightweight retrieval SDK facade and
extend the import regression to cover query expansion as well.

Query tokenization and installed-plugin exports remain unchanged.

* fix(memory): keep transcript identity parsing free of codecs

Move transcript filename grammar into an import-free leaf shared by artifact helpers and compression. Keep session-key runtime off the artifact and native codec import graph, with an SDK import regression.

* fix(tooling): include transcript names in PR wrapper sources

---------

Co-authored-by: Dallin Romney <[email protected]>
RomneyDa added a commit that referenced this pull request Oct 17, 2026
* fix(memory): reduce memory retained by retrieval workers

Route indexing and Forget identity helpers through session-key-runtime so
retrieval workers do not retain the unrelated session-store module graph.
Move dreaming identity classification to its session-key owner, preserving
the existing memory host facades and installed-plugin exports. Cover the
lightweight import boundary with a regression and document the SDK seam.

Continues #167327 with its contributor's credit on current main.

Co-authored-by: Dallin Romney <[email protected]>

* fix(memory): keep query expansion off the session-store facade

The current keyword planner added another pure helper import through the
session facade after the original worker-retention patch. Mac measurements
showed that retaining this edge erased the benefit of moving the two
identity consumers. Reuse the existing lightweight retrieval SDK facade and
extend the import regression to cover query expansion as well.

Query tokenization and installed-plugin exports remain unchanged.

* fix(memory): keep transcript identity parsing free of codecs

Move transcript filename grammar into an import-free leaf shared by artifact helpers and compression. Keep session-key runtime off the artifact and native codec import graph, with an SDK import regression.

* fix(tooling): include transcript names in PR wrapper sources

---------

Co-authored-by: Dallin Romney <[email protected]>
(cherry picked from commit 9d8180f)
@RomneyDa
RomneyDa deleted the fix/memory-search-session-identity-imports branch October 22, 2026 05:39
RomneyDa added a commit that referenced this pull request Oct 27, 2026
* fix(memory): reduce memory retained by retrieval workers

Route indexing and Forget identity helpers through session-key-runtime so
retrieval workers do not retain the unrelated session-store module graph.
Move dreaming identity classification to its session-key owner, preserving
the existing memory host facades and installed-plugin exports. Cover the
lightweight import boundary with a regression and document the SDK seam.

Continues #167327 with its contributor's credit on current main.

Co-authored-by: Dallin Romney <[email protected]>

* fix(memory): keep query expansion off the session-store facade

The current keyword planner added another pure helper import through the
session facade after the original worker-retention patch. Mac measurements
showed that retaining this edge erased the benefit of moving the two
identity consumers. Reuse the existing lightweight retrieval SDK facade and
extend the import regression to cover query expansion as well.

Query tokenization and installed-plugin exports remain unchanged.

* fix(memory): keep transcript identity parsing free of codecs

Move transcript filename grammar into an import-free leaf shared by artifact helpers and compression. Keep session-key runtime off the artifact and native codec import graph, with an SDK import regression.

* fix(tooling): include transcript names in PR wrapper sources

---------

Co-authored-by: Dallin Romney <[email protected]>
(cherry picked from commit 9d8180f)
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 P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S 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.

2 participants