restatedev / restatedev/sdk-python
RestateModelWrapper should not wrap `SdkInternalBaseException` as generic Exception; classify non-retryable provider errors as terminal
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 81
- Forks
- 22
- Avg merge
- 2d 2h
- Merged PRs (30d)
- 2
Description
When a journaled model step fails, Restate correctly uses SdkInternalException for replay control flow. The wrapper then does:
except SdkInternalBaseException as e:
raise Exception("Internal error during model call") from e
This conflicts with Restate’s Python error-handling guidance (re-raise internal exceptions; don’t catch them as generic Exception). Integrators must walk __cause__ chains to recover semantics.
For LLM provider non-retryable 4xx (e.g. invalid tool schema → HTTP 400), the failure should be TerminalError inside the journaled step, not a retryable transient. Otherwise Restate retries permanently invalid requests—contrary to the AI integration guide (“handle terminal errors”, bound LLM retries).
Proposed behavior:
except SdkInternalBaseException as e:
if isinstance(e, SuspendedException):
raise
# Optional: inspect e.__cause__ for provider HTTP errors
if is_non_retryable_provider_4xx(e.__cause__):
raise TerminalError("Model request rejected by provider", status_code=400) from e.__cause__
raise # re-raise SdkInternalBaseException unchanged — do NOT wrap in Exception(...)
Policy suggestion for upstream defaults:
| Provider status | Treatment |
|---|---|
| 400, 401, 403, 404, 422, … | TerminalError (non-retryable) |
| 408, 429 | Retryable (existing transient path) |
| 5xx | Retryable per RunOptions |
Proposals:
- Stop wrapping SdkInternalBaseException in generic Exception.
- Either adopt a default provider-status policy or expose a hook on RestateAgent / RestateModelWrapper for classifying model failures before journaling.
- Document recommended RunOptions(max_attempts=…) for LLM journal steps.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at RestateModelWrapper and trace the SdkInternalBaseException handling through journaled model steps and provider failures. Compare the behavior with the linked Python error-handling and AI integration guidance. Done means internal exceptions are re-raised unchanged, non-retryable provider 4xx failures become terminal, retryable statuses follow RunOptions, and the selected policy or hook is documented.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- ai, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100