Repository navigation
Start a refused retry timer again instead of failing the workflow on replay - #484
Merged
Merged
Conversation
…replay
When on_task_failure asks for a delayed retry, the executor starts the
timer __simpleflow_task_<task id> and, on later replays, looks at it in
do_handle_failure. That method decoded timer["control"] before looking
at timer["state"]. If SWF refused the timer (StartTimerFailed, e.g.
TIMER_CREATION_RATE_EXCEEDED), History.parse_timer_event records a
start_failed entry with no "control", so every replay raised KeyError
and the executor failed the execution with "Cannot replay the workflow:
KeyError('control')". The start_failed branch below was never reached,
and it would have failed the execution all the same: it raised a bare
TaskFailed, which replay also turns into "Cannot replay the workflow".
Read "control" only where it is used, for a fired or canceled timer.
For a refusal SWF may accept later (TIMER_CREATION_RATE_EXCEEDED,
OPEN_TIMERS_LIMIT_EXCEEDED), fall through to the normal failure
handling: on_task_failure decides again and the executor starts the
retry timer again, under the same id. SWF only refuses an id while a
timer with it is open, the refused one never opened, and successive
retries already reuse that id once the previous timer fired. This
mirrors ActivityTaskScheduleFailed, whose activity is scheduled again
on the next decision.
For any other cause (TIMER_ID_ALREADY_IN_USE, OPERATION_NOT_PERMITTED),
treat the task as failed the way an abort decision does: raise the
task's exception with TaskFailed(timer_id, cause) when it raises on
failure, else return its failed future.
History.parse_timer_event kept the decision_task_completed_event_id of
an existing entry when a start_failed arrived for the same id. On a
second or later retry the entry still held the first timer's decision,
which is older than the latest failure, so find_timer_associated_with
ignored the refused timer and the executor started it again whatever
the cause. A start_failed now records its own decision, as a started
timer already does.
The two new replay tests (an activity that fails with a delayed retry,
then a refused retry timer) run with no earlier retry and with one. On
the previous code, a refusal of the first retry timer fails with
KeyError('control') for both causes, and a permanent refusal on the
second retry starts the timer again.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ybastide
added a commit
that referenced
this pull request
Nov 29, 2026
…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>
ybastide
added a commit
that referenced
this pull request
Nov 29, 2026
…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>
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
A workflow no longer fails on replay when SWF refuses the timer behind a delayed retry. A delayed retry is
on_task_failurereturningdecide_retry(retry_wait_timeout=...), which starts the timer__simpleflow_task_<task id>.simpleflow/swf/executor.py,do_handle_failure:timer["control"]only for a fired or canceled timer, where it is used.TIMER_CREATION_RATE_EXCEEDED,OPEN_TIMERS_LIMIT_EXCEEDED), it falls through to the normal failure handling.on_task_failuredecides again, and the executor starts the retry timer again.TIMER_ID_ALREADY_IN_USE,OPERATION_NOT_PERMITTED), it treats the task as failed, the way an abort decision does. If the task raises on failure, the workflow fails withTaskFailed(timer_id, cause). Otherwise the decider gets the task's failed future.simpleflow/history.py,parse_timer_event: astart_failednow records its owndecision_task_completed_event_id, as astartedtimer already does.Why
do_handle_failuredecodedtimer["control"]before looking attimer["state"]. A timer that SWF refused with no earlierTimerStartedis stored with nocontrol. So every replay raisedKeyError('control'), and the executor failed the execution withCannot replay the workflow: KeyError('control').The
start_failedbranch below it was never reached. It would have failed the execution anyway: it raised a bareTaskFailed, whichreplayalso reports as "Cannot replay the workflow". Its arguments were("timer", id, cause); they are now(id, cause), as in_get_future_from_timer_event.There was a second bug, found while testing later retries. When a
start_failedarrived for an id already in the history,parse_timer_eventkept the decision id of the earlier timer. On a second or later retry, that decision is older than the latest failure. Sofind_timer_associated_withignored the refused timer, and the executor started it again whatever the cause. In 0.39.0, a refusal therefore crashed the workflow on the first retry, and on later retries it was re-issued forever even when the cause was permanent.#482 fixed the same kind of
KeyErrorfor plain timers. This is the retry-delay path, which it did not touch.Retry the refused timer, or fail the task?
This PR retries on the two transient causes and fails on the others.
ScheduleActivityTask(ActivityTaskScheduleFailed) is already rescheduled on the next decision, whatever its cause. Failing a long workflow because SWF throttled timer creation for a moment would be worse than retrying.__simpleflow_task_<task id>:find_timer_associated_withlooks the timer up by this fixed id, so a new id would also mean rewriting that lookup.StartTimerFailedtriggers a new decision at once, and that decision re-issues the timer. If SWF keeps refusing, this loops at about four history events per cycle, toward the 25,000-event limit. The activity precedent behaves the same way, and this PR adds no backoff.Tests
tests/test_simpleflow/swf/test_executor.py, built withHistoryBuilder.add_timer_start_failed: an activity fails, the workflow asks for a delayed retry, and SWF refuses the retry timer. Each runs with no earlier retry and with one earlier full retry cycle.TIMER_CREATION_RATE_EXCEEDED: the replay starts the same timer again, with the same id andcontrol. After that timer fires, the activity is scheduled again.OPERATION_NOT_PERMITTED: the replay fails the workflow withWorkflow execution error in activity-tests.data.activities.raise_on_failure: "OPERATION_NOT_PERMITTED".mainwithout this change:KeyError('control');OPERATION_NOT_PERMITTEDtest gets aStartTimer.history.pychange reverted, theOPERATION_NOT_PERMITTEDtest still gets aStartTimerafter one earlier retry.uv run --frozen --all-extras --group=dev pytest):main: 450 passed, 10 skipped, 3 xfailed.test_executor.pyruns on its own, three moto-backed tests in it fail withUnrecognizedClientException(test_submit_resolves_priorityand the two jumbo-field tests). They fail the same way onmain, and they pass in the full suite.uvx prek run --all-filesis clean.Found through the AI review of a Botify dependency bump to 0.39.0. That project retries some activities with a delay, and it needs a release carrying this fix.
🤖 Generated with Claude Code