Open
Conversation
Contributor
Author
|
Might also want SDK's blessing on this (hence @thomasjpfan tag)? |
thomasjpfan
reviewed
Mar 27, 2026
| # This function follows a scripted sequence to demonstrate the behavior: | ||
| # | ||
| # 1. **Call 1** — raises `TimeoutError` (retryable → Modal retries) | ||
| # 2. **Call 2** — raises `ConnectionError` (retryable → Modal retries) |
Contributor
There was a problem hiding this comment.
Do we have a list of exceptions that we'll retry? Do users want to configure their function so they can control when their retries?
I'm thinking of:
@app.function(retries=modal.Retries(max_retries=5, initial_delay=1.0))
def my_func():
try:
my_custo_funcdtion()
except MyCustomException as exc:
raise ModalRetriableError(...) from exc # signal to model that we want to retry.
Contributor
Author
There was a problem hiding this comment.
Do users want to configure their function so they can control when their retries
I have only gotten this request twice in the last year, so possibly not often enough to dedicate engineering...
Do we have a list of exceptions that we'll retry
Right now, retries are configured based on task status, and there is no exception filtering.
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.
Type of Change
This is a bit of a workaround for "custom retries" (i.e. retrying via
modal.Retrieson some exceptions, and circumventing retries on other, more fatal errors). It's based on this demo I made for Achira last year, and I'm bringing it up again because another customer asked for it here.The demo follows a scripted sequence of errors that requires each function execution to "know" which iteration it's on. This is accomplished with a

modal.Dictbut could potentially simplify this by perhaps choosing a random error? (but then, it's random)Monitoring Checklist
lambda-test: falseis provided in the example frontmatter and I have gotten approval from a maintainermodal run, or an alternativecmdis provided in the example frontmatter (e.g.cmd: ["modal", "serve"])cmdwith no arguments, or theargsare provided in the example frontmatter (e.g.args: ["--prompt", "Formula for room temperature superconductor:"]fastapito be installed locally (e.g. does not importrequestsortorchin the global scope or other code executed locally)Documentation Site Checklist
Content
modal-cdn.comBuild Stability
v1, not a dynamic tag likelatestpython_versionfor the base image, if it is used.debian_slim(add_python=...)?~=x.y.zor==x.y, or we expect this example to work across major versions of the dependency and are committed to maintenance across those versionsversion < 1are pinned to patch version,==0.y.zOutside Contributors
You're great! Thanks for your contribution.