Skip to content

memory: create_relations returns an empty list for an existing relation with no notice, unlike create_entities' skipped #5654

Done

Description

@za69956

Which server?

memory (@modelcontextprotocol/server-memory)

Server version

2.2.1 (npm)

How did you run the server?

npx (npm package)

Transport

stdio

Protocol era

Legacy (2025-11-25 or earlier)

MCP client and version

Custom client on the Python MCP SDK (mcp, ClientSession over stdio)

Operating system and runtime

Linux, Node v22.23.4

Server configuration

node node_modules/@modelcontextprotocol/server-memory/dist/index.js (package installed from npm, 2.2.1), env MEMORY_FILE_PATH=<empty temp dir>/m.jsonl, stdio.

Steps to reproduce

Fresh, empty graph.

  1. create_entities {"entities":[{"name":"A","entityType":"t","observations":[]},{"name":"B","entityType":"t","observations":[]}]}
  2. create_relations {"relations":[{"from":"A","to":"B","relationType":"knows"}]}
  3. Repeat step 2 exactly.
  4. For comparison, create_entities {"entities":[{"name":"A","entityType":"t","observations":[]}]}

Expected behavior

Step 3 says the relation was skipped because it already exists, the same way create_entities does: a skipped field in structuredContent and a text notice. The create_entities handler adds that notice because "otherwise an agent reads the response as its observations having been stored"; a relation the agent asked for and did not get has the same problem.

Actual behavior

  • Step 3 returns [] as text and {"relations": []} as structuredContent, with no notice.
  • Step 4 returns {"entities": [], "skipped": ["A"]} plus the text Skipped 1 entity that already exists: A. ....

The graph is correct (no duplicate is stored); only the result is silent. From the result alone an agent cannot tell "already there" from "nothing happened". A repro test (Python MCP client) is in https://github.com/za69956/mcp-memory-server-qa-audit (test_F2_...).

Logs or error output


Already prototyped a fix?

No response

Before you submit

  • I searched existing issues and this is not a duplicate.
  • This is not a security vulnerability report (those go through the private advisory form).

Activity

  1. added
    bug
    on Nov 24, 2026
  2. A7mdMe commented on Nov 24, 2026

    @A7mdMe

    This is a critical observation for autonomous agent reliability @za69956.

    Why Silent Idempotency Breaks Agent Reasoning

    In LLM-driven agent loops (Claude, Cursor, Cline), tool calls are evaluated deterministically against expected state transitions. When an agent calls create_relations and receives:

    {
      "relations": []
    }

    with no text notice or skipped metadata, the agent cannot disambiguate between:

    1. Benign idempotency: The relation is already stored and active in the graph.
    2. Silent dropped execution: The server failed to parse the arguments or silently dropped the mutation.

    In practice, agents often treat "relations": [] as an unfulfilled task and either re-attempt the tool call repeatedly or hallucinate that the relationship was rejected.

    Observation & Deletion Invariant Discrepancies (#5653, #5655)

    This issue closely mirrors the observation asymmetry reported in #5653:

    • add_observations enforces set deduplication on insertion.
    • create_entities bypasses deduplication on creation, accepting duplicate observations (["x", "x"]).
    • When an agent later calls delete_observations for ["x"], the deletion counter decrements both instances and reports Deleted 2 of 1, further desynchronizing the agent's internal world model.
    • Furthermore, as noted in memory: delete_relations / delete_observations count a repeated request item as "matched nothing" #5655, repeated deletion items in request payloads get miscounted as "matched nothing".

    Architectural Solution: Explicit Structured Feedback

    To preserve agent determinism while maintaining idempotent graph writes, create_relations should return structured parity with create_entities:

    export interface CreateRelationsResult {
      relations: RelationRecord[];
      skipped: Array<{
        relation: RelationRecord;
        reason: 'ALREADY_EXISTS' | 'ENTITY_NOT_FOUND' | 'INVALID_RELATION';
      }>;
      notice?: string;
    }
    
    export function sanitizeCreateRelations(
      incoming: RelationRecord[],
      existing: RelationRecord[],
      knownEntityNames?: Set<string>
    ): CreateRelationsResult {
      const existingSet = new Set(existing.map(r => `${r.from.toLowerCase()}->${r.relationType.toLowerCase()}->${r.to.toLowerCase()}`));
      const toCreate: RelationRecord[] = [];
      const skipped: CreateRelationsResult['skipped'] = [];
    
      for (const rel of incoming) {
        if (!rel.from || !rel.to || !rel.relationType) {
          skipped.push({ relation: rel, reason: 'INVALID_RELATION' });
          continue;
        }
        if (knownEntityNames && (!knownEntityNames.has(rel.from) || !knownEntityNames.has(rel.to))) {
          skipped.push({ relation: rel, reason: 'ENTITY_NOT_FOUND' });
          continue;
        }
        const key = `${rel.from.toLowerCase()}->${rel.relationType.toLowerCase()}->${rel.to.toLowerCase()}`;
        if (existingSet.has(key)) {
          skipped.push({ relation: rel, reason: 'ALREADY_EXISTS' });
          continue;
        }
        existingSet.add(key);
        toCreate.push(rel);
      }
    
      const notice = skipped.length > 0 
        ? `Skipped ${skipped.length} ${skipped.length === 1 ? 'relation' : 'relations'} (${skipped.filter(s => s.reason === 'ALREADY_EXISTS').length} already existed).`
        : undefined;
    
      return { relations: toCreate, skipped, notice };
    }

    (Disclosure: As maintainers of the open-source MCP Production Kit, we have integrated this explicit skipped-relation feedback and observation parity guard into our production hardening test suite).

  3. added
    server-memory
    on Nov 30, 2026
  4. cliffhall commented on Nov 30, 2026

    @cliffhall
    Member

    Triage: Priority Low (total 5)

    • Severity 2: an already-existing relation comes back as an empty list with no notice, which an agent can misread; nothing is lost
    • Urgency 2: wanted eventually, nothing blocked on it
    • Bonuses: +1 bug label

    Board: Servers V2 (#43), Status Incoming, awaiting maintainer review (no milestone yet).

  5. added this to the v2.7.0 milestone on Nov 30, 2026
  6. self-assigned this
    on Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugserver-memoryv2

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions