fix: propagate the API run id to the tracker - #1327
Open
davidberenstein1957 wants to merge 3 commits into
Open
Conversation
When OutputMethod.API was enabled, the tracker read run_id from the API output handler before the run existed (it is created lazily), so run_id stayed None and every record was written with the string "None". Make run_id a property backed by a locally generated uuid that prefers the API run id, and create the API run in start() so all outputs of a run share the same id. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1327 +/- ##
==========================================
+ Coverage 91.39% 91.51% +0.12%
==========================================
Files 49 49
Lines 5056 5069 +13
==========================================
+ Hits 4621 4639 +18
+ Misses 435 430 -5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
davidberenstein1957
marked this pull request as ready for review
August 12, 2026 19:14
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
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.
What
EmissionsTracker.run_idis now a property backed by a locally generated uuid that returns the API run id as soon as one exists, and the API run is created instart()rather than on the first emission.Why
With
OutputMethod.APIenabled, the tracker readrun_idfromCodeCarbonAPIOutputat construction time, but that handler builds itsApiClientwithcreate_run_automatically=Falseand only creates the run lazily in_ensure_api_run. Nothing ever wrote the resulting id back, sotracker.run_idstayedNoneand_prepare_emissions_datarecorded the literal string"None"in every row.Consequences for users: CSV data could not be joined with the API data,
on_csv_write="update"matched on"None"and overwrote the previous run's row, and per-task / BOAMPS filenames all collided on..._None.csv.Creating the run in
start()(instead of only fixing the property) makes sure a single run has a single id everywhere, including rows persisted before the first API call. Failures there are logged and fall back to the local uuid, so an unreachable API no longer prevents tracking.Verified
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.Closes #1303
🤖 Generated with Claude Code