Skip to content

test(memory): pin the graph file being destroyed from outside between operations - #5621

Open
cliffhall wants to merge 1 commit into
v2/mainfrom
v2/chore/5539-memory-external-destruction-tests
Open

cliffhall wants to merge 1 commit into
v2/mainfrom
v2/chore/5539-memory-external-destruction-tests

Conversation

@cliffhall

Copy link
Copy Markdown
Member

Closes #5539

Description

Adds one test file, src/memory/__tests__/external-destruction.test.ts, pinning what the memory server does when its graph file is destroyed from outside the process between two operations of a connected server. No source change.

Nine tests in four groups. Each starts from a server that has already saved one entity, then changes the file from outside:

State Pinned
Deleted read_graph returns an empty graph and does not recreate the file; the next create_entities recreates it holding only what that call added; add_observations on an entity that went with the file is refused (Entity with name Alice not found) and creates nothing
Truncated to zero bytes reads as an empty graph, logs nothing, and the read leaves the file empty; the next write saves only what it added
Replaced by a directory read_graph, create_entities and delete_entities each return a tool error starting EISDIR: with no structured content; no lock file or temp file is left beside the directory and nothing is put in it; the server serves again once the directory is removed
Orphaned memory.jsonl.<32 hex>.tmp beside the file loads read only the graph file (the remnant holds a complete record and a cut-off one, neither appears, nothing is logged); a save goes past it and leaves it byte-identical

What differs from the issue's proposal

  • Driven through an SDK Client over the in-memory transport (__tests__/helpers.ts, unchanged), not KnowledgeGraphManager directly. What these cases promise is what a client is told (an empty graph, or a tool error rather than an empty graph), and a manager call skips the error mapping that produces it. The reason is in the file's header.
  • A new file, not additions to knowledge-graph.test.ts.
  • An OS temp directory (makeTempGraph), not a directory under __tests__.
  • The directory case is adjusted, not copied. persistence.test.ts ("reports a graph file that cannot be read as a tool error") already pins a directory that is at the path when the server first looks, for read_graph, search_nodes, open_nodes, create_entities and the resource. What was unpinned is the file a running server already saved turning into a directory, that the failed calls leave no lock or temp file behind, and that the server recovers. Those are what this file asserts; it does not repeat the existing test's tool list.
  • Only the EISDIR code is asserted, not the text after it: whether Node appends the path differs by platform (memory: persistence EISDIR test fails on Node 26 (version-dependent error message) #5076, memory: persistence EISDIR test fails on macOS (the path suffix depends on the platform, not the Node version) #5162).
  • The other three cases (deleted mid-session, zero-byte file, temp remnant) were unpinned as the issue says: the existing suites cover "no file yet" only at a server's first call, blank lines only inside a non-empty file, and temp files only as "none left after a save".
  • Expected error output is kept off the console (console.error is spied), and the cases where nothing should be logged assert that.

Server Details

  • Server: memory
  • Changes to: tests only

Motivation and Context

#5539: the save is atomic and unreadable lines are never dropped, but how the server behaves when the file itself is destroyed between operations rested on implication, not on a test.

How Has This Been Tested?

No client-observable surface changes, so the evidence is a targeted probe.

  • npm test -w src/memory -- __tests__/external-destruction.test.ts: 9 passed; repeated 15 times in a row, 0 failures.
  • Mutation probe: with loadGraphWithUnreadable changed locally to map any read error to an empty graph (the failure the directory case guards against), both directory tests fail and the other seven pass. Reverted; not in the diff.
  • npm run local:gate exit 0 (macOS, Node 26), including the memory coverage gate and the interface diff (no interface changes).
  • Windows: not run locally. The assertions rely only on behavior the existing suite already depends on in the Windows CI leg: EISDIR from reading a directory (persistence.test.ts), and a directory listing taken straight after a write.

Breaking Changes

None.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

None of the four: test-only.

Checklist

  • I have read the MCP Protocol Documentation (not applicable: no protocol feature is touched)
  • My changes follow MCP security best practices (not applicable: tests only)
  • I have updated the server's README accordingly (not applicable: no tool, option or behavior changes)
  • I have added a changeset (npm run changeset) if this changes what a TypeScript server publishes (not applicable: nothing published changes)
  • I have tested this with an LLM client (not applicable: no server-facing change; see the probe above)
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling (not applicable: tests only)
  • I have documented all environment variables and configuration options (not applicable: none added)

🤖 Generated with Claude Code

… operations

One server stays connected while the graph file is deleted, truncated to
zero bytes, replaced by a directory, or joined by an orphaned temp file
from a killed run, and each case asserts what the client is told and what
is left on disk. Driven through the in-memory client harness rather than
KnowledgeGraphManager, since the promise is a tool error instead of an
empty graph.

Closes #5539

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Signed-off-by: cliffhall <cliff@futurescale.com>
@cliffhall cliffhall added the v2 label Nov 18, 2026
@changeset-bot

changeset-bot Bot commented Nov 18, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 21110fd

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

There are no active review issues for the test-only change covering external graph-file destruction and recovery.

No open issues 🎉

What changed in this PR

Adds nine characterization tests for #5539, pinning the memory server’s behavior when its graph file is changed externally between operations. No production code changes.

Changes:

  • Covers file deletion, zero-byte truncation, replacement by a directory, and orphaned temporary files.
  • Uses a connected SDK client to verify empty-graph responses, write behavior, and tool errors.
  • Checks recovery, leftover files, remnant preservation, and expected logging behavior.
File Description
src/​memory/​__tests__/​external-destruction.test.ts Adds client-level tests for external graph-file destruction and recovery.

Review effort: Balanced

@cliffhall

Copy link
Copy Markdown
Member Author

Copilot round 1: clean. The review (5962977525) posted no comments and no suppressed findings, so the loop ends here on the first clean round. Nothing was pushed after the opening commit 21110fd0.

@github-actions

Copy link
Copy Markdown
Contributor

memory: MCP interface diff

Base: 7f383a8e0f34 (Merge pull request #5597 from modelcontextprotocol/changeset-release/v2/main)
Head: the build in this checkout, at 1ec809977513 (Merge 21110fd into 7f383a8)

Diffed because it was named (--server).

✅ No interface changes detected.

Tools Prompts Resources Resource templates
Base 9 0 1 0
Head 9 0 1 0

Updated by this run for 21110fd0f2f29e70582fc9f1f05bc259d62e3820.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

memory: add tests for the data file being destroyed from outside the process

2 participants