Repository navigation
fix(core): send Bun.file bodies from Code Mode fetch - #65917
Conversation
There was a problem hiding this comment.
The fix works: in a throwaway Code Mode test against a local Bun.serve, a Bun.file body and its slice(1, 3) arrived as [object Object] on the base, and arrive as the file's bytes with this PR. Strings, Uint8Array and URLSearchParams are unchanged, and plain objects and response bodies now fail with the new error.
The new fetch.ts → bun.ts import creates an import cycle that blocks merging. With this PR, importing src/permission.ts, src/codemode/tool.ts or src/codemode/fetch.ts first throws ReferenceError: Cannot access 'node' before initialization at file-access.ts:327 (Permission.node). All three import cleanly on the base. As a result, at least 15 packages/core test files now fail before running any test, including tool-execute.test.ts (44 pass on the base), codemode-execute-options, tool-registry, aisdk, session-error, automation*, session-model-request* and tool-target-environment. opencode serve still starts, so the app's own import order avoids the cycle, and bun run check doesn't catch it. See the inline comment.
Also worth fixing: a Bun.file body now goes out with no Content-Type header, where Bun would send the file's type. Presigned URLs that sign the content type can reject that (inline).
tsc -b (the package's typecheck:tsc) passes. The public API is unchanged.
615fbd9 to
b4e0973
Compare
There was a problem hiding this comment.
Both earlier points are fixed. The import cycle is gone: permission.ts, codemode/tool.ts and codemode/fetch.ts import cleanly, and no packages/core test file I checked fails at load any more (tool-execute, codemode-execute-options and session-error together pass 64/64). A Bun.file body now goes out with the file's type as its Content-Type.
I re-ran a throwaway Code Mode test against a local Bun.serve server. On the base, a Bun.file body and its slice arrive as [object Object]. With this PR they arrive as the file's bytes with text/plain;charset=utf-8. Strings, Uint8Array and URLSearchParams are unchanged, plain objects and response bodies fail with the new error, and a missing file fails with ENOENT. tsc -b passes.
The public API is unchanged. Nothing new to raise.
Issue for this PR
No GitHub issue: reported as harness feedback (an upload from Code Mode stored "[object Object]").
Type of change
What does this PR do?
In Code Mode,
fetch(url, { method: "PUT", body: Bun.file(path) })didn't throw, but the request body was the 15 bytes[object Object]. ABunFilereaches the hostfetchas a plain copy of its fields, andglobalThis.fetchturns any object it doesn't recognize into that string. Uploads to presigned URLs then failed later with "file not found".BunFilebody (including aslice()) is now read through the same Bun file handleBun.writealready uses for copies, so it uses the read permissionBun.filealready got.A fetch body must be a string, a Uint8Array, URLSearchParams, or a file from Bun.file().instead of silently sending[object Object].The other half of the report,
bytes.byteLengthbeingundefined, is in the interpreter and is fixed separately in psychoscript.How did you verify your code works?
A throwaway test (not committed) ran Code Mode against a local
Bun.serveserver:Bun.filebody arrived as[object Object]slice(1, 3)sends just those bytes, strings,Uint8ArrayandURLSearchParamsare unchanged, and a plain object or a response body throws the error abovebun run checkandbun run lint:effect-simplificationspass.Screenshots / recordings
N/A
Checklist