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_eventis 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_sessionwaits until one session's buffered writes are in the store.flushwaits for every session. Reads such asget_sessionwait 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_eventordelete_sessionraisesSessionPersistenceError, whose__cause__is the last attempt's error. - Limitations include that a crash loses the writes that had not reached the store, that
Runner.runcloses 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 hereThe 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_sessionraisesSessionPersistenceErrorwith theConnectionErroras 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:
- Catch
SessionPersistenceErrorat the flush, and answer the client with an error rather than the reply. - 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_sessionand continue from that copy, which reflects what was actually stored. - 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.
- 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
DatabaseSessionServicerejects such a resend as stale, so the write is reported failed although the store has it.
What to change when adopting it
- Wrap the store and pass the buffered service to the runner, as the guide shows.
- Add
flush_sessionafter everyrun_asyncloop that ends in an acknowledgement, and before any code that reads the session from another process. - Use
run_async. The guide's limitation aboutRunner.runclosing its loop applies to the synchronous entry point. - Call
aclose()on shutdown, and treat itsSessionPersistenceErroras a failure in your logs and metrics, not as noise. - Keep one service per event loop. Applications that run several loops at once need one service each.
- For
adk webandadk api_server, the guide shows how to register abuffered:session service URI scheme in aservices.pynext 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
RuntimeErrorwhile 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_sessionfirst, or carries a written exception. SessionPersistenceErrorat the flush produces a client error and a freshget_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.