Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
58205cf
Add cancellable wait_for_review polling
thekarannagpal Nov 24, 2026
cccaa6a
Address Proofline review feedback on cancellation
thekarannagpal Nov 24, 2026
2bf161a
Address second Proofline review findings
thekarannagpal Nov 24, 2026
aeee907
Address third Proofline review findings
thekarannagpal Nov 24, 2026
f2e4288
Address fourth Proofline review findings
thekarannagpal Nov 24, 2026
3167ded
Address fifth Proofline review findings
thekarannagpal Nov 24, 2026
83c1ac9
Address sixth Proofline review findings
thekarannagpal Nov 25, 2026
cf1208a
Address seventh Proofline review findings
thekarannagpal Nov 25, 2026
473696c
Address eighth Proofline review findings
thekarannagpal Nov 25, 2026
6c684ea
Address ninth Proofline review findings
thekarannagpal Nov 25, 2026
7533b73
Address tenth Proofline review findings
thekarannagpal Nov 25, 2026
8fc5117
Address eleventh Proofline review findings
thekarannagpal Nov 25, 2026
2efa007
Address twelfth Proofline review findings
thekarannagpal Nov 25, 2026
d2ecdac
Address thirteenth Proofline review findings
thekarannagpal Nov 25, 2026
9388498
Address fourteenth Proofline review findings
thekarannagpal Nov 27, 2026
63c2476
Address fifteenth Proofline review findings
thekarannagpal Nov 27, 2026
0e4f110
Address sixteenth Proofline review findings
thekarannagpal Nov 28, 2026
c9753b6
Address seventeenth Proofline review findings
thekarannagpal Nov 28, 2026
4447440
Address eighteenth Proofline review findings
thekarannagpal Nov 28, 2026
5b3abb4
Address nineteenth Proofline review findings
thekarannagpal Nov 28, 2026
d27e21d
Address twentieth Proofline review findings
thekarannagpal Nov 28, 2026
c8f64b2
Address twenty-first Proofline review findings
thekarannagpal Nov 28, 2026
6d77f3f
Address twenty-second Proofline review findings
thekarannagpal Nov 29, 2026
bb817be
Address twenty-third Proofline review findings
thekarannagpal Nov 29, 2026
6590fa7
Address twenty-fifth Proofline review findings
thekarannagpal Nov 29, 2026
f091efc
Address twenty-sixth Proofline review findings
thekarannagpal Nov 29, 2026
9f3e7e4
Address twenty-seventh Proofline review findings
thekarannagpal Nov 29, 2026
c0772d8
Address twenty-eighth Proofline review findings
thekarannagpal Dec 3, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,35 @@ if outcome.status != "COMPLETED":
print(outcome.status, outcome.reason)
```

`head_commit_sha` is a full SHA of 40 or 64 hexadecimal characters; any other value raises `ValueError` before a request. A review pinned to another head ends the wait on the read that names it. Its outcome is `INCOMPLETE` whatever the review's own status, its last gap has the reason code `HEAD_COMMIT_MISMATCH`, and `reason` says that the review is pinned to another head commit. A settled review that names no head has `HEAD_COMMIT_UNAVAILABLE` instead and is not `COMPLETED` either. `outcome.review.head_commit_sha` is the commit the review is pinned to. A patch review's head is a derived revision ID, so no commit matches it. In a GitHub Actions `pull_request` job, `GITHUB_SHA` is the merge commit; pass the pull request's head.
`head_commit_sha` is a full SHA of 40 or 64 hexadecimal characters; any other value raises `ValueError` before a request. Argument validation comes first: an already set `cancel_event` returns `STOPPED` only after validation succeeds. A review pinned to another head ends the wait on the read that names it. Its outcome is `INCOMPLETE` whatever the review's own status, its last gap has the reason code `HEAD_COMMIT_MISMATCH`, and `reason` says that the review is pinned to another head commit. A settled review that names no head has `HEAD_COMMIT_UNAVAILABLE` instead and is not `COMPLETED` either. If `cancel_event` is also set and cancellation is observed before the deadline, cancellation takes precedence over that mismatch: the status is `STOPPED`, the mismatch or unavailable-head gap is still attached, and `reason` is the cancellation reason. The response must still pass normal validation. A signal first delivered at or after the deadline is ignored and does not override the mismatch; because the deadline is checked first, a mismatch observed only after expiry returns `TIMED_OUT` with the `HEAD_COMMIT_MISMATCH` or `HEAD_COMMIT_UNAVAILABLE` gap. `outcome.review.head_commit_sha` is the commit the review is pinned to. A patch review's head is a derived revision ID, so no commit matches it. In a GitHub Actions `pull_request` job, `GITHUB_SHA` is the merge commit; pass the pull request's head.

## Cancelling a wait

Pass `cancel_event` to stop a wait when your own code no longer needs the result: a `threading.Event` for `wait_for_review` on `ProoflineClient`, or an `asyncio.Event` for `wait_for_review` on `AsyncProoflineClient`. The synchronous method blocks its calling thread, so set a `threading.Event` from a separate setter thread, not from a task on that same thread. For `AsyncProoflineClient`, a task on the same loop may call `cancel.set()`; use `loop.call_soon_threadsafe(lambda: cancel.set())` when the setter is another thread so the event loop resolves the setter at dispatch time. If your application already owns `SIGINT` handling, route cancellation through that handler instead of replacing it with `loop.add_signal_handler`. Do not call `threading.Event.set()` directly from a Python signal handler; have the handler hand off to another thread instead.

```python
import threading

