code_puppy icon indicating copy to clipboard operation
code_puppy copied to clipboard

Summarization Fails Since Version 0.250 (`asyncio.run()` RuntimeError)

Open diegonix opened this issue 2 months ago • 0 comments

Summarization Fails Since Version 0.250 (asyncio.run() RuntimeError)

Version: code_puppy 0.252 Environment: Linux / Python 3.13 Configuration:

[puppy]
compaction_strategy = summarization

Description

Since upgrading to version 0.250, the summarization (compaction) feature consistently fails with a runtime error related to the event loop.

Even after truncating the history to reduce the message count, the summarization process still fails in the same way.


Steps to Reproduce

  1. Run /compact to trigger summarization. Example output:

    >>> /compact
    🤔 Compacting 762 messages using summarization strategy... (~296587 tokens)
    🔒 Protecting 128 recent messages (49772 tokens, limit: 50000)
    📝 Summarizing 634 older messages
    ~/.cache/uv/.../code_puppy/agents/base_agent.py:504: RuntimeWarning: coroutine '_run_agent_async' was never awaited
      return messages, []  # Return original messages on failure
    RuntimeWarning: Enable tracemalloc to get the object allocation traceback
    Summarization failed during compaction: asyncio.run() cannot be called from a running event loop
    ✨ Done! History: 762 → 762 messages via summarization
    🏦 Tokens: 296,587 → 296,587 (0.0% reduction)
    
  2. Truncate message history to reduce size:

    >>> /truncate 700
    Truncated message history from 729 to 700 messages (keeping system message and 699 most recent)
    
  3. Try /compact again — failure persists:

    >>> /compact
    🤔 Compacting 700 messages using summarization strategy... (~263787 tokens)
    🔒 Protecting 106 recent messages (49883 tokens, limit: 50000)
    📝 Summarizing 594 older messages
    Summarization failed during compaction: asyncio.run() cannot be called from a running event loop
    ~/.cache/uv/.../base_agent.py:504: RuntimeWarning: coroutine '_run_agent_async' was never awaited
      return messages, []  # Return original messages on failure
    ✨ Done! History: 700 → 700 messages via summarization
    🏦 Tokens: 263,787 → 263,787 (0.0% reduction)
    

Analysis

The issue appears to be caused by a nested call to asyncio.run() inside an already running event loop (likely from within the async agent runtime). This causes Python to raise RuntimeError: asyncio.run() cannot be called from a running event loop.

In previous versions, summarization likely used the same event loop context or safely awaited the coroutine. The change in 0.250 may have introduced a direct asyncio.run() call from a non-top-level async context.

diegonix avatar Nov 05 '25 20:11 diegonix