Skip to content

feat(memory): background graph extraction and agent loop integration (Phase 4, #1227)#1255

Merged
bug-ops merged 3 commits intomainfrom
feat/m33/graph-extraction
Mar 6, 2026
Merged

feat(memory): background graph extraction and agent loop integration (Phase 4, #1227)#1255
bug-ops merged 3 commits intomainfrom
feat/m33/graph-extraction

Conversation

@bug-ops
Copy link
Copy Markdown
Owner

@bug-ops bug-ops commented Mar 6, 2026

Summary

Phase 4 of graph memory epic (#1222): wire entity extraction into the agent loop as a fire-and-forget background task.

  • Background extraction: spawn_graph_extraction() on SemanticMemorytokio::spawn with configurable timeout (default 15s), graceful degradation on timeout/error
  • Agent loop integration: triggered after remember_with_parts() in persistence.rs, skips tool outputs and injection-flagged messages
  • Context injection: ContextSlot::GraphFacts added to FuturesUnordered pipeline, fetch_graph_facts() with token-budgeted formatting and entity name escaping
  • Graph recall: recall_graph() with fuzzy entity match + BFS traversal, HashMap cache for N+1 elimination, SQLite bind-param cap
  • Budget allocation: runtime-conditional split (5% semantic + 3% graph when enabled, 8% + 0% when disabled)
  • Extraction counter: atomic SQL increment in graph_metadata table
  • TUI status: "Extracting entities..." spinner during background extraction
  • Security: injection-flag guard, entity name escaping, PII redaction doc + startup warning

15 files changed, +1036/-18, 4216 tests passing (+4 net).

Closes #1227

Test plan

  • cargo +nightly fmt --check
  • cargo clippy --workspace -- -D warnings (without graph-memory)
  • cargo clippy --workspace --features full -- -D warnings
  • cargo nextest run --workspace --features full --lib --bins (4216 passed, 0 failed)
  • Background extraction does not block agent response
  • Injection-flagged messages skip extraction
  • Graph facts appear in context when entities exist
  • Empty graph / disabled config produces no graph facts
  • Extraction counter persisted atomically
  • Multi-hop BFS traversal test
  • Timeout degradation test (0s timeout, no panic)

…(Phase 4, #1227)

Wire graph entity extraction into the agent loop as a fire-and-forget
background task with configurable timeout and graceful degradation.

- Add spawn_graph_extraction() to SemanticMemory with tokio::spawn,
  cloning Arc<EmbeddingStore>, AnyProvider, and SqlitePool
- Integrate in persistence.rs: trigger after remember_with_parts(),
  skip tool outputs, skip injection-flagged messages (S2)
- Add ContextSlot::GraphFacts to FuturesUnordered context pipeline
- Add fetch_graph_facts() with token-budgeted formatting and entity
  name escaping against prompt injection (R-IMP-02)
- Add recall_graph() with fuzzy entity match, BFS traversal, HashMap
  cache for N+1 elimination, and SQLite bind-param cap (R-SUG-01/03)
- Runtime-conditional budget split: 5% semantic + 3% graph when
  enabled, 8% semantic + 0% graph when disabled (S3/S4)
- Atomic SQL extraction counter in graph_metadata table (S1)
- TUI status spinner during background extraction
- Security doc + startup warning for PII redaction gap (R-IMP-03)
- Remove dead GraphExtractionConfig.model field (R-IMP-01)
@github-actions github-actions bot added documentation Improvements or additions to documentation memory zeph-memory crate (SQLite) rust Rust code changes core zeph-core crate enhancement New feature or request size/XL Extra large PR (500+ lines) labels Mar 6, 2026
bug-ops added 2 commits March 6, 2026 02:31
Reconcile Phase 4 changes with Phase 3 (graph retrieval) that landed
on main:
- Remove duplicate recall_graph (keep graph::retrieval module version)
- Remove duplicate fetch_graph_facts (keep main's, add injection escaping)
- Remove duplicate GRAPH_FACTS_PREFIX (keep [known facts] prefix)
- Adopt GraphConfig as non-Option field (main's approach)
- Adopt balanced budget reallocation (7/7/3/29/4% with graph enabled)
- Adopt MAX_FRONTIER constant from main, keep visited_ids cap
- Fix test helpers to set graph_store on SemanticMemory
@bug-ops bug-ops enabled auto-merge (squash) March 6, 2026 01:36
@bug-ops bug-ops merged commit f8c1f4f into main Mar 6, 2026
28 checks passed
@bug-ops bug-ops deleted the feat/m33/graph-extraction branch March 6, 2026 01:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

feat(memory): background graph extraction and agent loop integration

1 participant