Skip to content

fix(core): stop dropping the first chunk of ffmpeg output in read_lines - #90

Merged
andykais merged 2 commits into
mainfrom
cursor/fix-file-processor-readlines-first-chunk-4aab
Oct 13, 2026
Merged

andykais merged 2 commits into
mainfrom
cursor/fix-file-processor-readlines-first-chunk-4aab

Conversation

@andykais-ai

@andykais-ai andykais-ai commented Sep 1, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • fixes FileProcessor::#readlines dropping the first chunk of ffmpeg stderr: the pre-loop reader.read() result was overwritten by the next read() before its value was ever appended to the buffer
  • fixes the related edge case where stderr that arrives in a single chunk yielded no lines at all (the loop body ran once with the done result, so the buffer stayed empty)
  • makes the generator a public static FileProcessor.read_lines method so it stays encapsulated in the class but can be unit tested directly
  • adds packages/core/test/file_processor.test.ts covering first-chunk lines, single-chunk streams, lines split across chunk boundaries, a trailing line with no newline, and an empty stream

The dropped output matters because this generator feeds thumbnail timestamp parsing (Parsed_showinfo ... pts_time:) and the Nothing was written into output file error detection, so lost lines can turn into wrong thumbnail counts or a generic subprocess error instead of a useful message.

Vision Testing

  • new unit tests pass on the fix, and 4 of the 5 steps fail when the old loop is restored (single-chunk stream returns [], first chunk lines missing)
  • replaying one identical recorded ffmpeg stderr chunk sequence through both readers: buggy reader reads 48 lines starting at Input #0, ..., fixed reader reads all 60 lines starting at ffmpeg version 6.1.1-... — exactly the 12 lines of the first 1894-byte chunk were being discarded
  • rebased on latest main; deno test -P=test --check --trace-leaks test in packages/core: 29 passed (101 steps) / 4 failed (5 steps), the same 4 failures as unmodified main (28 passed / same 4 failed), all pre-existing ffmpeg-version float precision mismatches documented in AGENTS.md
  • deno lint in packages/core is clean
Open in Web Open in Cursor 

@andykais
andykais marked this pull request as ready for review October 13, 2026 15:32
Comment thread packages/core/src/lib/file_processor.ts Outdated
if (lines.length > 0) {
buffer = lines.at(-1)!
}
async function * read_lines(stream: ReadableStream<Uint8Array>) {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see you exported a function to make this testable. I am fine with a unit test, but I still want class encapsulation. Move this to a static FileProcessor method

cursoragent and others added 2 commits October 13, 2026 15:59
…g lines

#readlines read one chunk before the loop and then immediately overwrote it
with the next read, so every line in ffmpeg's first stderr chunk was silently
discarded (and stderr that arrived in a single chunk produced no lines at all).

Moves the generator to a module-level read_lines function so it can be unit
tested directly.

Co-authored-by: kaisea.rpi <kaisea.rpi@gmail.com>
Co-authored-by: kaisea.rpi <kaisea.rpi@gmail.com>
@cursor
cursor Bot force-pushed the cursor/fix-file-processor-readlines-first-chunk-4aab branch from 0da52db to 6fbf2c8 Compare October 13, 2026 16:01
@andykais
andykais merged commit 7405b72 into main Oct 13, 2026
8 checks passed
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.

3 participants