Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions specs/memkernel-0-15-harness-foundations/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -237,3 +237,70 @@ B6–B11 follow from the spec and the review, and are stated so the review can c
live checkpoint matching its filters, and `out_of_scope` when it has some but none in the caller's effective
scope (B4). The MCP
response stays a JSON list.

## Amendment H3: the context diff (approved by the owner, 2026-11-24)

The H3 build (D5: FR-004, SC-2) as it will be built: a maintained eval tool over the receipts H1 writes, like the
repeated-mistake count. No server, tool, store or retrieval change. The owner decided C1 (refined), C2, C3 and C4 on
2026-11-24 and asked that the review's points be stated; C5–C9 follow from the spec and the review.

- **C1 Which receipt a memory is judged by (owner: yes, refined).** When a run received a memory more than once, the
diff compares the store with the **last receipt in the run that has that memory's hash** (its `memories` entry):
the context the run last worked from. A memory is `unknown` only when no receipt in the run has its hash, which
happens when every record that returned it was cut down (C7); it can still be `superseded` or `withdrawn` (C3).
- **C2 A different hashing scheme (owner: yes).** When a receipt's `content_hash_scheme` (A8) differs from the
current scheme, the diff reports `rehashed` and does not compare the hashes, so a change of scheme (#153) is never
reported as changed content. **The current scheme** is the one the installed memkernel's `compute_content_hash`
implements (`CONTENT_HASH_SCHEME`, today `sha256-raw`): records carry no scheme of their own, so the diff assumes
every stored hash was made by it, which holds for every store so far, since every memkernel to date hashes with
`sha256-raw`. If #153 lets records carry their scheme, the diff reads it from the record
instead, and #153's spec says so.
- **C3 Several statuses at once (owner: yes).** Each memory lists every status that applies; the report counts each
status. The combination rules: `missing` stands alone (there is nothing left to compare); `unknown` combines only
with `superseded` and `withdrawn`, which need no hash: they are read from the store now, not from a receipt; `unchanged` stands alone and means no other status applies;
`changed` and `rehashed` exclude each other (C2); every other pair can combine, for example `superseded` with
`source changed`, or `flagged` with `changed`.
- **C4 Checked like the count (owner: yes).** `eval/context-diff/diff.py` joins `mypy --strict` in CI's Type Check beside
`eval/repeat-mistakes/` (one line in `.github/workflows/`), since it is maintained the same way.
- **C5 Input and output.** `diff.py --store name=…,chroma=…,state=…,project=… --run <run_id> [--json report.json]`,
the count's store format. It reads every recall-log file of that store, rotated ones included, keeps the records
whose `run_id` is the run's (MCP recalls and hook blocks alike), and prints one line per memory plus the counts.
Exit codes: 0 when it printed a report (even one of only `unknown` entries, or none at all: a run whose recalls all
returned nothing still has records), 1 when no record in the store carries that `run_id` (a wrong id, or a log that
was off or rotated away), 2 for a usage error or a store it cannot open. It reads every scope (B8: an operator's tool, like the
count); a memory's scope never changes after it is created, so a lookup by `ref_id` finds it wherever it is.
- **C6 The statuses (FR-004).** Against the store now, read fresh: `missing` (no record, or expired; it stands
alone, since there is nothing left to compare); `superseded` (with
`superseded_by`, or `withdrawn` with its reason); `changed` (another `content_hash`, same scheme); `rehashed` (C2);
`flagged`, judged against the receipt's own `state`: `live` in the receipt and flagged in the store now (a memory
already `flagged` in its receipt gets no flag status, since the run saw the flag); `source changed` (the file under the project root no longer
hashes to the receipt's `source_hash` for a decision, or to its `content_hash` for code, as revalidation judges
them; a file that is gone counts as `source changed`, even for a receipt without a `source_hash`; a receipt without
the hash it would need, such as a decision saved before `source_hash` existed, whose file is still there gets no
source check); `unchanged`. Statuses combine as C3 says.
**Code chunks** are judged by the file record they belong to: the owner is found from the chunk's id
(`<owner>-chunk-<n>`, split at the last `-chunk-`; owner ids are UUIDs), so it is found even after the chunk record
was deleted, as a superseded snapshot's chunks are; a chunk whose owner cannot be found is `missing`. `superseded`, `withdrawn`, `missing` (only when the owner is gone) and `flagged` come from the owner, and
`source changed` compares the file with the owner's `content_hash`, since a chunk's own hash never matches the
whole file. Both of those hashes are made now, with the current scheme, so C2's check, which concerns the
receipt's hash, does not apply to them.
**What `source changed` can and cannot say:** it says only that the memory's `source` file now hashes differently
from the hash recorded for it: the file's text through memkernel's own `compute_content_hash`, the function
revalidation uses, so the two cannot drift apart. It cannot say the memory is now wrong (an
unrelated edit to the file counts); it checks only `source`, not other files the memory's text cites; a file
changed and changed back reads as unchanged; and a source outside the project root, or one it cannot read as text,
gets no source check, reported as such, rather than `source changed`.
- **C7 Cut-down receipts.** A record marked `memories_truncated` lists ref_ids without details: those memories are
judged by an earlier receipt that has their hash (C1), and are `unknown` only when none has, never `unchanged`. When
any of the run's records is marked `ref_ids_truncated`, the report says so in a note naming how many such records
there are: the run may have received memories the diff cannot list.
- **C8 No content.** Like a receipt, the report holds ref_ids, hashes, sources, scopes and statuses, never memory
content; README says to check it before sharing all the same, since sources are file paths.
- **C9 Tests (SC-2).** A run's receipts, after a decision it received is superseded and a code file it received
changes, diff as `superseded` and `source changed`; plus each other status (a deleted and an expired memory, a
withdrawn one, changed content, a newly flagged one and one already flagged in its receipt, a source file that is
gone with and without a `source_hash`, a source outside the project root), a code chunk whose snapshot was
superseded and its chunk records deleted, two statuses on one memory, `unknown` with `superseded`, a memory judged
by an earlier full receipt, a
scheme change, a receipt without a `source_hash`, a cut-down record, a private memory found across scopes, and the
three exit codes.
Loading