Repository navigation
fix(core): prevent stale local activity dispatch after eviction - #1839
Draft
hikaru-212 wants to merge 1 commit into
Draft
hikaru-212 wants to merge 1 commit into
hikaru-212 wants to merge 1 commit into
Conversation
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.
What was changed
LocalActivityManager::next_pendingdispatches a request only if that token matches the current registration for its(run_id, seq). Otherwise the request is dropped, the same way as when no registration exists: the registration's state is left alone, and the slot permit the request was paired with is released.u64advanced withchecked_add, so a manager never issues the same token twice. If the counter is ever exhausted, allocation panics instead of wrapping. Local activity task tokens grow from 14 to 18 bytes; Core still identifies them only by theirlocal_act_prefix.LocalActivityManagertests, a Core test for eviction and rebuild, and entries in both changelogs.Why?
A queued request carried only
(run_id, seq). Eviction removes the run's local activity registrations (#1304) but leaves requests that haven't been dispatched yet in the queue. When the rebuilt run scheduled the same seq,next_pendingfound the new registration by that key and dispatched the old request under the new token. The old request could then run for the rebuilt run's local activity and supply its result (#1838). Queued local retries went through the same path.The token check only holds if a manager never reissues a token. The previous
u32counter wrapped in release builds and panicked on overflow in debug builds. After 2^32 allocations, a retry queued before the wrap could therefore match a newer registration's token.The Core test triggers eviction with
request_workflow_eviction; it does not depend on #1835 or legacy queries.Checklist
Closes [Bug] Stale queued local activity can use a rebuilt run's task token and deliver the wrong result #1838
How was this tested?
The tests were run locally on 6eaaeeb with the same changes. The relevant upstream files were unchanged between 6eaaeeb and b233e9f. The tested patch matches this commit except for the allocator's doc comment. The PR head itself was not built locally.
Without the fix, three regression tests fail because stale queued requests can be dispatched under a newer registration:
queued_start_of_evicted_run_is_not_dispatched_for_rebuilt_runqueued_retry_of_evicted_run_is_not_dispatched_for_rebuilt_runevicted_before_polledcase ofcore_tests::local_activity_eviction::local_activity_queued_before_eviction_runs_only_for_rebuilt_runThe
kept_in_cachecase passes with and without the fix. With the fix, the Core test also checks the recorded marker and a cold replay of the resulting history.With the original
u32allocator, three tests fail:local_activity_tokens_stay_unique_past_u32_maxlocal_activity_token_allocation_stops_at_exhaustion_instead_of_wrappingqueued_retry_of_evicted_run_is_not_dispatched_after_tokens_pass_u32_maxThe last test fast-forwards the counter instead of allocating 2^32 tokens.
Each of three mutations fails at least one new or existing test: skipping the check for retries, binding a retry to the failed attempt's token, or deleting the new registration on a mismatch.
cargo test -p temporalio-sdk-core --lib --release, with debug assertions and overflow checks enabled fortemporalio-sdk-core: 693 passed, 1 ignored.cargo +nightly fmt --all -- --checkpasses, also on the PR head.cargo clippy -p temporalio-sdk-core --lib --tests --release -- -D warningspasses, withclippy::infallible_destructuring_matchallowed for an existing warning intemporalio-client.Not run:
cargo lint,cargo test-lint,cargo integ-test, the unchunked build, a real server, or a language SDK worker. The Core test uses mocked server responses.Any docs updates needed?
No additional documentation changes required. Both changelog entries have been added; no public API changes.