cancel = threading.Event()
# The wait blocks this thread; call cancel.set() from a separate setter thread.
outcome = client.wait_for_review(organization_id, review_id, cancel_event=cancel)
```

```python
import asyncio

cancel = asyncio.Event()
loop = asyncio.get_running_loop()
outcome = await async_client.wait_for_review(
organization_id,
review_id,
cancel_event=cancel,
)
# From a task on this loop: cancel.set()
# From another thread: loop.call_soon_threadsafe(lambda: cancel.set())
```

An event already set at entry, including with `timeout=0`, returns `STOPPED` before any request once argument validation has succeeded. A cancellable wait samples its deadline before validation, so validation counts toward the polling budget and can exhaust it without a request; without `cancel_event`, validation happens before the timeout clock starts. Cancellation is then checked before each poll, during the backoff, and after each read. A signal delivered while arguments are validated is bounded by that entry deadline, so one delivered at or after expiry is ignored. The backoff waits on a latch fed by the supplied event's own condition and waiter registration, so a `set()` followed by `clear()` while observation is active and before the deadline is still observed, overriding `wait()` implementations are never called by the SDK, and no short-slice polling is needed. An in-flight read is not interrupted: cancellation waits for that read to finish, including transport retries and their delays. Retry delays count toward the overall wait deadline, not a single per-attempt HTTP timeout. A signal first delivered at or after the overall deadline is ignored: it does not change the wait's result or suppress a read error that would otherwise propagate. Cancellation must be observable on the event you pass: call `set()` on that event. A cached bound standard `threading.Event.set()` still notifies that event's condition and works; a setter that bypasses the observed condition, or a direct mutation of a backing object, may not wake an in-progress backoff. For `asyncio.Event`, the setter must notify waiters registered on that same event; changing only a backing object's flag does not notify those waiters, though a flag that is still set can be observed at a check after a read. Subclasses whose `is_set()` directly delegates to the standard predicate are supported for both event types: a timely `set()` followed by `clear()` is observed. For a standard or directly delegating synchronous predicate, delivery is verified from the raw flag under the notification; other overridden synchronous predicates are checked after the condition lock is released, so they cannot deadlock that `set()` call. For `asyncio.Event`, native delivery verifies the supplied predicate inline and records cancellation only when it agrees; a rejected pulse leaves the waiter pending for a later verified signal. An override that hides the event's own flag is not supported. The SDK binds the caller's async event to the wait's loop through native registration before attaching its waiter and never assigns to the caller's `set()` attribute. An SDK-owned temporary binding is released when its last waiter is removed; if native waiters remain, ownership is retained until they drain, so the same event may be reused on another loop only after both SDK and native waiters are gone. An event already bound to a different loop, or carrying waiters from one, is rejected under the waiter-registration lock before the first request. A cancelled wait returns `ReviewOutcome` with `status == "STOPPED"` and `reason == "The wait was cancelled by the caller."`. When a review had already been read, `outcome.review` still holds that last record, including when cancellation lands during a read that raises `ProoflineError` or just before the next poll; other exceptions still propagate. A retained review must still pass the normal response validation, including its review ID and head-commit checks: validation errors from either the current response or the retained review propagate even when cancellation is set. When `head_commit_sha` is supplied, a retained review pinned to another head (or to no head) still carries the matching `HEAD_COMMIT_MISMATCH` or `HEAD_COMMIT_UNAVAILABLE` gap; the status remains `STOPPED` and `reason` remains the cancellation reason. Passing the wrong event type raises `TypeError` before any request. Without `cancel_event`, waits keep their existing polling and timeout behavior. HTTP 401 and 403 responses are not converted to `STOPPED`: even after a timely cancellation they still propagate to the caller.

## Review exports

Expand Down
Loading