elijahbenizzy opened a new pull request, #781:
URL: https://github.com/apache/burr/pull/781
Closes #761.
## Root cause
`TaskBasedParallelAction` (and its `MapStates` / `MapActions` /
`MapActionsAndStates` subclasses) compute each sub-application id as a
deterministic hash of `(parent_app_id, key)`. That determinism is load-bearing
for retry-on-failure and crash recovery: when the parent is rebuilt (e.g.
inside a retry loop, or via `initialize_from`), each sub-task gets the same id
it had on the prior attempt, so a cascading state initializer can find its
persisted checkpoint and resume.
The flip side, reported in #761, is that any user who combines a cascading
state initializer with a parent that re-enters the same parallel action (loop
in the graph, re-invocation against the same parent app id, etc.) will see the
parallel sub-apps replay their prior persisted state instead of running fresh.
## What this PR does
Promotes the inline sub-app id computation into a named, overridable method
on the base class, `TaskBasedParallelAction.sub_application_id(key, state,
context)`. The default implementation is unchanged -- it still returns
`_stable_app_id_hash(parent_app_id, key)` -- so existing behavior (including
retry-on-failure) is preserved bit-for-bit. Users who hit #761 can opt into
different cache behavior by overriding the hook on their subclass.
The previous attempt (PR #778, now closed) tried to fix this by changing the
default to salt with `context.sequence_id`. That broke
`tests/test_end_to_end.py::test_end_to_end_parallel_collatz_many_unreliable_tasks`
because `sequence_id` advances on every parent rebuild, so the retry path
could no longer locate the prior sub-app checkpoints. See #778 for the
diagnostic discussion. The conclusion was to keep the default and surface the
choice to the user.
## Example: opting into fresh-each-invocation (the #761 workaround)
```python
import uuid
from burr.core import ApplicationContext, State
from burr.core.parallelism import MapStates
class MyParallel(MapStates):
# ... states(), action(), reduce(), reads, writes ...
def sub_application_id(
self, key: str, state: State, context: ApplicationContext
) -> str:
# Salt with something that advances per invocation. This trades the
# resume-on-rebuild guarantee for fresh execution under a cascading
# state initializer.
return f"{context.app_id}:{key}:{uuid.uuid4()}"
```
For a business-key-pinned variant, derive from `state` contents instead.
## Test plan
- [x] All existing tests in `tests/core/test_parallelism.py` continue to
pass (19/19) -- the default hook returns the same value the inline computation
did.
- [x]
`tests/test_end_to_end.py::test_end_to_end_parallel_collatz_many_unreliable_tasks`
still passes -- this is the retry-on-failure case that #778 broke; it relies
on stable sub-app ids across parent rebuilds, which is preserved.
- [x] New:
`tests/core/test_parallelism.py::test_sub_application_id_override_enables_fresh_execution_with_cascading_initializer`
-- builds a parent with a `MapStates` subclass that overrides
`sub_application_id` to salt with a per-invocation counter, runs the parent
three times against a shared sub-app persister, and asserts that all 9 sub-task
executions actually run (rather than 3 of them running and the other 6
replaying stale persisted state).
--
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]