Repository navigation
fix(files): stream side-panel videos in byte ranges and stop 2-second full-file re-reads - #1854
Merged
Merged
Conversation
… full-file re-reads
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.
Problem
Playing a video in the Files side panel lags and stutters heavily, freezes briefly on open, and fails on files over 100 MB.
Two causes compound:
FilesPanelre-reads the entire video file through the daemon (files.readAssetin 8 MiB base64 chunks), reassembles it in the main process, clones the full buffer over Electron IPC into the renderer, hashes it, and discards it. With no in-flight guard and polling continuing while the panel is hidden, slow transfers pile up and stall playback.Uint8Array.fromon the renderer main thread, and hands<video>an in-memoryblob:URL instead of streaming byte ranges on demand.Expected behavior: videos open promptly, stream and seek smoothly without periodic stalls or large renderer memory spikes, and keep playing cleanly while unchanged on disk.
Change
mousse-media://): Registered a privileged streaming scheme (stream: true) on the main window's default session (src/main/ipc/mediaStream.ts,src/main/index.ts,src/main/ipc/registerGuiIpc.ts,src/preload/index.ts). Opening a video callsfs:openMediaUrl, which validates the file via one 1-bytefiles.readAssetcall through the daemon and returns an opaque per-window, per-profilemousse-media://asset/<token>URL. Chromium's<video>streams HTTP206 Partial Contentbyte ranges in 1 MiB chunks on demand and cancels cleanly on seek or close; handles are released when a tab closes, reloads, or the window closes.FilesPanelnow checksfs:assetStamp(size + write time via 1 byte) only for the active preview tab while the panel is showing and the window is visible, guards against overlapping in-flight polls, and reloads a video or image only when its stamp changes.Uint8Array.fromwith a zero-copyUint8Arrayview for Blob URL creation (images/PDFs), addedpreload="metadata"andplaysInlineto<video>, and constrained.files-video-previewwith flexbox (overflow: hidden) so high-resolution videos fit inside the panel without scrollbars.FileService.readAssetRangeallows streaming video files up to 4 GiB whilereadAssetandreadAssetInPieceskeep the 100 MiB cap for whole-file reads.Verification
Tier 4 (cross-area: daemon
FileService, main process protocol and IPC, preload, rendererFilesPanel).16804ce6e):PASS tests: 9 file(s), 104 test(s)$ npx vitest run tests/mediaStream.test.ts tests/fileServiceAssets.test.ts tests/mainFolderAccess.test.ts tests/filesByThread.test.ts tests/renderer/filesPanelVideo.test.ts tests/renderer/filesPanelFinalClose.test.ts tests/renderer/filesPanelEmpty.test.ts tests/renderer/filesPanelSearch.test.ts tests/renderer/fileLinksHeld.test.tsparseByteRange,MediaStreamRegistry200/206/416/HEAD/cancel/profile-binding/cleanup (tests/mediaStream.test.ts), >100 MB video range reads vs 100 MB cap on whole reads and images (tests/fileServiceAssets.test.ts,tests/mainFolderAccess.test.ts), andFilesPanelstreaming open, 2-second stamp-only polling, in-flight deduplication, hidden-panel pause, disk-change reload, and unmount cleanup (tests/renderer/filesPanelVideo.test.ts).PASS typecheck:node: no errors$ tsc --noEmit -p tsconfig.node.jsonPASS typecheck:web: no errors$ tsc --noEmit -p tsconfig.web.jsoneslinton all modified/added source files: 0 errors.MOUSSE_MEDIA_SCHEME_PRIVILEGES,MediaStreamRegistry,attachMediaProtocol, andFileService.readAssetRangeagainst a generated 6-second 1280×720 30fps WebM in a 480×400 window styled with.files-video-preview. Verifiedloadedmetadata(duration: 6,1280×720), HTTP206byte-range seek to4.0s(Chromium fetched the tail seek index at offset2981888), playback to4.6swith143frames decoded and0dropped frames, andhasScrollbars: false/fitsInsideBox: true.files.readAsset(offset, length)method unchanged).Notes
src/main/ipc/registerGuiIpc.tsandsrc/preload/index.tsare also touched by open PRs perf(ui): keep chat, sidebar, and composer responsive while subagents run #1853, feat(threads): one chain record for agent messages, and a likely loop waits for the person's Continue or Stop #1480, and perf(browser): a hidden Browser panel and the chat's access card stop polling agents' browser access #822 in unrelated sections.No issue