[FEAT] Improve Python SDK reliability, retries, and failure diagnostics
The Python SDK can currently surface generic or low-context errors when encountering common failure scenarios such as server unavailability, timeouts, or partial workflow registration failures. In both local development and production environments, this can make it difficult for users to quickly determine whether an issue is caused by connectivity, configuration problems, or transient infrastructure issues.
I’d like to improve the reliability and debuggability of the Python SDK by making these failure modes more explicit and easier to reason about. This would include centralizing request error handling, introducing clearer and more actionable exceptions for common scenarios, adding configurable timeout and retry behavior where appropriate, and improving healthcheck robustness while preserving backward compatibility with existing SDK usage.
While documenting common failure cases is an alternative, improving behavior directly in the SDK provides better defaults and faster feedback for users running Hatchet workflows in production. I’m happy to approach this incrementally and align on scope before implementation, and wanted to confirm that this is an area where contributions and potential longer-term ownership would be welcome.
hey @TheEleventhAvatar, would love to see a detailed sketch of your vision here before implementation to get a sense for what you’re thinking and make sure we’re aligned, but definitely agree with the broader goal!
That sounds good, happy to sketch it out.
At a high level, my thinking is to keep this incremental and non-invasive, focusing first on making existing failure modes easier to understand rather than changing behavior.
The initial scope I have in mind would be:
- Introduce a small, explicit exception hierarchy for the Python SDK (e.g. connection errors, timeouts, unexpected server responses) to replace generic exceptions while preserving existing control flow.
- Centralize request execution and error translation in a single place, so retries, timeouts, and diagnostics aren’t scattered across the SDK.
- Add conservative, opt-in timeout and retry defaults that can be configured, but do not change behavior for existing users unless explicitly enabled.
- Improve healthcheck failure reporting to clearly distinguish between connectivity issues and server-side readiness.
I’d plan to tackle this in small PRs (starting with exception normalization and centralized request handling), and avoid any breaking changes. If helpful, I can write up a more concrete proposal or pseudo-code for the first step before starting.
Let me know if this direction aligns with how you’re thinking about it, or if there’s a specific area you’d prefer to prioritize first.
~Sure, great! We have lots of improvements to our documentation that we need, in particular. And I'm also in favor of improving error messages to be more helpful. Happy to take a look if you give it a shot!~
Whoops, replied this in the wrong issue.
For this one, let me think about this for a bit and report back!
Okay, so I do think this is a good idea - would be happy to review PRs here. Some of these (e.g. the second) might prove to be more challenging than others, but would definitely like to see improvements on all of these fronts!
I have opened a small, scoped PR that improves Python SDK transport error diagnostics without changing retry behavior.
This addresses the diagnostics side of the issue; happy to follow up on retries separately if helpful.
I’ve split work on this issue into a few small, incremental PRs:
- PR #2942: improved Python REST client transport error diagnostics
- PR #2968: typed REST transport exceptions + improved diagnostics (no retry behavior changes)
- PR #2971: tests covering the current Tenacity retry predicate for REST + gRPC (documents existing behavior only)
The tests show the current policy:
- REST: retries
ServiceException(5xx) andNotFoundException(404) - gRPC: retries most errors except a small set of clearly permanent status codes
- REST transport errors (timeouts / connection / TLS / protocol) are not retried
Before proposing any behavior changes, such as whether or not 404s should be retried, whether transport errors should be retried, or how to handle 429, could you share preferred retry policy direction for the SDK? Especially for mutating operations where retries may duplicate side effects?
Happy to follow up with a small PR that aligns with whatever policy you prefer.
Thanks for the follow up! I think the current behavior is mostly correct with a couple caveats:
- We probably should be retrying timeouts, connection issues, etc.
- We ideally would have retry behavior be more configurable. I'm not too sure what this looks like yet (there's a bit of a hack to allow retries to be shut off via the client config, but that's it), but it'd be better to allow the client to have more granular control, if possible.
For mutating operations, we probably should not retry in most cases, although I'm wary of breaking changes here - there's more work to do on idempotency on the backend to make this safer.
Let me know if you have more questions here! Happy to discuss, lots to consider
Thank you @mrkaye97!
I can follow up with a small, conservative PR that retries REST transport errors without changing semantics for mutating operations.
Proposed scope for a first step:
- Retry
RestTransportError, but only for clearly idempotent requests, such asGET. - Leave current behavior unchanged for mutating ops for now.
- Add focused tests that assert
GETis retried while mutating verbs such asPOSTare not.
Before I begin, a couple quick contract questions to make sure this lines up with your expectations:
-
Are there any non
GETendpoints you would want treated as retryable, such asDELETEwhich is typically idepotent by nature, or should we strictly limit the initial change toGETuntil backend idempotency guarantees are stronger? -
On configurability: since we already have
TenacityConfigand a minimal retry hook, would you prefer:- keeping this PR non-configurable with retries having fixed behavior, and layering configurability later, or
- starting to extend existing config in a small way as part of this change?
Great!
- I'd say deletes are fine to retry, but honestly other than that it's a bit tricky to come up with a hard and fast rule. For instance, there are situations where retrying a POST should be fine, like creating a webhook (since if there's a duplicate name it'll just get rejected by the API), but I think not retrying these initially is fine
- I think starting to extend the config here is a reasonable strategy! I think maybe adding some more options to the tenacity config could be a good place to start, but happy to defer to you there
Thank you @mrkaye97!
I will do a small, conservative next PR that extends TenacityConfig to make REST retries more configurable, starting with transport level failures (timeouts / connection level errors) and scoping them to idempotent methods: GET, DELETE.
Plan for the next PR (no default behavior change):
- Add
TenacityConfigoptions to enable retryingRestTransportErrorfor a configurable set of REST methods (default: off; methods default toGETplusDELETEwhen enabled). - Keep existing retry behavior for HTTP errors (5xx / 404) unchanged.
- Add tests that prove: default = no transport retries; opt-in = retries for
GETplusDELETEonly.
Thanks for driving this forward @BloggerBust — really appreciate the thoughtful incremental approach and the detailed tests.
I’m glad to see the work broken down into transport diagnostics, retry predicate coverage, and configurable Tenacity improvements — that aligns well with the incremental direction I had in mind.
I’ll follow along on the TenacityConfig PR and review as well. If helpful, I’m also happy to focus on adjacent pieces like:
- gRPC parity for transport retry handling
- improving healthcheck error clarity
- documenting retry semantics once the policy stabilizes
Let me know if there’s a specific area that would be most useful to tackle next.
Thank you, I appreciate that!
I will wait for feedback on the TenacityConfig PR so we can stabilize the retry policy first. After that, documenting semantics and exploring parity areas like gRPC transport handling would make a lot of sense.
Thanks — that makes sense 👍
While we wait for the TenacityConfig PR to stabilize, I’ll start drafting documentation around the current retry semantics so behavior is explicit and easier to reason about.
I’m thinking of covering:
Current REST retry behavior (5xx / 404 / transport errors)
gRPC retry predicate behavior and differences from REST
How TenacityConfig affects both
Explicit notes around idempotency and mutating operations
Once the policy settles, we can align the docs with the final behavior.
After that, I can explore gRPC transport retry parity in a similarly incremental way — starting with diagnostics and tests before behavior changes.
Let me know if there’s a preferred place for the retry semantics documentation (SDK README vs docs site vs dedicated section).
Hi @mrkaye97,
I wanted to sanity check the intended retry semantics before expanding the policy further.
PR #3003 adds opt-in retries for REST transport failures, scoped by HTTP method. Default behavior remains unchanged.
Today, retry behavior looks like:
- REST: retries 5xx and 404 by default; transport errors are retried only if
retry_transport_errors=Trueand the method is inretry_transport_methods. - gRPC: retries most status codes except
{UNIMPLEMENTED, NOT_FOUND, INVALID_ARGUMENT, ALREADY_EXISTS, UNAUTHENTICATED, PERMISSION_DENIED}.
While reviewing the full call paths, I noticed a few semantic differences between REST and gRPC:
- REST retries 404, but gRPC
NOT_FOUNDis not retried. - gRPC retries
RESOURCE_EXHAUSTED(rate limiting / overload), but REST 429 is not currently retried. - For REST transport retries, the HTTP method is inferred by parsing
method=...from the exceptionreasonstring. This works, but it couples retry behavior to formatting inrest.py.
Before expanding retry behavior further, I would like to confirm intent:
- Is retrying 404 an intentional eventual consistency stance? If so, should it eventually be scoped (e.g., by HTTP methods GET/HEAD only)? And should gRPC
NOT_FOUNDalign? - Should REST gain an opt-in 429 policy, with bounded backoff /
Retry-After, to mirror gRPCRESOURCE_EXHAUSTED? - For gRPC, should retry behavior eventually distinguish between read-style RPCs (Get*/List*) and mutating RPCs (Trigger*/Put*/Create*) instead of applying a uniform retry policy?
If helpful, I can:
- update #3003 to pass the HTTP method explicitly for REST transport retry evaluation, thereby avoiding parsing it from the exception message, and/or
- follow up with a short doc PR clarifying current retry semantics and recommended production settings.
Thanks for the questions!
- If I understand correctly, then yeah - the reason we retry 404 over the REST API is that there's often some replication lag as we move data from the core db (which the gRPC API is hooked up to) and the OLAP db, which is what the REST API (largely) relies on.
- Yep, definitely - I'm surprised we're not retrying 429, actually. We probably should be by default, honestly
- Yeah, this seems reasonable to me
This issue has been stale for 90 days. Please update the issue or comment to keep it active. Otherwise, it will be closed in 5 days.