GeezerVison is showing github.com — fix(core): send Bun.file bodies from Code Mode fetch by rekram1-node · Pull Request #65917 · anomalyco/opencode
Conversation
Issue for this PR
No GitHub issue: reported as harness feedback (an upload from Code Mode stored "[object Object]").
Type of change
- Bug fix
- New feature
- Refactor / code improvement
- Documentation
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]. A BunFile reaches the host fetch as a plain copy of its fields, and globalThis.fetch turns any object it doesn't recognize into that string. Uploads to presigned URLs then failed later with "file not found".
- A
BunFile body (including a slice()) is now read through the same Bun file handle Bun.write already uses for copies, so it uses the read permission Bun.file already got.
- Any other object body, such as a fetch response, its stream or a plain object, now fails with
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.byteLength being undefined, 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.serve server:
- before: a
Bun.file body arrived as [object Object]
- after: the file's bytes arrive, a
slice(1, 3) sends just those bytes, strings, Uint8Array and URLSearchParams are unchanged, and a plain object or a response body throws the error above
bun run check and bun run lint:effect-simplifications pass.
Screenshots / recordings
N/A
Checklist
- I have tested my changes locally
- I have not included unrelated changes in this PR
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|