Skip to content

fix: make tracker.stop() idempotent - #1408

Merged
SaboniAmine merged 1 commit into
mlco2:masterfrom
sohammishra864-wq:fix/stop-idempotent-1307
Sep 7, 2026
Merged

fix: make tracker.stop() idempotent#1408
SaboniAmine merged 1 commit into
mlco2:masterfrom
sohammishra864-wq:fix/stop-idempotent-1307

Conversation

@sohammishra864-wq

Copy link
Copy Markdown
Contributor

Body:

Description

Make tracker.stop() idempotent so calling it multiple times does not produce duplicate emissions rows or trigger duplicate handler cleanup.

Related Issue

Closes #1307

Motivation and Context

When using the tracker as a context manager and also calling stop() explicitly to capture the return value, __exit__ calls stop() a second time. The second call ran the full measurement-persist-exit cycle again, writing a duplicate CSV row and double-calling every output handler's `exit()

The root cause: _start_time was never cleared after stopping, so the existing guard never triggered. Additionally, the lock release ran before the guard, causing a redundant
release on re-entry.

How Has This Been Tested?

  • Verified calling stop() twice returns the same emissions value without writing a
    duplicate row
  • Verified with block + explicit stop() produces a single CSV row

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or ting 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 read the **docs/hent.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@sohammishra864-wq
sohammishra864-wq requested a review from a team as a code owner September 6, 2026 21:20
@github-actions github-actions Bot added the size/S label Sep 6, 2026

@SaboniAmine SaboniAmine left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution!

@codecov

codecov Bot commented Sep 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.64%. Comparing base (3fcd4dc) to head (186dc4e).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1408      +/-   ##
==========================================
- Coverage   91.68%   91.64%   -0.04%     
==========================================
  Files          49       49              
  Lines        5136     5137       +1     
==========================================
- Hits         4709     4708       -1     
- Misses        427      429       +2     

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

@SaboniAmine
SaboniAmine merged commit 8171d13 into mlco2:master Sep 7, 2026
13 of 14 checks passed
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.

tracker.stop() is not idempotent: a second call writes a duplicate emissions row

2 participants