Repository navigation
feat: context receipts and run/agent/task correlation in the recall log (#119 H1) - #154
Merged
Merged
Conversation
…#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.
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 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 ofspec.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
recallandretaintakerun_id,agent_idandtask_id;MEMKERNEL_RUN_ID,MEMKERNEL_AGENT_IDandMEMKERNEL_TASK_IDset 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_idon memories (A2). A new memory keepsrun_idas provenance (metadata keyrun_id). Likesource_hash, it is set on creation only: a retain that matches an existing record keeps that record's. Older records load with""(SC-4).MEMKERNEL_RECALL_LOGon, each record (MCPrecalland hook blocks) addsrun_id,agent_id,task_id;memories, one entry per returned memory (ref_id,content_hash,content_hash_scheme=sha256-raw,sourceandsource_hashwhere set,stateliveorflagged, never content); andreturned_chars(an MCP recall's whole JSON response, as the agent receives it; a hook block's whole text). An MCP recall also logslatency_msandexcluded(supersededwith withdrawn,flagged,expired): the candidates the search's last window returned and the live filter dropped.order="newest"selects by metadata and logs noexcluded.ref_idsis unchanged.MEMKERNEL_RECALL_LOG_MAX_BYTESdrops query text, then trailingmemoriesentries (memories_truncated), then trailingref_ids(ref_ids_truncated), markedtruncated.ref_idsgo last, so the count keeps its evidence.eval/repeat-mistakes/count.pyaddsby_runandby_agent(per-id repeat and outcome counts;severalwhen one thread's records name more than one id) when the log has ids; without ids the report, details included, is as before.MemoryService.recallreturns the same list; the receipt comes back through an optionalreceipt=RecallReceipt()argument.retain/recallrows, 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.Tests
getshowsrun_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_idsrun_idon 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_…)test_a_recall_receipt_counts_each_exclusion_…,test_exclusions_are_the_last_windows_not_a_sum_over_windowstest_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 limittest_a_hook_record_lists_what_the_block_showed_with_the_process_idstest_an_over_long_id_setting_is_ignored_with_one_warningby_run/by_agent,several, no groups without idstests/unit/test_repeat_mistakes_count.py::test_repeats_are_grouped_by_the_harness_run_and_agent,test_a_log_without_harness_ids_reports_no_groupsChecks
ruff check,ruff format --check(src, tests, templates),mypy src/strict, andmypy --stricton the maintained eval tools (eval/repeat-mistakes/): clean. The first CI run failed that last check (a loop variable incount()reused a tuple's name);569d28frenames it.memkernel-0-15-harness-foundations: gate passes.several(A6 as approved), an empty id meaning "unset" (asretainalready treats it).For the reviewer
Review round 1 (569d28f → 8279d76)
returned_charsfor 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.recallrow listsrun_id?,agent_id?,task_id?;retain's row and docstring sayagent_idandtask_idare checked but not recorded.excluded; H2 addsout_of_scopeto the same counts.