Skip to content

feat: the context diff over a run's receipts (#119 H3) - #158

Merged
gosha70 merged 2 commits into
mainfrom
feat/119-h3-context-diff
Nov 24, 2026
Merged

gosha70 merged 2 commits into
mainfrom
feat/119-h3-context-diff

Conversation

@gosha70

@gosha70 gosha70 commented Nov 24, 2026 •

Copy link
Copy Markdown
Owner

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.

  • Statuses (C6), C3's rules: missing (deleted or expired; alone), superseded (and by what), withdrawn, changed, rehashed (another hashing scheme; hashes not compared, C2), flagged (needs review now, live in its receipt), source changed (the file is gone, even without a source_hash, or hashes differently through memkernel's compute_content_hash), unknown (no receipt has the hash; combines only with superseded and withdrawn), unchanged.
  • C1 (refined): each memory is judged by the last receipt in the run that has its hash.
  • Code chunks are judged by their file record: 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 whose chunk_refs lists it (revalidation's rule, a live owner preferred).
  • Root (the owner's change): source checks need root=; without it they are skipped and each memory with a source says no source check (no root given); a given root is named in the report (root, and the Root: line). A source outside the root, or unreadable, gets its own no source check (…) note.
  • Log completeness (the owner's change): unreadable log files are skipped and counted (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 whose ref_ids were cut short (C7).
  • No memory content in the report; every scope read. Exit codes: 0 report, 1 no record carries the run id, 2 usage error or a store it cannot open.
  • CI (C4): diff.py joins mypy --strict in .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 (missing alone); withdrawn, changed, rehashed; flagged against the receipt's state; two statuses on one memory; a gone file with and without a source_hash; a source outside the root; a chunk of a superseded snapshot after its chunk records were deleted; a pre-0.4 chunk listed in chunk_refs; unknown with superseded, 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; with unknown made to stand alone, the unknown test fails.

Checks

  • Fast suite: 1329 passed, coverage 95.06 %. ruff, mypy src/ strict, and mypy --strict on the three eval files (the CI line as changed): clean.
  • Origin alignment: the record was stale after the H3 amendment; re-reviewed against Feature: AI Harness Foundations — Scoped Knowledge, Reproducible Context, and Retrieval Observability #119 Part 2, no mismatch for H3; new record 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.
  • DeepSeek, three rounds: PASS, 0 blocking. Acted on: unreadable rotated files skipped (now counted), _resolve resolving the root itself, --help describing root=, the docstring's edges.

Two edge cases left as they are

  1. Equal timestamps across log files. Records are ordered by their time field. 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.
  2. Records without time or ref_ids. The recall log always writes both. A damaged record without time sorts first; one without ref_ids contributes no memories, even if it lists memories entries.

The owner's fixes (66ebe0c → head)

  • Sources are checked only for decisions and code, as revalidation does; another record's source is a label. A captured memory (source "capture") stays unchanged with a root given (test).
  • The store is opened without creating a collection (open_store checks 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).
  • Opening or reading the store failing exits 2, not 1 (test: a failing read).
  • Fast suite 1332 passed, 95.06 %; every CI command clean; DeepSeek PASS, 0 blocking.

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.
@gosha70
gosha70 merged commit 4bbeff1 into main Nov 24, 2026
9 checks passed
@gosha70
gosha70 deleted the feat/119-h3-context-diff branch November 24, 2026 17:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant