Skip to content

Commit 2b1305f

Browse files
committed
test(memory): assert unreadable lines survive the next write (#4885)
Turn the KNOWN BUG #4885 characterization into the expected behavior: the seeded unreadable lines are written back verbatim after the graph's own lines, and stay out of read_graph. Add the changeset. Signed-off-by: cliffhall <cliff@futurescale.com>
1 parent 215fd76 commit 2b1305f

2 files changed

Lines changed: 25 additions & 8 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@modelcontextprotocol/server-memory": patch
3+
---
4+
5+
Lines in the memory file that the server cannot read (malformed JSON, an entity or relation that fails validation, an unknown record type) are no longer deleted by the next write. They are still left out of the graph, and are now written back unchanged after the graph's own lines.

‎src/memory/__tests__/persistence.test.ts‎

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// Characterization tests for how the memory server persists its graph, driven
22
// through an SDK Client over an in-memory transport (#4854): the JSONL file
3-
// format, how unreadable lines are loaded and then rewritten, read and write
3+
// format, how unreadable lines are loaded and then kept on write, read and write
44
// failures as tool errors, the atomic temp-file save, and two servers sharing
5-
// one file. Tests that pin a known bug cite its issue (#4885, #4827, #4797),
5+
// one file. Tests that pin a known bug cite its issue (#4827, #4797),
66
// so the PR that fixes it has a test to change.
77
import { describe, it, expect, beforeEach, afterEach, vi } from "vitest";
88
import { promises as fs } from "fs";
@@ -167,12 +167,11 @@ describe("memory persistence over the protocol", () => {
167167
]);
168168
});
169169

170-
// KNOWN BUG #4885: pins current (wrong) behavior; the fix changes this assertion.
171-
// Characterizes #4885: the next write rewrites the file from the filtered
172-
// graph, so every unreadable line is deleted for good, and Bob loses two
173-
// valid observations because of one null. The relation to Bob now dangles.
174-
// The call reports success. The fix for #4885 changes this test.
175-
it("deletes the unreadable lines on the next unrelated write (#4885)", async () => {
170+
// #4885: the next write keeps the unreadable lines out of the graph but
171+
// writes them back verbatim, after the graph's own lines, so Bob keeps his
172+
// valid observations and the relation to him still has its entity on
173+
// disk. Blank lines carry no data and are not kept.
174+
it("keeps the unreadable lines on the next unrelated write (#4885)", async () => {
176175
await seed();
177176
vi.spyOn(console, "error").mockImplementation(() => {});
178177
const { client } = await open();
@@ -188,9 +187,22 @@ describe("memory persistence over the protocol", () => {
188187
'{"type":"entity","name":"Alice","entityType":"person","observations":["Works at Acme","Prefers email"]}',
189188
'{"type":"entity","name":"Carol","entityType":"person","observations":["New hire"]}',
190189
'{"type":"relation","from":"Alice","to":"Bob","relationType":"manages"}',
190+
'{"type":"entity","name":"Bob","entityType":"person","observations":["Allergic to penicillin","Lives in Haifa",null]}',
191+
'{"type":"entity","name":"Project X","observations":["Deadline 2026-10-01","Budget 40k"]}',
192+
'{"type":"relation","from":"Alice","to":"Bob"}',
193+
'{"type":"entity","name":"Trunc',
194+
'{"type":"entity","name":"A","entityType":"x","observations":[]}{"type":"entity","name":"B","entityType":"x","observations":[]}',
195+
"42",
196+
"null",
197+
'{"type":"note","text":"unknown type"}',
191198
"",
192199
].join("\n"),
193200
);
201+
// The kept lines stay out of the graph.
202+
expect((await call(client, "read_graph")).structuredContent).toEqual({
203+
entities: [alice, carol],
204+
relations: [aliceManagesBob],
205+
});
194206
});
195207
});
196208

0 commit comments

Comments
 (0)