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

オープン
#2,500 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
35/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
活発
技術スタック
go, sqlite
領域
backend, databases

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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.
主要言語
Go
スター
7.1k
フォーク
729
平均マージ
2時間 19分
マージ済み PR(30日)
167

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

Gentleman-Programming/engram のほかの issue

Gentleman-Programming/engram の issue をすべて見る

似ている issue

Go の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。