Repository navigation
feat: scope, private memory per agent and per task (#119 H2) - #156
Merged
Merged
Conversation
A memory is project (shared, the default) or private to the caller's agent or task: retain(scope="agent"|"task") with agent_id/task_id as tool arguments or MEMKERNEL_AGENT_ID/MEMKERNEL_TASK_ID. One predicate decides visibility on every read path: recall (both orders), get, ask, list_memories, consolidate's candidates, the hook blocks; wiki_export drafts project records only. Older records are project. Another agent's record is not found by get, ask, forget and promote. Writes: dedup per scope; promote keeps the source's scope, scope="project" publishes; a private record supersedes only its own scope (explicit and code's automatic supersede: one live snapshot per source and scope); a supersede target the caller cannot see is ignored; document parts stay shared and resolve only to a summary the caller can see. Checkpoints without a scope go to the caller's task, else agent, else project; latest-checkpoint recovery reads only that scope, with no fallback. Store maintenance (purge, revalidation, health counts, the unsaved-session report), the eval count and the admin API stay store-wide. Receipts: excluded adds out_of_scope and capped; an empty recall records empty_reason; an entry names a non-project scope. README: a Scope section and how tools sharing a store share ids; the Codex and Cursor templates say so. Spec: specs/memkernel-0-15-harness-foundations, amendment H2 (B1-B11).
…hem (#119 H2) consolidate(revalidate=True) returned every item the store-wide revalidation flagged, and the session-start block listed them, so agent b saw the source, type, reason and ref_id of agent a's private decision whose file changed. The listed items are now filtered by the caller; the counts stay store-wide and the admin API's revalidate keeps the full list. Test: a private decision citing a file that changes is listed for agent a and not for agent b.
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 second slice of issue #119: H2, scope and abstention (FR-001, FR-005, SC-1, SC-4, SC-6), built as the approved amendment H2 (#155: B1, B2, B3, B5 confirmed, B4 revised by the owner). It leaves #119 open for H3 (the context diff).
What's in it
Caller(agent_id, task_id)incore/models.pyseesprojectrecords and its own agent's and task's; a record without thescopekey isproject(SC-4).EVERYONEis store maintenance's and the operator's view. Applied in Python, after the store returns candidates.recall,retain,get,ask,forget,promote,consolidatetakeagent_id/task_id(defaultMEMKERNEL_AGENT_ID/MEMKERNEL_TASK_ID); the hook blocks use the process's;MemoryServicemethods takecaller=(default: the settings' ids).recall(both orders),get,ask,list_memories,consolidate's candidates, the session-start and compaction-recovery blocks (checkpoint, context, needs-review list, candidates),wiki_export(projectonly, B3). Another agent's record is not found (B2).retain(scope="project"|"agent"|"task"), refused without the id. Dedup per scope (a pre-H2 record and a newprojectone are one record).promotekeeps the source's scope;scope="project"publishes. A private record supersedes only its own scope (refused with an error otherwise); code's automatic supersede follows it (one live snapshot persourceand scope). A supersede target the caller cannot see is ignored and its link dropped; a missing target keeps its link as before (health reports it dangling). Document parts carry no scope and resolve only to a summary the caller can see.retain(checkpoint=true)withoutscope) checkpoints go to the caller's task, else agent, elseproject; latest-checkpoint recovery (session start, compaction recovery,recall(order="newest")) reads only that scope, never falling back toproject.excludedaddsout_of_scopeandcapped, each candidate counted once in that order; an empty recall recordsempty_reason(no_match,out_of_scope,excluded); an entry names its scope when it is notproject. The MCP response is still a JSON list.scope="project"hands off), the tool rows, config and recall-log rows. The Codex and Cursor templates say which ids carry a checkpoint. CHANGELOG under[Unreleased], with the behaviour change for anyone setting the ids.Tests
tests/unit/test_scope.py(27) andtests/e2e/test_mcp_scope.py; each SC-1 read path has a test where agent a's private record is invisible to agent b.recallrelevancetest_recall_returns_project_records_and_the_callers_own_onlyget,ask,list_memoriestest_get_ask_and_list_do_not_show_another_agents_recordtest_promotion_candidates_are_the_callers,test_another_agents_private_promotion_leaves_the_shared_source_a_candidatetest_the_session_start_block_shows_only_what_the_process_may_see,test_compaction_recovery_reads_only_the_processes_effective_scopewiki_exporttest_wiki_export_drafts_project_records_only_whoever_callstests/e2e/test_mcp_scope.pytest_a_checkpoint_goes_to_the_task_then_the_agent_then_the_project,test_latest_checkpoint_recovery_reads_only_the_effective_scope,test_the_hooks_recover_and_save_in_the_processes_effective_scopetest_an_unsaved_session_counts_a_checkpoint_in_any_scope,test_the_purge_removes_expired_private_records_whoever_runs_it,test_stats_count_every_recordtest_retain_names_only_the_callers_own_scope,test_dedup_is_per_scope_and_an_older_record_counts_as_project,test_promote_keeps_the_scope_and_publishes_only_when_asked,test_a_private_record_supersedes_only_its_own_scope,test_an_unseen_supersede_target_is_ignored_and_a_missing_one_keeps_its_link,test_forget_cannot_delete_another_agents_record,test_code_keeps_one_live_snapshot_per_source_and_scope,test_a_document_chunk_resolves_only_to_a_summary_the_caller_can_see,test_a_shared_body_is_found_through_each_owners_own_summarytest_recall_widens_past_out_of_scope_candidates,test_each_exclusion_is_counted_once_in_order_and_capped_is_counted,test_an_empty_recall_says_whyThe scope tests fail against two mutations: every caller seeing every record (12 fail) and
retainnever storing a scope (17 fail).Checks
00909d5.ruff check,ruff format --check,mypy src/strict,mypy --stricton the eval tools: clean.origin-alignment-2026-11-23-2114-build-h2.md; gate passes._dedup_hit's scope made required, and promoted sources counted only through copies the caller can see (a real gap, with a test). Its claim that document chunks take the first owner's scope was wrong (parts carry no scope); a test now shows each owner's summary finds a shared body.For the reviewer
supersedes=naming a missing record had stopped keeping its link, which the health report counts (test_status_resource_carries_health_summarycaught it).excludeddict; they now includeout_of_scopeandcapped(B10).order="newest"recall scans the checkpoints a second time, unscoped, to tellno_matchfromout_of_scope; only on an empty result.Review round 1 (00909d5 → 8397301)
consolidate(revalidate=True)returned every item the store-wide revalidation flagged, and the session-start block listed them, so agent b saw the source, type, reason andref_idof agent a's private decision whose file changed. The listed items are now filtered by the caller (_visible_ref); the counts stay store-wide; the admin API'srevalidatekeeps the full list.test_flags_found_by_this_pass_are_shown_only_to_who_can_see_them(a private decision citing a file that changes: listed for agent a, absent from agent b'sconsolidateand session start;changedstill counts it). It fails with the fix removed.ref_idis now skipped, not looked up).