Repository navigation
Fix byte ranges for thread-storage videos - #4343
Merged
ymichael merged 4 commits intoSep 25, 2026
Merged
Conversation
## Human comments ## What was wrong The HTTP range fix in #4343 still read and transferred the entire file through the daemon for every range. Seeking repeated that work, and videos larger than the daemon's 25 MiB whole-file cap could not be served. ## What changed Adds `host.read_file_chunk`: a root-confined, metadata-only or bounded byte read (at most 1 MiB) with an explicit revision guard. Thread-storage responses now stream these chunks with backpressure, stop future reads on cancellation, and check file revision before and after each daemon read. HEAD, cache hits, and unsatisfiable ranges do not read content. Overwrite, truncation, replacement, short reads, and later stream failures cannot silently complete with mixed or incomplete data. Host-daemon protocol **218 → 219** requires daemon updates. Plugin SDK **0.5.27 → 0.5.28** is required because the daemon command expands the generated declarations. Existing whole-file RPCs and other routes remain unchanged. Thread-storage downloads bypass their former size caps; HTML previews retain their 5 MiB limit and security headers. Storage ETags change from content SHA-256 to weak metadata validators, avoiding whole-file hashing. If-None-Match still supports 304; any If-Range falls back to full 200 because the ETag is weak. Revision checking detects normal filesystem changes but is not an immutable snapshot guarantee. Public SDK/CLI request shapes are unchanged. Behavior and compatibility are documented in `docs/debugging-and-qa.md`. This PR is stacked on #4343; review its incremental diff against that branch. Markdown video uses standard HTML markup, `<video src="clip.mp4" controls></video>`, through the existing rehype-raw/rehype-sanitize path. Added video/source attributes to the sanitizer, reused local file routing for src and poster, and enabled sanitized HTML in chat and plugin Markdown. The previous image-syntax extension is removed: `` remains an image. Existing directives and mentions survive sanitization. Plain Markdown keeps incremental rendering; HTML-containing documents use the existing whole-document HTML path. No new SDK members, CLI flags, or wire changes in this UI update. ## How you verified - Server streaming tests: 33 passed, covering ranges, conditional requests, HEAD, empty files, 40 MiB logical streams, backpressure, cancellation, aborts, short/misaligned chunks, and stream failures. - Public thread-data route tests: 88 passed, including the new RPC path, preview protections, oversized HTML rejection before content reads, and retryable file-change conflicts. - Existing whole-file response tests: 6 passed. - Daemon file tests: 27 passed, including a sparse file beyond 32 MiB, tiny ranged reads, unchanged legacy cap, stale revisions, root escapes, directories, and FIFOs. - Host-daemon contract suite: 72 passed, including chunk bounds and required confinement. - Turbo typechecks for server, host daemon, and host-daemon contract passed. - Built full head/base `pnpm start:worktree` servers at exact commits. The same 33,861,556-byte H.264 MP4 (with a padding box) yields 413 on #4343 and correct 206 byte ranges here. Full download and range bodies match source bytes. - Actual iOS 26.5 Safari in iPhone 17 Pro Simulator, via a local proxy omitting Content-Length: large video plays, emits seeked at 8.0008 seconds, and pauses without a media error. The base cannot load it. Controls were invoked through WebDriver script; native-touch automation and macOS Safari remain unverified. - Actual Chromium clicks in the full inline thread preview play, seek, and pause the large video. - Changing a 40 MiB file during a live transfer terminates its response after 2 MiB; it does not complete with mixed versions. All executed CI checks pass at final head `c425c4b4bd0481fcec3224a9b21e2761eed4c3e9`; optional iOS and Node compatibility jobs were skipped by the workflow. The rebuilt final-head server also passes the large-file range check. Follow-up to #4339 and #4343. HTML Markdown renderer: 122 targeted app tests pass, covering chat/plugin file routing, sanitizer protections, nested source/poster, preserved directives and mentions, text-only previews, and video DOM retention. App lint and typecheck pass. Chromium and real iOS Simulator Safari played and sought the 32.3 MiB stored file through a local cookie-enforcing streaming proxy using the HTML markup at this head (Safari 1.922s playing, 8.812s after seeking; no media errors). [Live HTML-in-Markdown video test](https://ymichael--23542.getbb.app/threads/thr_q5hgpzv6xz). Authenticated public Connect still awaits user verification. > AGENT GENERATED
ymichael
deleted the
bb/investigate-and-fix-reported-github-issue-thr_vqhcbgtd94
branch
September 25, 2026 18:10
ymichael
added a commit
that referenced
this pull request
Sep 30, 2026
## Human comments ## What was wrong #4343 added `allowHtml` to the conversation `MarkdownPreview`s so that agent-written `<video>` would render. One of those was the user message bubble (`CollapsibleMessageText`). Because of that, any user message containing `<` went through the `rehype-raw` + `rehype-sanitize` pipeline, and typed tags like `<details>`, `<b>` and `<img>` rendered as real elements instead of the literal text. Before #4343, react-markdown turned those raw nodes into text. ## What changed - `apps/app/src/components/thread/timeline/ConversationMessageContent.tsx`: removed `allowHtml` from the user bubble's `MarkdownPreview`. User messages render Markdown as before and show HTML tags literally. Assistant and generated messages still render sanitized HTML and `<video>`. - This is the fix the issue proposed. ## How you verified - Added a test in `ConversationMessageContent.test.tsx` that renders a user message containing `<details><summary>x</summary>hidden</details>` and `inline <b>bold</b> here`. It asserts that no `<details>` or `<b>` elements exist and that the tags appear as literal text. The test fails without the fix and passes with it. - `pnpm exec turbo run test --filter=@bb/app -- src/components/thread/timeline/ConversationMessageContent.test.tsx`: 13/13 pass, including the assistant `<video>` routing and user image routing tests. - `pnpm exec turbo run typecheck lint --filter=@bb/app`: passes, 0 errors. - Not checked in the running app. Fixes #4546 🤖 Generated with [Claude Code](https://claude.com/claude-code) > AGENT GENERATED Co-authored-by: Claude Opus 5.5 <[email protected]>
This was referenced Nov 17, 2026
ymichael
added a commit
that referenced
this pull request
Nov 17, 2026
…de (#7702) ## Human comments ## What was wrong `MarkdownPreview` turned off incremental rendering when `allowHtml` was set and the content contained `<`. Most `<` in agent output are not HTML (code fences, `Array<T>`, `a < b`). For those messages, each completed block caused a full parse of the settled message. That parse also ran rehype-raw and rehype-sanitize. #4343 states the intent "Plain Markdown retains incremental rendering". The `<` check was a cheap stand-in for "plain". ## What changed - `markdown-incremental-pieces.ts`: each piece summary records whether its mdast has an `html` node (checked only when the piece contains `<`). `resolveMarkdownPieces` returns `hasHtml`. - `markdown-preview.tsx`: with incremental blocks on, the preview uses the sanitized whole-document path only if a piece has a real `html` node. Without incremental blocks, the old `<` check stays. - Real HTML keeps the whole-document path, because an HTML block can span several pieces. - Messages with `<` only in code now render like messages without `<`. One visible effect: footnote ids no longer get the second `user-content-` prefix from the sanitizer (see the comment on #6274). ## How you verified - New tests in `markdown-incremental-pieces.test.ts`: - `<` in code spans, fences and prose gives `hasHtml: false`. - `<kbd>`, a `<details>` block and an HTML comment give `true`. - A settled HTML piece keeps `true` while later pieces stream. - `pnpm exec turbo run typecheck --filter=@bb/app` and `test --filter=@bb/app -- markdown Conversation`: pass. This includes the incremental and cold-HTML differential tests. Fixes #7695 > AGENT GENERATED --------- Co-authored-by: Michael Yong <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
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.
Human comments
What was wrong
Thread-storage videos could not seek reliably because the raw-file route ignored HTTP byte ranges. The initial range fix still read and transferred each whole file through the daemon, so large videos exceeded the whole-file cap.
What changed
Thread-storage responses now serve single bounded, open-ended, and suffix ranges with
206; unsatisfiable ranges return416, while malformed or unsupported ranges fall back to200. The server streams bounded file chunks from the daemon with backpressure, cancellation, and file-revision checks. HEAD and cache hits avoid content reads. HTML previews retain their size limit and security headers.Markdown video uses sanitized HTML
<video>and<source>elements with local file routing. Plain Markdown retains incremental rendering. Storage ETags are now weak metadata validators;If-Rangetherefore falls back to a full200. The host-daemon protocol moves from 218 to 219, and the Plugin SDK from 0.5.27 to 0.5.28. The public SDK and CLI request shapes do not change. Details and limits are documented indocs/debugging-and-qa.md.This PR includes the streaming and Markdown video work from #4351, which was squash merged into this branch. The 2 KiB raw and 256-byte compressed thread-route bundle budget adjustment accounts for the new Markdown video renderer after merging current
main; the built closure is 2281.5 KiB raw and 613.6 KiB brotli.How you verified
206ranges and matching bytes. Chromium and iOS 26.5 Simulator Safari played and sought the video through a local proxy; authenticated public Connect playback remains unverified.mainreproduced a 1.7 KiB raw bundle-budget failure; after the documented budget adjustment, the local app build and bundle check pass. CI on this head is running.Fixes #4339