Repository navigation
Keep ProoflineError typed across pickle, copy and process pools - #51
Open
lavshashank wants to merge 2 commits into
Open
lavshashank wants to merge 2 commits into
lavshashank wants to merge 2 commits into
Conversation
BaseException rebuilds an exception as type(self)(*self.args). ProoflineError
passes only its status message to Exception.__init__, so the rebuild called
ProoflineError("Proofline request failed (HTTP n).") and raised TypeError.
pickle, copy and deepcopy all failed, and one problem raised in a
ProcessPoolExecutor worker broke the whole pool with BrokenProcessPool
instead of reaching the caller.
__reduce__ now rebuilds the error from status, type and detail and restores
title, refusal, repository_name and any notes as state. str and repr are
unchanged, and the token, which redaction already removed, is never part of
the error.
A process pool chains the worker's formatted traceback to the error the parent receives. Assert it names only the status, like repr and str, and carries neither the private detail nor the token.
Member
|
Codex review: Please merge current main and resolve the error/transport/test conflicts while retaining the current structured-error fields and redaction behavior. Rerun the pickle/copy/process-pool regressions and |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
ProoflineErrorcannot be pickled or copied:BaseExceptionrebuilds an exception astype(self)(*self.args).ProoflineError.__init__passes only its status message to
Exception.__init__, soargsis("Proofline request failed (HTTP 403).",), and the rebuild calls the constructor withouttypeanddetail.copy.copyandcopy.deepcopyfail the same way.Motivation
The real-world failure is concurrency. When a
ProcessPoolExecutorworker raises aProoflineError, the parent cannot unpickle it, and the pool shuts down withBrokenProcessPool. With 4 jobs on a 2-worker pool, each getting a 403 from the API, all 4futures fail with
BrokenProcessPool. The caller never sees the status, title, detail ortyped refusal, and unrelated pending jobs fail as well. The same applies to
multiprocessing.Pool,loop.run_in_executorwith a process pool, and task queues thatserialize results with pickle. These are common ways to fan out review exports or review
requests across repositories.
Implementation
proofline/_transport.py:ProoflineError.__reduce__returns(type(self), (self.status, self.type, self.detail), self.__dict__.copy()).Pickle and
copyrebuild the error through its real constructor, then restoretitle,refusal,repository_nameand anyadd_notenotes as instance state. Nothing underproofline/_generated/changes: the attrs refusal models already pickle.README.md: one sentence under "Errors and refusals" stating the guarantee.Technical decisions
__reduce__instead of changingargs. Passing every field toException.__init__would change
str(error)into a tuple and break the documented rule thatreprandstrshow only the status.__dict__. Fields added later and notes are kept withoutmaintaining a list of names.
detailand the refusal, because the caller needsthem in the parent process. They never contain the token:
problem()redacts it beforethe error is built, and every round-trip test asserts the token is absent from the bytes.
as
__cause__. The test asserts that the chain names only the status, matching the repo'sexisting diagnostic tests.
and supporting them would need a module-level rebuild function for a case that doesn't
exist.
Testing
tests/test_http.py:test_review_requests_return_each_documented_refusal(existing; 10 refusal reasons ×sync/async) now also asserts that every refusal survives
copy,deepcopyand pickleprotocols 0–5. Type, status, type URN, detail, title,
refusal.to_dict(),repository_name,
strandreprmust be equal, and the token must be absent from thepickled bytes.
test_sdk_problems_round_trip_through_pickle_and_copy: errors the SDK creates itself(invalid response, timeout, redirect, keyword fields) round-trip, and notes are kept.
test_problem_raised_in_a_worker_process_reaches_the_caller_typed(integration): aspawn-based
ProcessPoolExecutorworker calls the loopback HTTP server and gets a 403.The parent receives a typed
ProoflineErrorwith the token redacted, its traceback chainholds no private text or token, and a second job on the same pool also completes, so the
pool survives.
Against the original
_transport.py, these tests give 25 failed (TypeError, andBrokenProcessPoolfor the pool test). With the change they all pass.Verification
python3 scripts/check.pyon Python 3.13.12 (the CI command):main@ 45b27baEnd-to-end reproduction, run from the repository root:
main:FAIL BrokenProcessPool× 4typed 403 urn:proofline:forbidden Token lacks reviews:read.× 4Proofline review
I installed Proofline on my own account (
lavshashank, limited to a fork of this repository)and reviewed this change as a PR inside the fork
(lavshashank#1).
13575cc45b27ba..13575ccbe9f11cbe9f11c45b27ba..be9f11cThe walkthrough described the change correctly in three steps: the rebuild hook, then the
round-trip and pool tests, then the README guarantee. A clean result is not proof, so I
also checked the points below myself:
the parent's error. Proofline did not raise this. I asserted the chain contains only the
status text, matching this repository's diagnostic tests (commit
be9f11c).detail. That is the purpose of the change; thetoken is never part of the error.
exact CI command locally (table above).