Skip to content

Compaction Metadata Causes AttributeError in v1.21+ #4082

Closed

Description

@nicwang119

Describe the issue
When using App(..., events_compaction_config=...) with ADK v1.21.0+, the session crashes after compaction is triggered (e.g., on the 4th message if compaction_interval=3).
The error is caused by event.actions.compaction being inserted as a raw dict, while downstream ADK code expects a structured object with attributes like .start_timestamp.

This leads to:

AttributeError: 'dict' object has no attribute 'start_timestamp'

To Reproduce

  1. Install google-adk==1.21.0 or later
  2. Run the following code:
from google.adk.agents import LlmAgent
from google.adk.models.google_llm import Gemini
from google.adk.app import App
from google.adk.runners import Runner
from google.adk.sessions import DatabaseSessionService
from google.adk.config import EventsCompactionConfig

chatbot_agent = LlmAgent(
    model=Gemini(model="gemini-2.5-flash-lite"),
    name="text_chat_bot",
    description="Agent with memory and compaction",
)

research_app_compacting = App(
    name="research_app_compacting",
    root_agent=chatbot_agent,
    events_compaction_config=EventsCompactionConfig(
        compaction_interval=3,
        overlap_size=1,
    ),
)

db_url = "sqlite+aiosqlite:///my_agent_data.db"
session_service = DatabaseSessionService(db_url=db_url)

research_runner_compacting = Runner(
    app=research_app_compacting,
    session_service=session_service,
)

# Run 4 turns (turn 3 triggers compaction)
async def run_session():
    await research_runner_compacting.run_async(
        user_id="u1", session_id="compaction_demo", new_message="Turn 1"
    )
    await research_runner_compacting.run_async(
        user_id="u1", session_id="compaction_demo", new_message="Turn 2"
    )
    await research_runner_compacting.run_async(
        user_id="u1", session_id="compaction_demo", new_message="Turn 3"
    )  # compaction triggers here
    await research_runner_compacting.run_async(
        user_id="u1", session_id="compaction_demo", new_message="Turn 4"
    )  # 💥 crashes here
  1. See the error:
File ".../contents.py", line 306, in _process_compaction_events
  if compaction.start_timestamp is not None:
AttributeError: 'dict' object has no attribute 'start_timestamp'

Expected behavior
ADK should store event.actions.compaction as a structured object (e.g., CompactionAction) or automatically convert dicts to object format before accessing attributes.


Desktop (please complete the following information):

  • OS: Ubuntu (Kaggle Notebook)
  • Python version (python -V): 3.12.12
  • ADK version (pip show google-adk): 1.21.0

Model Information:

  • Are you using LiteLLM: No
  • Which model is being used: gemini-2.5-flash-lite

Screenshots

Image ---

Activity

  1. added
    services[Component] This issue is related to runtime services, e.g. sessions, memory, artifacts, etc
    on Jan 6, 2026
  2. added theissue type on Jan 6, 2026
  3. changed the title [-]Compaction Metadata Causes AttributeError in v1.19+[/-] [+]Compaction Metadata Causes AttributeError in v1.21+[/+] on Jan 6, 2026
  4. wuliang229 commented on Jan 7, 2026

    @wuliang229
    Collaborator

    @nicwang119 this should be fixed by 838530e, but the fix will not be needed by the new schema. The current schema used by DatabaseSessionService is going to be deprecated soon, and in the next release, new databases created will use the new schema with JSON serialization. See https://github.com/google/adk-python/discussions/3605 for more details.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    services[Component] This issue is related to runtime services, e.g. sessions, memory, artifacts, etc

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions