Add phase field to file_status JSON output (start/end lifecycle events)
Description
This PR adds an optional "phase" field to "type": "file_status" JSON output to indicate lifecycle stages of file processing.
"phase": "start"is emitted when processing of a file begins"phase": "end"is emitted for final file status events (default if not explicitly provided)
Implementation details
- JSON construction remains centralized in
Archiver.print_file_status - START events are emitted in
CreateMixIn._process_anybefore dispatching tofso.process_* - START emission is guarded with
retry == 0to avoid duplicate events - START is only emitted for valid, processable file types (no sockets, doors, ports, or unknown types)
- END events reuse existing call sites, with
"phase"defaulting to"end"
Behavior
JSON mode (--log-json --list)
- Emits paired start/end events for each processed file
- No duplicate or orphan events
Non-JSON mode (--list)
- Behavior unchanged
- Logging guarded to avoid
None pathoutput
Compatibility
- Fully backward compatible
- Existing fields (
type,status,path) unchanged "phase"is additive and optional
Checklist
- [x] PR is against
master - [ ] New code has tests and docs where appropriate (not included in this PR)
- [ ] Tests pass (not executed locally)
- [x] Commit messages are clean and focused
Codecov Report
:x: Patch coverage is 47.50000% with 21 lines in your changes missing coverage. Please review.
:white_check_mark: Project coverage is 83.33%. Comparing base (2ac51d7) to head (a9c76f7).
:warning: Report is 2 commits behind head on master.
:white_check_mark: All tests successful. No failed tests found.
| Files with missing lines | Patch % | Lines |
|---|---|---|
| src/borg/archiver/create_cmd.py | 42.85% | 9 Missing and 7 partials :warning: |
| src/borg/archiver/__init__.py | 58.33% | 2 Missing and 3 partials :warning: |
Additional details and impacted files
@@ Coverage Diff @@
## master #9532 +/- ##
==========================================
- Coverage 83.36% 83.33% -0.04%
==========================================
Files 87 87
Lines 15447 15496 +49
Branches 2311 2332 +21
==========================================
+ Hits 12878 12913 +35
- Misses 1818 1823 +5
- Partials 751 760 +9
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
I’ll update the implementation to ensure start and end events are emitted consistently for all files, including --read-special, by wrapping the entire processing lifecycle (including chunk-based processing).
I’ll also add tests to cover these scenarios and ensure consistent behavior.
Hi @ThomasWaldmann,
I've updated the implementation to ensure lifecycle events are emitted only around actual file processing.
- Lifecycle emission is now placed in
process_fileandprocess_pipe, wrapping the chunk processing logic. - This ensures correct coverage for
--read-specialand other chunk-based paths. - Lifecycle events are not emitted for trivial or cached files (e.g., when chunks are reused).
_process_anyis no longer involved in lifecycle emission.
Start/end pairing is guaranteed via try/finally, and existing status event behavior remains unchanged.
Please let me know if anything else needs adjustment.
@ThomasWaldmann, I'm working on addressing your review feedback. I'm also planning to submit a GSoC 2026 proposal building on this PR, extending consistent structured JSON output to borg check and borg extract as well. I've drafted a proposal and would appreciate a quick look before I submit if you have time. Happy to share a Google Doc.