From c90a092d714b7fcedd767954e6864a381a5316c7 Mon Sep 17 00:00:00 2001 From: gosha70 Date: Tue, 24 Nov 2026 07:45:06 -0500 Subject: [PATCH 1/2] spec: H3 amendment, the context diff (#119) eval/context-diff/diff.py over a run's receipts (FR-004, SC-2). Approved by the owner: C1 (the last receipt in the run with the memory's hash; unknown only when none has it), C2 (a different hashing scheme is "rehashed", never "changed"), C3 (statuses combine, with stated rules), C4 (strict type check in CI). Also stated: flagged judged against the receipt's state, what "source changed" can and cannot say, where the current hashing scheme comes from, a note when ref_ids were cut short, exit codes. --- .../spec.md | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/specs/memkernel-0-15-harness-foundations/spec.md b/specs/memkernel-0-15-harness-foundations/spec.md index 0c397c3..4a46381 100644 --- a/specs/memkernel-0-15-harness-foundations/spec.md +++ b/specs/memkernel-0-15-harness-foundations/spec.md @@ -237,3 +237,60 @@ 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). +- **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` and `unknown` each stand alone (there is nothing to compare); `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 [--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`; a receipt without the hash it would need, such as a decision + saved before `source_hash` existed, gets no source check); `unchanged`. Statuses combine as C3 says. + **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, a source outside the project root), two statuses on one memory, 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. From 809d1b375c430ebcf56c95fdbc302dd41b56ecd8 Mon Sep 17 00:00:00 2001 From: gosha70 Date: Tue, 24 Nov 2026 07:56:28 -0500 Subject: [PATCH 2/2] spec: H3 amendment, the owner's fixes (#119) A code chunk is judged by the file record it belongs to (found from the chunk id, so also after its chunk record was deleted): superseded, withdrawn, missing and flagged come from the owner, and source changed compares the file with the owner's content_hash. unknown combines with superseded and withdrawn (read from the store, not a receipt); missing still stands alone. A gone file counts as source changed even without a source_hash. Tests: a chunk of a superseded snapshot, unknown with superseded, a gone file with and without a source_hash. --- .../spec.md | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/specs/memkernel-0-15-harness-foundations/spec.md b/specs/memkernel-0-15-harness-foundations/spec.md index 4a46381..7dda5f0 100644 --- a/specs/memkernel-0-15-harness-foundations/spec.md +++ b/specs/memkernel-0-15-harness-foundations/spec.md @@ -247,7 +247,7 @@ repeated-mistake count. No server, tool, store or retrieval change. The owner de - **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). + 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` @@ -256,9 +256,10 @@ repeated-mistake count. No server, tool, store or retrieval change. The owner de `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` and `unknown` each stand alone (there is nothing to compare); `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`. + 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 [--json report.json]`, @@ -274,8 +275,15 @@ repeated-mistake count. No server, tool, store or retrieval change. The owner de `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`; a receipt without the hash it would need, such as a decision - saved before `source_hash` existed, gets no source check); `unchanged`. Statuses combine as C3 says. + 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 + (`-chunk-`, 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 @@ -291,6 +299,8 @@ repeated-mistake count. No server, tool, store or retrieval change. The owner de - **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, a source outside the project root), two statuses on one memory, a memory judged by an earlier full receipt, a + 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.