Skip to content

fix: discard generated segment output that has no probeable duration#181

Open
seonghobae wants to merge 1 commit into
mainfrom
fix/output-validation
Open

fix: discard generated segment output that has no probeable duration#181
seonghobae wants to merge 1 commit into
mainfrom
fix/output-validation

Conversation

@seonghobae

Copy link
Copy Markdown
Contributor

Problem

_execute_segment_conversion validates a freshly generated segment output by probing its duration:

output_duration = _probe_output_duration(first_result, ...)

probe_media (via _parse_probe_payload) raises MediaShrinkerError when the output has no usable/zero duration or no audio stream. ffmpeg can exit 0 yet still produce a truncated/empty output (e.g. a degenerate last segment, or a -ss past the end). In that case the exception propagated straight out of the conversion:

  • The invalid generated file was left orphaned on disk — unlike the too_large / too_long / duration_mismatch cases, which all discard the file.
  • Worse, on the next run _find_valid_existing_output re-probes that leftover file, raises again, and the corrupt output poisons the source permanently (it is never cleaned up).

This matches two of the audited failure modes: a duration parse that mishandles missing/zero, and discard logic that leaves an invalid file.

Fix

Guard the probe with a MediaShrinkerError handler that discards the invalid output via the existing _discard_invalid_generated_output helper and returns a graceful duration_mismatch result (output_path=None, duration_seconds=None). Minimal, localized to the duration-validation region.

Test

Added test_convert_segment_discards_output_that_has_no_probeable_duration, which fakes an ffmpeg that writes a file the probe cannot read a duration for. It fails on the pre-fix code (raises MediaShrinkerError, file left on disk) and passes after the fix (status duration_mismatch, file removed).

Gates

  • coverage on media_shrinker.py: 100%
  • interrogate: 100%
  • Full suite: 114 tests, only the 5 pre-existing macOS os.listxattr errors (baseline) — no new failures.

🤖 Generated with Claude Code

_execute_segment_conversion probed the freshly generated output for its
duration without guarding against probe_media raising MediaShrinkerError.
ffmpeg can exit 0 yet produce a truncated/empty output whose duration is
missing or zero; _parse_probe_payload raises for such files. The exception
propagated out of the conversion, so the invalid output file was orphaned
on disk (and re-probed/re-raised on every subsequent run) instead of being
discarded like the too_large/too_long/duration_mismatch cases.

Wrap the probe in a MediaShrinkerError guard that discards the invalid
output via _discard_invalid_generated_output and returns a graceful
duration_mismatch failure with output_path=None.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CJRVbDrp1vGYkJgNHMGPpG
@seonghobae seonghobae enabled auto-merge (squash) July 6, 2026 14:26
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.

1 participant