Skip to content

Add --save-session-on-runtime flag to adk run for crash recovery #5485

@fuleinist

Description

@fuleinist

Is your feature request related to a specific problem?

When using adk run for development or long-running agent sessions, unexpected crashes cause complete session loss. Re-running adk run creates a fresh session with no context, forcing the agent to re-explain context and waste tokens on re-generation. This is especially painful for long multi-turn sessions.

Describe the Solution You'd Like

Add a --save-session-on-runtime flag (or config option) to adk run that periodically saves session state (tool call history, agent state, conversation context) to persistent storage during execution, not just on graceful exit.

On crash/re-run, the agent can resume from the last saved checkpoint rather than starting fresh. This mirrors the "session resume" pattern common in chat interfaces.

Describe Alternatives You've Considered

  1. Manual save — users periodically call a save tool manually. Works but requires discipline and is error-prone.
  2. Checkpointing via after_tool_callback — possible but requires custom user code, not built-in.
  3. Accepting crashes — just eat the token waste and re-run. Current behavior.

Proposed API / Implementation

adk run --save-session-on-runtime --checkpoint-interval 60

When enabled:

  • Every N seconds (configurable), the session state is serialized to disk/SQLite
  • On next adk run with the same session_id, the agent loads the last checkpoint instead of starting fresh
  • Checkpoint includes: conversation history, tool call log, agent memory state, turn count

Impact on your work

High impact — we run multi-hour agent sessions where a crash loses 30+ minutes of context. The token cost of re-explaining context is significant (50k+ tokens per recovery).

Willingness to contribute

Yes — I can implement this if the design is agreed upon.

Metadata

Metadata

Assignees

Labels

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

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions