Skip to content

fix: remove double usage_count increment in Session.retire()#1816

Merged
vdusek merged 1 commit intomasterfrom
fix/session-retire-double-increment
Mar 30, 2026
Merged

fix: remove double usage_count increment in Session.retire()#1816
vdusek merged 1 commit intomasterfrom
fix/session-retire-double-increment

Conversation

@vdusek
Copy link
Copy Markdown
Collaborator

@vdusek vdusek commented Mar 28, 2026

Summary

  • Session.retire() incremented _usage_count, but callers (mark_good(), mark_bad()) already increment it before calling retire(), causing a double-increment when a session is retired at the usage limit.
  • Removed the redundant _usage_count += 1 from retire().
  • Added tests covering the no-double-increment invariant for mark_good(), mark_bad(), and direct retire() calls.

Test plan

  • Existing session tests pass
  • New tests verify usage_count is incremented exactly once per mark_good()/mark_bad() call, even when retirement is triggered

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@vdusek vdusek added t-tooling Issues with this label are in the ownership of the tooling team. adhoc Ad-hoc unplanned task added during the sprint. labels Mar 28, 2026
@vdusek vdusek self-assigned this Mar 28, 2026
@vdusek vdusek added t-tooling Issues with this label are in the ownership of the tooling team. adhoc Ad-hoc unplanned task added during the sprint. labels Mar 28, 2026
@github-actions github-actions bot added this to the 137th sprint - Tooling team milestone Mar 28, 2026
@github-actions github-actions bot added the tested Temporary label used only programatically for some analytics. label Mar 28, 2026
@vdusek vdusek requested review from Mantisus and Pijukatel March 28, 2026 09:37
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 28, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.24%. Comparing base (02a18ea) to head (3d72b64).
⚠️ Report is 9 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1816   +/-   ##
=======================================
  Coverage   92.23%   92.24%           
=======================================
  Files         157      157           
  Lines       10863    10881   +18     
=======================================
+ Hits        10020    10037   +17     
- Misses        843      844    +1     
Flag Coverage Δ
unit 92.24% <ø> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 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.

Copy link
Copy Markdown
Collaborator

@Mantisus Mantisus left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Copy Markdown
Collaborator

@Pijukatel Pijukatel left a comment

Choose a reason for hiding this comment

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

What if someone retires a session explicitly by directly calling session.retire()?

While ugly, I think it would be safer to avoid the increment in the branches that call the retire. Something like:

    def mark_bad(self) -> None:
        """Mark the session as bad after an unsuccessful session usage."""
        self._error_score += 1

        # Retire the session if it is not usable anymore
        if not self.is_usable:
            self.retire()
        else:
            self._usage_count += 1

@Pijukatel
Copy link
Copy Markdown
Collaborator

What if someone retires a session explicitly by directly calling session.retire()?

While ugly, I think it would be safer to avoid the increment in the branches that call the retire. Something like:

    def mark_bad(self) -> None:
        """Mark the session as bad after an unsuccessful session usage."""
        self._error_score += 1

        # Retire the session if it is not usable anymore
        if not self.is_usable:
            self.retire()
        else:
            self._usage_count += 1

Actually, it does not matter. You can ignore this comment

@vdusek vdusek merged commit c40d411 into master Mar 30, 2026
60 of 61 checks passed
@vdusek vdusek deleted the fix/session-retire-double-increment branch March 30, 2026 08:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

adhoc Ad-hoc unplanned task added during the sprint. t-tooling Issues with this label are in the ownership of the tooling team. tested Temporary label used only programatically for some analytics.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants