v0.2.0: server sync — async traces, dual auth, scrubber-proxy mode, rater client - #1
Closed
UltraInstinct0x wants to merge 3 commits into
Closed
v0.2.0: server sync — async traces, dual auth, scrubber-proxy mode, rater client#1UltraInstinct0x wants to merge 3 commits into
UltraInstinct0x wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR syncs the Python SDK to Panel server surface v0.2.0 by refactoring the SDK into modular modules, expanding the operator API surface (including async parity), and adding retry/scrubber/auth behaviors plus updated tests and docs.
Changes:
- Refactors the package from a monolithic
__init__.pyclient into modularclient/errors/types/signing/scrubber/retrymodules and bumps version to0.2.0. - Adds new operator methods (e.g.,
ingest_units,score_unit,skill_review,ingest_trace_and_wait) with async equivalents and introduces rater clients. - Adds pytest/respx coverage for signing, scrubber JWT structure, trace polling, and 429 retry behavior; updates README + adds CHANGELOG.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
tests/test_sdk_sync.py |
New tests for v0.2.0 signing/scrubber/retry/async trace ingest behaviors. |
tests/test_client.py |
Removes the previous test suite superseded by the new sync suite. |
README.md |
Updates install + documents v0.2.0 options/methods/errors. |
pyproject.toml |
Bumps version and defines test dependencies + pytest asyncio mode. |
panel_sdk/types.py |
Adds typed VerifyResult and TraceResult dataclasses. |
panel_sdk/rater.py |
Adds sync/async rater clients for pool fetch and judgment submission. |
panel_sdk/errors.py |
Introduces typed exceptions (PanelError, PanelRateLimitError, PanelScrubberError). |
panel_sdk/client.py |
Implements sync + async Panel clients with signing, scrubber modes, retry/backoff, and new endpoints. |
panel_sdk/_signing.py |
Adds canonicalization + HMAC/JWT helpers and score canonical string builder. |
panel_sdk/_scrubber.py |
Implements scrubber header/body handling for off/self-sign/proxy modes. |
panel_sdk/_retry.py |
Adds retry decision/delay helpers and typed error parsing. |
panel_sdk/__init__.py |
Updates public exports for the new modular package layout and version. |
CHANGELOG.md |
Adds a v0.2.0 changelog entry describing the refactor and new surface. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| def retry_delay_seconds(status_code: int, attempt: int, retry_after_s: float | None) -> float: | ||
| """Return capped sleep duration before next retry.""" | ||
| if status_code == 429: | ||
| return min(30.0, retry_after_s or 1.0) |
|
|
||
| def canonical_json(value: Any) -> str: | ||
| """Return compact canonical JSON string.""" | ||
| return json.dumps(value, separators=(",", ":"), sort_keys=False) |
| except ValueError: | ||
| retry_after_s = None | ||
| if isinstance(payload, dict) and payload.get("retry_after_s") is not None: | ||
| retry_after_s = float(payload["retry_after_s"]) |
Comment on lines
+97
to
+113
| retry_after_s: float | None = None | ||
| if response.status_code == 429: | ||
| ra = response.headers.get("Retry-After") | ||
| if ra: | ||
| try: | ||
| retry_after_s = float(ra) | ||
| except ValueError: | ||
| retry_after_s = None | ||
| if isinstance(payload, dict) and payload.get("retry_after_s") is not None: | ||
| retry_after_s = float(payload["retry_after_s"]) | ||
| if should_retry(response.status_code, attempt, self.max_retries): | ||
| delay = retry_delay_seconds(response.status_code, attempt, retry_after_s) | ||
| blocking_sleep(delay) | ||
| attempt += 1 | ||
| continue | ||
| parse_error_response(response.status_code, payload, response.text) | ||
|
|
Comment on lines
+128
to
+135
| while time.time() < deadline: | ||
| polled = self.fetch_trace(result.trace_id) | ||
| status = str(polled.get("status", "")) | ||
| if status and status != "pending": | ||
| return polled | ||
| blocking_sleep(poll_interval_seconds) | ||
| raise TimeoutError("trace polling timed out") | ||
|
|
Comment on lines
+51
to
+53
| return cls( | ||
| status=status, | ||
| trace_id=str(payload.get("trace_id", "")), |
| from panel_sdk._retry import blocking_sleep, parse_error_response, retry_delay_seconds, should_retry | ||
| from panel_sdk._scrubber import build_scrubber_headers, build_scrubber_headers_async | ||
| from panel_sdk._signing import canonical_json, canonical_score_string, hmac_sha256_hex | ||
| from panel_sdk.errors import PanelRateLimitError |
Comment on lines
+82
to
+90
| respx.post(f"{BASE}/api/v1/traces").mock( | ||
| return_value=httpx.Response(202, json={"trace_id": "tr_2", "status": "pending", "poll": "/v1/traces/tr_2"}) | ||
| ) | ||
| route = respx.get(f"{BASE}/api/v1/traces/tr_2").mock( | ||
| side_effect=[ | ||
| httpx.Response(202, json={"trace_id": "tr_2", "status": "pending"}), | ||
| httpx.Response(200, json={"trace_id": "tr_2", "status": "done", "unit_ids": ["u1"]}), | ||
| ] | ||
| ) |
Comment on lines
+19
to
+50
| class RaterClient: | ||
| """Synchronous rater client using site-key auth only.""" | ||
|
|
||
| def __init__(self, *, base_url: str, site_key: str, timeout_seconds: float = 10.0, client: httpx.Client | None = None) -> None: | ||
| """Initialize RaterClient.""" | ||
| self.base_url = base_url.rstrip("/") | ||
| self.site_key = site_key | ||
| self._client = client or httpx.Client(timeout=timeout_seconds) | ||
|
|
||
| def next_unit(self, pool: str, rater_id: str) -> dict[str, Any]: | ||
| """Fetch next unit from rater pool.""" | ||
| response = self._client.get( | ||
| f"{self.base_url}/api/rater/next", | ||
| headers={"x-panel-site-key": self.site_key}, | ||
| params={"pool": pool, "rater_id": rater_id}, | ||
| ) | ||
| payload = _json_or_raw(response) | ||
| if not (200 <= response.status_code < 300): | ||
| parse_error_response(response.status_code, payload, response.text) | ||
| return payload | ||
|
|
||
| def submit_judgment(self, unit_id: str, choice: str) -> dict[str, Any]: | ||
| """Submit a rater judgment choice.""" | ||
| response = self._client.post( | ||
| f"{self.base_url}/api/rater/judgment", | ||
| headers={"x-panel-site-key": self.site_key, "content-type": "application/json"}, | ||
| json={"unit_id": unit_id, "choice": choice}, | ||
| ) | ||
| payload = _json_or_raw(response) | ||
| if not (200 <= response.status_code < 300): | ||
| parse_error_response(response.status_code, payload, response.text) | ||
| return payload |
Owner
Author
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.
Summary
This PR syncs the Python SDK to panel server surface v0.2.0.
New/updated methods
PanelClient.ingest_trace(source_agent, blob, trace_id=None) -> TraceResultPanelClient.ingest_trace_and_wait(source_agent, blob, trace_id=None, max_wait_seconds=60, poll_interval_seconds=1.5)PanelClient.fetch_trace(trace_id)PanelClient.ingest_units(units)PanelClient.score_unit(ref=None, unit_id=None)PanelClient.skill_review(skill_name, diff, ...)PanelClient.verify_token(token)(signature unchanged)AsyncPanelClientRaterClient.next_unit(pool, rater_id)RaterClient.submit_judgment(unit_id, choice)AsyncRaterClientSurface changes
client.py,rater.py,_signing.py,_scrubber.py,_retry.py,errors.py,types.pyfrom panel_sdk import PanelClientremains valid0.2.0Auth + scrubber behavior
_signing.pysite_secret_source="raw"(x-panel-ingest-secret)off,self-sign,proxyError types
PanelErrorPanelRateLimitError(scope,retry_after_s)PanelScrubberErrorRetry/backoff
Retry-After/ payloadretry_after_s(capped)Tests
Added tests (pytest + respx) for:
ingest_trace_and_wait)Retry-AfterBreaking changes
ingest_unit/fetch_unitconvenience methods in favor of spec-alignedingest_unitsand server-sync surface.