Visitar URL original
fix: CLIJSONDecodeError survives pickle and copy by Sathwik-giddi · Pull Request #1494 · anthropics/claude-agent-sdk-python · GitHub
Skip to content

fix: CLIJSONDecodeError survives pickle and copy - #1494

Open
Sathwik-giddi wants to merge 1 commit into
anthropics:mainfrom
Sathwik-giddi:fix/clijsondecodeerror-pickle
Open

Sathwik-giddi wants to merge 1 commit into
anthropics:mainfrom
Sathwik-giddi:fix/clijsondecodeerror-pickle

Conversation

@Sathwik-giddi

Copy link
Copy Markdown

Problem

CLIJSONDecodeError cannot be reconstructed by pickle or copy, so any multiprocessing boundary it crosses (ProcessPoolExecutor) breaks with BrokenProcessPool instead of surfacing the error.

The default exception reconstruction protocol calls type(e)(*e.args), but e.args holds only the formatted message — one argument short of the (line, original_error) constructor.

Fix

Add a __reduce__ that reconstructs from (self.line, self.original_error), mirroring the protocol ResultError already documents and its existing test test_result_error_survives_pickle_and_copy. This keeps the signature intact and avoids a doubled message (Failed to decode JSON: Failed to decode JSON: ...) that making original_error optional alone would produce, since args holds the already-formatted text.

Testing

  • New test_json_decode_error_survives_pickle_and_copy asserts pickle/copy round-trips preserve line, the original error type, and the message (with a guard against doubling).
  • ruff check, ruff format, mypy clean; full suite passes.

Fixes #1394

The default exception reconstruction protocol calls type(e)(*e.args),
but e.args holds only the formatted message — one argument short of the
(line, original_error) constructor — so pickle, copy, and therefore
multiprocessing/ProcessPoolExecutor fail with a TypeError and take down
the pool. Add __reduce__ that reconstructs from the original inputs,
matching the protocol ResultError already uses.

Fixes anthropics#1394

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CLIJSONDecodeError cannot be pickled or copied, breaking ProcessPoolExecutor

1 participant