Recovery flow
- User's next message arrives with a session ID.
- Runtime asks the SessionStore for that session.
- Store loads session row + last N messages + relevant events.
- Runtime reconstructs the in-memory Session object.
- Agent processes the new turn as if nothing happened.
Advertisement
The load query
public Optional load(String sessionId) {
var session = jdbc.queryOne(
"SELECT * FROM adk_sessions WHERE id = ?",
sessionId);
if (session.isEmpty()) return Optional.empty();
var messages = jdbc.query(
"SELECT role, content FROM adk_messages" +
" WHERE session_id = ? ORDER BY turn DESC LIMIT ?",
sessionId, HISTORY_WINDOW);
return Optional.of(rebuild(session.get(), reverse(messages)));
} Advertisement
How many messages to load
Match your context window budget. Loading 100 messages when the model only accepts 20 is wasted latency. Configure per model.