feat(store): record memory provenance the model cannot write
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 初心者へのやさしさ
- 35/100
調査の方向性
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 の本文から書いたものです。
説明
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:
- 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.
- Prompts captured by the
UserPromptSubmithook and prompts saved throughmem_save_promptare 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_promptshave an emptysource_inbox_id. capture_project_provenancehas 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 --projectfrom 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
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
Gentleman-Programming/engram のほかの issue
-
status:needs-review type:bug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
Gentleman-Programming/engram#2512 ·
メンテナーはふだん 1 日以内に返信
-
status:needs-review
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
Gentleman-Programming/engram#2502 ·
メンテナーはふだん 1 日以内に返信
-
status:needs-review type:bug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
Gentleman-Programming/engram#2501 ·
メンテナーはふだん 1 日以内に返信
-
status:needs-review type:feature
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
Gentleman-Programming/engram#2416 ·
メンテナーはふだん 1 日以内に返信
-
status:needs-review type:bug
難易度 4/5 3〜5日 初心者へのやさしさ 57/100
Gentleman-Programming/engram#2513 ·
メンテナーはふだん 1 日以内に返信
Gentleman-Programming/engram の issue をすべて見る
似ている issue
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
AvengeMedia/DankMaterialShell#4490 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
stefanpejcic/OpenPanel#1415 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100