pub struct RetryingGateway<G: ModelGateway> { /* private fields */ }Expand description
A ModelGateway that retries an inner gateway under a RetryPolicy.
The wrapper is an ordinary gateway — no new trait, no runner option, off
unless the host builds one — and every attempt sends the same
ModelRequest.
- Only
ModelInvokeErrorKind::TransientandModelInvokeErrorKind::TimedOutfailures are retried.Permanent,Undecodable,InvalidRequest,CancelledandUnknownOutcomeare never retried, and there is no setting for that. invokeandstreamshare the policy; each logical call counts its own attempts.streamreads the inner stream’s first item before returning. An inner error, or a first item that is aStreamDelta::Errorwith a retryable kind, starts another attempt. Any other first item is handed on followed by the rest of the stream, and the call is never retried from then on — a failure after the first delta reaches the caller unchanged. An inner stream that ends before yielding any item is classifiedUnknownOutcomeand never retried.- A wait is raced against the caller’s
CallControl: cancellation during a wait returnsCancelled, and a wait that would reach the parent deadline returns the last error instead of waiting. The wrapper never extends the parent deadline and never cancels the parent token. - A server-requested delay (
ModelInvokeError::retry_delay) is waited as given while it is at or belowmax_server_delay; above the ceiling the call fails at once. Without one, the wrapper uses its own jittered exponential backoff. - One
tracingevent per retry records the attempt, the failure kind and the wait.
Implementations§
Source§impl<G: ModelGateway> RetryingGateway<G>
impl<G: ModelGateway> RetryingGateway<G>
Sourcepub fn new(inner: G, policy: RetryPolicy) -> Self
pub fn new(inner: G, policy: RetryPolicy) -> Self
Wraps inner with policy. The wrapped value stays reachable
through RetryingGateway::inner; a host that wants a shared trait
object builds the wrapper around the concrete gateway and coerces
Arc::new(RetryingGateway::new(gateway, policy)) to
Arc<dyn ModelGateway>.
Sourcepub fn policy(&self) -> &RetryPolicy
pub fn policy(&self) -> &RetryPolicy
The retry policy in force.
Trait Implementations§
Source§impl<G: Clone + ModelGateway> Clone for RetryingGateway<G>
impl<G: Clone + ModelGateway> Clone for RetryingGateway<G>
Source§impl<G: ModelGateway> Debug for RetryingGateway<G>
impl<G: ModelGateway> Debug for RetryingGateway<G>
Source§impl<G: ModelGateway> ModelGateway for RetryingGateway<G>
impl<G: ModelGateway> ModelGateway for RetryingGateway<G>
Source§fn invoke<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
request: &'life1 ModelRequest,
control: &'life2 CallControl,
) -> Pin<Box<dyn Future<Output = Result<ModelOutput, ModelInvokeError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn invoke<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
request: &'life1 ModelRequest,
control: &'life2 CallControl,
) -> Pin<Box<dyn Future<Output = Result<ModelOutput, ModelInvokeError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Runs one logical invocation, returning the
assembled
ModelOutput, or a classified ModelInvokeError.
Cancellation and the deadline arrive through control.Source§fn stream<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
request: &'life1 ModelRequest,
control: &'life2 CallControl,
) -> Pin<Box<dyn Future<Output = Result<ModelStream, ModelInvokeError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn stream<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
request: &'life1 ModelRequest,
control: &'life2 CallControl,
) -> Pin<Box<dyn Future<Output = Result<ModelStream, ModelInvokeError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Streams one logical output. Once any delta has been yielded, transparent
retries are prohibited. The final Done alone supplies material for
submission. Default implementation: degenerates to a
single
StreamDelta::Done after invoke — providers that never
implemented streaming keep working through the same port; streaming
providers override to expose real token increments.Auto Trait Implementations§
impl<G> Freeze for RetryingGateway<G>where
G: Freeze,
impl<G> RefUnwindSafe for RetryingGateway<G>where
G: RefUnwindSafe,
impl<G> Send for RetryingGateway<G>
impl<G> Sync for RetryingGateway<G>
impl<G> Unpin for RetryingGateway<G>where
G: Unpin,
impl<G> UnsafeUnpin for RetryingGateway<G>where
G: UnsafeUnpin,
impl<G> UnwindSafe for RetryingGateway<G>where
G: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more