mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #3811] [Issue]: Scene-video endpoints buffer full MP4s and ignore range requests #2055
Labels
No labels
android
bug
bugfix
ci
client
code freeze pause
container
dependencies
docs
documentation
duplicate
enhancement
feature
feature
feature
feature-creep
fixed-in-refactor
fixed-in-staging
good first issue
help wanted
in-pr
in-pr
needs-codeowner-decision
normal-scope
old-codebase
old-codebase
pull-request
qol
question
refactor
regression
revisit later
roadmap
scope-risk
scope-risk
server
server
shared
soup
upstream
windows
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Pasta-Devs/Marinara-Engine#2055
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @Xelvanis on GitHub (Jul 19, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/3811
Originally assigned to: @SpicyMarinara on GitHub.
Summary
The two scene-video file endpoints synchronously read each complete MP4 into a
Bufferand do not honor HTTP byte-range requests. Playback and seeking can therefore allocate and transfer an entire video per request while blocking the Node event loop during disk reads.Affected routes:
packages/server/src/routes/gallery.routes.ts—/api/gallery/scene-videos/file/:chatId/:filenamepackages/server/src/routes/game.routes.ts—/api/game/scene-videos/file/:chatId/:filenameExpected behavior
Scene-video files should be streamed. A valid request such as
Range: bytes=0-9should return206 Partial Content,Content-Range,Accept-Ranges: bytes, and only the requested bytes. Existing database ownership and path-containment checks must remain in place.Actual behavior
Both endpoints call
readFileSync(filePath)and send the resulting full buffer. Fastify therefore returns200with the complete file even when the request contains a validRangeheader.Generated-video downloads are allowed to reach
VIDEO_GEN_MAX_RESPONSE_BYTES, which defaults to 167,772,160 bytes (160 MiB). One large playback request can therefore synchronously read and allocate roughly that amount; concurrent playback or repeated seeking can multiply the pressure, especially on Termux.Steps to reproduce
/api/gallery/scene-videos/file/...or/api/game/scene-videos/file/...URL.200response withoutAccept-RangesorContent-Range, rather than a 10-byte206response.A controlled Fastify comparison reproduced the same behavior without a live video: sending a 1,024-byte buffer ignored
Range: bytes=0-9and returned all 1,024 bytes with status 200. Serving a file through the repository's installedreply.sendFile()infrastructure returned status 206 with a 10-byte body and the expected range headers.Environment
<video>sources; browser execution was not required for the HTTP reproductionLogs, screenshots, or video
Controlled response comparison:
Additional context
The endpoints were introduced together in commit
22bb11ef3as part of the scene-video generation workflow. Client consumers include native<video>elements inChatImageLightbox.tsx,ChatGallery.tsx,GameSurface.tsx, andGameSessionReplay.tsx.Smallest fix direction: retain the existing database-row authorization, filename validation, and
assertInsideDirchecks, then use a streaming path with standard range handling for both endpoints. Prefer the already-installedreply.sendFile()/sendimplementation if its decorator is guaranteed in API-only mode; otherwise centralize a small, tested streaming helper rather than hand-duplicating range parsing. Cover normal 200 streaming, 206 ranges, suffix/open-ended ranges, invalid 416 ranges, HEAD, and client disconnect cleanup.No live 160 MiB file or real-browser playback test was run.
Template check
Please uncheck (untick) the box below before submitting so we know you read the template. It is intentionally pre-checked:
@SpicyMarinara commented on GitHub (Jul 19, 2026):
Claimed by @SpicyMarinara for the assigned issue sweep on
agent/assigned-issue-sweep. I will keep the fix scoped to this issue and link the draft PR once the first proof-backed patch is pushed.@SpicyMarinara commented on GitHub (Jul 19, 2026):
Implementation will continue in draft PR #3814 after the launcher slice.
@SpicyMarinara commented on GitHub (Jul 19, 2026):
Fixed in draft PR #3814. Both authenticated scene-video routes retain their row-ownership, filename, existence, and containment checks, then stream through the existing Fastify file sender. The decorator is now available in API-only mode too. Regression coverage passes for full 200 responses, fixed/suffix/open-ended 206 ranges, invalid 416 ranges, HEAD, immutable caching, and both route implementations; server TypeScript validation also passes.
@SpicyMarinara commented on GitHub (Jul 19, 2026):
Addressed in ready-for-review PR #3814. Both protected scene-video routes retain their authorization and containment checks while streaming MP4 files with GET, HEAD, and byte-range support. Focused HTTP regressions and the full local validation gate pass.