Repository navigation
Add scan_revision: start a scan with one request_id and safe retries - #62
Open
thirumal1206 wants to merge 2 commits into
Open
thirumal1206 wants to merge 2 commits into
thirumal1206 wants to merge 2 commits into
Conversation
Starts a scan on a ref or exact commit on the sync and async clients, sending the same request_id on every attempt so a retry resolves to the first scan. Retries 429, 502 to 504, timeouts and connection failures, four attempts with jittered backoff. With commit_sha and wait=True the wait is held to that commit, as in wait_for_review.
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.
What this adds
scan_revisionon the sync and async clients. It scans a ref or an exact commit and, withwait=True, waits for the review. Until now Python only had the generatedrequest_scan, a bare POST, so every caller had to work out retries on their own.The problem
Picture a CI job starting a scan. The API accepts it, but the reply is slow and the client times out. The job sees an error, retries with a fresh
request_id, and a second scan starts for the same commit.sequenceDiagram participant CI as CI job participant API as Proofline API CI->>API: scan, id A API-->>API: accepted CI--xAPI: timeout, error raised CI->>API: caller retries, new id B API-->>API: second scanThe fix
The API already returns the first result when it sees a
request_idagain. So the helper picks one id and sends it on every attempt. It retries 429, 502, 503, 504, timeouts and connection failures, up to four attempts with jittered backoff.sequenceDiagram participant CI as CI job participant API as Proofline API CI->>API: scan, id A API-->>API: accepted CI--xAPI: timeout, SDK waits CI->>API: SDK retries, same id A API-->>CI: first result, no second scanI kept the retry in the helper rather than in
RetryTransport, which never retries a POST, and shouldn't. This endpoint is the exception because it carries its own idempotency key. If every attempt fails, the error carries therequest_idas a note, so a caller can pick up where it left off. The README shows how to derive a stable id from your CI run.Worth a look
reforcommit_sha. Blank input, a badbudget_creditsand (withwait=True) a badtimeoutraiseValueErrorbefore anything is sent.commit_shaandwait=True, the wait is held to that commit.REPOSITORY_UNAVAILABLEreturns without waiting.timeoutbounds the wait only.ScanResponse | ReviewOutcomedepending onwait. I kept it simple;@overloadonwaitwould tighten it if you prefer.How I checked it
Tests first, each one seen failing before the code went in. 51 new cases run against both clients on the repo's loopback server.
ruff,mypy,scripts/contracts.py(one new helper entry, likeiter_export_pages),scripts/generate.py --checkand the full suite (267 tests) all pass.I also ran it against the real API, on a trial organisation with a small private repo:
request_idgaveCREATED, thenEXISTINGwith the same resolution and review, on both clients.budget_creditsgot a 400, and was not retried.commit_shawithwait=Truewaited and returned an outcome for that commit. The review itself endedFAILED(CODE_ASSESSMENT_UNAVAILABLE); I didn't dig into why.What I couldn't verify: retries after a real 429, 503 or timeout (loopback only), a wait pinned to another commit, and what a scan costs against its
budget_creditscap.Possible next steps
Honour
Retry-After(needs a header field onProoflineError), a small helper that derives a stable id, and the same helper in the TypeScript SDK. Happy to pick any of these up if useful.How I worked
Sequence diagrams are how I get my head around a repo and its data flow, so I started there, using gitdiagram, then picked the Python SDK. I used Claude to help map the code and write the tests and implementation, test first, and I went through each change myself.
AGENTS.mdasks for my session prompts in a hidden comment. I wasn't sure what they would add for you, so I declined, but I'm happy to walk through how I did this task.