fix(credits): seed cold-start usage gauge from subscription.credits_remaining - #41221
Open
entropy-0x wants to merge 1 commit into
Open
entropy-0x wants to merge 1 commit into
entropy-0x wants to merge 1 commit into
Conversation
…emaining The cold-start credits seed computed the subscription usage fraction from a mismatched pair of fields: the numerator came from `paid_service_access_info.subscription_credits_remaining` while the denominator came from `subscription.monthly_credits`. The canonical /usage gauge (`build_nous_credits_snapshot`) pairs `subscription.credits_remaining` with `subscription.monthly_credits`, and the two remaining-balance fields can hold different values. As a result the cold-start usage-band notices (50/75/90%) were derived from a different balance than the gauge and could fire at the wrong threshold or stay silent when the user was actually over a band. This aligns the seed's numerator with its denominator so the session-open band notice matches what /usage displays. ## What does this PR do? Fixes the field source used to compute the subscription used_fraction in the cold-start credits seed. `_credits_state_from_account` now reads the subscription remaining balance from `subscription.credits_remaining` — the same object that supplies the denominator `subscription.monthly_credits` — instead of the unrelated `paid_service_access_info.subscription_credits_remaining`. This makes the session-open usage-band notices consistent with the /usage gauge. ## Related Issue N/A ## Type of Change - [x] 🐛 Bug fix (non-breaking change that fixes an issue) - [ ] ✨ New feature (non-breaking change that adds functionality) - [ ] 🔒 Security fix - [ ] 📝 Documentation update - [ ] ✅ Tests (adding or improving test coverage) - [ ] ♻️ Refactor (no behavior change) - [ ] 🎯 New skill (bundled or hub) ## Changes Made - `agent/credits_tracker.py`: in `_credits_state_from_account`, read the subscription remaining balance from `subscription.credits_remaining` (paired with `subscription.monthly_credits`) for both `subscription_micros` and `subscription_usd`, instead of `paid_service_access_info.subscription_credits_remaining`. - `tests/agent/test_credits_cold_start.py`: add two regression tests that build an account where the two remaining-balance fields differ and assert the seed's `used_fraction` matches the subscription-object pairing and fires the usage band. ## How to Test 1. `python -m pytest tests/agent/test_credits_cold_start.py -q` — passes. 2. Revert the one-line field change and rerun: the two new tests fail (`used_fraction` is 0.10 instead of 0.75, and no `credits.usage` notice fires). 3. `python -m pytest tests/agent/test_credits_tracker.py tests/agent/test_credits_policy.py tests/agent/test_nous_credits_gauge.py tests/agent/test_nous_credits_snapshot.py tests/agent/test_credits_fixture_snapshot.py -q` — 166 tests pass. ## Checklist ### Code - [x] I've read the [Contributing Guide](https://github.com/NousResearch/hermes-agent/blob/main/CONTRIBUTING.md) - [x] My commit messages follow [Conventional Commits](https://www.conventionalcommits.org/) (`fix(scope):`, `feat(scope):`, etc.) - [x] I searched for [existing PRs](https://github.com/NousResearch/hermes-agent/pulls) to make sure this isn't a duplicate - [x] My PR contains **only** changes related to this fix/feature (no unrelated commits) - [x] I've run the affected suites (`tests/agent/test_credits_*`, 166 tests) and they pass - [x] I've added tests for my changes (required for bug fixes, strongly encouraged for features) - [x] I've tested on my platform: macOS 15 (Darwin 25.5) ### Documentation & Housekeeping - [x] I've updated relevant documentation (README, `docs/`, docstrings) — or N/A - [x] I've updated `cli-config.yaml.example` if I added/changed config keys — or N/A - [x] I've updated `CONTRIBUTING.md` or `AGENTS.md` if I changed architecture or workflows — or N/A - [x] I've considered cross-platform impact (Windows, macOS) per the compatibility guide — or N/A - [x] I've updated tool descriptions/schemas if I changed tool behavior — or N/A
Collaborator
|
Thanks for the focused regression fix. The premise remains valid on current main: Automated hermes-sweeper review. |
This branch has not been deployed
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.
The cold-start credits seed computed the subscription usage fraction from a
mismatched pair of fields: the numerator came from
paid_service_access_info.subscription_credits_remainingwhile thedenominator came from
subscription.monthly_credits. The canonical /usagegauge (
build_nous_credits_snapshot) pairssubscription.credits_remainingwith
subscription.monthly_credits, and the two remaining-balance fields canhold different values. As a result the cold-start usage-band notices (50/75/90%)
were derived from a different balance than the gauge and could fire at the wrong
threshold or stay silent when the user was actually over a band.
This aligns the seed's numerator with its denominator so the session-open band
notice matches what /usage displays.
What does this PR do?
Fixes the field source used to compute the subscription used_fraction in the
cold-start credits seed.
_credits_state_from_accountnow reads the subscriptionremaining balance from
subscription.credits_remaining— the same object thatsupplies the denominator
subscription.monthly_credits— instead of theunrelated
paid_service_access_info.subscription_credits_remaining. This makesthe session-open usage-band notices consistent with the /usage gauge.
Related Issue
N/A
Type of Change
Changes Made
agent/credits_tracker.py: in_credits_state_from_account, read thesubscription remaining balance from
subscription.credits_remaining(pairedwith
subscription.monthly_credits) for bothsubscription_microsandsubscription_usd, instead ofpaid_service_access_info.subscription_credits_remaining.tests/agent/test_credits_cold_start.py: add two regression tests that buildan account where the two remaining-balance fields differ and assert the seed's
used_fractionmatches the subscription-object pairing and fires the usage band.How to Test
python -m pytest tests/agent/test_credits_cold_start.py -q— passes.(
used_fractionis 0.10 instead of 0.75, and nocredits.usagenotice fires).python -m pytest tests/agent/test_credits_tracker.py tests/agent/test_credits_policy.py tests/agent/test_nous_credits_gauge.py tests/agent/test_nous_credits_snapshot.py tests/agent/test_credits_fixture_snapshot.py -q— 166 tests pass.Checklist
Code
fix(scope):,feat(scope):, etc.)tests/agent/test_credits_*, 166 tests) and they passDocumentation & Housekeeping
docs/, docstrings) — or N/Acli-config.yaml.exampleif I added/changed config keys — or N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — or N/A