Repository navigation
fix: propagate the API run id to the tracker - #1327
davidberenstein1957 wants to merge 3 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1327 +/- ##
==========================================
+ Coverage 91.70% 91.77% +0.07%
==========================================
Files 49 49
Lines 5157 5169 +12
==========================================
+ Hits 4729 4744 +15
+ Misses 428 425 -3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
The tracker generated its own run_id and never picked up the one the API created, so API-backed runs persisted a local uuid (or the string "None") instead of the run id the server knows about. Create the API run in start(), where the output handler is already wired, and adopt its run id when there is one. run_id stays a plain writable attribute. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
08cdabf to
0221c73
Compare
Verdict: ✅ Approve with one fix suggestedThe bug is real. With API output, Issue to fix: CSV and API ids can still differ (medium)
Nits:
|
Log the start() fallback once as a warning, and document the blocking run creation and the run_id switch. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
|
Made the changes in d53e2de: run_id now syncs to the API run once it's created late (with a test for API down at start then recovering), the start() fallback logs once as a warning, docs mention the blocking call and the run_id switch, PR description fixed, and master merged in. |
Description
EmissionsTracker.run_idused to start as a locally generated uuid and never got updated once the API created its own run id, becauseCodeCarbonAPIOutputcreates the API run lazily and nothing wrote the resulting id back onto the tracker. This PR moves the API run creation intostart()and makesrun_idswitch to the API run id as soon as it exists. If the API is down atstart(),run_idswitches as soon as a later emission creates the run, with a warning that earlier records used the local id.Related Issue
Fixes #1303
Motivation and Context
With
OutputMethod.APIenabled,tracker.run_idstayedNoneand_prepare_emissions_datarecorded the literal string"None"in every row. This broke joining CSV data with API data, brokeon_csv_write="update"(it matched on"None"and overwrote the previous run's row), and caused per-task / BOAMPS filenames to collide on..._None.csv.How Has This Been Tested?
tests/test_emissions_tracker.py::TestCarbonTracker::test_run_id_with_api_output_is_never_noneassertstracker.run_idis notNoneand that the run id written toemissions.csvmatches the API run id. It fails onmasterand passes with this change.uv run pytest tests/test_emissions_tracker.py tests/output_methods tests/test_tracking_inference.py tests/test_api_call.py -qpasses locally.Screenshots (if appropriate):
N/A
Types of changes
AI Usage Disclosure
Checklist: