Practical technical guides / Recent development: ADK Python 2.15.0 (19 November 2026)

Flush Buffered ADK Sessions Before Reporting a Durable Turn

ADK Python 2.15.0 adds an experimental BufferedSessionService. Appends return before the store has the events; flush_session is the durability boundary.

By Sandeep Belgavi · Published 2026-11-21

ADK Python 2.15.0 adds an experimental BufferedSessionService. Appends return before the store has the events; flush_session is the durability boundary.

What changed on 19 November

Google's Agent Development Kit for Python released version 2.15.0 on 19 November 2026 (UTC). Among its features are two related changes to sessions: BaseSessionService.append_events, which batches buffered writes, and a new BufferedSessionService, which writes session events to a wrapped store in the background. The release ships a guide for it, and the guide marks it experimental, so the API may change. Running it also logs an EXPERIMENTAL warning.

This is a real latency improvement for agents backed by a remote session store. It also moves a boundary that many applications rely on without saying so: the moment at which a turn is stored. This guide reads the documented behaviour, measures it with the released package, and turns it into a rule for when an application may tell its client that a turn is done.

What the guide says

The facts below are from the 2.15.0 guide for BufferedSessionService, read on 21 November 2026:

  • A turn appends many events, and with a remote store each append_event is a round trip. The buffered service applies each event to the session object and returns at once. A background writer sends the events to the wrapped store in the order they were appended.
  • The runner does not flush the service yet. The guide says to flush the session after each run, before telling the client that the turn is done, and to close the service on shutdown so in-flight writes reach the store.
  • flush_session waits until one session's buffered writes are in the store. flush waits for every session. Reads such as get_session wait for the writes whose effects they return, and a read never raises a write failure.
  • A failed write is not retried by default. The service drops that write and the session's later buffered writes, because storing a later event without the earlier one would leave a gap. The session's next flush_session, append_event or delete_session raises SessionPersistenceError, whose __cause__ is the last attempt's error.
  • Limitations include that a crash loses the writes that had not reached the store, that Runner.run closes its event loop when the run ends and so cancels writes in flight, and that the service is not thread-safe.

The middle two points are the ones to design around. Returning from append_event now means "accepted into memory", not "stored". flush_session is the durability boundary.

A measurement with the released package

The companion example installs google-adk==2.15.0 and wraps an InMemorySessionService subclass that waits 50 ms before storing each event and can fail one chosen write. It appends the four events of a synthetic help-desk turn for CASE-9101 at the fictional Belgavi's Book Store, as a runner would, and records what the wrapped store holds at the moment each acknowledgement policy would answer the client. No model is called and no runner is used.

service = BufferedSessionService(store)
session = await service.create_session(app_name=APP, user_id=USER, session_id=SID)
for i in range(4):
    await service.append_event(session, event(i))
# ack_after_append would answer the client here
await service.flush_session(app_name=APP, user_id=USER, session_id=SID)
# flush_then_ack answers here

The results, from one run on Windows with Python 3.13:

  • Acknowledging after the appends: the session object holds 4 events and the store holds 0. The appends returned in a few milliseconds. All 4 reach the store by the time the service is closed.
  • Flushing, then acknowledging: the store holds all 4 at acknowledgement. The flush took between about 200 and 360 ms across runs, at least four sequential writes of 50 ms each. That is the latency the buffer had hidden.
  • Third write fails, flush first: flush_session raises SessionPersistenceError with the ConnectionError as its cause. The store holds 2 events, as the guide describes: the failed write and the one after it were dropped. The application can answer the client with an error.
  • Third write fails, acknowledge first: the client was already told the turn was done. The failure surfaces only when aclose() raises at shutdown, and the store holds 2 of the 4 events.

One more detail appeared in the measurement. After flush_session had raised the failure, a later aclose() did not raise it again. The guide says a flush of every session reports each failure once. So if code catches the error at the flush and ignores it, nothing later will repeat it.

