Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Wire EventMemory as backend for LongTermMemory#1395

Merged
malatewang merged 13 commits into
MemMachine:mainfrom
edwinyyyu:wire_event_memory_backend
May 14, 2026
Merged

Wire EventMemory as backend for LongTermMemory#1395
malatewang merged 13 commits into
MemMachine:mainfrom
edwinyyyu:wire_event_memory_backend

Conversation

@edwinyyyu

@edwinyyyu edwinyyyu commented May 8, 2026

Copy link
Copy Markdown
Contributor

Purpose of the change

Alternative to #1304.
#1304 added EventMemory as a parallel memory subsystem highly exposed via API.
We want to make large changes only after careful design, so this PR instead adds EventMemory as a backend for the existing long-term memory, with minimal behavioral differences.

Description

No chunking/segmentation, old API.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Refactor (does not change functionality, e.g., code style improvements, linting)
  • Documentation update
  • Project Maintenance (updates to build scripts, CI, etc., that do not affect the main project)
  • Security (improves security without changing functionality)

Testing

  • Unit Test
  • Integration Test
  • End-to-end Test
  • Test Script (please provide)
  • Manual verification (list step-by-step instructions)

Checklist

  • I have signed the commit(s) within this pull request
  • My code follows the style guidelines of this project (See STYLE_GUIDE.md)
  • I have performed a self-review of my own code
  • I have commented my code
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added unit tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules
  • I have checked my code and corrected any misspellings

Maintainer Checklist

  • Confirmed all checks passed
  • Contributor has signed the commit(s)
  • Reviewed the code
  • Run, Tested, and Verified the change(s) work as expected

@edwinyyyu edwinyyyu force-pushed the wire_event_memory_backend branch from f570bd7 to 6e45f17 Compare May 8, 2026 21:52
@edwinyyyu edwinyyyu changed the title Claude initial wiring Wire EventMemory as backend for LongTermMemory May 8, 2026
Signed-off-by: Edwin Yu <[email protected]>

Example configs

Signed-off-by: Edwin Yu <[email protected]>
@edwinyyyu edwinyyyu force-pushed the wire_event_memory_backend branch from 280f09d to da58952 Compare May 8, 2026 22:11
@edwinyyyu edwinyyyu requested a review from malatewang May 8, 2026 22:11
@edwinyyyu edwinyyyu marked this pull request as ready for review May 8, 2026 22:17
edwinyyyu added 2 commits May 8, 2026 15:35
Signed-off-by: Edwin Yu <[email protected]>
Signed-off-by: Edwin Yu <[email protected]>
@edwinyyyu edwinyyyu force-pushed the wire_event_memory_backend branch from 456bc43 to 8f6fb0d Compare May 8, 2026 22:41
@edwinyyyu edwinyyyu marked this pull request as draft May 8, 2026 23:33
Signed-off-by: Edwin Yu <[email protected]>
@edwinyyyu edwinyyyu force-pushed the wire_event_memory_backend branch 4 times, most recently from 4cd2ff6 to 501f052 Compare May 9, 2026 00:45
Signed-off-by: Edwin Yu <[email protected]>
@edwinyyyu edwinyyyu force-pushed the wire_event_memory_backend branch from 501f052 to 4704400 Compare May 9, 2026 00:54
Signed-off-by: Edwin Yu <[email protected]>
@edwinyyyu edwinyyyu force-pushed the wire_event_memory_backend branch from 6d11900 to fcd62a9 Compare May 11, 2026 20:20
@edwinyyyu edwinyyyu marked this pull request as ready for review May 11, 2026 20:56
@edwinyyyu edwinyyyu added this to the v0.3.9 milestone May 11, 2026
@edwinyyyu edwinyyyu marked this pull request as draft May 12, 2026 00:22
@edwinyyyu

Copy link
Copy Markdown
Contributor Author
User-supplied filterable_metadata can clobber system fields → cross-producer / cross-session impersonation

  long_term_memory.py:495-508: properties.update(episode.filterable_metadata) runs after _producer_id, _session_key, _episode_uid
  etc. are set. Any colliding key from the client wins. There is no key filter anywhere in the path from EpisodeEntry.metadata →
  episodic_memory.py:223 → episode.filterable_metadata → _episode_to_event.

  The test test_episode_to_event.py:134-144 literally asserts this behavior:
  filterable_metadata={"_producer_id": "shouldnt-overwrite"}
  ...
  assert event.properties["_producer_id"] == "shouldnt-overwrite"
  # comment: "If we ever want to protect system fields ... we'll need an explicit validator"

  A client sending {"_producer_id": "victim", "_session_key": "other-session"} gets indexed under those spoofed identities.
  search_scored(property_filter=producer_id="victim") then surfaces the attacker's content under the victim's identity, and the
  dedup-by-_episode_uid (long_term_memory.py:294-299) collapses results across spoofed and real episode uids. The declarative path is
   safe because it mangles user keys with a metadata. prefix — only the event path regressed.

