Repository navigation
Keep the worker running through a Server failover's 500 and 503 - #383
Merged
Merged
Conversation
A Cloud HA run (durable-workflow/cloud#752, run 2) saw the Server answer HTTP 500 during a database failover; the PHP SDK worker exited. The Python pollers and heartbeats already rode that out, but three gaps remained: - A 500 without a protocol reason was not transient. An activity completion or failure report hit by one was dropped after the client's three quick attempts, and registration hit by one stopped Worker.run(). It is now transient like an upstream 502/503/504. Typed 5xx reasons, retryable: false and 4xx refusals keep their handling. - A workflow-task completion was given up after about a second. A transient failure is now resent with the shared backoff while the task's lease_expires_at covers the next wait (60 s when unknown). Each resend carries the same task, lease owner, attempt and commands, so lease fencing is unchanged. Other retryable failures keep the three-attempt budget. - Retry-After was ignored. Errors raised for HTTP responses now carry the parsed value (delta-seconds or HTTP-date) as retry_after. Polls, registration, activity outcomes and workflow-task completions wait at least that long, capped at 60 s, and TransportRetryPolicy honours it up to max_backoff_seconds. Retry waits go through an injectable Worker._retry_sleep. The new tests drive a fake Server through 500, 503 with Retry-After, then success for polling, activity completion and a replayed workflow-task completion (new replay-regression fixture), and check the bounded waits. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The Server answers a database failover with
500 {"reason":"server_error",...}. Count that generic reason as transient
like an untyped 5xx, so registration, activity outcomes and workflow-task
completions retry it. Typed reasons and retryable:false stay definitive.
The fake-Server failover test now sends the Server's real body.
A Retry-After value longer than ten digits is treated as a very long wait
(callers cap it) instead of raising OverflowError or ValueError.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Member
Author
|
Independent review: PASS at
Non-blocking items to pick up later:
🤖 Generated with Claude Code |
rmcdaniel
enabled auto-merge (squash)
November 26, 2026 00:50
rmcdaniel
disabled auto-merge
November 26, 2026 00:51
Member
Author
|
Delta check: I updated the branch with a merge from main. The new head is |
rmcdaniel
enabled auto-merge (squash)
November 26, 2026 00:51
|
This was referenced Nov 26, 2026
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.



Follow-up to a finding from the Cloud HA run in durable-workflow/cloud#752 (run 2). During a database primary failover, the Server answered an activity poll with HTTP 500, and the PHP SDK worker exited. This PR checks the Python worker for the same failure and closes the gaps it found.
What already held
So
Worker.run()did not exit on a poll-time 500.Gaps fixed
Plain HTTP 500 was not transient.
_transient_runtime_errorcovered only 502, 503 and 504 without a protocol body. A 500 such as{"message": "Server Error"}was not transient, which caused two problems:POST /worker/registerstoppedWorker.run()at startup.It is now transient, with the same rule as 502/503/504: no typed
reason. A 5xx with a typedreason,retryable: false, 501, and every 4xx keep their current handling.Workflow-task completion gave up after about 1 s. It made 3 worker attempts × 3 transport attempts and then dropped the completion, so the task waited for its lease to expire. Transient failures are now resent with the shared backoff
uniform(0, min(4, 0.25·2^(n-1)))while the task'slease_expires_atcovers the next wait, or for 60 s when the lease is unknown. When the lease runs out the worker logs an error. Each resend has the same task ID, lease owner,workflow_task_attemptand commands, and the request bytes are identical, so lease fencing is unchanged. Lease and attempt refusals of a resend are still never reported as a workflow-task failure. Other retryable errors, such as a typed 5xx or a builtinTimeoutError, keep the 3-attempt budget.Retry-Afterwas ignored everywhere. The client now parses the header, in both the delta-seconds and HTTP-date forms, intoDurableWorkflowError.retry_after. Polls, registration, activity outcomes and workflow-task completions wait at least that long, capped at 60 s.TransportRetryPolicyhonours it between its own attempts, capped atmax_backoff_seconds.Unchanged on purpose
/failreports: the Server redelivers the task at lease expiry, and replay fails it again.Tests
tests/test_worker_transient_5xx_retry.pydrives a fake Server (httpx.MockTransportwith a realClient) through 500, then 503 withRetry-After, then success, with sleeps injected throughWorker._retry_sleep:Worker.run()end to end: covers the activity poll and the activity completion. It asserts that the worker is still running, the completion was delivered once, and the waits are[0.25, 2.0](delta-seconds) and[0.25, ≤3](HTTP-date).failover-completion-resend-cold-history, which is also registered in the corpus harness. It checks three byte-identical sends and that the expected result is delivered.Retry-After: 86400is capped at 60 s. Resending stops when the lease runs out. A typed 5xx keeps 3 attempts. A 409 is not resent.parse_retry_afterhandles both forms, andTransportRetryPolicycaps the header.tests/test_worker_transient_runtime.py: the classification table now expects a bare 500 to be transient, and a new case checks that registration survives repeated 500s.python:3.12(3.12.16): the targeted modules pass, along with ruff, mypy and the regression-corpus validator. The new tests also pass on 3.10.Docs:
docs/reference/worker.mdhas new sections, "Workflow-task completions through transient failures" and "Server failover andRetry-After", and an updated list of transient failures. CHANGELOG: entry under Unreleased → Fixed.🤖 Generated with Claude Code