Skip to content

Keep propagated attributes on the task, not on the shared Activity or Workflow - #486

Merged
ybastide merged 1 commit into
mainfrom
fix/propagate-attribute-per-task
Nov 29, 2026
Merged

ybastide merged 1 commit into
mainfrom
fix/propagate-attribute-per-task

Conversation

@ybastide

Copy link
Copy Markdown
Contributor

What

propagate_attribute now writes onto the task, not onto the shared object:

  • simpleflow/activity.py: new TaskActivity(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 a TaskActivity it 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=True is used once inside Group(..., raises_on_failure=False). From then on, a standalone use of it in another execution handled by the same process fails silently, because default_failure_handling reads payload.raises_on_failure from 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

  • Overlay, not copy. A copy freezes the Activity at propagation time. Code that sets something on the shared Activity just before scheduling (botify replaces meta with per-execution binaries) would then schedule with stale values. With the overlay, only the propagated attributes are per task.
  • TaskActivity skips Activity.__init__, so it is not added to the registry.
  • Failure handling needs no change. swf.task.ActivityTask.from_generic_task and WorkflowTask.from_generic_task pass task.activity / task.workflow through, so payload, default_failure_handling and on_task_failure see the per-task values. The local executor reads task.activity as well.
  • Workflows get a subclass rather than an overlay object, because the class is instantiated, passed to get_task_list(workflow, ...) and checked with issubclass. Keeping __module__/__name__ keeps the child workflow type name (module + "." + __name__) unchanged. The class is built with type(shared)(...), so a custom metaclass is kept.
  • Interface change: after propagation, task.activity is some_activity and task.workflow is SomeWorkflow no longer hold. Unwrap with task.activity.shared, or use issubclass for workflows. Attribute reads (task.activity.name, .raises_on_failure, .meta, …) are unchanged.
  • Out of scope: FuncGroup still re-applies only raises_on_failure to 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 own raises_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 inside Group(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:

  • Against the old 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.
  • Full suite on this branch (env -u AWS_CREDENTIALS uv run --group dev pytest -n 4 tests): 460 passed, 10 skipped, 3 xfailed.
  • With AWS_CREDENTIALS set in my shell, 3 MockSWFTestCase tests reach real SWF and fail with UnrecognizedClientException. That happens on clean origin/main too.

🤖 Generated with Claude Code

… 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
ybastide merged commit 255ea23 into main Nov 29, 2026
8 checks passed
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

1 participant