Skip to content

Add scan_revision: start a scan with one request_id and safe retries - #62

Open
thirumal1206 wants to merge 2 commits into
prooflinedev:mainfrom
thirumal1206:scan-revision
Open

thirumal1206 wants to merge 2 commits into
prooflinedev:mainfrom
thirumal1206:scan-revision

Conversation

@thirumal1206

Copy link
Copy Markdown

What this adds

scan_revision on the sync and async clients. It scans a ref or an exact commit and, with wait=True, waits for the review. Until now Python only had the generated request_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 scan
Loading

The fix

The API already returns the first result when it sees a request_id again. 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 scan
Loading

I 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 the request_id as 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

  • Exactly one of ref or commit_sha. Blank input, a bad budget_credits and (with wait=True) a bad timeout raise ValueError before anything is sent.
  • With commit_sha and wait=True, the wait is held to that commit.
  • REPOSITORY_UNAVAILABLE returns without waiting. timeout bounds the wait only.
  • Any other error is raised straight away.
  • The return type is ScanResponse | ReviewOutcome depending on wait. I kept it simple; @overload on wait would 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, like iter_export_pages), scripts/generate.py --check and the full suite (267 tests) all pass.

I also ran it against the real API, on a trial organisation with a small private repo:

  • The same request_id gave CREATED, then EXISTING with the same resolution and review, on both clients.
  • Two different ids for the same commit each started their own scan, which is the case this helper prevents.
  • The same id with a different budget_credits got a 400, and was not retried.
  • commit_sha with wait=True waited and returned an outcome for that commit. The review itself ended FAILED (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_credits cap.

Possible next steps

Honour Retry-After (needs a header field on ProoflineError), 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.md asks 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.

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

No deployments
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.

1 participant