restatedev / restatedev/sdk-python

RestateModelWrapper should not wrap `SdkInternalBaseException` as generic Exception; classify non-retryable provider errors as terminal

Open
#225 0 comments 0 reactions 0 assignees View on GitHub

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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.