Skip to content

feat(memory): deterministic durable-memory recall injection for app sessions (QA 4A) - #90

Merged
cryptolir merged 2 commits into
mainfrom
feat/app-memory-recall-injection
Jun 27, 2026
Merged

cryptolir merged 2 commits into
mainfrom
feat/app-memory-recall-injection

Conversation

@cryptolir

Copy link
Copy Markdown
Owner

What

Fixes Issue 2 of the QA-fix plan (#89): durable memory not recalled across chats (report 4A). A goal saved in one app chat ("build a daily writing routine") was not recalled in a new chat — the agent asked the user to remind it.

Root cause (verified, not guessed)

  • Saving works. graphiti-mcp logs show add_episode succeeded for the test user, and a live search_memory_facts against that group returns the exact fact: "טל shares that her goal for this month is to establish a daily writing routine."
  • Retrieval is the gap. It is discretionary — the agent must call search_memory_facts, and under the slim app prompt it often skips that at the start of a new chat. There was no deterministic recall (unlike app_profile, which is injected every turn).

Fix — deterministic recall injection (mirrors the proven app_profile bootstrap)

  • src/agents/graphiti-recall-client.ts — read-only search_memory_facts over the streamable-HTTP MCP endpoint. Preserves the graphiti-proxy capability boundary (codex P1): the only scope input is a server-derived groupId; unsafe/missing ids fail closed; the outbound call hard-sets group_ids:[groupId] and there is no parameter by which a caller could pass group_id/group_ids/center_node_uuid. Uses node:http with Host: localhost:8000 (the server requires it), exactly like the proxy. Timeboxed via AbortController.
  • src/agents/memory-recall-context.ts — appendMemoryRecallBootstrapFile: resolves the appUserId (resolveAppUserId → appUserIdFromSessionKey fallback), derives the group id byte-identically to the life-memory-scope hook (app_<sanitized>), fetches the top ~8 facts, injects them as a synthetic MEMORY_RECALL.md. ~2.5s timebox + fail-open. No cross-turn cache (codex P2 — a TTL cache could serve stale "no memories" right after a write; deferred until write-invalidation exists).
  • src/agents/bootstrap-files.ts — chained after appendAppProfileBootstrapFile (post-shaping, so it's never excluded and is budgeted by the clamp).
  • ops/graphiti-life/agents-md-memory-section.md — one line telling the agent the top facts are pre-injected as MEMORY_RECALL.md; lean on it first, search only for more.

Tests / checks

  • 27 vitest across the two new suites: pure extractors, wire+scope+timebox against a local mock MCP server (asserts group_ids:[groupId], no forbidden scope fields forwarded, the Host header, timeout abort), hook group-id parity, fail-open, and a no-stale-cache guard (two turns, the second sees a just-written fact).
  • pnpm check (format + tsgo + lint) green. Existing app-profile-context suite still green (49 total).

Deploy note (not in this PR)

The deployed life workspace AGENTS.app.md on the host is seeded from agents-md-memory-section.md — it needs the same one-line sync at roll time. Gateway env already has GRAPHITI_URL (defaults to http://graphiti-mcp:8000/mcp); no new config required.

🤖 Generated with Claude Code

Liran Peretz and others added 2 commits June 27, 2026 19:14
…essions

Report 4A: a goal saved in one app chat was not recalled in a new chat. Saving
works (verified: add_episode succeeded + search_memory_facts returns the fact);
the gap is retrieval — it is discretionary and the slim app prompt often skips
search_memory_facts at the start of a new chat.

Mirror the proven app_profile bootstrap: fetch the user's top durable facts
server-side and inject them as a synthetic MEMORY_RECALL.md context file every
turn (app sessions only), so recall no longer depends on the model searching.

- graphiti-recall-client.ts: read-only search_memory_facts over the streamable
  -HTTP MCP endpoint, mirroring the graphiti-proxy capability boundary — the only
  scope input is a server-derived groupId, unsafe ids fail closed, the call hard
  -sets group_ids:[groupId] and no caller group_id/group_ids/center_node_uuid can
  pass through. node:http (Host: localhost:8000) like the proxy; timeboxed.
- memory-recall-context.ts: appendMemoryRecallBootstrapFile — group id derived
  byte-identically to the life-memory-scope hook; ~2s timebox + fail-open; NO
  cross-turn cache (codex P2: avoid stale recall right after a write).
- bootstrap-files.ts: chain after appendAppProfileBootstrapFile (post-shaping).
- agents-md-memory-section.md: note that MEMORY_RECALL.md is pre-injected.
- 27 vitest (incl. wire/scope/timebox + hook group-id parity + fail-open + no
  -stale-cache). pnpm check (format + tsgo + lint) green.

Implements Issue 2 of docs/experiments/plans/qa-fixes-2026-06-26.md (#89).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
oxfmt 0.33.0 flags two files this branch does not otherwise touch
(SKILL.md, the cron-generated bug_list.md) — identical to main, whose
older CI run passed. Reformat them so the `check` gate is green here.
Note: the daily bug_list autoscan cron will re-drift bug_list.md unless
it also formats / is ignored (separate follow-up).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@cryptolir
cryptolir merged commit ed9f2a5 into main Jun 27, 2026
16 of 24 checks passed
@cryptolir
cryptolir deleted the feat/app-memory-recall-injection branch June 27, 2026 18:51
cryptolir added a commit that referenced this pull request Jun 27, 2026
#91)

STATUS.md: new Last Session entry for the deterministic durable-memory recall
roll — PR #90, image v2026.06.27.1 (sourceSha ed9f2a5), pinned to life only,
rollback v2026.06.20.3; prod E2E smoke confirmed (new chat recalls the saved goal
on the first message). INFRASTRUCTURE.md: bump the life-ahead pin to v2026.06.27.1.

Co-authored-by: Liran Peretz <[email protected]>
Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
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