Registry Mirror
Skip to content

Conversation

@backnotprop

Copy link
Copy Markdown
Owner

Video attachments in the Inbox: the person watches a film an agent attached and comments at moments. Built as approved (design record .product/approved/inbox-video/, approved 2026-10-15, with the owner's answers: the paused frame rides each Mac comment, the phone app plays natively, v1 plays over the Wi-Fi or the tailnet only).

What changed

Kind video, from the bytes (packages/shared/inbox/video.ts)

  • MP4/MOV by the ftyp brands (a video major or compatible brand; an image or audio major brand such as avif, heic or M4A stays out). WebM by its EBML DocType webm; Matroska stays file. Image sniffing runs first, so AVIF stays an image.
  • An MP4/MOV's duration_ms, width and height come from a seek-based walk of the boxes (moov/mvhd, the first vide track's tkhd) through the send's own descriptor. A moov after a 461 MB mdat is reached in a few small reads. A file whose tracks hold no video stays file.
  • New optional record fields (additive): media_type, duration_ms, width, height. Older readers see file.

Range (packages/server/inbox-byte-range.ts)

  • GET /api/inbox/attachments/:id/video[?version=sent]: kind video only (415 attachment_not_video), GET only, sniffed video/* type, inline, the image route's sandbox CSP, nosniff, CORP same-origin, cross-site refused.
  • /download takes the same Range handling.
  • Range is built by hand from the opened, checked descriptor, never Bun.file(path):
    • one range: 206 with Content-Range;
    • no range or several ranges: 200;
    • unsatisfiable: 416 with bytes */size;
    • an If-Range that does not match: 200.
  • ETag: the sent version's sha256, or a weak stat tag for the current file.
  • An answer of 1 MiB or less carries Content-Length. A longer answer streams and Bun sends it chunked (checked on 1.3.14: Bun drops Content-Length on a stream that does not finish at once). The total is in Content-Range. This is noted in the contract.

Phone door

  • New allowlist row attachments/:id/video.
  • For a GET, the door forwards Range and If-Range (only those two) and returns the window's 206, Content-Range, Accept-Ranges and ETag unchanged. This covers /download too.
  • Relay (asDevice): a sealed command carries no headers in v1. It gets the whole file, or 413 result_too_large past one frame, without reading it. This is documented.

