Skip to content

feat: context receipts and run/agent/task correlation in the recall log (#119 H1) - #154

Merged
gosha70 merged 3 commits into
mainfrom
feat/119-h1-receipts
Nov 23, 2026
Merged

gosha70 merged 3 commits into
mainfrom
feat/119-h1-receipts

Conversation

@gosha70

@gosha70 gosha70 commented Nov 23, 2026 •

Copy link
Copy Markdown
Owner

The first slice of issue #119 (harness foundations): H1, receipts and correlation (FR-002, FR-003, FR-006). It leaves #119 open for H2 (scope and abstention) and H3 (the context diff).

Spec: specs/memkernel-0-15-harness-foundations, with the H1 amendment at the end of spec.md, approved by the owner on 2026-11-23 (A1, A2 and A8 were theirs; A3–A7 follow from the spec and the review). S4 of issue #59 is filed as #153; A8 is what lets H3 come before it.

What's in it

  • Correlation (FR-002, A1, A7). recall and retain take run_id, agent_id and task_id; MEMKERNEL_RUN_ID, MEMKERNEL_AGENT_ID and MEMKERNEL_TASK_ID set them per process, and a call's value wins. At most 128 characters each: a longer call argument is refused with an error naming the limit; a longer setting is ignored with one warning per process.
  • run_id on memories (A2). A new memory keeps run_id as provenance (metadata key run_id). Like source_hash, it is set on creation only: a retain that matches an existing record keeps that record's. Older records load with "" (SC-4).
  • Receipts (FR-003, A3, A4, A8). With MEMKERNEL_RECALL_LOG on, each record (MCP recall and hook blocks) adds run_id, agent_id, task_id; memories, one entry per returned memory (ref_id, content_hash, content_hash_scheme = sha256-raw, source and source_hash where set, state live or flagged, never content); and returned_chars (an MCP recall's whole JSON response, as the agent receives it; a hook block's whole text). An MCP recall also logs latency_ms and excluded (superseded with withdrawn, flagged, expired): the candidates the search's last window returned and the live filter dropped. order="newest" selects by metadata and logs no excluded. ref_ids is unchanged.
  • Size (A5). A record over MEMKERNEL_RECALL_LOG_MAX_BYTES drops query text, then trailing memories entries (memories_truncated), then trailing ref_ids (ref_ids_truncated), marked truncated. ref_ids go last, so the count keeps its evidence.
  • The count (FR-006, A6). eval/repeat-mistakes/count.py adds by_run and by_agent (per-id repeat and outcome counts; several when one thread's records name more than one id) when the log has ids; without ids the report, details included, is as before.
  • MemoryService.recall returns the same list; the receipt comes back through an optional receipt=RecallReceipt() argument.
  • Docs. README: the retain/recall rows, the three settings, the recall-log rows (receipt fields, cut order), the count's grouping; CHANGELOG under [Unreleased]. The full "Using memkernel from a harness" section (FR-007) is US4, after H3.
  • Leftover from feat: one memkernel store across Codex, Cursor and Antigravity (Closes #107) #152: the README's Codex row says store paths must not contain spaces (the hook command passes them unquoted). I left out "or quote them": whether quoting works depends on whether Codex runs the command through a shell, which I could not verify.

Tests

What Test
A call's ids win over the process's; receipt fields; latency, size, exclusions; get shows run_id; over-long ids refused (SC-3) tests/e2e/test_recall_log_tool.py::test_an_mcp_recall_record_is_a_receipt_with_the_callers_ids
run_id on new records, kept on a dedup hit, empty on older records (SC-4) tests/unit/test_harness_receipts.py (test_a_new_record_keeps_…, test_a_dedup_hit_keeps_…, test_a_record_without_a_run_loads_…)
Exclusions counted per reason; counts are the last window's, not a sum (fails with summing) test_a_recall_receipt_counts_each_exclusion_…, test_exclusions_are_the_last_windows_not_a_sum_over_windows
A5 cut order test_a_long_query_is_cut_before_any_detail, test_details_are_cut_before_ref_ids, test_ref_ids_go_last, and the 4,096-byte floor with ids at their limit
Hook record: shown memories, block length, process ids test_a_hook_record_lists_what_the_block_showed_with_the_process_ids
Over-long setting ignored with one warning test_an_over_long_id_setting_is_ignored_with_one_warning
by_run / by_agent, several, no groups without ids tests/unit/test_repeat_mistakes_count.py::test_repeats_are_grouped_by_the_harness_run_and_agent, test_a_log_without_harness_ids_reports_no_groups

Checks

  • Fast suite: 1282 passed (at 8279d76), coverage 94.92 % (gate 80 %). Slow suite: 13 passed (at 00f36c1).
  • ruff check, ruff format --check (src, tests, templates), mypy src/ strict, and mypy --strict on the maintained eval tools (eval/repeat-mistakes/): clean. The first CI run failed that last check (a loop variable in count() reused a tuple's name); 569d28f renames it.
  • Origin alignment for memkernel-0-15-harness-foundations: gate passes.
  • DeepSeek peer review, three rounds on the exact change: PASS, 0 blocking (a fourth, on the one-word rename, was INCONCLUSIVE with two notes and no defects). Acted on: a test that the exclusion counts are the last window's, and a receipt lookup that can never fail a recall. Not acted on: the cut order (A5 as specified), several (A6 as approved), an empty id meaning "unset" (as retain already treats it).

For the reviewer

  • With the log on, a hook block now looks up each memory it shows (about ten by-id reads at session start) to fill the receipt; none with the log off.
  • The MCP tool passes a receipt on every recall, log on or off; filling it uses records the live filter already loaded.

Review round 1 (569d28f → 8279d76)

  • returned_chars for an MCP recall is now the length of the whole response the agent receives, not the sum of the previews (amendment A3 updated); the e2e test compares it with what the MCP client received.
  • README: the recall row lists run_id?, agent_id?, task_id?; retain's row and docstring say agent_id and task_id are checked but not recorded.
  • Left for H2: the per-session limit on captured records is not counted in excluded; H2 adds out_of_scope to the same counts.
  • All CI commands pass locally; DeepSeek PASS, notes only.

…#119 H1)

recall and retain take run_id, agent_id and task_id (or MEMKERNEL_RUN_ID,
MEMKERNEL_AGENT_ID, MEMKERNEL_TASK_ID for the process; a call's value wins),
at most 128 characters each: a longer argument is refused, a longer setting
ignored with one warning. A new memory keeps run_id as provenance; a dedup hit
keeps the original's; older records load with none.

With the recall log on, each record is a context receipt: the ids, and per
returned memory its content_hash with the hashing scheme (sha256-raw), source,
source hash and state, never content; the characters returned; and for an MCP
recall its latency and the candidates the last search window dropped as
superseded, flagged or expired. A record over the size limit drops query text,
then the per-memory details, then trailing ref_ids. Hook blocks log the same
receipt with the process's ids.

The repeated-mistake count groups its report by run and agent when the log
has ids. The recall response and the MCP tool set are unchanged.

Spec: specs/memkernel-0-15-harness-foundations, amendment H1 (A1-A8). Also the
README note that Codex hook store paths must not contain spaces (from #152).
returned_chars summed only the previews; the agent receives the whole JSON
response (ref ids, scores, tags, flags), several times larger. It is now the
response's length, as a hook block's is the block's, so the receipt says how
much context a recall added (#119 scenario 3). Amendment A3 says so.

Also: the README's recall row lists run_id, agent_id and task_id, and retain's
docstring and README row say agent_id and task_id are checked but not recorded.
@gosha70
gosha70 merged commit 80c1330 into main Nov 23, 2026
11 checks passed
@gosha70
gosha70 deleted the feat/119-h1-receipts branch November 23, 2026 21:59
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