Skip to content

Commit f121f43

Browse files
committed
fix(memory): preserve statusless manager reads
1 parent 990d0ba commit f121f43

4 files changed

Lines changed: 34 additions & 23 deletions

File tree

‎docs/plugins/sdk-migration.md‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,12 @@ Memory managers now return `status: "ok"` for successful excerpts and
9090
and empty ranges distinct from missing files without relying on pagination
9191
metadata.
9292

93-
At registration, the host normalizes pre-status results returned by older
94-
external memory managers, including the legacy `{ text: "", path }` missing
95-
sentinel. New producers should emit the explicit status; registered-input
96-
normalization remains available through the next Plugin SDK major.
93+
At registration, every statusless result from an older external memory manager
94+
preserves its legacy successful-read semantics and becomes `status: "ok"`,
95+
including empty results without range metadata. Only an explicit
96+
`status: "not_found"` reports absence. New producers must emit that status for
97+
missing files; registered-input normalization remains available through the
98+
next Plugin SDK major.
9799

98100
### Channel state migration declarations
99101

‎src/plugins/compat/registry-records.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export const PLUGIN_COMPAT_RECORDS = [
1212
...DEPRECATION_MARKING_COMPAT_RECORDS,
1313
MEDIA_LEGACY_PROJECTION_COMPAT_RECORD,
1414
{
15-
code: "memory-read-result-missing-sentinel",
15+
code: "memory-read-result-statusless-success",
1616
status: "deprecated",
1717
owner: "sdk",
1818
introduced: "2026-04-28",
@@ -21,11 +21,11 @@ export const PLUGIN_COMPAT_RECORDS = [
2121
removalGate: "next-plugin-sdk-major",
2222
replacement: '`MemoryReadResult` with explicit `status: "ok" | "not_found"`',
2323
docsPath: "/plugins/sdk-migration#memory-read-missing-results",
24-
surfaces: ['external memory manager `{ text: "", path }` missing-file results'],
24+
surfaces: ["statusless external memory manager read results"],
2525
diagnostics: ["host memory-manager acquisition adapter"],
2626
tests: ["src/plugins/memory-runtime.test.ts", "src/plugins/compat/registry.test.ts"],
2727
releaseNote:
28-
"External memory managers should return explicit ok/not-found statuses; the host temporarily normalizes pre-status registered inputs.",
28+
"External memory managers must return explicit not-found status for absence; statusless results retain legacy successful-read semantics through the next Plugin SDK major.",
2929
},
3030
{
3131
code: "context-engine-legacy-host-param-default",

‎src/plugins/memory-runtime.test.ts‎

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ describe("memory runtime handles", () => {
235235
expect(mocks.loadPluginRegistryHandle).not.toHaveBeenCalled();
236236
});
237237

238-
it("normalizes legacy missing reads once while preserving manager lifecycle", async () => {
238+
it("preserves statusless reads as successful while preserving manager lifecycle", async () => {
239239
const canonicalEmpty = {
240240
status: "ok",
241241
text: "",
@@ -262,14 +262,18 @@ describe("memory runtime handles", () => {
262262
}): Promise<LegacyMemoryReadResult | MemoryReadResult> {
263263
this.#readCalls += 1;
264264
switch (relPath) {
265-
case "memory/legacy-empty.md":
265+
case "memory/legacy-bare-empty.md":
266+
return { text: "", path: relPath };
267+
case "memory/legacy-ranged-empty.md":
266268
return { text: "", path: relPath, from: 1, lines: 0 };
269+
case "memory/legacy-nonempty.md":
270+
return { text: "legacy", path: relPath };
267271
case canonicalEmpty.path:
268272
return canonicalEmpty;
269273
case canonicalMissing.path:
270274
return canonicalMissing;
271275
default:
272-
return { text: "", path: relPath };
276+
throw new Error(`unexpected read path: ${relPath}`);
273277
}
274278
}
275279

@@ -313,18 +317,29 @@ describe("memory runtime handles", () => {
313317
expect(Reflect.get(second.manager ?? {}, "readFile")).toBe(
314318
Reflect.get(first.manager ?? {}, "readFile"),
315319
);
316-
await expect(first.manager?.readFile({ relPath: "memory/missing.md" })).resolves.toEqual({
317-
status: "not_found",
320+
await expect(
321+
first.manager?.readFile({ relPath: "memory/legacy-bare-empty.md" }),
322+
).resolves.toEqual({
323+
status: "ok",
318324
text: "",
319-
path: "memory/missing.md",
325+
path: "memory/legacy-bare-empty.md",
320326
});
321-
await expect(first.manager?.readFile({ relPath: "memory/legacy-empty.md" })).resolves.toEqual({
327+
await expect(
328+
first.manager?.readFile({ relPath: "memory/legacy-ranged-empty.md" }),
329+
).resolves.toEqual({
322330
status: "ok",
323331
text: "",
324-
path: "memory/legacy-empty.md",
332+
path: "memory/legacy-ranged-empty.md",
325333
from: 1,
326334
lines: 0,
327335
});
336+
await expect(
337+
first.manager?.readFile({ relPath: "memory/legacy-nonempty.md" }),
338+
).resolves.toEqual({
339+
status: "ok",
340+
text: "legacy",
341+
path: "memory/legacy-nonempty.md",
342+
});
328343
await expect(first.manager?.readFile({ relPath: canonicalEmpty.path })).resolves.toBe(
329344
canonicalEmpty,
330345
);
@@ -333,7 +348,7 @@ describe("memory runtime handles", () => {
333348
);
334349
await first.manager?.close?.();
335350
expect(manager.isClosed()).toBe(true);
336-
expect(manager.readCalls()).toBe(4);
351+
expect(manager.readCalls()).toBe(5);
337352
});
338353

339354
it("authorizes raw hits inside the selected plugin runtime scope", async () => {

‎src/plugins/memory-runtime.ts‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,7 @@ function normalizeRegisteredMemoryReadResult(
4242
if (result.status === "ok" || result.status === "not_found") {
4343
return result;
4444
}
45-
return result.text === "" &&
46-
result.from === undefined &&
47-
result.lines === undefined &&
48-
result.truncated === undefined &&
49-
result.nextFrom === undefined
50-
? { status: "not_found", text: "", path: result.path }
51-
: { ...result, status: "ok" };
45+
return { ...result, status: "ok" };
5246
}
5347

5448
function normalizeRegisteredMemoryManager(

0 commit comments

Comments
 (0)