Mac window (VideoAttachmentView.tsx)

  • Native <video controls preload="metadata"> (#t=0.001 as a poster), fit to the stage, with full screen.
  • Tile caption: "MP4 video · 7:41 · 1920 × 1080 · 461.0 MB", with Play.
  • Comment dots on a rail under the player; a click seeks.
  • Comment row: time chip, paused frame, Mark up (ImageAnnotator on the frame), Comment.
    • Typing pauses the film and pins the moment.
    • The frame is drawn from the <video> to a canvas and kept as a JPEG through /api/inbox/markups.
  • The panel lists the comments by time, each with a time pill that seeks. This uses a new optional compareAnnotations prop on AnnotationPanel; with it absent, the panel is unchanged.
  • Video focus claims the arrow keys. No new shortcuts.
  • A media error shows the Download card.
  • Phone web layout as in the mock: the film on top, then meta and comment count, the rail, the comments, and "Comment at 1:42".

Comments and Send

  • Annotations use blockId: "video", inboxVideo: { time }, and the frame in images.
  • The store now allows them on video, and refuses another blockId or a missing or negative time.
  • Send sorts them by time and writes At 1:42 (102.4 s of 7:41) under each heading, with the frame's path. This uses ui's new export-only exportLocation; nothing else's output changes. It is the same function the phone surface's export_feedback calls.

Also

  • Open in: the OS default player for mp4, m4v, mov and webm (bytes re-checked at launch).
  • The MCP and inbox --help attachment descriptions mention videos; the mod's bundled tool list was regenerated.

Docs: CLAUDE.md (Attachments, Range, Phones, relay, routes table), adr/implementation/inbox-mobile.md (allowlist rows and new section 11 from CONTRACT-ADDITIONS.md), the marketing Inbox reference, and the ui README.

Tests

  • packages/shared/inbox/video.test.ts:
    • sniffing (brands, WebM vs Matroska, AVIF, audio);
    • the header walk: v0 and v1 boxes, faststart, 64-bit mdat, a 461 MB film read sparsely, hostile sizes, audio-only;
    • a real ffmpeg H.264/VP8 encode when ffmpeg is on the PATH.
  • packages/server/inbox-byte-range.test.ts: the Range decision table.
  • packages/server/inbox-video.test.ts, against a real Inbox:
    • kind and metadata;
    • 200, 206 across chunk boundaries, 416, several ranges, stale If-Range, HEAD and other kinds refused, cross-site refused;
    • the sent version and a re-render;
    • /download Range;
    • annotation allowed and validated;
    • the door forwarding Range and If-Range with matching headers;
    • a relay asDevice command getting the whole file.
  • packages/inbox/videoAttachment.test.tsx (DOM; added to the workflow's DOM list): tile, player src, dots seek, panel pills seek, typing pauses and pins, frame upload then save, unplayable card, phone layout, feedback text.
  • tests/e2e/inbox-video.spec.ts (compiled binary): a VP8 WebM that Playwright records in the test.
    • It plays by Range (206 seen), and is paused, pinned and commented with its frame.
    • Seeking works from the rail dot and the panel pill.
    • Mark up draws on the frame.
    • Send is read back by wait_for_reply, with the JPEG and the PNG on disk.
    • The phone layout is checked.
  • tests/e2e/surface.spec.ts: an export_feedback with video records keeps them, by time.
  • Existing tests that used 'video' as the "unknown kind" now use a made-up kind.

Results:

  • bun run typecheck: clean.
  • bun test: 8175 pass, 0 fail.
  • Related DOM tests: 51 pass.
  • E2E: inbox-video, inbox-attachments-kinds, inbox-attachment-stepping and surface all pass on the compiled binary.

No binary fixtures are committed: every film is built in the test.

Not in this PR

  • Relay streaming (Range through sealed commands): v1.1, per the approval.
  • Frame upload from the phone: phone comments are timestamp-only in v1.
  • The native phone player (AVPlayer / ExoPlayer) is the Workspaces repo's part; the contract is in section 11.
  • WebM records no duration or size (the brief chose this), so its feedback line reads At 0:02 (2.2 s) without "of …".

Kind `video` decided from the bytes (MP4/MOV ftyp brands, WebM EBML
DocType), with an MP4/MOV's length and frame size read from its header by
seeking (moov may follow a huge mdat). A `video` route and `/download`
answer HTTP Range by hand from the already opened, checked descriptor
(206, 416, If-Range, ETag). The phone door forwards Range and If-Range and
returns the window's 206 unchanged; a relay command carries no Range and
gets the whole file (or 413), as before.

The window plays the film in a native <video>, with a rail of comment dots
that seek, a comment row (time chip, paused frame, Mark up, Comment) where
typing pauses and pins the moment, and the frame kept through the markups
route. Comments are `blockId: "video"` with `inboxVideo: { time }`; Send
lists them by time with "At 1:42 (102.4 s of 7:41)" and the frame's path,
in the window and the phone surface's export_feedback alike.

Design record: .product/approved/inbox-video (approved 2026-10-15).
# Conflicts:
#	AGENTS.md
#	adr/implementation/inbox-mobile.md
#	packages/server/inbox-devices.ts
#	tests/e2e/playwright.config.ts
…mocked

- File handles: Bun 1.3.14 loses a FileHandle.close() made while a read is
  in flight (an aborting client's cancel arrives mid-read), and a client gone
  before the answer starts gets a stream Bun never reads or cancels. The
  stream now closes after the read in flight returns, and an idle watchdog
  (30 s, streamIdleMs for tests) closes any body left unpulled. The image
  route's stream is the same one now. Tests count open descriptors back to
  baseline after both kinds of disconnect (lsof / /proc/self/fd).
- ETag: the current file's stat tag is strong (If-Range compares strongly);
  a weak If-Range never matches.
- exportLocation: dropped from a client's annotation on store, and from a
  stored record at export, so only the computed line prints.
- Panel: "Comments · By time", the moment and the frame atop each video
  card without the repeated quote (AnnotationPanel title / titleNote /
  cardParts); the tile counts "· 2 comments".
Bun 1.3.14 pulls a streamed body as fast as the file reads, whatever the
client's socket takes, so a slow viewer on bytes=0- of a large film had the
whole range read into memory. A 206 now carries at most 8 MiB: an
open-ended or longer range is answered from its start for 8 MiB with the
matching Content-Range, and the player asks again from there (RFC 9110
allows a shorter answer). Applies to /video and to Range requests on
/download; a plain no-Range download is unchanged (noted in the backlog).

Contract and docs say a 206 may cover less than asked. Tests: the cap
table, one capped answer reads at most 8 MiB from the file, and a player
reading and seeking a 30 MB film across capped answers. Also fixes the
door's allowlist comment to name all three forwarded headers.
@backnotprop
backnotprop merged commit 8d001e7 into main Oct 15, 2026
32 checks passed
@backnotprop
backnotprop deleted the feat/inbox-video branch October 15, 2026 04:22
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