Skip to content

The avatar picker streams its file instead of posting it base64 - #1163

Merged
grunion-ai merged 1 commit into
mainfrom
codex/weave-fix-1857-wf-11201602
Nov 20, 2026
Merged

grunion-ai merged 1 commit into
mainfrom
codex/weave-fix-1857-wf-11201602

Conversation

@grunion-ai

Copy link
Copy Markdown
Owner

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: 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 to the same attach route.

  • public/app.js: avatarUpload calls streamUpload on the same prepare-then-PUT path the attachments field uses. It passes preview: false, which streamUpload now 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 not attachments. It now takes an avatar field too, and still refuses every other field by name.
  • src/engine.js: attachToField refused 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: the field an 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

attachToField refused 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.js avatarUpload and 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.mjs case "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.mjs is 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 on page.waitForResponse: Timeout 20000ms exceeded because no PUT /api/uploads was ever sent. After it, the picker makes one POST /api/uploads grant declaring the size and type and carrying no content, one PUT /api/uploads with Content-Type: application/octet-stream, and no request anywhere carrying a bytes key. 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.mjs gains 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, and avatarUpload in public/app.js names streamUpload and no longer names fileBase64.

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

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
@grunion-ai
grunion-ai merged commit 1d6ef84 into main Nov 20, 2026
17 checks passed
@grunion-ai
grunion-ai deleted the codex/weave-fix-1857-wf-11201602 branch November 20, 2026 22:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants