Skip to content

A memory an agent saves in its own namespace during a coding plugin session never links to code #715

Open

Description

@zlareb1

Company or project name

No response

Component

MCP server

Use case

Memories link to code only when code_namespace_for (server/memory/app/code_link_reads.py) finds a code namespace: the memory is written in one, or a repo:<id> tag names a configured repository (namespace_for_tags, server/code/app/memory_links.py). The Claude Code and Codex plugins add that tag to what their hooks capture, but a lesson the agent saves itself with loom_memory_set in its own (non-code) namespace goes straight to the server without it: the plugin's MCP header helper sends only X-Loom-Code-Scope, which the server applies to code.* calls and loom_search's repository gate, never to memory.set. So the lessons an agent writes on purpose to its own namespace, the ones most worth linking, never show up under code.symbol lessons unless the agent adds the tag by hand. Team file rules already link: the plugin's loom-memory skill ("Team file rules" in SKILL.md and reference.md) writes them into the repository's primary code namespace, where code_namespace_for finds the repository through trunk_namespace without a repo: tag.

Describe the solution you'd like

Propose and implement one of:

  • (a) On memory.set over MCP, when the session carries a code scope, add the scope's repo:<id> tag unless the call names its own repo: tag. X-Loom-Code-Scope carries org/namespace, not the tag: map it back to the configured repository's repo_tag, and apply it in server/transport/mcp_call.py next to apply_code_scope (defined in server/code/domain/scope.py). This touches the write path, so follow the identity and provenance rules in .claude/rules/memory-plane.md.
  • (b) Tell the agent to pass the tag: the primer line in integrations/claude-code-plugin/lib/session-start.mjs (which today tells it to pass repo:<id> to loom_search only), and the loom_memory_set description in server/transport/mcp_descriptions.py. Edit only the Claude Code plugin's file, then run python scripts/codegen/agent_plugin_sync.py to copy it to integrations/codex-plugin/lib/session-start.mjs: make lint runs the script with --check, which fails unless the Codex copy matches byte for byte.

Either way, add a test that a memory saved in a plugin session is linked by the next memory_code_links pass. Discuss the choice in this issue first.

How to test: make format-check lint typecheck test-unit passes; for option (a), make test-unit-cov passes too: server/transport/mcp_call.py falls under the server/transport/ branch-coverage floor (86.0) in tests/inventory/coverage_floors.toml, which that target and CI check; for option (b), node --test integrations/claude-code-plugin/tests/*.test.mjs passes too (those tests cover the hook scripts the Claude Code and Codex plugins share).

Describe alternatives you've considered

The agent can add repo:<id> by hand today; nothing tells it to, so in practice it does not.

Where the need comes from

The need is mine, an AI tool helped shape the proposal

Additional context

Related: #644 (code.symbol returns no lessons when the memory_code_links reads exceed code_enrich_timeout_s). Both are about the lessons code.symbol shows from memory_code_links: this issue is about memories that never get a link, #644 about linked ones the read drops on a large table. Check the new links in memory_code_links itself, so the test does not depend on that read's time bound.

Size: L (several days, with review of the write path). Read CONTRIBUTING.md first (signed-off commits), and comment here to say you are working on it.

Activity

  1. added
    enhancement
    help wanted
    on Nov 16, 2026
  2. 0mandrock1 commented on Nov 19, 2026

    @0mandrock1
    Contributor

    I'd like to work on this and align on the choice before opening a PR.

    I favour (b) as an incremental, low-risk fix:

    • Update the Claude Code session-start primer and the loom_memory_set tool description so an agent saving a memory about the current repository includes its actual repo:<id> tag, even when writing into the agent's own namespace.
    • Sync the generated Codex plugin with agent_plugin_sync.py.
    • Cover both the repository-specific primer and the downstream memory_code_links behaviour in regression tests.

    Trade-off: (b) preserves the existing server write-path/provenance semantics, but it is best-effort: the agent may still omit the tag. If the requirement is deterministic linkage regardless of agent instruction-following, then (a) would be the right architecture, with the corresponding identity/provenance review.

    I have a local candidate and test evidence for (b), but won't open a PR until we agree on that trade-off. Would you prefer the smaller best-effort change now, or the server-side guarantee in (a)?

  3. zlareb1 commented on Nov 19, 2026

    @zlareb1
    MemberAuthor

    @0mandrock1 please implement (a).

    The plugin already adds repo:<id> to rows it captures from the checkout. A memory the agent saves itself with memory.set never gets that tag: X-Loom-Code-Scope only fills the namespace on code.* calls. With no tag, memory_code_links has no repository to link against, so the lesson never shows up on the code.

    Asking the agent to pass the tag, in the primer or the memory.set description, leaves the link up to the model. This issue exists because the model does not pass it. A test of that change can only show that a caller who sends the tag gets a link.

    On MCP memory.set, when the session has a code scope and the call has no repo: tag, add that scope's repo:<id> in server/transport/mcp_call.py next to apply_code_scope. Leave the memory write path as it is. actor and source_class stay stamped by the server.

    • A call that already has a repo: tag keeps it.
    • Map the header to a configured repository and use that repository's tag. An unknown scope adds nothing.
    • The header's org must match the write. A write into another code namespace stays with that repository.
    • A row is linked only when its text names a symbol or it has files. A preference saved in the session gets the tag and no symbol link.

    A line in the memory.set description can say the agent may pass a different repo: tag. That line does not create the link.

  4. added
    up-for-grabs
    on Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementhelp wantedup-for-grabs

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions