Class PersistBarrier

java.lang.Object
com.google.adk.flows.llmflows.PersistBarrier

public final class PersistBarrier extends Object
Lets BaseLlmFlow's multi-step loop wait until the Runner -- the sole event persister -- has appended the current step's events, so the next step's request (built from session.events() by Contents) is not assembled from a stale session. The Runner calls markPersisted(InvocationContext, String) (or markFailed(InvocationContext, String, Throwable)) after each append; the flow calls awaitPersisted(InvocationContext, List) between steps. State lives in the per-invocation InvocationContext.callbackContextData() map, shared across the agent tree.

Each event id maps to a CompletableSubject: pending until its append finishes, then terminally completed or failed. The subject retains its terminal state, so awaitPersisted/mark* may happen in any order and a late await -- e.g. at a higher flow level across an agent transfer -- resolves immediately. If an append fails, the matching await fails with that error rather than blocking forever.

Thread-safe and lock-free: markPersisted/markFailed may run off-thread (async appendEvent) concurrently with awaitPersisted; ConcurrentHashMap.computeIfAbsent(K, Function) hands both sides the same subject, which itself serializes its terminal signal against subscription.