Repository navigation
feat: the context diff over a run's receipts (#119 H3) - #158
Merged
Merged
Conversation
eval/context-diff/diff.py --store ...[,root=...] --run <run_id> [--json ...] reads the run's receipts from the recall log (MCP recalls and hook blocks carrying its run_id) and reports, per memory the run received, its statuses against the store now: missing (deleted or expired, alone), superseded (and by what), withdrawn, changed, rehashed (another hashing scheme, hashes not compared), flagged (against the receipt's state), source changed (the source file is gone or hashes differently, through compute_content_hash), unknown (only cut-down receipts; combines with superseded and withdrawn) or unchanged. Each memory is judged by the last receipt in the run with its hash; a code chunk by its file record (parent_ref, the id's prefix once the chunk is gone, or a pre-0.4 owner's chunk_refs, as revalidation recognises it). Source checks need root=; without it they are skipped and each memory says "no source check (no root given)"; a given root is named in the report. Unreadable log files are skipped and counted, and a run with no records says the log was incomplete when any were. A note counts records whose ref_ids were cut short. No memory content; every scope read. Exit 0 report, 1 no record carries the run id, 2 usage or store error. CI's strict type check covers it. Spec: specs/memkernel-0-15-harness-foundations, amendment H3 (C1-C9).
…re read-only (#119 H3) As revalidation, only decisions and code have their source checked; another record's source is a label (a captured record's "capture" named a missing file and read as "source changed"). The store is opened without creating a collection: a store without the project's collection exits 2, and the run creates nothing. Opening or reading the store failing exits 2, not 1. Tests: a captured memory stays unchanged with a root; a missing collection exits 2 and creates none; a failing read exits 2.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The third slice of issue #119: H3, the context diff (FR-004, SC-2), built as the approved amendment H3 (#157, with the owner's fixes). It leaves #119 open: US4 (the README "Using memkernel from a harness" section) and the instruction-template note follow in their own PR.
What's in it
eval/context-diff/diff.py --store name=…,chroma=…,state=…,project=…[,root=…] --run <run_id> [--json report.json], a maintained eval tool like the repeated-mistake count. No server, tool, store or retrieval change.missing(deleted or expired; alone),superseded(and by what),withdrawn,changed,rehashed(another hashing scheme; hashes not compared, C2),flagged(needs review now,livein its receipt),source changed(the file is gone, even without asource_hash, or hashes differently through memkernel'scompute_content_hash),unknown(no receipt has the hash; combines only withsupersededandwithdrawn),unchanged.parent_ref; the id's prefix (<owner>-chunk-<n>) once the chunk record is gone, as after a supersede; or, for a chunk from before 0.4, the code record whosechunk_refslists it (revalidation's rule, a live owner preferred).root=; without it they are skipped and each memory with a source saysno source check (no root given); a given root is named in the report (root, and theRoot:line). A source outside the root, or unreadable, gets its ownno source check (…)note.unreadable_log_files, and a note that the log is incomplete); a run with no records says so too when any file was unreadable. A note counts records whoseref_idswere cut short (C7).diff.pyjoinsmypy --strictin.github/workflows/ci.yml.Tests
tests/unit/test_context_diff.py(16): SC-2 (a superseded decision and a changed code file); unchanged with no content in the report; deleted and expired (missingalone);withdrawn,changed,rehashed;flaggedagainst the receipt's state; two statuses on one memory; a gone file with and without asource_hash; a source outside the root; a chunk of a superseded snapshot after its chunk records were deleted; a pre-0.4 chunk listed inchunk_refs;unknownwithsuperseded, and an earlier full receipt; a private memory across scopes; the cut-short note; no root and a named root; unreadable log files; the three exit codes. Mutation checks: with the owner-from-id rule removed, the chunk test fails; withunknownmade to stand alone, theunknowntest fails.Checks
ruff,mypy src/strict, andmypy --stricton the three eval files (the CI line as changed): clean.origin-alignment-2026-11-24-0845-build-h3.md. Noted there, unchanged by H3: Part 2's "explainable record of why knowledge was selected" is what the receipt records (query, filters, exclusion counts), as the approved spec decided._resolveresolving the root itself,--helpdescribingroot=, the docstring's edges.Two edge cases left as they are
timefield. Two records of one run with the same timestamp, in different log files, have no defined order, so C1's "last receipt" could pick either. Times are recorded to the microsecond, so this needs two recalls of one run in the same microsecond, written either side of a rotation.timeorref_ids. The recall log always writes both. A damaged record withouttimesorts first; one withoutref_idscontributes no memories, even if it listsmemoriesentries.The owner's fixes (66ebe0c → head)
sourceis a label. A captured memory (source"capture") staysunchangedwith a root given (test).open_storechecks the collection exists before the adapter, which would create it): a store without the project's collection exits 2 and the run creates none (test).