Repository navigation
[Python] Fail bundles on state write errors - #39992
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #39992 +/- ##
=============================================
+ Coverage 56.16% 79.74% +23.57%
=============================================
Files 1124 487 -637
Lines 178336 82280 -96056
Branches 1489 0 -1489
=============================================
- Hits 100170 65613 -34557
+ Misses 75645 16667 -58978
+ Partials 2521 0 -2521
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
📋 Review Summary
This PR fixes a silent data-loss bug in Python portable worker state handling by ensuring that state write (append and clear) response errors are checked during commit() across SynchronousBagRuntimeState, SynchronousSetRuntimeState, and SynchronousOrderedListRuntimeState. It also properly awaits both the clear and extend futures in SynchronousBagRuntimeState when a state is cleared and then appended to within the same bundle, and upgrades _DeferredCall.get() in sdk_worker.py to propagate error responses across chunked state appends.
🔍 General Feedback
- The shared
_await_state_commithelper and the updated_DeferredCall.get()logic cleanly and consistently surface runner-reportedStateResponse.errormessages across all three user state types. - Unit test coverage in
RuntimeStateCommitTestis thorough, covering single append/clear failures, clear-then-append sequences, multi-chunkextendfailures, and set compaction failures.
💡 Tip: Comment /gemini review on this pull request to trigger a new Gemini code review.
|
Assigning reviewers: R: @shunping for label python. Note: If you would like to opt out of this review, comment Available commands:
The PR bot will only process comments in the main thread (not review comments). |
|
/gemini review |
There was a problem hiding this comment.
📋 Review Summary
This PR fixes a critical reliability issue in the Python SDK harness where runner-reported state write errors (StateResponse.error) were ignored during state commit, and clear futures in SynchronousBagRuntimeState were overwritten when followed by an extend call. The introduction of _await_state_commit and the updated future tracking across SynchronousBagRuntimeState, SynchronousSetRuntimeState, and SynchronousOrderedListRuntimeState are clean, well-structured, and thoroughly covered by unit tests.
🔍 General Feedback
- The consolidation of future awaiting and error checking into
_await_state_commitcleanly handles both single and multi-step state mutations (e.g., clear followed by append, set compaction, and chunked appends). - Consider propagating
WorkCancelledExceptionwhenStateResponse.error_reason == CANCELLEDto stay consistent withGrpcStateHandler._blocking_request.
💡 Tip: Comment /gemini review on this pull request to trigger a new Gemini code review.
| response.error for response in responses if response and response.error | ||
| ] | ||
| if errors: | ||
| raise RuntimeError('\n'.join(errors)) |
There was a problem hiding this comment.
🟢 Nit: In GrpcStateHandler._blocking_request (sdk_worker.py), state responses with response.error_reason == beam_fn_api_pb2.StateResponse.ErrorReason.CANCELLED raise WorkCancelledException rather than RuntimeError so that SdkHarness._execute logs the cancellation at INFO level instead of ERROR. Consider checking error_reason here (and propagating it in GlobalCachingStateHandler.extend's _DeferredCall) for consistency with state read error handling.
Python runtime state commits ignore
StateResponse.error, so a runner-reported write failure can still complete the bundle successfully. When an append follows a clear, the clear future is overwritten and its response is never checked.This change checks pending write responses before completing bag, set, and ordered-list state commits, and retains both futures when an append follows a clear. Write errors fail the bundle through the existing failure handling; successful commits send the same state requests.
Local worker validation passed, and the regressions fail against the unfixed implementation. Run the Python unit suite with:
When cross-bundle user-state caching is enabled, a retry needs a runner-supplied cache token that prevents reuse of state cached by the failed bundle.
addresses #123orfixes #456).CHANGES.mdwith noteworthy changes.See CONTRIBUTING.md for contribution guidelines.