fix(nous): ignore non-finite rate limit resets - #51951
Conversation
tonydwb
left a comment
There was a problem hiding this comment.
Hermes Agent Review
Verdict: Approved — Clean, well-scoped change with appropriate tests.
Reviewed as part of batch review session 2026-06-24d.
Reviewed by Hermes Agent
teknium1
left a comment
There was a problem hiding this comment.
Thanks for addressing the malformed-header cooldown path; the current-main premise is real (agent/nous_rate_guard.py:62-64 accepts positive infinity, which reaches persistence at lines 111-114).
Problems
agent/nous_rate_guard.py:160converts persistedreset_atwithfloat(...), but the enclosing handler does not catchValueError. Valid JSON containing a nonnumeric string will now escape instead of failing closed. Please catch it and clean up/ignore that invalid state; add a regression test.- The same header class remains in
agent/rate_limit_tracker.py:78-89:_safe_int("inf")raisesOverflowError, while_safe_float("inf")can feed_fmt_seconds()at line 148. Please reject non-finite values there too and add parser/display coverage.
Suggested changes
- Extend the guard-state test matrix with a nonnumeric persisted
reset_at. - Add non-finite rate-limit-tracker tests for both integer and reset fields.
Automated hermes-sweeper review.
| with open(path, encoding="utf-8") as f: | ||
| state = json.load(f) | ||
| reset_at = state.get("reset_at", 0) | ||
| reset_at = float(state.get("reset_at", 0) or 0) |
There was a problem hiding this comment.
float() raises ValueError for a valid JSON value such as "reset_at": "bad", but this function's except clause still excludes ValueError. Please fail closed here (and remove or ignore the invalid state) so a corrupted-but-parseable state file cannot escape this guard.
GottZ
left a comment
There was a problem hiding this comment.
This was generated by AI during triage.
Summary
Two PRs touch the Nous rate-limit guard but address distinct failure classes: #18782 makes text I/O explicitly UTF-8 across several modules, while #51951 rejects non-finite rate-limit values that could create an infinite cooldown or formatting failures.
Related pull requests
- #18782 [closed]
related— (+197/-12) — merged via #71078: This broader encoding fix adds explicit UTF-8 reads and writes across Copilot, model metadata, the Nous rate guard, cron, and delivery paths; it remains relevant because its commits were cherry-picked into the class-wide encoding cleanup with authorship preserved. - #51951
related— (+118/-9) — keep open pending fixes: The diff correctly rejects non-finite reset and bucket values, removes persisted infinite cooldowns, and guards duration formatting. The contributor keep_open review identifies two remaining gaps: a nonnumeric persisted reset_at can still raise ValueError, and the equivalent non-finite parsing/display paths in agent/rate_limit_tracker.py are not covered.
Suggested consolidation
Merge #51951 after addressing the contributor keep_open review with invalid-string persisted-state cleanup and corresponding rate_limit_tracker.py guards and tests; #18782 is not a duplicate and needs no reopening because its relevant changes were merged through #71078.
Cross-PR triage: Reviewed 2 pull requests and 0 issues in this complex. Each diff was read against this issue; Assessment working set: 23 kB of PR diffs, 5 kB of issue/PR text, 4 kB of discussion (5 comments), 0 verify verdicts. verdicts reflect diff content, not PR titles. Part of an automated triage batch.
Summary
Infinitybreaker state and clean up non-finite state files when readWhy
Malformed or non-finite rate-limit headers such as
retry-after: infcould be recorded as an infinite cross-session cooldown. The storedInfinitystate then madenous_rate_limit_remaining()returninf, andformat_remaining()or bucket parsing could raiseOverflowErrorinstead of falling back safely.Tests
python -m pytest tests/agent/test_nous_rate_guard.py -qpython -m pytest tests/agent/test_nous_rate_guard.py tests/agent/test_rate_limit_tracker.py tests/run_agent/test_nous_429_fallback_reentry.py -qpython -m py_compile agent/nous_rate_guard.pypython scripts/check-windows-footguns.py --all