Skip to content

fix(multi-agent): admit mem_agent_share is a copy + add shared-from audit tag#458

Merged
memtomem merged 1 commit intomainfrom
fix/multi-agent-share-semantic
Apr 24, 2026
Merged

fix(multi-agent): admit mem_agent_share is a copy + add shared-from audit tag#458
memtomem merged 1 commit intomainfrom
fix/multi-agent-share-semantic

Conversation

@memtomem
Copy link
Copy Markdown
Owner

Summary

mem_agent_share had three contradictory descriptions of what it does:

  • Docstring line 127: "Creates a copy of the chunk in the target namespace"
  • Comment line 146-147: "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 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:

  1. Admits the function is a copy. Docstring rewritten to spell out
    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.
  2. Adds a shared-from=<source-uuid> audit tag to the copy so
    audit tooling can walk one hop back to the source. Tag uses =
    (not :) to avoid collisions with namespace-style tag schemes.
  3. Dedups the audit chain on re-share. If the source already
    carried an inherited shared-from=... tag (from a prior share), it
    is 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_tags
helper 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_links table — is a separate change
that 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: fresh
    share, 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

…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]>
@memtomem memtomem force-pushed the fix/multi-agent-share-semantic branch from 6741952 to d2251b8 Compare April 24, 2026 22:01
@memtomem memtomem merged commit e1310aa into main Apr 24, 2026
7 checks passed
@memtomem memtomem deleted the fix/multi-agent-share-semantic branch April 24, 2026 22:01
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 24, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants