Conversation
|
Might also want SDK's blessing on this (hence @thomasjpfan tag)? |
| # 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) |
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.
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.
There was a problem hiding this comment.
In this example, is the proposal to have users do this?
try:
my_custom_function()
except MyCustomException as exc:
raise ConnectionError("manually trigger retry")There was a problem hiding this comment.
Since modal.Retries will catch all exceptions in general, it depends which approach makes sense for the app.
This would be the pattern for e.g. an inference app that should retry except for specific circumstances (e.g. invalid input)
try:
custom_f()
except CRASHABLE_EXCEPTIONS as exc:
return exc # bypass modal.Retries
else:
raise # triggers retry
This would be the pattern for e.g. a training function that should always crash except for timeouts
try:
custom_f()
except modal.exception.ExecTimeoutError as exc:
raise exc # use modal.Retries
else:
return # something's wrong , stop retrying
There was a problem hiding this comment.
User wise, I guess it's hard to know what the crashable exceptions are.
| # 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) |
There was a problem hiding this comment.
User wise, I guess it's hard to know what the crashable exceptions are.
|
|
||
| # Return instead of raise — Modal sees success, stops retrying | ||
| print(" -> non-retryable, returning error to stop retries") | ||
| return error |
There was a problem hiding this comment.
DevX wise, is it good to have Modal see a success here? It kind of hides the failure in the UI, etc.
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.