Repository navigation
Conversation
operation_errors() turned every exception that wasn't a ProoflineError or httpx.HTTPError into "Proofline returned an invalid API response" and dropped the context. That also caught errors raised while the request was still being built, like an unknown keyword or a dict passed as the body, so a local typo looked like a server problem and the traceback was gone. No request had even been sent. The retry transports now set a RESPONDED context var when a 2xx response comes back. operation_errors() only maps to the static problem after that; before it, the original exception propagates. Decode failures on a body that did arrive still map to invalid-response with the private body kept out of the traceback.
Proofline caught this on the first commit: RESPONDED was only set for 2xx, so a 4xx/5xx body nested deeper than json can decode raised RecursionError inside problem(), and operation_errors let it through because the flag was still false. Before that commit the catch-all had turned it into invalid-response. Two changes: - problem() treats RecursionError like any other undecodable body, so the caller gets the real status and "HTTP error without a problem document". This also fixes export_reviews and the MCP calls, which leaked the same RecursionError on main because they don't go through operation_errors at all. - The transports set RESPONDED as soon as any response comes back, not only on 2xx, so anything unexpected while handling a server reply still maps to the SDK problem.
This was referenced Nov 22, 2026
apoorvarohilla
added a commit
to apoorvarohilla/sdk-python
that referenced
this pull request
Nov 23, 2026
prooflinedev#75 already catches RecursionError where problem() decodes the body, so this change no longer does. The HTML 503 test keeps its exact sleeps. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 23, 2026
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.
While reading
operation_errors()inproofline/_transport.pyI noticed it catches every exception that isn't aProoflineErrororhttpx2.HTTPErrorand re-raises it as the staticinvalid-responseproblem withfrom None. For a body that came back from the server and failed to decode, that's what you want. But the generated_get_kwargsruns inside the same block, so mistakes made while the request is still being built get the same treatment:Neither call sends a request, yet the error says Proofline replied, and the original
TypeError/AttributeErrorand its traceback are gone. You end up checking the token and the network when the problem is a typo. A bug in the SDK's own request building would be hidden the same way.Fix
The mapping really depends on one thing: did a response arrive?
RetryTransportandAsyncRetryTransportnow set aRESPONDEDcontext var as soon as a response comes back, whatever the status.operation_errors()clears the flag on entry. If something raises before a response came back, the original exception goes through untouched. After a response, the behaviour is the same as before.I put this in the transport and left the generated code alone.
client.pyand the template-generatedOperations(request_scantoday) both go throughoperation_errors(), so one change covers both andtemplates/stays as it is. AContextVarkeeps the flag separate per thread and per asyncio task, so concurrent calls on one client don't see each other's state.The private-body guarantee is unchanged: a decode failure on a body that did arrive still uses
from None.test_successful_private_body_decoder_failure_is_staticstill passes, and the new test checks it again forrequest_scan.Proofline review
I ran Proofline on this branch in my own fork first: Shiivu13#1. The finding and my reply are on that PR; this one is the same two commits rebased onto 7.1.0.
Proofline flagged one serious issue on the first commit, and it was right. I had only set
RESPONDEDon 2xx. A 4xx/5xx body nested deeper thanjsoncan decode ([* 100000 fits easily in 8 MiB) raisesRecursionErrorinsideproblem(), and with the flag still falseoperation_errors()let it through raw. Onmainthe catch-all had hidden that asinvalid-response, so this was a regression I introduced. I reproduced it against the loopback server for 400 and 500 in sync and async before touching anything.While reproducing it I also found the same
RecursionErrorleaking onmainfromexport_reviewsand the MCP calls, because they don't go throughoperation_errors()at all. The second commit fixes both:problem()treatsRecursionErrorlike any other undecodable body, so the caller gets the real status and "Proofline returned an HTTP error without a problem document." That covers operations, exports and MCP in one place.One thing I left out on purpose: a 200 MCP reply nested that deep still raises
RecursionErrorfrom_mcp._decode, and so would a deep line in an NDJSON export. Both are like that onmaintoo and live outside the transport, so I'd rather send them as a separate small PR than grow this one.Tests
Three new tests in
tests/test_http.py, run in sync and async mode against the loopback server:test_caller_errors_before_any_request_are_not_reported_as_api_responsescovers an unknown keyword, a dict body onrequest_patch_reviewand on the generatedrequest_scan, and a missing argument. Each one raises its ownTypeErrororAttributeErrorwith a traceback, and the server sees zero requests.test_a_body_that_arrives_still_decodes_to_the_static_sdk_problemmakes a caller error first, then checks that a malformed 200 still maps toinvalid-responseforget_findingandrequest_scanwithout the private body in the traceback.test_problem_nested_past_the_decoder_limit_stays_a_typed_problemsends a too-deep body with 400 and 500 toget_finding,request_scanandexport_reviews, and expects aProoflineErrorwith that status.All 8 cases fail on current
main. The deep-nesting one also fails on the first commit of this branch alone, which is how Proofline's finding showed up.I also ran a few things by hand that aren't worth a permanent test: a typo and a slow malformed reply running at the same time under
asyncio.gatherand on two threads sharing one sync client (each got its own error), a 503 withRetry-After: 0followed by a good or a malformed 200, a header timeout, a refused connection, and a typo straight after anexport_reviewscall. All behaved as described above.ruff and mypy are clean and 226 tests pass. The full
scripts/check.pyrun is green on Linux on my fork: https://github.com/Shiivu13/sdk-python/actions/runs/44877733204. One note: on Windows,test_body_stream_deadline_does_not_turn_authority_into_timeoutsometimes fails withWinError 10053. It fails the same way on an untouchedmain(once in three runs for me), so it isn't related to this change.