The rule for acknowledging a turn

If the client, or any other system, will act on the belief that a turn is stored, flush that session first. In practice, that covers a chat interface that shows a reply as delivered, an API that returns 200, a queue consumer that acknowledges a message, and a workflow engine that records a step as complete. Each of these makes a promise the buffer has not kept yet.

There are cases where acknowledging before the flush is acceptable. The reply may be ephemeral, so that losing the stored history of one turn is a cost you have accepted. Or the client may retry turns idempotently. Either way, make that a written decision per endpoint rather than a side effect of swapping the session service.

Handling a persistence error

The guide's advice for code that already handles StaleSessionError on unbuffered stores is to also check __cause__ on SessionPersistenceError. More generally:

  1. Catch SessionPersistenceError at the flush, and answer the client with an error rather than the reply.
  2. Do not reuse the in-memory session object. It still holds the dropped events, and an append to it raises again. Read the session from the store with get_session and continue from that copy, which reflects what was actually stored.
  3. Decide whether the turn should be re-run. The store has the first events of the turn but not the rest. A re-run against the stored copy repeats the model call, so any tool the turn called must be idempotent before you automate this.
  4. Turn on retries only for a store that keeps a resent event once. The guide notes that retries can resend an event the store already committed, and that DatabaseSessionService rejects such a resend as stale, so the write is reported failed although the store has it.

What to change when adopting it

  1. Wrap the store and pass the buffered service to the runner, as the guide shows.
  2. Add flush_session after every run_async loop that ends in an acknowledgement, and before any code that reads the session from another process.
  3. Use run_async. The guide's limitation about Runner.run closing its loop applies to the synchronous entry point.
  4. Call aclose() on shutdown, and treat its SessionPersistenceError as a failure in your logs and metrics, not as noise.
  5. Keep one service per event loop. Applications that run several loops at once need one service each.
  6. For adk web and adk api_server, the guide shows how to register a buffered: session service URI scheme in a services.py next to your agents.

What stays the same

Two processes writing to one session still conflict as they would without buffering. A store that checks versions rejects one write, and the buffered service reports it as SessionPersistenceError. Shared app: and user: state still reaches the store in append order across sessions, so a change to that scope waits for earlier changes from other sessions, including their retries. Buffering changes when writes happen, not who wins.

Failure modes to test

  • A store that fails the k-th write, for every k in a turn. Assert that the client sees an error and that the stored session ends before the failed event.
  • A process killed after the appends and before the flush. Assert that a restarted process sees the turn as missing, and that your client-side behaviour for a missing turn is acceptable.
  • A flush whose error is caught and logged. Assert that it is counted, because aclose() will not report it again.
  • Two event loops sharing one service, which should raise RuntimeError while writes are in flight, according to the guide.

When not to buffer

If the session store is local and fast, such as an SQLite file on the same machine, the latency saved is small and the new failure window is not worth it. If every turn is acknowledged to a client that acts on it, the flush is required anyway, and the saving is limited to overlapping the store writes with the rest of the turn. The buffer pays off when a turn appends many events to a remote store and something other than the acknowledgement, such as streaming partial replies, benefits from not waiting on each write.

Verification checklist

  • Every acknowledgement path calls flush_session first, or carries a written exception.
  • SessionPersistenceError at the flush produces a client error and a fresh get_session.
  • aclose() runs on shutdown and its errors are counted.
  • A test with the example's failing store reproduces 2 stored events after a third-write failure.

Run the example yourself

The slow and failing store over the released google-adk 2.15.0 BufferedSessionService, with five tests. No model is called. Companion code on GitHub; its README lists the prerequisites, exact commands, expected output and limits.

Primary references and authorship

Sources read 21 November 2026. Original explanation, measurements and synthetic examples by Sandeep Belgavi. Views are my own and do not represent any employer, past or present.

Related on this site: