Recovery flow

  1. User's next message arrives with a session ID.
  2. Runtime asks the SessionStore for that session.
  3. Store loads session row + last N messages + relevant events.
  4. Runtime reconstructs the in-memory Session object.
  5. 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.