Skip to content

Preserve exception fields through worker fallback reconstruction - #462

Open
mayankdhingra02 wants to merge 1 commit into
wool-labs:mainfrom
mayankdhingra02:fix/exception-fallback-fields
Open

mayankdhingra02 wants to merge 1 commit into
wool-labs:mainfrom
mayankdhingra02:fix/exception-fallback-fields

Conversation

@mayankdhingra02

Copy link
Copy Markdown

Summary

A worker rebuilds an exception as type(error)(*error.args) when incidental state prevents pickling. Several Wool exceptions currently put a formatted message in args, so reconstruction changes their class, loses typed fields, or formats the message twice. Store their structured constructor fields in args and render messages with __str__.

Closes #439.

Proposed changes

  • Preserve ChainContention, RPC errors, serialization errors and their warning collections, Rejected, and ProtobufImportError through direct reconstruction, pickle and worker frames. Keep local task identities available while putting stable diagnostic representations on the wire. Retain the old contention reconstruction function so existing pickles still load.
  • If an exception-valued constructor field itself has unpicklable attachments, repair its usable arguments and attributes only after the normal fallback paths fail. Memoize shared references and bound recursion; intrinsically unpicklable non-exception arguments and cyclic constructor arguments still use the existing RuntimeError demotion.
  • Document the argument contract: use str(error) for the rendered message. SerializationError now accepts one message plus cause and value_repr, replacing arbitrary positional message arguments.

Test cases

# Test Suite Given When Then Coverage Target
1 Exception reconstruction Each affected exception and RPC subclasses Rebuild from args, pickle, or a worker frame Class, message and typed fields survive Constructor and primary-path identity
2 Exception reconstruction Unpicklable side state Send an exception response frame Fallback warns and preserves structured identity Actual worker serializer fallback
3 Task contention Live task fields Cross two successive wire hops Local task identity remains available; received representations and message stay stable Task-safe arguments and repeated hops
4 Structured exception fields Unpicklable attachments on a cause, original error, or nested warning cause Fall back through the worker frame Usable nested fields and aliases survive Avoid a new demotion caused by structured arguments
5 Subprocess probe Two self-references with unpicklable state, or cyclic constructor arguments Serialize with a ten-second process bound Shared aliases survive; impossible argument cycles demote promptly Bounded graph reconstruction
6 Legacy reduction An old contention reduction naming the legacy helper Unpickle and repickle it All contention kinds load with stable fields and messages Existing pickle compatibility
7 Exception reconstruction Empty RPC fields or an intrinsically unpicklable non-exception argument Reconstruct or send the error Message variants remain stable; unsupported arguments still demote Boundary controls

Validation on Python 3.13.3 / macOS:

  • Unit suite: pytest -m 'not integration' --cov-fail-under=98 -q — 2,851 passed, 1 skipped, 2 expected failures; 98.30% coverage.
  • Integration suite: pytest -m integration --cov-fail-under=70 -q — 422 passed, 1 expected failure; 84.76% coverage.
  • New reconstruction suite: 51 passed. The initial 38-case suite reproduced 20 failures on the original implementation.
  • Pyright: 0 errors and 0 warnings. Ruff lint and format checks pass for all changed Python files.
  • Independent review repeated the affected tests, checked real previous-version pickle/protobuf payloads, and verified shared-reference repair and bounded cycles.

The Linux / Python 3.11–3.13 CI matrix has not run locally.

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.

Preserve an exception's class and fields through the worker serializer's fallback

1 participant