Fix multi-segment recording data loss during recovery #1514
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.
Summary
Fixes #1509 - Multi-segment recordings (from pause/resume) lose middle segments during recovery/remux.
Root Cause: The recovery process sorted segment directories alphabetically, causing
segment-10to come beforesegment-2. Combined with index assignment from enumeration, this caused wrong segments to be processed/deleted.Changes:
create_project_configTest Plan
display.mp4andcamera.mp4after recording stopsBefore fix: Only segments 0, 1, 10, 11 preserved; segments 2-9 lost
After fix: All segments 0-9 preserved correctly
🤖 Generated with Claude Code
Greptile Summary
Fixed multi-segment recording data loss during recovery caused by alphabetical sorting treating
segment-10as coming beforesegment-2. The recovery process now uses natural numeric sorting to order segment directories correctly, and parses the segment index directly from folder names (segment-N) instead of relying on enumeration position. Additionally,create_project_confignow uses the actual segment path from metadata instead of reconstructing it from the loop index.Key changes:
create_project_config(line 913)Confidence Score: 5/5
u32::MAX), and the segment index parsing is straightforward with proper fallback to 0.Important Files Changed
Sequence Diagram
sequenceDiagram participant FS as File System participant RM as RecoveryManager participant Sort as Sorting Logic participant Proc as Processing Loop Note over RM: analyze_incomplete() RM->>FS: read_dir(segments_dir) FS-->>RM: [segment-0, segment-1, ..., segment-10, segment-2] RM->>Sort: sort_by_key(natural numeric) Note over Sort: Parse "segment-N" → u32<br/>segment-10 → 10<br/>segment-2 → 2 Sort-->>RM: [segment-0, segment-1, segment-2, ..., segment-10] loop For each segment_entry RM->>Proc: Parse index from folder name Note over Proc: "segment-2" → index=2<br/>(not enumerate index!) Proc->>RM: RecoverableSegment{index: 2, ...} end Note over RM: build_recovered_meta() RM->>RM: Use seg.index for segment_base path Note over RM: segment_base = "content/segments/segment-{seg.index}" Note over RM: create_project_config() RM->>RM: Use segment.display.path from metadata Note over RM: No longer reconstruct from loop index