Repository navigation
Conversation
A resumed session reloads cached turn metadata as JSON dicts, then appends live metadata models, so _aggregate_list raised TypeError at the end of the run. Keep the live models and drop the cached dicts. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
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.
Fixes #92.
Summary
After
session(resume=True), the cached turns ofrun_metadata_by_turncome back from JSON as plain dicts, and the new run appends live metadata models for the same tool names. At the end of the run_aggregate_listhitdict + ToolUseCountMetadata, which raisedTypeErrorafter the agent had already finished.Changes
_aggregate_list: when a dict meets a live model, keep the model and skip the dict, whichever comes first. Dict with dict still merges, and model with model still uses__add__.tests/test_aggregate_metadata.pyfor both orders, a mixed list, and the dict-only case. Before the fix, three of the four fail.CHANGELOG.md: anUnreleased/Fixedentry.This fix is opinionated
It stops the crash, but it loses information: counts from before the resume are not included in the totals, because a cached dict cannot be turned back into the right model class here. I chose it as the smallest change that touches no cache format. I have not checked whether anything besides the logger reads these totals.
If you would rather keep the old counts, the alternatives I considered are:
run_metadata_by_turnout of the cached state, which changes what the cache storesHappy to switch to either if you prefer one.
Validation
uv run pytest tests/test_aggregate_metadata.py tests/test_agent.py tests/test_logging.pypasses (67 passed, 1 skipped). I did not run the whole suite.ruff format --check,ruff checkandty checkpass on the changed files.aggregate_metadatadirectly.🤖 Generated with Claude Code