Skip to content

Preserve updated Q after cache eviction - #17

Open
Frankie-Xu wants to merge 2 commits into
MemTensor:mainfrom
Frankie-Xu:fix/q-cache-eviction-metadata
Open

Frankie-Xu wants to merge 2 commits into
MemTensor:mainfrom
Frankie-Xu:fix/q-cache-eviction-metadata

Conversation

@Frankie-Xu

@Frankie-Xu Frankie-Xu commented Sep 18, 2026

Copy link
Copy Markdown

MemoryService keeps both a fast _q_cache and a _mem_cache of memory objects. After a successful Q update, FIFO eviction can remove an ID from _q_cache; retrieval then falls back to that memory object's stale metadata.q_value and can silently lose the learned value.

Synchronize cached memory metadata after successful non-None single or batch updates. If the metadata object rejects assignment, invalidate that _mem_cache entry so the next retrieval uses the existing storage read path instead of reusing a stale fallback. This preserves the Q-learning formula, FIFO policy, retrieval scoring, and existing error contract without adding cross-process or concurrency behavior.

Validation:

  • On main c1b322c, the original single/batch eviction regressions failed (learned -0.5/0.5 fell back to 0.0).
  • A read-only metadata regression then failed on the first PR17 revision because the stale entry remained cached.
  • At head 4a2d77c, five unittest cases pass; the same five pass under pytest and from a clean git archive export.
  • Coverage includes single and batch updates, FIFO eviction, negative and zero Q values, persistence failures without cache/metadata pollution, q-cache snapshot round-trip, rejected metadata assignment, and fresh storage rehydration.
  • Tests execute the real MemoryService retrieval/update and QValueUpdater paths with only MemOS import types, in-memory persistence, fixed embeddings, and a contract-shaped read-only metadata double substituted. MemoryOS==1.0.0 is declared but not installed locally, so no live integration is claimed.
  • compileall and git diff --check pass.

This is independent of PR #14's finite-value validation and PR #16's single-update Q-cache publication.

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.

1 participant