feat: expose Gemini RetryInfo retry_delay() on VertexApiError and Error #19

Closed
opened 2026-10-27 12:22:58 +00:00 by andreban · 0 comments
Owner

Problem

  1. In src/types/error.rs, VertexApiError.details is currently typed as Option<Vec<ErrorType>>, where ErrorType (#[serde(tag = "@type")]) only defines three variants (ErrorInfo, Help, BadRequest). When Vertex AI returns a 429 RESOURCE_EXHAUSTED response whose error.details array includes a {"@type": "type.googleapis.com/google.rpc.RetryInfo", "retryDelay": "37s"} entry (or any other google.rpc.* detail type), serde_json::from_str::<VertexErrorResponse>(&body) fails to deserialize ErrorType and falls back to Error::HttpStatus { status, body }.
  2. Downstream consumers (agent-rig's Error::ProviderTransient { message, retry_after } and devrel-pr-reviewer's VertexModel) need Error::retry_delay(&self) -> Option<Duration> and VertexApiError::retry_delay(&self) -> Option<Duration> to extract the server-supplied retryDelay hint, matching andreban/geologia#25 (69e4108).

Proposed Changes (porting andreban/geologia@69e4108)

  1. src/types/error.rs:
    • Change VertexApiError.details to Option<Vec<serde_json::Value>> (or add a RetryInfo variant plus an #[serde(other)] fallback on ErrorType so unknown detail types never break VertexApiError deserialization).
    • Add pub fn retry_delay(&self) -> Option<std::time::Duration> on VertexApiError that searches self.details for an entry with @type equal to "google.rpc.RetryInfo" or ending with "/google.rpc.RetryInfo", reads "retryDelay" (or "retry_delay"), and parses the protobuf duration string ("<secs>s" or "<secs>.<nanos>s").
  2. src/error.rs:
    • Add pub fn retry_delay(&self) -> Option<std::time::Duration> on gemini_rs::error::Error delegating Error::VertexError(e) => e.retry_delay() and returning None for other variants.
  3. Tests:
    • Port the unit tests from andreban/geologia@69e4108 covering integer and fractional retryDelay values ("37s", "1.5s"), multiple details entries, malformed durations, and Error::retry_delay() delegation.
## Problem 1. In `src/types/error.rs`, `VertexApiError.details` is currently typed as `Option<Vec<ErrorType>>`, where `ErrorType` (`#[serde(tag = "@type")]`) only defines three variants (`ErrorInfo`, `Help`, `BadRequest`). When Vertex AI returns a `429 RESOURCE_EXHAUSTED` response whose `error.details` array includes a `{"@type": "type.googleapis.com/google.rpc.RetryInfo", "retryDelay": "37s"}` entry (or any other `google.rpc.*` detail type), `serde_json::from_str::<VertexErrorResponse>(&body)` fails to deserialize `ErrorType` and falls back to `Error::HttpStatus { status, body }`. 2. Downstream consumers (`agent-rig`'s `Error::ProviderTransient { message, retry_after }` and `devrel-pr-reviewer`'s `VertexModel`) need `Error::retry_delay(&self) -> Option<Duration>` and `VertexApiError::retry_delay(&self) -> Option<Duration>` to extract the server-supplied `retryDelay` hint, matching [`andreban/geologia#25`](https://github.com/andreban/geologia/pull/25) (`69e4108`). ## Proposed Changes (porting `andreban/geologia@69e4108`) 1. **`src/types/error.rs`**: - Change `VertexApiError.details` to `Option<Vec<serde_json::Value>>` (or add a `RetryInfo` variant plus an `#[serde(other)]` fallback on `ErrorType` so unknown detail types never break `VertexApiError` deserialization). - Add `pub fn retry_delay(&self) -> Option<std::time::Duration>` on `VertexApiError` that searches `self.details` for an entry with `@type` equal to `"google.rpc.RetryInfo"` or ending with `"/google.rpc.RetryInfo"`, reads `"retryDelay"` (or `"retry_delay"`), and parses the protobuf duration string (`"<secs>s"` or `"<secs>.<nanos>s"`). 2. **`src/error.rs`**: - Add `pub fn retry_delay(&self) -> Option<std::time::Duration>` on `gemini_rs::error::Error` delegating `Error::VertexError(e) => e.retry_delay()` and returning `None` for other variants. 3. **Tests**: - Port the unit tests from `andreban/geologia@69e4108` covering integer and fractional `retryDelay` values (`"37s"`, `"1.5s"`), multiple `details` entries, malformed durations, and `Error::retry_delay()` delegation.
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: andreban/gemini-rs#19