borg icon indicating copy to clipboard operation
borg copied to clipboard

Add phase field to file_status JSON output (start/end lifecycle events)

Open YK-03 opened this issue 8 months ago • 4 comments

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_any before dispatching to fso.process_*
  • START emission is guarded with retry == 0 to 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 path output

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

YK-03 avatar Mar 22 '26 14:03 YK-03

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.

codecov[bot] avatar Mar 22 '26 17:03 codecov[bot]

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.

YK-03 avatar Mar 22 '26 17:03 YK-03

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_file and process_pipe, wrapping the chunk processing logic.
  • This ensures correct coverage for --read-special and other chunk-based paths.
  • Lifecycle events are not emitted for trivial or cached files (e.g., when chunks are reused).
  • _process_any is 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.

YK-03 avatar Mar 24 '26 06:03 YK-03

@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.

YK-03 avatar Mar 28 '26 15:03 YK-03