fix(agent): normalise last_status_at to float in PooledCredential.from_dict (#25516)#25531
Closed
Bartok9 wants to merge 1 commit into
Closed
fix(agent): normalise last_status_at to float in PooledCredential.from_dict (#25516)#25531Bartok9 wants to merge 1 commit into
Bartok9 wants to merge 1 commit into
Conversation
…m_dict
Pool state files serialise last_status_at as an ISO-8601 string.
_exhausted_until() performs arithmetic directly on the field value
(entry.last_status_at + _exhausted_ttl(...)), which raises
TypeError: can only concatenate str (not "int") to str
when the entry is rehydrated from disk — crashing every outbound
request to a GPT-family provider until the pool file is deleted.
Fix: apply _parse_absolute_timestamp() to the field in from_dict() so
it is always stored as a float epoch, matching its declared type
annotation and the expectations of _exhausted_until(). The same
helper already normalises ISO-8601 and epoch-millisecond values used
elsewhere in this module.
Add two regression tests:
- ISO-8601 string round-trip no longer raises TypeError
- epoch-millisecond integer is divided correctly to epoch-seconds
Fixes NousResearch#25516
Collaborator
Contributor
Author
|
Superseded by #25528 which has a more comprehensive fix ( |
1 task
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.
Summary
Fixes #25516 — GPT pool entries crash with
TypeErroron rehydration.Root Cause
Pool state files serialise
last_status_atas an ISO-8601 string (viato_dict()/ JSON round-trip). When the entry is reloaded from disk and_exhausted_until()is called, it performswhich raises
TypeError: can only concatenate str (not "int") to str— crashing every outbound request to a GPT-family provider until the pool state file is manually deleted.Fix
Apply the existing
_parse_absolute_timestamp()helper to thelast_status_atfield insidePooledCredential.from_dict(). This helper already handles ISO-8601 strings, epoch-millisecond integers, and float-epoch values and is used for all other timestamp fields in this module. Adding it here keepslast_status_atafloatat all times, matching its declared type annotation and the expectations of_exhausted_until().Changes
agent/credential_pool.py— 5-line guard infrom_dict()after the dataclass is assembled; normaliseslast_status_atthrough_parse_absolute_timestamp()when the field is present and non-None.tests/agent/test_credential_pool.py— two regression tests:TypeError;_exhausted_until()returns a floatBefore / After
Testing
python3 -m pytest tests/agent/test_credential_pool.py::test_from_dict_normalises_iso_last_status_at tests/agent/test_credential_pool.py::test_from_dict_normalises_epoch_ms_last_status_at -v # 2 passed in 1.93s