addenergyx opened a new pull request, #39384:
URL: https://github.com/apache/beam/pull/39384

   Fixes #39383
   
   **The bug.** `GlobalCachingStateHandler.blocking_get` caches partially 
materialized bag state as a `ContinuationIterable` across bundles, keyed by the 
user-state cache token. The iterable's lazy remainder holds the continuation 
token minted by the read that created it 
(`functools.partial(self._lazy_iterator, state_key, coder, 
continuation_token)`).
   
   Continuation tokens can become permanently invalid — e.g. Dataflow revokes 
them together with the work item that created them ("work token no longer valid 
on the backend"). When that happens, iterating the cached object raises, but 
nothing invalidates the cache entry: the user-state cache token is unchanged, 
so every subsequent bundle reading that state cell is served the same poisoned 
object and replays the dead token. A fresh read would succeed, but never 
happens. The stage retries forever and its watermark stalls.
   
   Observed in production on Dataflow (Python streaming, Streaming Engine, 
Runner v2, Beam 2.74.0) with a stateful transform whose bag state exceeded one 
page: unbounded "work token no longer valid" retry storms wedging the stage; 
disappears when state stays under one page (no continuation token → plain list 
cached → unreachable code path).
   
   **The fix.** Invalidate the cache entry when iterating the continuation 
fails, so the next read loads fresh state. Under transient failures this costs 
one extra reload; under permanent token invalidation it is the difference 
between self-healing and an infinite retry storm. The change is backward 
compatible: `ContinuationIterable.on_failure` defaults to `None`, and 
`_partially_cached_iterable` behaves as before when no cache key is passed.
   
   **Validation.** The new regression test 
`CachingStateHandlerTest.test_failed_continuation_invalidates_cached_iterable` 
is a deterministic unit repro (no Dataflow required): it uses a state-handler 
fake with epoch-scoped token revocation, so revoked tokens fail while fresh 
reads succeed — matching real runner semantics.
   
   - RED (without the fix): the test fails — the second bundle's read is served 
the cached iterable and raises `RuntimeError: continuation token no longer 
valid` from the dead token.
   - GREEN (with the fix): the full `sdk_worker_test.py` passes (including all 
pre-existing tests), and `statecache_test.py` passes unchanged — 35 passed 
across both files.
   
   ------------------------
   
   Thank you for your contribution! Follow this checklist to help us 
incorporate your contribution quickly and easily:
   
    - [x] Mention the appropriate issue in your description (for example: 
`addresses #123`), if applicable. This will automatically add a link to the 
pull request in the issue. If you would like the issue to automatically close 
on merging the pull request, comment `fixes #<ISSUE NUMBER>` instead.
    - [ ] Update `CHANGES.md` with noteworthy changes.
    - [ ] If this contribution is large, please file an Apache [Individual 
Contributor License Agreement](https://www.apache.org/licenses/icla.pdf).
   
   See the [Contributor Guide](https://beam.apache.org/contribute) for more 
information on how to make review process smoother.
   
   To check the build health, please visit 
[https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md](https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md)
   
   GitHub Actions Tests Status (on master branch)
   
------------------------------------------------------------------------------------------------
   [![Build python source distribution and 
wheels](https://github.com/apache/beam/workflows/Build%20python%20source%20distribution%20and%20wheels/badge.svg?branch=master&event=schedule)](https://github.com/apache/beam/actions?query=workflow%3A%22Build+python+source+distribution+and+wheels%22+branch%3Amaster+event%3Aschedule)
   [![Python 
tests](https://github.com/apache/beam/workflows/Python%20tests/badge.svg?branch=master&event=schedule)](https://github.com/apache/beam/actions?query=workflow%3A%22Python+Tests%22+branch%3Amaster+event%3Aschedule)
   [![Java 
tests](https://github.com/apache/beam/workflows/Java%20Tests/badge.svg?branch=master&event=schedule)](https://github.com/apache/beam/actions?query=workflow%3A%22Java+Tests%22+branch%3Amaster+event%3Aschedule)
   [![Go 
tests](https://github.com/apache/beam/workflows/Go%20tests/badge.svg?branch=master&event=schedule)](https://github.com/apache/beam/actions?query=workflow%3A%22Go+tests%22+branch%3Amaster+event%3Aschedule)
   
   See [CI.md](https://github.com/apache/beam/blob/master/CI.md) for more 
information about GitHub Actions CI or the [workflows 
README](https://github.com/apache/beam/blob/master/.github/workflows/README.md) 
to see a list of phrases to trigger workflows.
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to