Skip to content

#644 Streamed attachment uploads in Session Chat - #855

Merged
ivanfenenko merged 5 commits into
mainfrom
feature/644-streamed-attachment-uploads
Oct 27, 2026
Merged

ivanfenenko merged 5 commits into
mainfrom
feature/644-streamed-attachment-uploads

Conversation

@ivanfenenko

@ivanfenenko ivanfenenko commented Oct 26, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Stage 1, timeline (first commit): metadata.attachments entries show as a chip for non-image files and as an aspect-correct inline image (220 pt/dp height cap, no square crop) for images, on user and assistant messages. Image bytes load through /api/fs/read/* and any failure degrades to the chip. Tapping opens a full-screen viewer that letterboxes on black and dismisses from the close control or a tap outside the image. The Attached file: prompt lines are hidden from the bubble text.
  • Stage 2, streamed upload (second commit): on a v2 server whose /openapi.json still declares POST /api/experimental/fs/write (required path query, octet-stream body, 200 data.path) and whose /api/info declares paths.tmp, files stream to <tmp>/uploads/<uuid>/<name> with progress and cancel on the existing attachment chip. Mime detection uses shared vectors (shared/attachment-mime/attachment-mime-cases.json); images and PDFs the model reads (≤ 20 MB) stay inline, everything else uploads. Duplicates (same name and size in the draft) are refused, and send waits for pending uploads. The prompt carries the Attached file: line plus metadata.attachments, and the file stays out of files[].
  • Failures: contract miss (404/405/400/415, or a 200 without data.path) clears the flag for the connection and sends that file the old way with no new error; every other status (401/403, 408, 409, 413, 422, 429, 5xx), a timeout or a lost connection shows "Upload failed" and keeps the flag; cancel is silent.
  • Preview location differs from the issue text: /api/fs/read/* is confined to its location[directory] (write is not), so the session directory cannot read an upload under paths.tmp. Android reads uploads with paths.tmp as the location and the relative path; iOS uses the file's parent folder. Both were verified against a v2 server.

Checks

  • Android: ./gradlew :app:testDebugUnitTest passes (new tests: contract shape, mime vectors, decision/duplicate/classification/prompt text, upload API, preview location, adapter and event projection, composer upload flow).
  • iOS: full unit suite passes (2793 tests on an iPhone 17 simulator), including the shared mime vectors and the composer upload tests.
  • Review pass (third commit): classification now matches the issue table exactly, unknown-model, declared-mime and contract-shape behavior are aligned across platforms with tests on both, and duplicated decisions, repeated unwrapping and a misnamed failure type were cleaned up with no behavior change.
  • Each stage commit builds and passes on its own: the Stage 1 commit has no upload code.
  • Real apps against the scenario harness on a v2 server: a zip uploaded and sent on Android (server stored metadata.attachments, chip shown); a text file uploaded on iOS; inline images keep their aspect ratio; the Android viewer letterboxes and ignores a tap on the image.

Evidence

Screenshots in the evidence comment.

Issue

Risks / Follow-ups

  • Not driven in the apps: the progress hairline, cancel and the "Upload failed" flow (local uploads finish too fast to catch; covered by unit tests), the iOS full-screen viewer, and an image over 20 MB going through the upload path.
  • A slash command sent with an uploaded file gets the Attached file: line in its text but no metadata, because the v2 command body has no metadata field, so no chip appears for it.
  • The duplicate check applies to every draft attachment, including inline ones.
  • The write route is experimental upstream; the contract check keeps the flag off if its shape changes.
  • Messages cached before this change keep showing the Attached file: line until they reload.

🤖 Generated with Claude Code

ivanfenenko and others added 2 commits October 27, 2026 00:06
Stage 1 on both apps. A v2 prompt's metadata.attachments entries render as a
chip for non-image files and as an aspect-correct inline image (height capped,
no square crop) for images, on user and assistant messages. Image bytes load
through the v2 file read route, which only serves files inside its
location[directory], so the file's own folder is the location; any failure
degrades to the chip. Tapping an image opens a full-screen viewer that
letterboxes on black and dismisses from the close control or a tap outside the
image. The "Attached file:" prompt lines are dropped from the bubble text.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Stage 2 on both apps. On a v2 server whose /openapi.json still declares
POST /api/experimental/fs/write (required path query, octet-stream body, 200
data.path) and whose /api/info declares paths.tmp, a picked file is detected
as text, binary or a native type (shared vectors in shared/attachment-mime) and
either rides inline as a data URL (images and PDFs the model reads, up to
20 MB) or is streamed to <tmp>/uploads/<uuid>/<name> with progress and cancel
on the existing attachment chip. Send waits for pending uploads, and a file
with the same name and size as one in the draft is refused. The prompt gets an
"Attached file:" line plus metadata.attachments and the file stays out of
files[].

A contract miss (404/405/400/415 or a 200 without data.path) clears the flag
for the connection and sends the file the old way with no new error; transport
and auth failures show "Upload failed"; cancel is silent.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@ivanfenenko

ivanfenenko commented Oct 26, 2026 •

Copy link
Copy Markdown
Collaborator Author

Screenshots from the real apps against the scenario harness (v2 server, scripted model, fixture data only).

Shot iOS Android
Uploaded files as chips; inline image
Inline image, aspect kept
Full-screen viewer, letterboxed not captured
Composer chip / uploaded text file

@ivanfenenko
ivanfenenko marked this pull request as ready for review October 26, 2026 23:20
…cation

Spec fixes, both apps: only 404, 405, 400 and 415 (or a 200 without data.path)
are a contract miss, so 409, 413, 422 and every other status show "Upload
failed" and keep uploads on; with no known model images and PDFs go inline and
everything else uploads; a type declared as application/octet-stream falls back
to the extension (new shared vectors with an optional filename); Android's
contract check follows allOf/anyOf/oneOf and requires a JSON 200; a generic
file never goes inline when uploads are unavailable; "Attached file:" lines are
hidden only when the same message's metadata names that path.

Standards fixes: unrelated reformatting removed from MessageModels and
SessionCacheCodec (Android); one inline-or-reject decision shared by the add
path and the contract-miss fallback; Attachment.uploadedServerPath and an
inline-attachments helper replace the repeated unwrapping and the forced cast;
server paths and prompt text moved out of AttachmentUploadFailure, which now
only classifies. The viewer letterbox uses the theme scrim on Android and the
image corners use the small radius token on iOS; the viewer's black letterbox
stays literal on iOS and the Android close icon stays white because no token
fits.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review: 2 finding(s) that 2+ of 3 passes agreed on.

8 finding(s) from a single pass, not posted
  • ios/OpenCode Mobile/OpenCode Mobile/Domain/Message/Attachment/AttachmentLoader.swift:142 high: Upload decision and byteCount use fileSize ?? 0 (muse-spark-1.3-contributor)
  • android/app/src/main/java/dev/opencode/mobile/domain/message/remote/MessageDomainAdapter.kt:480 medium: Inbox merge keeps an empty Text part for attachment-only prompts (muse-spark-1.3-contributor)
  • android/app/src/main/java/dev/opencode/mobile/domain/connection/V2ServerContract.kt:104 medium: Upload contract checks first 200 content type instead of application/json (muse-spark-1.3-contributor)
  • ios/OpenCode Mobile/OpenCode Mobile/UI/SessionChat/Region/SessionChatComposer.swift:833 medium: Contract-miss fallback loses the attachment's known mime and can drop the file (deepseek-v4.1-flash)
  • android/app/src/main/java/dev/opencode/mobile/domain/message/MessageModels.kt:139 medium: Uploaded attachments no longer trigger the file-backed v1 body, so v1 sends an empty URL (deepseek-v4.1-flash)
  • ios/OpenCode Mobile/OpenCode Mobile/Domain/Event/EventDomainAdapter.swift:385 medium: Uploaded parts are never emitted for top-level metadata because of the early return (deepseek-v4.1-flash)
  • android/app/src/main/java/dev/opencode/mobile/data/remote/AttachmentUploadApi.kt:63 medium: A failed response-body read on a 200 is treated as a contract miss (deepseek-v4.1-flash)
  • ios/OpenCode Mobile/OpenCode Mobile/Domain/Message/Attachment/AttachmentUploadPolicy.swift:21 low: Unknown model never reads natively, unlike Android (muse-spark-1.3-contributor)

opencode pr-review · passes: muse-spark-1.3-contributor, glm-5.3-flash, deepseek-v4.1-flash · $0.533

ivanfenenko and others added 2 commits October 27, 2026 19:51
A probe that found the write route but could not read /api/info cached
"no tmp directory" for the server version, so streamed uploads stayed off
until the release changed. Such a result is now marked unread and not
cached, so the next probe reads it again; a 200 without paths.tmp is still
a final answer. Same change on Android and iOS.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ivanfenenko
ivanfenenko merged commit 326bb0f into main Oct 27, 2026
5 checks passed
@ivanfenenko
ivanfenenko deleted the feature/644-streamed-attachment-uploads branch October 27, 2026 19:07
ivanfenenko added a commit that referenced this pull request Oct 27, 2026
* Close finished issues with Fixes in pull requests

The feature skill's PR body example showed a bare "- #<number>", which
only links the issue, so #855 merged without closing #644. Make
"Fixes #<number>" the default for a PR that finishes its issue, re-decide
it when a staged draft becomes complete, and check closingIssuesReferences
during merge readiness.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Show both Issue line forms in the feature PR body example

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
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.

1 participant