Skip to content

feat(memory): add MemGuard type-aware retrieval composition - #6226

Merged
bug-ops merged 1 commit into
mainfrom
feat/issue-6086/memguard-type-aware-retrieval
Jul 13, 2026
Merged

feat(memory): add MemGuard type-aware retrieval composition#6226
bug-ops merged 1 commit into
mainfrom
feat/issue-6086/memguard-type-aware-retrieval

Conversation

@bug-ops

@bug-ops bug-ops commented Jul 13, 2026

Copy link
Copy Markdown
Owner

Summary

  • Adds a retrieval-only, fetch-time gate on ContextAssembler::schedule_context_fetchers so a turn can compose evidence from only the functionally relevant memory type(s), instead of always fetching every source unconditionally.
  • New FunctionalType enum (episodic / user_fact / behavioral_rule / reasoning_strategy / cross_session_summary / graph_fact) maps onto the existing per-collection/per-table memory sources — no new storage, no write-path change, category payload left dead/untouched.
  • Five of six gated fetchers respect the active type set; fetch_corrections (behavioral rules / past corrections) stays unconditionally composed as a documented safety-critical invariant.
  • [memory.type_aware_compose] config section, enabled = false by default — a byte-for-byte no-op identical to pre-change behavior. Optional intent_scoped widening reuses the existing heuristic memory router; no new LLM call in v1.
  • Full integration: config/default.toml advisory block, --init wizard prompts, --migrate-config step, CHANGELOG entry.

Background

Code-grounded audit found Zeph already had functional-type isolation at the storage layer (six Qdrant collections, several dedicated SQLite tables) but no equivalent selectivity at retrieval time — every turn composed all memory types regardless of need. The design went through two adversarial critique rounds before implementation: round 1 (critical) corrected an initial premise that assumed a single undifferentiated vector pool; round 2 (significant) dropped an underspecified new trait method in favor of gating the existing per-slot fetchers directly, and corrected the user-fact source mapping. See .local/specs/064-memguard-type-aware-memory-retrieval/spec.md for the full spec and revision history (not included in this diff — .local/ is gitignored).

Closes #6086

Test plan

  • cargo +nightly fmt --check
  • cargo clippy --profile ci --workspace --all-targets --features "desktop,ide,server,chat,pdf,scheduler,testing" -- -D warnings
  • cargo nextest run --config-file .github/nextest.toml --workspace --features "desktop,ide,server,chat,pdf,scheduler" --lib --bins (13456+ passed)
  • cargo test --doc on all touched crates
  • Rustdoc gate (RUSTFLAGS="-D warnings" RUSTDOCFLAGS="--deny rustdoc::broken_intra_doc_links") clean, full workspace
  • Dedicated regression test for the fetch-splitting fix (fetch_document_rag must survive Episodic exclusion)
  • SC#4 test asserting actual PreparedContext type-exclusion at the gather() level (not just fetcher count)
  • Independent security audit: zero findings, corrections path confirmed always-on, config parsing confirmed fail-closed on unknown type strings
  • Independent performance validation: gate confirmed genuinely zero-cost when disabled, excluded fetchers confirmed never scheduled (not just filtered post-hoc)

@github-actions github-actions Bot added enhancement New feature or request documentation Improvements or additions to documentation memory zeph-memory crate (SQLite) rust Rust code changes core zeph-core crate config Configuration file changes size/XL Extra large PR (500+ lines) labels Jul 13, 2026
@bug-ops
bug-ops force-pushed the feat/issue-6086/memguard-type-aware-retrieval branch 2 times, most recently from 927da20 to 88ad8e2 Compare July 13, 2026 17:18
@bug-ops
bug-ops enabled auto-merge (squash) July 13, 2026 17:18
Add a retrieval-only, fetch-time gate on context assembly so a turn can
compose only the functionally relevant memory types instead of always
fetching all sources. Introduces a FunctionalType enum spanning the
existing per-collection/per-table memory sources (episodic, user facts,
behavioral rules, reasoning strategies, cross-session summaries, graph
facts) and gates five of the six ContextAssembler fetchers on the active
set; corrections stay unconditionally composed as a safety-critical
invariant. No new storage, no write-path change, and the feature is a
byte-for-byte no-op when disabled (the default).

Closes #6086
@bug-ops
bug-ops force-pushed the feat/issue-6086/memguard-type-aware-retrieval branch from 88ad8e2 to 8f6683d Compare July 13, 2026 17:19
@bug-ops
bug-ops merged commit 2e8d096 into main Jul 13, 2026
43 checks passed
@bug-ops
bug-ops deleted the feat/issue-6086/memguard-type-aware-retrieval branch July 13, 2026 17:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

config Configuration file changes core zeph-core crate documentation Improvements or additions to documentation enhancement New feature or request memory zeph-memory crate (SQLite) rust Rust code changes size/XL Extra large PR (500+ lines)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

research(memory): MemGuard type-aware retrieval — zeph-memory recall never selects by functional memory type (arXiv:2605.28009)

1 participant