feat(store): record memory provenance the model cannot write

Abierto
#2,500 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
5/5
Tiempo estimado
Más de una semana
Aptitud para principiantes
35/100
Tipo de issue
Nueva funcionalidad
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
go, sqlite

Línea de trabajo

Start by tracing how observations and prompts are stored and queried, including the UserPromptSubmit hook and mem_save_prompt paths; the issue does not name files or tests. The requested change spans runtime and model metadata, prompt provenance, observation-to-prompt links, and search and export filters. Done means stored data can distinguish hook-captured user prompts from tool-saved prompts and identify observation runtime, model when available, and matching prompt.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

status:needs-review type:feature
Existing Issue Search
  • I searched existing issues and will add evidence to a canonical tracker when applicable.

(Searched for "provenance", "mem_save_prompt", "prompt source" and "observation provenance agent". The closest are #1817 and #1833, which are about consolidation provenance, and #2211, which is about the project a prompt is filed under. None of them covers who authored a memory.)

🔍 Observed Consequence

When an agent saves a memory, the only record of who the information came from (the user, the agent's own inference, a web page, a tool) is whatever the model writes in the content. If a prompt injection is planted in a web page or in a tool's output, it can make the agent write "the user said X". The memory is then stored and recalled in later sessions as if the user had said it.

Engram already records some provenance outside the model: the session, the timestamp, tool_name = subagent-stop for subagent captures, and marked_by_* on relation judgments. Two gaps remain:

  1. An observation has no field set by the runtime, rather than by the model, that says which runtime saved it, with which model, and whether the turn that produced it had a user prompt captured by the hook.
  2. Prompts captured by the UserPromptSubmit hook and prompts saved through mem_save_prompt are stored the same way. So when an external check compares a memory that claims "the user said X" against the session's stored prompts, it cannot tell a prompt the user really typed from one the agent wrote.

Measured on my store (engram 3.7.2, 2026-11-27):

  • All 2,418 rows in user_prompts have an empty source_inbox_id.
  • capture_project_provenance has no rows for prompts (0 of the 794 prompts from the last 14 days).
  • No column distinguishes the hook path from the tool path.
  • In the last 14 days, 382 of 383 observations saved from an agent session and 211 of 211 subagent captures have user prompts in the same session, so a cross-check is possible for most memories. The 147 observations saved with engram save --project from the CLI have none.
💡 Desired Outcome

Using only the stored data, without trusting the model's text, I can tell for each observation:

  • which runtime saved it (Claude Code, Codex, OpenCode, …);
  • which model saved it, when the runtime exposes that;
  • whether it was written in a turn that had a user prompt captured by the hook, and which prompt that was.

For each stored prompt, I can also tell whether it came from the hook (the user typed it) or from a tool call (the agent wrote it).

Search and export can filter on these fields.

📦 Affected Area

Store (database, queries)

Release Context

engram 3.7.2 (Homebrew) on Linux, Claude Code with the engram plugin 0.1.6. OpenCode writes to the same store.

🔄 Workarounds and Constraints

My current plan has two parts. Each new memory gets a line in its content naming the agent and the source class (said by the user, inferred by the agent, taken from the web or from a tool). An external check then compares each "said by the user" against the session's stored prompts and flags the ones it cannot match.

Neither part is independent of the model: the content line is written by the model, and so is any prompt saved through mem_save_prompt. Memories saved from the CLI into another project also have no session prompts to compare against.

📎 Additional Context
  • Microsoft Security Blog, "Guarding AI memory" (2026-06-22): "Establish intent and provenance before persistence" and "Enforce boundaries outside the model".
  • TMA-NM, arXiv 2606.24322 (preprint, single author): the agent's own summarization is the first channel that launders provenance. In the author's tests, provenance fixed at write time, combined with independent corroboration, blocked the attacks.
Lenguaje dominante
Go
Estrellas
7.1k
Forks
729
Merge medio
2 h 19 min
PR fusionados (30 d)
167

Preparar el entorno

Abrir en Codespaces

Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de Gentleman-Programming/engram

Todos los issues de Gentleman-Programming/engram

Issues similares

Más issues de Go

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.