The 16 November 2026 ADK Java fix moves pending state deltas entry by entry with remove(key, value), so a write made during the transfer is no longer lost. Reproduced.
A one-line pattern with a lost write in it
On 16 November 2026 the Agent Development Kit for Java received a short fix on its main branch: commit fca65ef, titled "keep a state write made while NodeRunner moves pending deltas". The change adds 13 lines and removes 4 in NodeRunner, and adds a 45-line regression test. It is worth reading closely because the pattern it replaces, copy everything from a concurrent map and then clear it, appears in a great deal of Java code outside agent frameworks, and it loses data in exactly the same way.
The fix was not in a tagged release on that date. The latest ADK Java release then was v1.14.0 from 2 November, so anyone pinning a release would not have it until a later version. Two other commits from the same day tighten what an agent node may see of other nodes' inputs and history; this guide covers only the state-transfer fix.
What the runner was doing
In the ADK Java workflow runtime, code running inside a node records state changes and artifact changes in its context's event actions. Those pending changes are maps, stateDelta and artifactDelta, declared as ConcurrentMap and created as ConcurrentHashMap. When the node runner emits an event, a method called withPendingDeltas moves the pending entries onto the event so each change is sent once, and the session applies them when it stores the event.
Before the fix, the move was:
actions.stateDelta().putAll(stateDelta);
actions.artifactDelta().putAll(artifactDelta);
stateDelta.clear();
artifactDelta.clear();Between putAll and clear, another thread can write to stateDelta. A tool callback running concurrently, or any code holding the same context, might set a key that was just copied to a newer value, or add a key that was not there. clear() then removes it. The write was neither copied into this event nor left for the next one. It is simply gone, and nothing reports an error.
The fix
The commit replaces the four lines with a helper that moves entries one at a time and removes each only if it still holds the value that was copied:
private static <V> void moveEntries(Map<String, V> from, Map<String, V> to) {
for (Map.Entry<String, V> entry : from.entrySet()) {
to.put(entry.getKey(), entry.getValue());
from.remove(entry.getKey(), entry.getValue());
}
}ConcurrentMap.remove(key, value) is an atomic conditional removal: it removes the entry only if the key is currently mapped to that value. If another thread replaced the value after the copy, the removal fails and the newer value stays pending for the next event. A key added during the loop is either seen by the iterator and moved, or not seen and left in the map; ConcurrentHashMap iterators are weakly consistent, so either outcome is possible, and both are safe because nothing removes an entry that was not copied.
Why a concurrent map was not enough
It is tempting to assume that using ConcurrentHashMap made the old code safe. Each individual call was thread safe: putAll copied a consistent set of entries and clear removed whatever was present when it ran. The bug is in the gap between two thread-safe calls. A concurrent collection guarantees that its own operations do not corrupt it; it says nothing about a sequence of operations being atomic. Any read-then-modify sequence on shared state needs either a single atomic operation that expresses the whole intent, such as remove(key, value), compute or replace(key, old, new), or external locking that every writer respects.
Reproducing the lost write
A race that depends on timing is a poor teaching test, because a passing run may never hit the window. The upstream regression test avoids timing altogether. It installs a ConcurrentHashMap subclass as the state delta whose remove(key, value) and clear() first perform a replace("count", 1, 2) and then call the real method. The write therefore happens exactly between the copy and the cleanup, every time, and the test checks that the stored session ends with the newer value.
The companion probe uses the same technique outside ADK, with a hook that fires once, either at clear() or at the conditional removal of a chosen key. Each scenario starts with two pending writes, refund_status=drafted and attempt=1, drains twice into two events as a runner would, and folds both events into stored state. Recorded on JDK 23.0.2:
| Drain strategy and concurrent write | First event | Second event | Stored state |
|---|---|---|---|
Copy then clear, newer attempt=2 written | attempt=1, refund_status | empty | attempt=1 |
Move entries, attempt=2 written after its copy | attempt=1, refund_status | attempt=2 | attempt=2 |
Move entries, attempt=2 written before its copy | attempt=2, refund_status | empty | attempt=2 |
Copy then clear, new key approver written | attempt=1, refund_status | empty | no approver |
Move entries, new key approver written | attempt=1, refund_status | approver | approver present |
Move entries, equal value attempt=1 written | attempt=1, refund_status | empty | attempt=1 |
Copy-then-clear lost both kinds of write. Moving entries kept every write, either in the current event or the next one. The direction of the result never changed; only which event carried the newer value did, depending on whether the iteration reached the key before or after the write.
The equal-value case
The last row is the one subtle point. If the concurrent write stores a value equal to the one already copied, remove(key, value) succeeds and the second write is removed along with the first. For a state map that records the latest value of each key, nothing is lost: the event carries the value the key now holds. For a map whose entries mean events or increments, where writing 1 twice should count twice, conditional removal by value is not enough. That design needs a version per entry, such as a counter or a wrapper object compared by identity, or a structure that is swapped rather than drained.
For ADK's deltas, which describe the latest value of each state key and the latest version of each artifact, value semantics are what the runtime wants.
Draining concurrent maps in general
The same three-line rewrite applies wherever code snapshots a concurrent map and then clears it: metrics buffers, dirty-key sets, outbox maps, pending configuration changes. The options, from simplest to most robust:
- Per-entry move with conditional removal, as in the fix. Correct for last-value semantics, no extra allocation.
- Swap the map. Hold the map in an
AtomicReferenceand replace it with a fresh empty map withgetAndSet; drain the old one. Writers must re-read the reference on each write, or a writer holding the old map will write into a map nobody drains. - Use a queue. If every write matters, record writes in a
ConcurrentLinkedQueueand drain withpoll()until empty. Each write is removed exactly once.
What does not work is any variant of read-all then clear-all, including new HashMap<>(map) followed by map.clear(), and entrySet().removeIf(e -> true) after a copy.
What to do if you use ADK Java
Check whether your code writes state from more than one thread inside a node: tool callbacks scheduled on other executors, reactive pipelines that complete on a different thread, or listeners. If it does, a release containing commit fca65ef closes the window in the runner; confirm which release includes it before relying on it, since 16 November is after v1.14.0. If you have your own code that collects state for events, look for the copy-then-clear pattern there too.
To test it in your own code, use the upstream technique: subclass the map, perform the competing write inside the cleanup method, and assert on stored state. Random multi-threaded stress tests can complement that, but they cannot prove the window is closed.
Limits of this analysis
The probe is a standalone illustration of the pattern, not ADK code, and it shows the interleaving, not how often it occurs in practice. No ADK application was run for this guide. The upstream commit includes its own regression test, which is the authoritative check of the runtime behaviour.