Visitar URL original
fix: make CLI JSON decode errors pickleable by Nandaninaulaa · Pull Request #1489 · anthropics/claude-agent-sdk-python · GitHub
Skip to content

fix: make CLI JSON decode errors pickleable - #1489

Open
Nandaninaulaa wants to merge 1 commit into
anthropics:mainfrom
Nandaninaulaa:codex/fix-cli-json-decode-error-pickling
Open

Nandaninaulaa wants to merge 1 commit into
anthropics:mainfrom
Nandaninaulaa:codex/fix-cli-json-decode-error-pickling

Conversation

@Nandaninaulaa

Copy link
Copy Markdown

Summary

  • Make CLIJSONDecodeError preserve its original constructor arguments during pickle and copy reconstruction.
  • Add regression coverage for both operations.

Closes #1394.

Testing

  • python -m pytest tests/test_errors.py -q (10 passed)

@mangeshraut712 mangeshraut712 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The __reduce__ arguments match the constructor, and the pickle plus copy.copy test is the right regression for a multiprocessing boundary. Two follow-ups: deepcopy is untested, and sibling errors with a custom __init__ still have the same problem.

self.original_error = original_error
super().__init__(f"Failed to decode JSON: {line[:100]}...")

def __reduce__(self) -> tuple[Any, tuple[str, Exception]]:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copy.copy uses this, but the test never runs copy.deepcopy. Worth adding, since a worker may clone the error that way. Also, MessageParseError.__init__(message, data) and ProcessError.__init__(message, exit_code, stderr) will still fail to unpickle with TypeError / a dropped constructor argument for the same reason CLIJSONDecodeError did. If those can also cross a process boundary, they need the same __reduce__ (or a shared helper on ClaudeSDKError). I'd either add them in this PR or note them as a follow-up so they are not forgotten.

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

2 participants