Skip to content

Commit aba6618

Browse files
committed
computer: Recognize message-only missing media
1 parent fa3cf0d commit aba6618

2 files changed

Lines changed: 41 additions & 4 deletions

File tree

packages/computer/src/tools/ai.test.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,6 +1069,42 @@ describe("createAITools filesystem tools", () => {
10691069
});
10701070
});
10711071

1072+
it("recognizes message-only missing media errors", async () => {
1073+
const store = memoryStore({ size: 2 });
1074+
store.readChunks = () => ({
1075+
[Symbol.asyncIterator]() {
1076+
return this;
1077+
},
1078+
async next(): Promise<IteratorResult<Uint8Array>> {
1079+
throw new Error("ENOENT: no such file or directory");
1080+
},
1081+
});
1082+
const tool = createReadTool({ store, maxModelBytes: 4 });
1083+
const output = await executeTool(tool, { path: "/workspace/image.png" });
1084+
1085+
await expect(modelOutput(tool, { path: "/workspace/image.png" }, output)).resolves.toEqual({
1086+
type: "error-text",
1087+
value: "Could not read file bytes: /workspace/image.png",
1088+
});
1089+
});
1090+
1091+
it("does not confuse unrelated no-such errors with missing media", async () => {
1092+
const failure = new Error("SQLITE_ERROR: no such table: vfs_chunks");
1093+
const store = memoryStore({ size: 2 });
1094+
store.readChunks = () => ({
1095+
[Symbol.asyncIterator]() {
1096+
return this;
1097+
},
1098+
async next(): Promise<IteratorResult<Uint8Array>> {
1099+
throw failure;
1100+
},
1101+
});
1102+
const tool = createReadTool({ store, maxModelBytes: 4 });
1103+
const output = await executeTool(tool, { path: "/workspace/image.png" });
1104+
1105+
await expect(modelOutput(tool, { path: "/workspace/image.png" }, output)).rejects.toBe(failure);
1106+
});
1107+
10721108
it("does not hide unrelated inline media read failures", async () => {
10731109
const failure = new Error("storage unavailable");
10741110
const store = memoryStore({ size: 2 });

packages/computer/src/tools/fs/read.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -313,11 +313,12 @@ function validateBoundedReadLimit(name: string, value: number): number {
313313
}
314314

315315
function isMissingFileError(error: unknown): boolean {
316+
if (error === null || typeof error !== "object") return false;
317+
const candidate = error as { code?: unknown; message?: unknown };
318+
if (candidate.code === "ENOENT") return true;
316319
return (
317-
error !== null &&
318-
typeof error === "object" &&
319-
"code" in error &&
320-
(error as { code?: unknown }).code === "ENOENT"
320+
typeof candidate.message === "string" &&
321+
(/\bENOENT\b/i.test(candidate.message) || /no such (?:file|path)\b/i.test(candidate.message))
321322
);
322323
}
323324

0 commit comments

Comments
 (0)