fix(multi-agent): admit mem_agent_share is a copy + add shared-from audit tag#458
Merged
fix(multi-agent): admit mem_agent_share is a copy + add shared-from audit tag#458
Conversation
4 tasks
…udit tag The docstring on `mem_agent_share` contradicted itself in three ways: * Line 127: "Creates a copy of the chunk in the target namespace" * Line 146-147 comment: "Create a cross-reference link instead of copying" * Actual implementation: `mem_add(...)` — a brand-new chunk with a fresh UUID and no link back to the source. The third version was the truth. The other two misled callers (and were amplified on https://memtomem.com/ltm/multi-agent/) into expecting reference-link semantics that the storage layer does not implement. Changes: 1. Docstring now admits the function performs a **copy**, not a link, and explains that the name is kept for API stability while true share semantics live in a follow-up RFC. 2. The copy now carries a `shared-from=<source-uuid>` tag so audit tools can walk one hop back to the source. Tag format uses `=` not `:` to avoid collisions with namespace-style tag schemes. 3. Source tags are carried over verbatim with one exception: any inherited `shared-from=...` is dropped before appending the new stamp, so a chain of re-shares produces `shared-from=<immediate parent>` only — never a growing audit chain. The dedup logic is extracted into a top-level `_build_shared_tags` helper so the contract can be unit-tested without standing up MCP components. `TestSharedFromTags` pins fresh-share, source-order preservation, single-parent dedup, multi-stale-tag dedup, and empty source tags. True cross-reference linking (no duplication, bidirectional propagation, storage-level chunk_links table) is out of scope here and tracked as a follow-up RFC. Co-Authored-By: Claude <[email protected]>
6741952 to
d2251b8
Compare
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Summary
mem_agent_sharehad three contradictory descriptions of what it does:mem_add(...)— a brand-new chunk with a freshUUID and no link back to the source.
The third version is the truth. The other two misled callers (and were
amplified on the multi-agent guide)
into expecting reference-link semantics that the storage layer does not
implement.
This PR:
that the new chunk has a fresh UUID, that delete/update on the source
does not propagate, and that the name is preserved for API stability
while true share semantics are tracked in a follow-up RFC.
shared-from=<source-uuid>audit tag to the copy soaudit tooling can walk one hop back to the source. Tag uses
=(not
:) to avoid collisions with namespace-style tag schemes.carried an inherited
shared-from=...tag (from a prior share), itis dropped before appending the new stamp — so the new chunk holds
shared-from=<immediate parent>only, never a growing chain.The dedup logic is extracted into a top-level
_build_shared_tagshelper so the contract is unit-testable without standing up MCP
components.
Out of scope (follow-up RFC)
True cross-reference linking — no duplication, bidirectional
propagation, storage-level
chunk_linkstable — is a separate changethat needs schema migration. Tracked as a follow-up.
Test plan
uv run pytest packages/memtomem/tests/test_multi_agent.py -v—15 pass (10 existing sanitize + 5 new
TestSharedFromTags: freshshare, source-order preservation, single-parent dedup, multi-stale
dedup, empty source tags).
uv run pytest -m "not ollama"— 2334 passed, 46 deselected.uv run ruff check+ruff format --check— clean.🤖 Generated with Claude Code