You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
save_replay copies up to an hour of segments synchronously and writes the footage 3x #293
copyShared uses Buffer.alloc + readSync + writeFileSync per segment on the server's event loop (up to ~1800 two-second segments), then the data is rewritten by the joined.mp4 concat and again by the cut.
The code comment says "copying takes milliseconds", which only holds for short buffers.
Impact
Saving a long buffer (e.g. 3600 s at ~5 Mbps, ~2.2 GB) blocks the MCP event loop for seconds: tool calls, progress notifications and recorder child handlers stall; disk writes are ~3x the clip size.
Steps to reproduce
start_recording { replayBufferSec: 3600 }, let it fill
save_replay { lastSec: 3600 } and observe the server stop responding during the snapshot
Suggested fix
Copy with async streams (createReadStream/pipeline, still opened for shared read). Drop the joined.mp4 intermediate by cutting straight from the concat list (inpoint/outpoint in the list or -ss on the concat demuxer).
Acceptance criteria
No synchronous bulk IO on the event loop in save_replay
One fewer full rewrite of the footage
Getting started
Relevant files: src/utils/replay.ts
How to run tests: npm run build && npm test (also npm run typecheck and npm run lint)
Partly fixed in a6cfc9b: the snapshot copy (copyShared) now streams each segment asynchronously (a shared read up to its current size, abortable), so save_replay no longer does synchronous bulk IO on the event loop. Verified with a new copy test and the replay integration and tool-layer tests (75 passed).
Still open: dropping the joined.mp4 intermediate. The cut seeks in that mp4 because MPEG-TS seeking is not exact, so cutting straight from the concat list (inpoint, or -ss on the concat demuxer) needs a frame-accuracy check against the current output before it replaces the join.
Closing. The impact (synchronous bulk IO blocking the server for seconds) was fixed in a6cfc9b, where segments are streamed asynchronously. I tested the remaining idea, dropping the joined.mp4 intermediate, against the current output on real 2 s MPEG-TS segments (keyframe each second), comparing durations and decoded frames at several points:
inpoint on the first segment: wrong for a mid-segment start (about 0.37 s of video lost, frames offset).
-ss on the concat demuxer: identical for 5.5 s and 7.3 s cuts, but a 9.9 s cut lost about 0.7 s of video. The total also has to come from summed segment durations (ffprobe reports N/A for a concat list), which is off by a few ms and shifts short cuts.
The join-then-cut path is what makes the cut exact, so it stays on purpose. The cost is one extra write of at most the requested window.
Activity
TMHSDigital commentedon Nov 10, 2026
Partly fixed in a6cfc9b: the snapshot copy (
copyShared) now streams each segment asynchronously (a shared read up to its current size, abortable), so save_replay no longer does synchronous bulk IO on the event loop. Verified with a new copy test and the replay integration and tool-layer tests (75 passed).Still open: dropping the
joined.mp4intermediate. The cut seeks in that mp4 because MPEG-TS seeking is not exact, so cutting straight from the concat list (inpoint, or -ss on the concat demuxer) needs a frame-accuracy check against the current output before it replaces the join.perf(save_replay): stream the snapshot copy off the event loop (#293)
docs(changelog): list the save_replay streaming change under 0.49.0
TMHSDigital commentedon Nov 16, 2026
Closing. The impact (synchronous bulk IO blocking the server for seconds) was fixed in a6cfc9b, where segments are streamed asynchronously. I tested the remaining idea, dropping the joined.mp4 intermediate, against the current output on real 2 s MPEG-TS segments (keyframe each second), comparing durations and decoded frames at several points:
The join-then-cut path is what makes the cut exact, so it stays on purpose. The cost is one extra write of at most the requested window.