fix: remove double usage_count increment in Session.retire()#1816
fix: remove double usage_count increment in Session.retire()#1816
Conversation
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Pijukatel
left a comment
There was a problem hiding this comment.
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 |
Summary
Session.retire()incremented_usage_count, but callers (mark_good(),mark_bad()) already increment it before callingretire(), causing a double-increment when a session is retired at the usage limit._usage_count += 1fromretire().mark_good(),mark_bad(), and directretire()calls.Test plan
usage_countis incremented exactly once permark_good()/mark_bad()call, even when retirement is triggered🤖 Generated with Claude Code