@edwinyyyu edwinyyyu marked this pull request as ready for review May 13, 2026 23:00

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR wires EventMemory as an alternative backend for the existing long-term episodic memory, behind a new backend discriminator ("declarative" | "event"). Legacy configs without a backend field continue to deserialize as declarative (backwards compatible), while the configuration wizard now generates event-backed configs by default and offers a vector-store selection (Qdrant / SQLite-USearch / sqlite-vec). The LongTermMemory facade is refactored into a dispatcher between two backend params types, exposing a slimmer public surface (search_scored, delete_episodes, drop_session_partition) and removing the older search / get_episodes / get_matching_episodes / delete_matching_episodes / sanitize_property_filter / episode_from_declarative_memory_episode methods.

Changes:

  • Introduce a discriminated LongTermMemoryConf (Declarative vs Event) and corresponding API spec / response / update fields (backend, vector_store, segment_store, properties_schema), with property-type validation at request time.
  • Add EventMemory-backed long-term memory: episode-to-event translation, deterministic uuid5 mapping, reserved-key rejection, filter-field validation, metric-aware score thresholding, and drop_session_partition for partition lifecycle.
  • Update the resource manager to construct/cache segment stores from SQL engines; update the configuration wizard, sample configs, server defaults, and clients (Python SDK + tests) to support the new backend.

Reviewed changes

Copilot reviewed 42 out of 42 changed files in this pull request and generated 20 comments.

Show a summary per file
File Description
sample_configs/episodic_memory_config.{cpu,gpu,nebula}.sample Document the new event backend and Qdrant/SQLite vector-store options.
packages/server/src/memmachine_server/server/api_v2/router.py Translate v2 ProjectConfigLongTermMemoryConfPartial; expose event-backend fields.
packages/server/src/memmachine_server/server/api_v2/config_service.py Backend-flip handling; surface event-backend fields in config responses.
packages/server/src/memmachine_server/server/api_v2/config_router.py Forward new event-backend fields on PUT.
packages/server/src/memmachine_server/main/memmachine.py Backend-aware LTM default resolution; narrow exception catch.
packages/server/src/memmachine_server/installation/configuration_wizard.py Default to event backend + interactive vector-store selection.
packages/server/src/memmachine_server/episodic_memory/long_term_memory/ New backends, params, service-locator helpers, facade refactor.
packages/server/src/memmachine_server/episodic_memory/event_memory/segmenter/passthrough_segmenter.py New passthrough segmenter implementation.
packages/server/src/memmachine_server/episodic_memory/event_memory/segment_store/sqlalchemy_segment_store.py Map bare filter fields to _<field> instead of raising.
packages/server/src/memmachine_server/episodic_memory/episodic_memory.py Use drop_session_partition() on delete-session.
packages/server/src/memmachine_server/common/resource_manager/{,resource_manager}.py Add get_segment_store and get_episode_storage interfaces.
packages/server/src/memmachine_server/common/configuration/episodic_config.py Discriminated LTM config, new sub-configs, merge resolution.
packages/common/src/memmachine_common/api/{spec,config_spec}.py New backend / event-backend fields and properties_schema validation.
packages/client/src/memmachine_client/{client,config,project}.py Plumb new event-backend params through SDK.
packages/server/server_tests/**, packages/client/client_tests/** New / updated tests for backend switching, event wiring, wizard prompts.
.github/workflows/{installation,test-server,test-python-client}.yml Install all local memmachine_* wheels by direct path.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread sample_configs/episodic_memory_config.nebula.sample Outdated
Comment thread .github/workflows/test-server-package.yml
Signed-off-by: Edwin Yu <[email protected]>
@edwinyyyu edwinyyyu force-pushed the wire_event_memory_backend branch 3 times, most recently from 632bc8e to 56eb8bc Compare May 14, 2026 20:38
Signed-off-by: Edwin Yu <[email protected]>
@edwinyyyu edwinyyyu force-pushed the wire_event_memory_backend branch from 56eb8bc to a35a144 Compare May 14, 2026 20:43
@malatewang malatewang merged commit a5cf59d into MemMachine:main May 14, 2026
42 of 44 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants