Repository navigation
The avatar picker streams its file instead of posting it base64 - #1163
Merged
Merged
Conversation
The JSON attach request holds the body buffer, the parsed string and the
decoded bytes in memory at once, so a file costs about three times its size
in heap while the request runs. The attachments field already avoids that:
public/app.js streamUpload prepares an upload grant and PUTs raw bytes,
which the server pipes to weave.streamBlob. The avatar picker still posted
{name, mime, bytes} with the file base64-encoded.
The picker now calls streamUpload, the same prepare-then-PUT path, and asks
for no preview, so an avatar stores exactly what it stored before. The JSON
attach route is untouched and stays the inline path for scripts and MCP.
Two server-side guards had to move with the decision. The upload grant
refused any field that was not attachments; it now takes an avatar field
too, and still refuses every other field by name. attachToField refused a
staged avatar outright, because Issue #1428 left the picker on inline bytes
by Issue #706's design and made that boundary explicit; it now sniffs the
image type from the head of the staged blob, the way the preview check
already reads a staged upload, so an avatar is still accepted only as a
PNG, JPEG, GIF or WebP whichever path it arrives on.
A database-blob workspace keeps working without a fallback in the picker:
the PUT handler reads the body into one buffer when the workspace has no
disk path, which is still one copy instead of three.
test/upload-stream.test.mjs case "an avatar field takes its bytes, not a
streamed upload (Issue #1428)" asserted the behaviour this Issue reverses.
It is now "an avatar field takes a streamed upload too, and only a file
field does", carrying both Issue numbers, and it drives the whole route:
prepare, PUT, the sniffed type, the bytes on disk and the field value.
(Issue #1857)
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Change-Id: I4228588f3d28de746a3f5b6093d3c1a3f4669587
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes weave Issue #1857 (https://weave.grunion.ai/w/weave, Development/Issue #1857), split out of Issue #1429.
What changed
The JSON attach request holds the body buffer, the parsed string and the decoded bytes in memory at once, so a file costs about three times its size in heap while the request runs. The attachments field already avoids that:
streamUploadprepares an upload grant and PUTs raw bytes, which the server pipes toweave.streamBlob. The avatar picker still posted{name, mime, bytes}with the file base64-encoded to the same attach route.public/app.js:avatarUploadcallsstreamUploadon the same prepare-then-PUT path the attachments field uses. It passespreview: false, whichstreamUploadnow takes, so an avatar stores exactly what it stored before: one blob, no preview beside it.src/routes.js: the upload grant refused any field that was notattachments. It now takes anavatarfield too, and still refuses every other field by name.src/engine.js:attachToFieldrefused a staged avatar outright. It now sniffs the image type from the head of the staged blob, the way the preview check already reads a staged upload, so an avatar is accepted only as a PNG, JPEG, GIF or WebP whichever path it arrives on.src/handbook/guides/agent-access-mcp.md: thefieldan upload grant takes is an attachments or avatar field.The JSON attach route is untouched and stays the inline path for scripts and MCP. A database-blob workspace needs no fallback in the picker: when the workspace has no disk path the PUT handler reads the body into one buffer instead of staging it, which is still one copy rather than three.
The decision this reverses
attachToFieldrefused a staged avatar because Issue #1428 left the picker on inline bytes by Issue #706's design and made that boundary explicit in code. Issue #1428's own note records the reason as design, not a constraint: "public/app.jsavatarUploadand the workspace logo keep inline bytes by #706's own design, so they are not part of this." Issue #1857 reverses that call for the picker. The workspace logo is not in scope and still takes inline bytes.So
test/upload-stream.test.mjscase "an avatar field takes its bytes, not a streamed upload (Issue #1428)" is now "an avatar field takes a streamed upload too, and only a file field does (Issue #1857, reversing Issue #1428)", carrying both Issue numbers. It drives the whole route: prepare, PUT, the sniffed type, the bytes on disk and the field value.Verification
Targeted suites, 364 cases over 19 files,
fail 0, nothing skipped, both lanes green:avatar-field,avatar-upload-browser,avatar-faces-browser,upload-core,upload-stream,upload-concurrency,mcp-upload,attachment-size-limit,attachments-field,attachment-retry-browser,attachment-drop-browser,ui-contract,no-inline-comments,changelog-fragments,agent-surface,handbook,docs-drift,file-preview,attachments-preview.test/avatar-upload-browser.test.mjsis the new suite, written first. Its case drives the real picker on a record page and reads every/api/request the page makes. Before the fix it failed onpage.waitForResponse: Timeout 20000ms exceededbecause noPUT /api/uploadswas ever sent. After it, the picker makes onePOST /api/uploadsgrant declaring the size and type and carrying no content, onePUT /api/uploadswithContent-Type: application/octet-stream, and no request anywhere carrying abyteskey. The stored file reads the full size, the type sniffed from the streamed bytes and no preview blob. A second case checks the face the page then draws is the file that was streamed.test/avatar-field.test.mjsgains four cases: a streamed avatar lands with its type sniffed from the bytes on disk, a streamed non-image is refused by type with nothing left behind, an upload grant takes an avatar field and still refuses a text field, andavatarUploadinpublic/app.jsnamesstreamUploadand no longer namesfileBase64.No markup or stylesheet changed, so both themes are untouched; the browser suite drives the real control rather than a mock.
🤖 Generated with Claude Code