Skip to content

Skip cached dicts when aggregating mixed metadata on resume - #119

Open
renziver wants to merge 1 commit into
ArtificialAnalysis:mainfrom
renziver:fix/resume-metadata-aggregation
Open

renziver wants to merge 1 commit into
ArtificialAnalysis:mainfrom
renziver:fix/resume-metadata-aggregation

Conversation

@renziver

Copy link
Copy Markdown

Fixes #92.

Summary

After session(resume=True), the cached turns of run_metadata_by_turn come 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_list hit dict + ToolUseCountMetadata, which raised TypeError after 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 in tests/test_aggregate_metadata.py for both orders, a mixed list, and the dict-only case. Before the fix, three of the four fail.
  • CHANGELOG.md: an Unreleased / Fixed entry.

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:

  • rebuild the metadata models when the cache is loaded, which keeps every count but needs to know which class each dict came from
  • leave run_metadata_by_turn out of the cached state, which changes what the cache stores

Happy to switch to either if you prefer one.

Validation

  • uv run pytest tests/test_aggregate_metadata.py tests/test_agent.py tests/test_logging.py passes (67 passed, 1 skipped). I did not run the whole suite.
  • ruff format --check, ruff check and ty check pass on the changed files.
  • Not tested through a real resumed session, only through aggregate_metadata directly.

🤖 Generated with Claude Code

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

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant