Skip to content

Fix replay and bookkeeping bugs: directed signals, refused markers and schedules, canceled events, CLI - #487

Merged
ybastide merged 13 commits into
mainfrom
fix/replay-bookkeeping
Nov 29, 2026
Merged

ybastide merged 13 commits into
mainfrom
fix/replay-bookkeeping

Conversation

@ybastide

@ybastide ybastide commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

What

Five fixes from the "Not addressed" list of #485, plus five found while making them, one commit each. Seven are on the replay path, three are CLI only. Two more commits fix order-dependent tests.

  • A directed signal is sent even if this workflow received a signal of the same name. simpleflow/swf/executor.py, find_signal_event:
  • A refused marker fails its future and is not recorded again. simpleflow/swf/executor.py:
    • find_marker_event returns the latest recorded marker with the task's details, else the latest record_failed entry for that marker name;
    • _get_future_from_marker_event tested state == "failed", which the parser never writes. It now tests record_failed and gives a TaskFailed(marker_name, cause) future.
  • A refused activity schedule backs off, or fails. simpleflow/swf/executor.py, resume_refused_task:
    • transient causes (ACTIVITY_CREATION_RATE_EXCEEDED, OPEN_ACTIVITIES_LIMIT_EXCEEDED, ACTIVITY_ID_ALREADY_IN_USE, ACTIVITY_TYPE_DOES_NOT_EXIST) start a timer __simpleflow_schedule_failed_<refusal event id>_<activity id>, and the activity is scheduled again once it fires. The delay is 2^n s for the n-th refusal in a row, capped at 300 s. A successful schedule resets n. The first ACTIVITY_TYPE_DOES_NOT_EXIST still creates the type and schedules again at once;
    • any other cause (ACTIVITY_TYPE_DEPRECATED, DEFAULT_*_UNDEFINED, OPERATION_NOT_PERMITTED) is a failed attempt: a TaskFailed(<activity id>, <cause>) future through handle_failure, so raises_on_failure, retry and on_task_failure apply;
    • simpleflow/history.py: a schedule_failed entry carries id, schedule_failed_id, schedule_failed_count and the refusal's decision_task_completed_event_id. get_event_id knows schedule_failed_id.
  • A refused child workflow start is handled the same way. resume_child_workflow also goes through resume_refused_task:
    • transient causes (CHILD_CREATION_RATE_EXCEEDED, OPEN_CHILDREN_LIMIT_EXCEEDED, OPEN_WORKFLOWS_LIMIT_EXCEEDED, WORKFLOW_TYPE_DOES_NOT_EXIST) start a timer __simpleflow_start_failed_<refusal event id>_<workflow id>, with the same delays; the first missing type is created and started again at once;
    • any other cause, WORKFLOW_ALREADY_RUNNING included, is a failed attempt, counted the same way;
    • simpleflow/history.py: a start_failed entry carries start_failed_count, reset when the child starts. get_event_id knows start_failed_id. Type creation moves to create_workflow_type.
  • A refused backoff timer no longer reschedules the task at once. resume_refused_task, by the timer's cause:
    • OPEN_TIMERS_LIMIT_EXCEEDED: the decision the refusal brings waits; the next one (after a DecisionTaskCompleted that follows the refusal) starts the same timer again;
    • TIMER_CREATION_RATE_EXCEEDED: the same timer starts again at once;
    • any other cause is a failed attempt, counted like a permanent refusal; TaskFailed keeps the task's cause as reason, with the timer and its cause in details.
  • A failure-retry timer refused for OPEN_TIMERS_LIMIT_EXCEEDED waits too. do_handle_failure: the decision the refusal brings returns a pending future and no decision; a later one starts the timer again, as before. TIMER_CREATION_RATE_EXCEEDED is unchanged.
  • ActivityTaskCanceled and WorkflowExecutionCanceled are parsed. simpleflow/history.py: both branches tested cancelled; the state is canceled.
    • A canceled activity entry now has state canceled, with canceled_id and canceled_timestamp.
    • History.workflow has state canceled, with canceled_id, canceled_timestamp, decision_task_completed_event_id and details.
  • The CLI reads histories with activities that were never scheduled. simpleflow/swf/stats/pretty.py (status, get_task, info) and simpleflow/swf/helpers.py (find_activity) no longer raise KeyError on a refused schedule or on a cancel request for an unknown activity id.
  • simpleflow workflow.info reads histories that start with a signal. simpleflow/swf/stats/pretty.py: info takes the first and last tasks' timestamps through a new get_task_timestamp, which also knows a signal's timestamp and a not-yet-started child workflow's initiated_event_timestamp.
  • simpleflow workflow.info shows the workflow's input. simpleflow/swf/stats/pretty.py: the input column comes from WorkflowExecutionStarted, the first event, instead of the first task.
  • Tests no longer depend on their order.
    • tests/conftest.py imports moto before any test module. tests.data.constants creates the SWF boto3 client at import and it is cached for the process; moto 4 only stubs clients created after its import. Run first, test_executor.py made later @mock_swf tests call the real SWF endpoint.
    • TestSettings restores simpleflow.settings: it left METROLOGY_PATH_PREFIX = "123", so test_metrology, run after it, read from the wrong key.
  • simpleflow/swf/mapper/models/history/builder.py: new helpers add_marker_record_failed, add_activity_task_cancel_requested, add_activity_task_canceled and add_workflow_execution_canceled.

Why

Signals. find_signal_event looked the task up by name in history.signals before looking at its target. A workflow that had received a_signal and then submitted signal("a_signal", workflow_id="other") got a finished future carrying the received input, and no SignalExternalWorkflowExecution decision was made. The other workflow never got the signal.

Markers. RecordMarkerFailed is parsed as record_failed, and find_marker_event kept only recorded markers. A refused marker was never found, so RecordMarker was issued again on every decision. The only documented cause is OPERATION_NOT_PERMITTED, which does not go away by itself.

Refused schedules. A schedule_failed entry made the executor schedule the activity again in the next decision, whatever the cause. SWF answers a failed decision with a new decision task, so a permanent refusal looped until the execution hit its event cap, and a rate or limit refusal was retried at full speed. Two refused activities that were never scheduled also shared one handled_failures entry (get_event_id returned None for both), and do_handle_failure's timer lookup raised KeyError on such an entry.

Refused child starts. A refusal other than a missing type became a failed future through the default retry handling, which compares the history's retry with the child's; refusals never incremented it, so a child with retry > 0 was started again on every decision until the event cap. A rate or limit refusal failed the attempt instead of waiting, and a missing type was created and started again at once, for ever if the refusal persisted. initiatedEventId is 0 for every cause but WORKFLOW_ALREADY_RUNNING, so two refused children also shared one handled_failures entry.

Refused backoff timers. When the backoff timer was refused, the task was tried again at once: under the open-activities and open-timers limits together, that was task refused, timer refused, task refused…, two decisions per turn.

Refused failure-retry timers. do_handle_failure (#484) treated a retry timer refused for OPEN_TIMERS_LIMIT_EXCEEDED as never started, and on_task_failure started it again in the same decision: timer refused, started again, refused…

Canceled. Event states are the SWF event type minus its prefix, snake_cased, so both events give canceled. The two parser branches never ran:

  • a canceled activity kept its previous state (cancel_requested, started or scheduled). The executor's own state == "canceled" branch was unreachable, the future stayed pending, the activity kept counting as open, and a workflow waiting on it blocked;
  • a canceled execution kept state started in History.workflow.

CLI. A schedule_failed entry with no earlier schedule has no id, name, version, input nor scheduled_id. A cancel_requested entry for an unknown activity id has only its id. On such a history:

  • workflow.tasks raised KeyError('name');
  • workflow.info raised KeyError('input') when the entry was the first task;
  • task.info raised KeyError('id');
  • activity.rerun raised KeyError('scheduled_id') before reaching the activity asked for.

info read f"{state}_timestamp" from the first and last tasks. A received signal only has timestamp, and a child workflow that is initiated but not started only has initiated_event_timestamp. A history whose first task is a signal raised KeyError('signaled_timestamp'), and one ending or starting on a child workflow waiting to start raised KeyError('start_initiated_timestamp'). The last task already fell back to timestamp; the first did not.

info also filled its input column from the first task: the first activity's or child workflow's input, or the first received signal's. Only a history with no task showed the workflow's input.

Choices

  • What counts as a signal to itself. Executor.signal fills in the workflow's own workflow_id and run_id when no workflow_id is given, so a self-signal normally carries both. It keeps being found in the received signals, as before. A signal to the same workflow_id with another run_id (an earlier run of a continue-as-new chain) is a directed signal.
    • A self-signal is still matched by name only: a signal of that name received from anyone finishes its future. That is the existing behaviour and I left it.
  • Refused marker → failed future, never retried. Same choice as Replay a raced timer cancel and an in-flight or refused signal correctly #485 for refused signals. futures.wait returns None for it; the refusal is in future.exception.
    • RecordMarkerFailed has no details, so a refusal cannot be tied to one MarkerTask. It stands for every marker of that name that has no recorded match. A recorded marker with the task's details always wins, whatever the order, so a history where a later attempt succeeded replays as recorded.
    • get_event_details("marker", …) and list_markers are unchanged.
  • Refusals as attempts. Refusals do not increment the history's retry. For a permanent refusal, the failure context's event gets retry = earlier failures + refusals in a row − 1, the value a failed execution would have had, so attempt_number counts them. Each retry refused again raises it: the default handling stops after retry attempts, and attempt-based stop strategies in on_task_failure stop too.
    • Behaviour change: a mandatory activity whose schedule is permanently refused now fails its workflow (after its retries). It used to be rescheduled until the event cap.
  • WORKFLOW_ALREADY_RUNNING is not transient. The running execution may be another one, running for an unbounded time; it stays a failed attempt, as it was.
  • Waiting on OPEN_TIMERS_LIMIT_EXCEEDED is safe: the limit is per execution (1,000 open timers), so this execution's own timers will fire and bring a decision. A decision task timeout adds no DecisionTaskCompleted, so it waits again.
  • The same rule for both timers. The backoff timer and the failure-retry timer wait through one decided_since helper.
  • TIMER_CREATION_RATE_EXCEEDED still loops while SWF throttles. It is an account-wide token bucket (StartTimer: 2,000, refilled at 200/s), so nothing in the execution is sure to wake it: the timer starts again at once, paced by decision round trips. Same choice as the failure-retry timer (Start a refused retry timer again instead of failing the workflow on replay #484).
  • Backoff timer per refusal. The timer id holds the refusal event id, so a fired timer from an earlier refusal never stands for a later one, and it is distinct from the failure-retry timer (__simpleflow_task_<id>). One open timer per waiting activity; their number is bounded by the activities the executor keeps open.
  • Key rename: cancelled_timestamp → canceled_timestamp, plus a new canceled_id. The old key was never written, since its branch never ran, and it could not have been read either: stats and the CLI read f"{state}_timestamp". ActivityTaskEventDict follows. The workflow branch already derived its keys from the state.
  • Behaviour change for canceled activities. Their future is now cancelled instead of pending for ever. futures.wait returns None for it, and canvas groups and chains see cancelled.
  • CLI: tolerant readers, not a fuller parser. The parser could set id and name on a refused schedule, but it cannot for the cancel request, and its entries also feed the decider. Changing the four readers is the smaller change and stays off the decision path.
    • status shows the name, else the refused activity type's name, else the activity id.
    • find_activity skips entries that were never scheduled: there is nothing to run again. Asking for one gives the usual Couldn't find activity.

Tests

New tests, built with simpleflow.swf.mapper.models.history.builder.History:

  • tests/test_simpleflow/swf/test_executor.py
    • TestSentSignalReplay:
      • a directed signal is sent despite a received signal of the same name;
      • a delivered directed signal is not sent again after such a received signal;
      • a self-signal (no target, own workflow_id, own workflow_id and run_id) is found in the received signals;
      • a self-signal not yet received is sent to the workflow's own ids;
      • a signal to another run of its workflow_id is sent.
    • TestRefusedMarkerReplay:
      • a refused marker gives no new RecordMarker decision and a TaskFailed("a_marker", "OPERATION_NOT_PERMITTED") future;
      • a recorded marker wins over a refusal, in both orders;
      • a refusal for another marker name does not count.
    • TestRefusedScheduleReplay:
      • a first ACTIVITY_TYPE_DOES_NOT_EXIST creates the type and schedules again at once (control), and the type is created again on a later refusal (control);
      • each transient cause, and a second ACTIVITY_TYPE_DOES_NOT_EXIST, give a StartTimer and no ScheduleActivityTask;
      • the activity waits while its timer is started and is scheduled once it fires; a refused timer schedules it at once;
      • the delay doubles up to 300 s over 10 refusals, with a distinct timer each time, and restarts at 2 s after a successful schedule;
      • a permanent refusal fails the future (optional activity: the workflow completes) or the workflow (mandatory activity); with retry=2, two refusals are rescheduled and the third fails the workflow;
      • a permanent refusal reaches on_task_failure with the cause, the activity id in event["id"] and attempt_number == 1;
      • two refused activities each get their own cause.
    • TestRefusedChildStartReplay:
      • a first WORKFLOW_TYPE_DOES_NOT_EXIST creates the type and starts the child again at once (control);
      • each transient cause, and a second WORKFLOW_TYPE_DOES_NOT_EXIST, give a StartTimer and no StartChildWorkflowExecution;
      • the child waits while its timer is started and is started once it fires;
      • the delay restarts at 2 s after the child started (it continues at 8 s without the reset);
      • with retry=2, two permanent refusals are started again and the third fails the workflow;
      • a permanent refusal reaches on_task_failure with the cause, the workflow id and attempt_number == 1 (control: this already worked);
      • two refused children each get their own cause.
    • TestRefusedBackoffTimerReplay (it replaces a test that pinned the immediate reschedule):
      • OPEN_TIMERS_LIMIT_EXCEEDED, for an activity and a child workflow: no decision right after the refusal, then the same StartTimer (id and delay) once another event brought a decision;
      • a decision task timeout keeps it waiting;
      • TIMER_CREATION_RATE_EXCEEDED, for both: the same StartTimer at once;
      • OPERATION_NOT_PERMITTED: an optional activity's future fails with the task's cause and the timer's in details; a mandatory one fails the workflow; with retry=2, the third refusal fails it.
    • TestCaseNotNeedingDomain.test_a_retry_timer_refused_for_too_many_open_timers_waits_for_the_next_decision, after 0 and 1 earlier retries: no decision right after the refusal nor after a decision task timeout, then the same StartTimer once another event brought a decision.
    • TestCanceledReplay:
      • a canceled activity, started or not: cancelled future, the workflow completes, and the entry has canceled_id, canceled_timestamp and details;
      • a canceled workflow execution is parsed.
  • tests/test_simpleflow/swf/stats/test_pretty.py:
    • status, get_task and info on a history with a refused schedule, a cancel request for an unknown id and a scheduled activity;
    • info's execution time with a signal as the only task, a signal before an activity, and an activity before a child workflow that is only initiated;
    • info's input with an activity first, a signal first, and no task (control). test_info above pinned the first task's input (None) and now expects the workflow's ({}).
  • tests/test_simpleflow/test_helpers.py: find_activity skips never-scheduled entries and still finds the scheduled one by scheduled_id or activity_id.

Results:

  • Before each fix, with its tests in place:
    • signals: 2 fail (the directed signal, and the signal to another run); the others are controls;
    • markers: 1 fails (the refused marker); the others are controls;
    • canceled: all 3 fail (both activity subtests and the workflow test);
    • CLI: all 4 fail, with the four KeyErrors listed above;
    • info timestamps: all 3 fail, with KeyError('signaled_timestamp') or KeyError('start_initiated_timestamp');
    • info input: the activity-first and signal-first tests fail with the task's input; the no-task control passes;
    • refused schedules: 9 of the 11 tests fail, every one rescheduling at once; the 2 controls pass;
    • refused child starts: the transient, timer, retries and two-children tests fail (transient causes fail the workflow, retry=2 starts the child for ever, both children get the first cause); the 2 controls pass;
    • refused backoff timers: all 7 cases fail, each scheduling the task again at once;
    • refused failure-retry timer: both subtests fail, starting the timer again at once.
  • Full suite as CI runs it (uv run --frozen --all-extras --group=dev pytest): 495 passed, 10 skipped, 3 xfailed (508 collected). The same with AWS_CREDENTIALS set in the shell, which used to send 3 tests to the real SWF.
  • Order: every test file run alone passes, and all of them in reverse order pass. Before:
    • test_executor.py alone: 3 failed, UnrecognizedClientException from the real SWF;
    • test_executor.py + test_dataflow.py -k "Refused or schedule_failed": test_activity_not_found_schedule_failed failed the same way;
    • reverse order: test_metrology failed with a HeadObject 404 (the old test_settings.py then test_metrology.py reproduces it).
  • uvx prek run --all-files is clean.

Not addressed

  • Nothing known.

🤖 Generated with Claude Code

ybastide and others added 4 commits November 28, 2026 19:07
find_signal_event looked a SignalTask up in history.signals first, by
name only. history.signals holds the signals this workflow received, so
it says nothing about a signal this workflow sends to another one.

Failure scenario: a workflow receives "a_signal" and then submits
signal("a_signal", workflow_id="other"). The received signal was taken
for the task's event, the future was finished with the received input,
and no SignalExternalWorkflowExecution decision was ever made. The other
workflow never got the signal.

The received signals are now consulted only for a signal the workflow
sends to itself: no workflow_id, or its own workflow_id with no run_id
or its own run_id. Anything else is matched against the deliveries and
the in-flight or refused sends, as before. A signal to another run of
the same workflow_id is a directed signal.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
find_marker_event kept only "recorded" markers, so a marker SWF refused
(RecordMarkerFailed, parsed as "record_failed") was never found.
_get_future_from_marker_event did have a branch for it, but it tested
state == "failed", a state the parser never writes.

Failure scenario: the decider's IAM policy denies RecordMarker, the only
documented cause (OPERATION_NOT_PERMITTED). Each replay found no event
for the MarkerTask and issued RecordMarker again; each refusal schedules
a new decision task, so the workflow looped on the same refused decision.

find_marker_event now returns, in order: the latest recorded marker with
the task's details, else the latest refusal for that marker name. The
future branch tests "record_failed" and yields TaskFailed(name, cause).
RecordMarkerFailed has no details, so a refusal cannot be tied to one
MarkerTask: it stands for every not-yet-recorded marker of that name.

The history builder gains add_marker_record_failed.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Event states are the SWF event type name minus its prefix, snake_cased:
ActivityTaskCanceled and WorkflowExecutionCanceled both give "canceled".
Two parser branches in history.py tested "cancelled", so they never ran
and both events were dropped.

Failure scenario, activity: an activity is canceled (cancel requested,
then ActivityTaskCanceled). The entry stayed "cancel_requested", or
"started"/"scheduled" without a request, so the executor's own
state == "canceled" branch was unreachable: the future stayed pending,
the activity kept counting as open, and a workflow waiting on it blocked
until its own timeout.

Failure scenario, workflow: History.workflow kept state "started" for a
canceled execution (visible in the CLI's history dump).

Both branches now test "canceled". The activity branch wrote a
"cancelled_timestamp" key that no reader could find: stats and the CLI
read f"{state}_timestamp". It now writes "canceled_timestamp" and
"canceled_id", like the other terminal states, and ActivityTaskEventDict
follows. The workflow branch already derived its keys from the state.

The history builder gains add_activity_task_cancel_requested,
add_activity_task_canceled and add_workflow_execution_canceled.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Two kinds of activity entries lack the keys of a scheduled one:
- a refused schedule (ScheduleActivityTaskFailed) with no earlier
  ActivityTaskScheduled has state, cause and activity_type, but no id,
  name, version, input nor scheduled_id;
- a cancel request for an activity id the history does not know has an
  id, but no name, version, input nor scheduled_id.

Failure scenario: on a workflow whose history holds such an entry,
`simpleflow workflow.tasks` raised KeyError('name') (pretty.status),
`workflow.info` raised KeyError('input') when the entry was the first
task (pretty.info), `task.info` raised KeyError('id') (pretty.get_task)
and `activity.rerun` raised KeyError('scheduled_id') before reaching the
activity asked for (helpers.find_activity).

The readers now tolerate the missing keys, rather than the parser
inventing them: these entries feed the decider too, and it was not
worth changing what it sees for a display problem.
- status shows the name, else the refused activity type's name, else
  the activity id;
- get_task falls back on the task id and the refused activity type, and
  on None for the input;
- info reports no input instead of raising;
- find_activity skips entries that were never scheduled: there is
  nothing to run again, so asking for one gives the usual
  "Couldn't find activity."

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
ybastide and others added 3 commits November 28, 2026 23:39
…k has no state timestamp

pretty.info computed the execution time from the first and last entries
of history.tasks, reading f"{state}_timestamp" from them. Two kinds of
task have no such key:

- a received signal ("signaled") carries a plain `timestamp`;
- a child workflow not started yet ("start_initiated") carries
  `initiated_event_timestamp`.

So a history whose first task is a signal raised
KeyError('signaled_timestamp'), and one whose first or last task is a
child workflow still waiting to start raised
KeyError('start_initiated_timestamp'). The last task already fell back
to `timestamp`; the first did not.

get_task_timestamp reads the state timestamp, then `timestamp`, then
`initiated_event_timestamp`, and info uses it for both ends. The
execution time keeps its meaning: last task minus first task.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
pretty.info filled its `input` column from the first task of the
history: the first activity's or child workflow's input, or the first
received signal's. Only a history with no task fell back to the
workflow's input, from the first event.

The input now always comes from the first event,
WorkflowExecutionStarted. The parser already relies on it being first
(event ids start at 1). An absent SWF input decodes to {}.

The existing test_info pinned the first task's input (None); it now
expects the workflow's ({}).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A ScheduleActivityTaskFailed entry made the executor schedule the
activity again in the next decision, whatever the cause. SWF answers a
failed decision with a new decision task, so a refusal that does not go
away (deprecated type, missing default timeout or task list,
OPERATION_NOT_PERMITTED) looped until the execution hit its event cap,
and a rate or limit refusal was retried at full speed.

Transient causes (ACTIVITY_CREATION_RATE_EXCEEDED,
OPEN_ACTIVITIES_LIMIT_EXCEEDED, ACTIVITY_ID_ALREADY_IN_USE,
ACTIVITY_TYPE_DOES_NOT_EXIST) now start a timer, and the activity is
scheduled again once it fires. The delay is 2^n seconds for the n-th
refusal in a row, capped at 300 s; a successful schedule resets n. The
first ACTIVITY_TYPE_DOES_NOT_EXIST still creates the type and schedules
again at once, as before; later ones create it and wait. The timer id,
__simpleflow_schedule_<refusal event id>_<activity id>, is distinct per
refusal and from the failure-retry timer (__simpleflow_task_<id>), so a
fired timer from an earlier refusal never stands for a later one.

Any other cause is a failed attempt: the task's future fails with
TaskFailed(<activity id>, <cause>) and goes through handle_failure, so
raises_on_failure, `retry` and on_task_failure apply. Refusals do not
increment the history's `retry`, so the failure context's event gets
`retry` = earlier failures + refusals in a row - 1, the value a failed
execution would have had. Each retry that is refused again raises it,
so the default handling stops after `retry` attempts and attempt-based
stop strategies in on_task_failure stop too. Before, a deprecated type
or a missing default was rescheduled until the event cap; a mandatory
activity now fails its workflow.

History: a schedule_failed entry now carries id (the activity id),
schedule_failed_id, schedule_failed_count and the refusal's
decision_task_completed_event_id. schedule_failed_id lets
handled_failures key a never-scheduled entry (get_event_id returned
None for all of them, so two refused activities in one replay shared
one outcome). The decision id is what do_handle_failure's timer lookup
reads; it raised KeyError on a never-scheduled entry. on_task_failure
implementations read event["id"].

If the backoff timer itself is refused (e.g. OPEN_TIMERS_LIMIT_EXCEEDED),
the activity is scheduled again at once.

Not changed: a child workflow's refused start still goes through the
default retry handling without incrementing `retry`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ybastide ybastide changed the title Fix four replay and bookkeeping bugs: directed signals, refused markers, canceled events, CLI on refused schedules Fix replay and bookkeeping bugs: directed signals, refused markers and schedules, canceled events, CLI Nov 29, 2026
ybastide and others added 6 commits November 29, 2026 01:31
A StartChildWorkflowExecutionFailed other than WORKFLOW_TYPE_DOES_NOT_EXIST
became a TaskFailed future through handle_failure, and the default
handling compared the history's `retry` with the child's: refusals never
incremented `retry`, so a child with retry > 0 was started again on
every decision until the execution hit its event cap. A rate or limit
refusal failed the attempt instead of waiting, and a missing type was
created and started again at once, for ever if the refusal persisted.
Two children refused before being initiated (initiatedEventId is 0 for
every cause but WORKFLOW_ALREADY_RUNNING) also shared one
handled_failures entry: get_event_id returned None for both.

resume_refused_activity becomes resume_refused_task, used by both
resume_activity and resume_child_workflow:

- transient causes (CHILD_CREATION_RATE_EXCEEDED,
  OPEN_CHILDREN_LIMIT_EXCEEDED, OPEN_WORKFLOWS_LIMIT_EXCEEDED,
  WORKFLOW_TYPE_DOES_NOT_EXIST for children) start a timer
  __simpleflow_<refusal state>_<refusal event id>_<task id>, delay 2^n s
  capped at 300 s; the first missing type is created and tried again at
  once;
- any other cause is a failed attempt, with
  `retry` = earlier failures + refusals in a row - 1.

WORKFLOW_ALREADY_RUNNING stays a failed attempt: the running execution
may be another one, for an unbounded time.

History: a child start_failed entry gains start_failed_count, reset when
the child starts, and get_event_id knows start_failed_id. The type
creation moves to create_workflow_type; create_activity_type skips a
type already created in this replay. The activity backoff timer is now
named __simpleflow_schedule_failed_<id>_<task id>.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…used

When SWF refused the StartTimer of a refused activity or child
workflow, resume_refused_task scheduled the task again at once. Under
OPEN_ACTIVITIES_LIMIT_EXCEEDED plus OPEN_TIMERS_LIMIT_EXCEEDED that is
a loop: task refused, timer refused, task refused..., two decisions per
turn, until a limit clears or the execution hits its event cap.

Now, by the timer's cause:

- OPEN_TIMERS_LIMIT_EXCEEDED: the limit is per execution (1,000 open
  timers), so this execution's own timers will fire. The decision that
  the refusal brings waits (pending future, no decision); a later
  decision, i.e. one after a DecisionTaskCompleted that follows the
  refusal, starts the same timer again. A decision task timeout adds no
  DecisionTaskCompleted, so it waits again.
- TIMER_CREATION_RATE_EXCEEDED: start the same timer again at once.
  This is an account-wide token bucket (StartTimer: 2,000, refilled at
  200/s); nothing else is sure to wake the execution, so this stays a
  loop paced by decision round trips while SWF throttles. Same choice
  as the failure-retry timer (#484).
- anything else (OPERATION_NOT_PERMITTED, TIMER_ID_ALREADY_IN_USE): a
  failed attempt, through the same path and attempt count as a
  permanent refusal. TaskFailed keeps the task's refusal cause as
  reason; details name the timer and its cause.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…imers limit

do_handle_failure treats a refused failure-retry timer
(__simpleflow_task_<id>) with a cause in
TRANSIENT_START_TIMER_FAILED_CAUSES as never started, and asks
on_task_failure again, which starts the same timer again in the same
decision. For OPEN_TIMERS_LIMIT_EXCEEDED that is a loop, timer refused,
timer started again, refused..., until a timer of the execution happens
to fire between two turns.

The limit is per execution (1,000 open timers), so this execution's own
timers will fire and bring a decision. Now the decision that the
refusal brings returns a pending future and no decision; a later one,
i.e. after a DecisionTaskCompleted that follows the refusal, starts the
timer again as before. A decision task timeout adds no
DecisionTaskCompleted, so it waits again. TIMER_CREATION_RATE_EXCEEDED
still starts it again at once, as #484 chose.

Same rule as for the backoff timer of a refused task, through the same
decided_since helper.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
tests.data.constants builds DOMAIN = Domain("TestDomain") at import,
which creates the SWF boto3 client and caches it for the process
(boto3_utils.get_or_create_boto3_client). moto 4 hooks into botocore
when it is imported and only stubs clients created after that. When the
first test module imports tests.data.constants before anything imports
moto, every later @mock_swf test reuses an unstubbed client and calls
the real SWF endpoint, failing with UnrecognizedClientException (with
the fake keys from pytest's env) or worse with real credentials.

Two orders hit it: test_executor.py run alone (3 MockSWFTestCase tests),
and test_executor.py with test_dataflow.py under
-k "Refused or schedule_failed" (test_activity_not_found_schedule_failed).
The full run passed only because an earlier module imported moto first.

tests/conftest.py imports moto, and pytest loads it before any test
module.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
test_overriding_a_setting left METROLOGY_PATH_PREFIX = "123" (and
test_change_multiple_settings left FOO and BAR) in simpleflow.settings
for the rest of the process. test_metrology, run after it, uploaded
under 123/local/local/ and read local/local/activity.0.json back:
HeadObject 404. The default order runs test_metrology.py before
test_simpleflow/, which is why it passed.

setUp patches the module's namespace with mock.patch.dict and swaps
_keys for a copy, since put_setting adds to it in place.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Both branches add tests to tests/test_simpleflow/swf/test_executor.py; keep both.
@ybastide
ybastide merged commit 8775a06 into main Nov 29, 2026
8 checks passed
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