chore(sync): adapt to upstream v0.82.1 - #4
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6e71a288e4
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| status = _status(error) | ||
| if status is None: | ||
| return hasattr(error, "status_code") or hasattr(error, "status") | ||
| return status in {408, 409, 429} or status >= 500 |
There was a problem hiding this comment.
Retry SDK connection exceptions without HTTP status
When max_retries is positive and OpenAI or Anthropic raises APIConnectionError/APITimeoutError, these SDK exceptions generally have neither status_code nor status, so this branch returns false and the request is never retried. These transient connection and timeout failures should be classified as retryable explicitly rather than relying on HTTP-status attributes.
Useful? React with 👍 / 👎.
| max_retries=(options.max_retries or 0) if options else 0, | ||
| max_retry_delay_ms=options.max_retry_delay_ms if options else None, | ||
| cancel_event=options.cancel_event if options else None, |
There was a problem hiding this comment.
Pass the agent cancel event to provider options
When a provider is invoked through Agent, Agent.abort() sets the event passed into _stream_assistant_response, but that function constructs SimpleStreamOptions without cancel_event; consequently this expression always receives None and an in-progress provider retry backoff cannot be interrupted. Forward the loop's cancellation event into the stream options used by both providers.
Useful? React with 👍 / 👎.
| task.cancel() | ||
| if cancelled in done: | ||
| raise asyncio.CancelledError |
There was a problem hiding this comment.
Preserve aborted semantics when retry sleep is cancelled
When a caller supplies cancel_event and sets it during retry backoff, this raises CancelledError, but both provider drive() functions catch BaseException and convert it into an ErrorEvent(reason="error") with stop_reason="error" (usually with an empty message). Consumers therefore see a provider failure rather than the supported aborted terminal state; handle cancellation separately in the providers and emit the aborted result.
Useful? React with 👍 / 👎.
| try: | ||
| delay = float(retry_after) * 1000 | ||
| except ValueError: | ||
| parsed = email.utils.parsedate_to_datetime(retry_after) | ||
| delay = float(parsed.timestamp()) * 1000 - time.time() * 1000 | ||
| return _validate_delay(delay, maximum, str(error)) |
There was a problem hiding this comment.
Fall back when Retry-After is malformed
When a retryable response from a compatible provider or proxy contains a nonnumeric, malformed Retry-After value, parsedate_to_datetime() raises ValueError here and aborts the request instead of using the exponential fallback despite retries remaining. Treat an unparseable HTTP-date like an absent header so transient failures can still be retried.
Useful? React with 👍 / 👎.
| isolated_options = { | ||
| **options, | ||
| "session_id": str(uuid.uuid4()), | ||
| "cache_retention": "none", |
There was a problem hiding this comment.
Apply compaction isolation options in built-in providers
When compaction uses either built-in OpenAI or Anthropic provider, these newly assigned values do not isolate anything because neither provider reads session_id or cache_retention when building its request (the fields otherwise only occur in the option models). The summary therefore uses the provider's normal routing and cache behavior despite the random session and none retention; translate these options into the appropriate request parameters or headers before relying on them here.
Useful? React with 👍 / 👎.
What changed
Why
Upstream pi v0.82.1 introduced constrained sampling, provider retry behavior changes, and compaction cache/session isolation that required corresponding Python SDK compatibility updates.
Validation
uv run ruff checkuv run ruff format --checkuv run python -m mypyuv run python -m pytest— 207 passed, 14 integration tests deselected