redis / redis/agent-memory-server

Docket worker cannot serialize litellm exceptions after task failure

Open
#231 0 comments 0 reactions 1 assignee View on GitHub

@bsbodden is already working on this.

Since Mar 19, 2026.

bug
Dominant language
Python
Stars
316
Forks
63
Avg merge
14d 23h
Merged PRs (30d)
1

Description

When a background task fails with a litellm exception (rate limit, timeout, connection error, etc.), the docket worker cannot serialize the exception for the result queue.

What happens

docket/worker.py calls cloudpickle.dumps(e) on any exception from a failed task. The dumps succeeds, but cloudpickle.loads() later tries to reconstruct the exception by calling ExceptionClass.__init__() without arguments. litellm exception classes require message, model, and llm_provider as positional args, so this raises TypeError.

The worker can't store or report the error. The task silently disappears.

Affected classes

All litellm exception types: APIConnectionError, RateLimitError, Timeout, ServiceUnavailableError, BadRequestError, AuthenticationError, NotFoundError, ContentPolicyViolationError, InternalServerError, BadGatewayError, PermissionDeniedError, UnprocessableEntityError, APIError, APIResponseValidationError, ContextWindowExceededError.

Reproduction

import cloudpickle
import litellm

exc = litellm.exceptions.RateLimitError(
    message="rate limited", model="gpt-4", llm_provider="openai"
)
data = cloudpickle.dumps(exc)
cloudpickle.loads(data)  # TypeError: __init__() missing required positional arguments

Fix

Monkey-patch __reduce__ on litellm exception classes so cloudpickle reconstructs them via Exception.__new__() + __dict__ restoration, bypassing __init__. See agent_memory_server/litellm_pickle_compat.py.

The root cause is upstream in litellm — their exception classes don't implement pickle protocol methods. Reported separately there.

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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.