Skip to content

fix(cli): report actual emissions file path - #1331

Open
davidberenstein1957 wants to merge 3 commits into
masterfrom
fix/cli-output-path-report
Open

davidberenstein1957 wants to merge 3 commits into
masterfrom
fix/cli-output-path-report

Conversation

@davidberenstein1957

@davidberenstein1957 davidberenstein1957 commented Aug 12, 2026 •

Copy link
Copy Markdown
Collaborator

Description

codecarbon/cli/monitor.py now asks the tracker's output handlers for their save_file_path instead of reconstructing the path from config keys. This keeps the CLI correct if the path logic changes, prints nothing when CSV output is disabled (previously a confidently wrong path), and handles multiple file handlers.

Related Issue

Fixes #1322

Motivation and Context

The codecarbon monitor post-run report resolved the emissions file path from tracker._conf["output_file"], which is only the basename. os.path.abspath then resolved it against the current working directory, so any output_dir other than the default "." produced a path where the file does not actually exist. The CLI defaults to log_level="error", which suppresses the correct INFO line FileOutput logs, so the wrong path was the only one the user saw. This is a display-only change; no measurement or file-writing behavior is affected.

How Has This Been Tested?

Three new tests in tests/cli/test_monitor.py: test_run_and_monitor_reports_output_dir, test_run_and_monitor_reports_relative_path_from_cwd, and test_run_and_monitor_reports_no_path_without_file_output. The first and third fail on master and pass with this change. uv run pytest tests/cli/test_monitor.py -q → 10 passed.

Screenshots (if appropriate):

N/A

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

AI Usage Disclosure

  • 🟥 AI-vibecoded
  • 🟠 AI-generated
  • ⭐ AI-assisted
  • ♻️ No AI used

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the docs/how-to/contributing.md document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Also includes a related fix reporting the BoAmps output path in the CLI summary, with a relative-path test in tests/test_boamps_output.py.

@codecov

codecov Bot commented Aug 12, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.70%. Comparing base (e5e46ab) to head (869852b).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1331   +/-   ##
=======================================
  Coverage   91.70%   91.70%           
=======================================
  Files          49       49           
  Lines        5157     5158    +1     
=======================================
+ Hits         4729     4730    +1     
  Misses        428      428           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@davidberenstein1957
davidberenstein1957 marked this pull request as ready for review August 12, 2026 19:14
@davidberenstein1957
davidberenstein1957 requested a review from a team as a code owner August 12, 2026 19:14
@davidberenstein1957
davidberenstein1957 force-pushed the fix/cli-output-path-report branch from 5dc9467 to 4bf4bcb Compare August 19, 2026 14:26
The monitor report resolved the output path from `output_file` alone, which is
only the basename, so `os.path.abspath` resolved it against the CWD and
ignored `output_dir`. Users were told the file was somewhere it was not.

Ask the output handlers for their `save_file_path` instead, which also prints
nothing when CSV output is disabled. Keeps the `typing_extensions.Annotated`
import the CLI needs on older Pythons.

Closes #1322

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@davidberenstein1957
davidberenstein1957 force-pushed the fix/cli-output-path-report branch from ba5bab5 to cbf6e59 Compare August 20, 2026 06:14
@benoit-cty

Copy link
Copy Markdown
Contributor

🤖 This review comment was written and posted by Claude Opus 5.5 (AI assistant), at the request of @benoit-cty. Findings were checked by reading the code and running tests locally (merged with current master where relevant), but please double-check before acting on them.

Verdict: ✅ Approve with nits

The bug is real. The CLI report used abspath(_conf["output_file"]), which ignores output_dir. The new tests fail on master. Reading save_file_path from each output handler, and printing no path when CSV output is off, is the right fix.

Nits:

  1. BoAmps output also writes files but has no save_file_path, so its files are not reported. Consider giving it a save_file_path, or reporting every handler that has one.
  2. The description lists test_run_and_monitor_reports_relative_path_from_cwd, which is not in the diff. Please update the description, or add the test.
  3. The branch is behind master; please update it.

davidberenstein1957 and others added 2 commits September 23, 2026 16:44
BoAmpsOutput now exposes save_file_path once a report is written, so the
monitor summary lists it. Add the relative-path test the PR description
mentions.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@davidberenstein1957

Copy link
Copy Markdown
Collaborator Author

Made the changes in 869852b: merged master, BoAmps reports now listed, added the relative-path test.

BoAmpsOutput sets save_file_path after writing its report, so the CLI summary picks it up with no special case.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

codecarbon monitor prints a "Saved to" path that ignores output_dir

2 participants