Repository navigation
Conversation
The batch response callback queued one results entry per distinct ID of
the batch, but flush() removed the batch's future from tracking upon
consuming the first entry. When processElement or finishBundle flushed at
that moment, the batch future was no longer tracked, so finishBundle
skipped waitForFutures and the remaining per-ID results landed only after
the inputCount == outputCount check, intermittently failing the bundle
with IllegalStateException ("Expected requestCount == responseCount").
Build the full batch result locally inside the callback and queue it as
a single results entry instead, so that consuming the entry in flush()
implies the entire batch has been emitted, making futures.remove safe.
Also make the failure callback null-safe when an ID is no longer pending,
mirroring the success path.
Fixes #6026
Co-Authored-By: Xirp Agent (glm-5-3) <xirp-agent@users.noreply.ghe.spotify.net>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #6027 +/- ##
==========================================
+ Coverage 62.33% 62.40% +0.07%
==========================================
Files 326 326
Lines 11867 11877 +10
Branches 832 835 +3
==========================================
+ Hits 7397 7412 +15
+ Misses 4470 4465 -5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
s278gupt
marked this pull request as ready for review
November 13, 2026 17:11
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
BaseAsyncBatchLookupDoFnintermittently failed bundles with:Fixes #6026.
Root cause
The batch response callback in
handleOutputqueued oneresultsentry per distinct ID of the batch, whileflush()removes the batch's future fromfuturesupon consuming an entry. IfprocessElementorfinishBundleflushed while the callback was still iteratingkeyedInputs(having queued the first ID's entry but not the rest):flush()consumed the first entry and removed the batch's future from tracking,finishBundlethen saw an emptyfuturesmap and skippedwaitForFutures,inputCount == outputCountcheck — failing it.The window is load-dependent (any batch with 2+ distinct IDs), so the failure is intermittent and the runner retries the bundle, re-executing all of its lookups.
Fix
Build the complete per-batch result list locally inside the callback and queue it as a single
resultsentry (both success and failure paths). Consuming that entry inflush()now implies the entire batch has been emitted, sofutures.remove(key)is legitimate — restoring the one-entry-per-tracked-future invariant the unbatchedBaseAsyncDoFnalready has. With this,finishBundle'swaitForFutures(which is guaranteed to complete only after the queueing callback body finishes for all three future types) always runs before the final flush and count check.Additionally, the failure callback now null-checks
inputs.remove(id)and logs (previously an NPE risk), mirroring the success path.Test
AsyncBatchLookupDoFnTestgains a deterministic reproducer that drives the DoFn directly: a 2-element batch whose callback is parked mid-batch (after ID "1" is produced, before ID "2" is queued), an extra element triggersflush()mid-callback, then the bundle ends. Verified it fails onmainwith the issue's exact exception (Expected requestCount == responseCount, but 3 != 2) and passes with this change.Validation
scio-coretransforms.*suites: 82 tests + 85 ScalaCheck cases pass (incl.AsyncDoFnSpec3×100)scio-grpcGrpcBatchDoFnTestpasses;scio-google-cloud-platformcompiles (both extend the changed class; public API unchanged)javafmtCheck,scalafmtCheck,headerCheckpass