-
Notifications
You must be signed in to change notification settings - Fork 116
core: services: recoder_extractor: Add mcap recover #3667
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
joaomariolago
merged 1 commit into
bluerobotics:master
from
patrickelectric:add-mcap-recover
Dec 9, 2025
Merged
core: services: recoder_extractor: Add mcap recover #3667
joaomariolago
merged 1 commit into
bluerobotics:master
from
patrickelectric:add-mcap-recover
Dec 9, 2025
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Reviewer's GuideAdds an async MCAP integrity check-and-repair step using the external Sequence diagram for MCAP check and recover before video extractionsequenceDiagram
participant Extractor as extract_mcap_recordings
participant Checker as check_and_recover_mcap
participant OS as asyncio_subprocess
participant McapBinary as mcap_CLI
Extractor->>Checker: check_and_recover_mcap(mcap_path)
Checker->>Checker: shutil.which(mcap)
alt mcap binary missing
Checker-->>Extractor: return
else mcap binary available
Checker->>Checker: validate mcap_path exists
alt mcap_path missing
Checker-->>Extractor: return
else mcap_path exists
Checker->>OS: create_subprocess_exec(mcap doctor mcap_path)
OS-->>Checker: returncode, stdout, stderr
alt doctor success
Checker-->>Extractor: return
else doctor failure
Checker->>OS: create_subprocess_exec(mcap recover mcap_path -o mcap_path)
OS-->>Checker: recover_returncode, recover_stdout, recover_stderr
alt recover success
Checker-->>Extractor: return
else recover failure
Checker-->>Extractor: return
end
end
end
end
Extractor->>OS: create_subprocess_exec(mcap-foxglove-video-extract mcap_path)
OS-->>Extractor: extraction result
Class diagram for updated recorder_extractor main moduleclassDiagram
class RecorderExtractorMainModule {
+async build_thumbnail_bytes(path: Path) bytes
+async extract_mcap_recordings() None
+async check_and_recover_mcap(mcap_path: Path) None
}
class AsyncioSubprocess {
+create_subprocess_exec(*cmd) Process
}
class Process {
+async communicate() tuple
+returncode int
}
RecorderExtractorMainModule --> AsyncioSubprocess : uses
AsyncioSubprocess --> Process : creates
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey there - I've reviewed your changes and found some issues that need to be addressed.
- When running
mcap recover, consider writing to a temporary file and then atomically moving it over the original path to avoid corrupting the only copy if the recover process produces a bad or partial file. - You can simplify the subprocess handling by using
text=True(orencoding="utf-8",errors="ignore") increate_subprocess_execinstead of manually decodingstdout/stderrbytes in both the doctor and recover calls. - The
check_and_recover_mcapfunction currently logs full stdout/stderr for both doctor and recover; consider truncating or summarizing very large outputs to keep logs readable and to avoid log bloat on large or noisy files.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- When running `mcap recover`, consider writing to a temporary file and then atomically moving it over the original path to avoid corrupting the only copy if the recover process produces a bad or partial file.
- You can simplify the subprocess handling by using `text=True` (or `encoding="utf-8"`, `errors="ignore"`) in `create_subprocess_exec` instead of manually decoding `stdout`/`stderr` bytes in both the doctor and recover calls.
- The `check_and_recover_mcap` function currently logs full stdout/stderr for both doctor and recover; consider truncating or summarizing very large outputs to keep logs readable and to avoid log bloat on large or noisy files.
## Individual Comments
### Comment 1
<location> `core/services/recorder_extractor/main.py:111-120` </location>
<code_context>
+ and if it fails, run mcap recover to fix the file.
+ """
+ # Check if mcap binary exists
+ mcap_binary = shutil.which("mcap")
+ if not mcap_binary:
+ logger.warning("mcap binary not found, skipping doctor/recover check")
+ return
+
+ # Ensure path is absolute and exists
+ if not mcap_path.exists():
+ logger.warning(f"MCAP file not found: {mcap_path}")
+ return
+
+ logger.info(f"Running mcap doctor on {mcap_path}")
+ # Run mcap doctor
+ doctor_cmd = ["mcap", "doctor", str(mcap_path)]
+ doctor_proc = await asyncio.create_subprocess_exec(
+ *doctor_cmd,
</code_context>
<issue_to_address>
**suggestion (bug_risk):** Use the resolved `mcap_binary` path for commands instead of hardcoding "mcap".
You already resolve the `mcap` binary with `shutil.which`, but `doctor_cmd` and `recover_cmd` still call the hardcoded `"mcap"`. Please use `mcap_binary` instead (e.g. `doctor_cmd = [mcap_binary, "doctor", str(mcap_path)]`) so the invoked binary always matches what was found on PATH.
Suggested implementation:
```python
logger.info(f"Running mcap doctor on {mcap_path}")
# Run mcap doctor
doctor_cmd = [mcap_binary, "doctor", str(mcap_path)]
```
Search in `check_and_recover_mcap` for where `recover_cmd` is defined (likely later in the function) and update it similarly:
- Change `recover_cmd = ["mcap", "recover", ...]` to `recover_cmd = [mcap_binary, "recover", ...]`.
This ensures both doctor and recover invocations use the same resolved `mcap_binary` path from `shutil.which("mcap")`.
</issue_to_address>
### Comment 2
<location> `core/services/recorder_extractor/main.py:141` </location>
<code_context>
+ logger.error(f"mcap doctor failed for {mcap_path} (code={doctor_proc.returncode}): {stderr}")
+ logger.info(f"Running mcap recover to fix {mcap_path}")
+ # Run mcap recover to replace the file
+ recover_cmd = ["mcap", "recover", str(mcap_path), "-o", str(mcap_path)]
+ recover_proc = await asyncio.create_subprocess_exec(
+ *recover_cmd,
</code_context>
<issue_to_address>
**issue (bug_risk):** Writing recover output directly over the input file risks data loss on partial failures.
Because input and `-o` output paths are identical, a partial write or mid-run failure from `mcap recover` could corrupt the file with no untouched copy left. Consider writing to a temp file in the same directory and only replacing the original on success (e.g., via `Path.replace`) so the original remains intact if recovery fails.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
934ea4e to
31ff8d8
Compare
Signed-off-by: Patrick José Pereira <patrickelectric@gmail.com>
31ff8d8 to
0fde2db
Compare
joaomariolago
approved these changes
Dec 9, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 by Sourcery
Add an automatic integrity check and recovery step for MCAP recordings before thumbnail extraction.
Enhancements:
mcap doctoron MCAP files and invokemcap recoverwhen corruption is detected.mcapCLI or target file is unavailable.