Repository navigation
Keep propagated attributes on the task, not on the shared Activity or Workflow - #486
Merged
Merged
Conversation
… Workflow ActivityTask.propagate_attribute did setattr(self.activity, ...) and WorkflowTask.propagate_attribute did setattr(self.workflow, ...). Both targets are shared. The Activity is the module-level object every task built from it uses, and the workflow is a class. So Group(..., raises_on_failure=False), or any attribute a canvas propagates, rewrote the declared semantics for every later task in the decider process, across executions, last writer wins. Failure scenario: an activity declared raises_on_failure=True is used once inside Group(..., raises_on_failure=False). From then on, a standalone use of that activity in another execution handled by the same process fails silently: default_failure_handling reads payload.raises_on_failure, and payload is the shared, now-mutated Activity. The opposite also happens: Chain(raises_on_failure=True) makes an optional activity mandatory everywhere. In botify this let a visits feature turn the url mapper's mandatory activities optional, so a later link-rel mapping failure went unnoticed and its dependents ran on missing files. ActivityTask: on its first propagated attribute, the task wraps its activity in a TaskActivity. The wrapper holds the task's own attributes and reads everything else through to the shared Activity, so later changes to the Activity (e.g. a `meta` set just before scheduling) still reach the task. A copy would freeze them. TaskActivity skips Activity's __init__, so it is not registered. Its `shared` attribute gives back the original. swf ActivityTask.from_generic_task passes task.activity through, so payload, default_failure_handling and on_task_failure see the per-task values. The local executor reads task.activity too. WorkflowTask: on its first propagated attribute, the task replaces its workflow with a subclass that keeps the class's __module__, __name__ and __qualname__. The child workflow type name (module + __name__), issubclass checks and instantiation are unchanged. Behaviour change: an activity or workflow used both inside and outside a propagating canvas keeps its declared semantics outside it. Code that compared task.activity (or task.workflow) by identity with the shared object after propagation must unwrap it (TaskActivity.shared, or __mro__[1] / issubclass for workflows). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ybastide
added a commit
that referenced
this pull request
Nov 29, 2026
Both branches add tests to tests/test_simpleflow/swf/test_executor.py; keep both.
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
propagate_attributenow writes onto the task, not onto the shared object:simpleflow/activity.py: newTaskActivity(Activity). It holds one task's attributes and reads every other attribute through to the shared Activity (shared).simpleflow/task.py,ActivityTask.propagate_attribute: on the first propagated attribute, the task wraps its activity in aTaskActivityit owns, then sets the attribute there.simpleflow/task.py,WorkflowTask.propagate_attribute: on the first propagated attribute, the task replaces its workflow with a subclass it owns. The subclass keeps the original__module__,__name__and__qualname__.Why
The Activity is the module-level object every task built from it uses, and a workflow is a class.
Group(..., raises_on_failure=False),Chain(raises_on_failure=True)and any other propagated attribute therefore rewrote the declared semantics for every later task in the decider process, across executions, with the last writer winning.Failure scenario: an activity declared
raises_on_failure=Trueis used once insideGroup(..., raises_on_failure=False). From then on, a standalone use of it in another execution handled by the same process fails silently, becausedefault_failure_handlingreadspayload.raises_on_failurefrom the mutated Activity. It also works the other way: an optional activity becomes mandatory everywhere.In botify, a visits feature turned the url mapper's mandatory activities optional, so a later link-rel mapping failure went unnoticed and its dependents ran on missing files. Botify carries a monkeypatch for this (botify-hq/botify#16411) until a release has this fix.
Choices
metawith per-execution binaries) would then schedule with stale values. With the overlay, only the propagated attributes are per task.TaskActivityskipsActivity.__init__, so it is not added to the registry.swf.task.ActivityTask.from_generic_taskandWorkflowTask.from_generic_taskpasstask.activity/task.workflowthrough, sopayload,default_failure_handlingandon_task_failuresee the per-task values. The local executor readstask.activityas well.get_task_list(workflow, ...)and checked withissubclass. Keeping__module__/__name__keeps the child workflow type name (module + "." + __name__) unchanged. The class is built withtype(shared)(...), so a custom metaclass is kept.task.activity is some_activityandtask.workflow is SomeWorkflowno longer hold. Unwrap withtask.activity.shared, or useissubclassfor workflows. Attribute reads (task.activity.name,.raises_on_failure,.meta, …) are unchanged.FuncGroupstill re-applies onlyraises_on_failureto the tasks it builds, as before.Tests
tests/test_simpleflow/test_task.py: group attributes land on the task, not on the activity; two tasks of one activity keep their ownraises_on_failure; a later change to the activity reaches the task; group attributes land on a child workflow task's subclass, with the same module/name/qualname and task name.tests/test_simpleflow/swf/test_executor.py(TestFailureSemanticsStayOnTheTask): replays a workflow that uses a mandatory activity and a mandatory child workflow insideGroup(raises_on_failure=False). A later execution whose standalone use of each fails must still fail the workflow. The controls without the optional use fail it either way.Results:
task.py, 5 of the new tests fail (3 unit, 2 replay). The 1 that passes is the read-through test, which also holds on the old code because the activity was never wrapped there.env -u AWS_CREDENTIALS uv run --group dev pytest -n 4 tests): 460 passed, 10 skipped, 3 xfailed.AWS_CREDENTIALSset in my shell, 3MockSWFTestCasetests reach real SWF and fail withUnrecognizedClientException. That happens on cleanorigin/maintoo.🤖 Generated with Claude Code