@@ -99,9 +99,14 @@ def __init__(
9999 self ._requests_being_added : dict [str , asyncio .Future [bool ]] = {}
100100 """In-flight `add_batch_of_requests` markers, keyed by request ID.
101101
102+ Coordinates only concurrent `add_batch_of_requests` calls sharing this one client instance (e.g. several
103+ producer coroutines adding requests in the same process). It does not coordinate separate client instances
104+ or processes, which each keep their own markers; deduplication across clients still relies on the platform.
105+
102106 Each future resolves once the platform call that is adding the request settles: `True` if the request was
103- committed, `False` otherwise. Concurrent producers of the same request await it instead of re-sending,
104- which preserves deduplication while still avoiding false success when the original add fails.
107+ committed, `False` otherwise. A concurrent call adding the same request awaits the future instead of
108+ re-sending it, which avoids a duplicate platform write while still avoiding false success when the original
109+ add fails.
105110 """
106111
107112 self ._initialized_caches = False
@@ -159,7 +164,7 @@ async def add_batch_of_requests(
159164 awaited_in_flight .append ((request , self ._requests_being_added [request_id ]))
160165 else :
161166 # Push the request to the platform. Probably not there, or we are not aware of it. Register an
162- # in-flight marker so concurrent producers dedupe against it; caching is deferred until the
167+ # in-flight marker so a concurrent call dedupes against it; caching is deferred until the
163168 # platform confirms the request was accepted (see below).
164169 new_requests .append (request )
165170 self ._requests_being_added [request_id ] = loop .create_future ()
@@ -193,7 +198,7 @@ async def add_batch_of_requests(
193198 # Add the locally known already present processed requests based on the local cache.
194199 api_response .processed_requests .extend (already_present_requests )
195200 finally :
196- # Release the in-flight markers we registered. Committed requests tell concurrent producers the
201+ # Release the in-flight markers we registered. Committed requests tell concurrent callers the
197202 # request reached the platform; everything else (unprocessed, API error, cancellation) tells them
198203 # it did not, so they retry instead of reporting false success.
199204 for request in new_requests :
0 commit comments