← Back to Pull requests

feat(agent): control model retry attempts with a deadline-aware policy (issue #313) #356

Closed
unknown closed this pull request without merging on Nov 07, 2026 03:17 UTC
View on GitHub
unknown unknown commented on Nov 04, 2026 06:57 UTC
Author

Describe what this PR does / why we need it

ModelRetryInterceptor repeats a failed model call, but three properties of that sequence were not controlled. The retryability of a failure was guessed from the text of the exception message, so a permanent rejection that happened to mention a timeout was repeated, while a transient failure with an unfamiliar message was not. The sequence ignored the deadline of the run and started the next provider call even after the run had expired. And a cancelled run kept the sequence alive, because cancellation is delivered through the execution guard of the run while the loop only observed thread interruption. The backoff itself blocked the calling thread with Thread.sleep, while the streaming path waited reactively, so a single policy had two blocking semantics and neither of them observed the run control.

This PR turns the retry into a controlled policy. The decision is made by a neutral contract that classifies the failure, bounds the number of attempts and observes the deadline and the cancellation of the run, and it reports a stable stop reason instead of an exhausted retry.

Does this pull request fix one issue?

Fixes #313

Describe how you did it

The contract lives in io.github.agentic.ai.agent.retry in argi-agent-api, which depends neither on Reactor nor on the graph runtime, so the independent ReAct engine and the graph based framework share it. ModelCallFailureCategory and ModelCallFailure describe the classification of a failure, ModelCallFailureClassifier and TypeBasedModelCallFailureClassifier classify by failure type and cause chain instead of by message text, RetryPolicy carries the bounded configuration, RetryStopReason and RetryDecision describe the terminal state of a sequence, and ModelRetryController owns the attempt counter, the deadline and the decision.

The run guard reaches the interceptor through ModelRequest, which gained an optional ExecutionGuard field. The field is typed and is never part of the request attributes that the adapters forward to a provider. The independent ReAct engine passes the control of its execution context and the framework node passes the guard of the run configuration, so both engines propagate the guard of the run they execute, and a copied request keeps the guard.

ModelRetryInterceptor now delegates its decisions to the controller. Before every attempt the controller checks the guard and the deadline: when the deadline has passed, when less than the configured reserve remains, or when the next backoff would outlive the deadline, the sequence stops before another call is dispatched. With a guard present the backoff waits in slices and checks the guard before every slice, so a cancelled or expired run ends the wait instead of dispatching another call. A stopped run is reported with the reason of the guard and is never reported as an exhausted retry, and the stop signal is propagated unchanged.

The existing configuration keeps its behaviour: the retryable exception predicate stays the default decision and every existing builder option keeps its default value. The type based classifier, the retryable categories, the reserved deadline time and the clock are opt in. The backoff calculation moved into the neutral policy, so the framework helper that duplicated it was removed together with its test; the growth, the cap and the zero delay stay covered by the controller test.

How was it tested / verified?

The new tests are offline and model independent. ModelRetryControllerTest covers the attempt bound, the classification of a permanent failure, the growth and the bound of the backoff, an expired deadline, a deadline without room for another attempt, a backoff that would outlive the deadline, a cancelled run and a classification that ignores the text of the message. ModelRetryInterceptorControlledTest covers the interceptor end to end: three consecutive failures perform exactly three calls, an explicit classifier keeps a permanent failure at one call even when its message mentions a timeout, the legacy predicate still decides when no classifier is configured, a cancellation during the backoff performs no further call and reports the stop signal of the guard, a deadline that cannot fit another attempt stops the sequence, the usage reported to the engine comes from the successful attempt only, and a copied request keeps the guard. ReActAgentExecutionGuardTest and AgentLlmNodeExecutionGuardTest assert that both engines propagate the guard of the run into the model request. The existing retry, cancellation and node tests are unchanged and stay green.

The change was verified with the full reactor build including the tests, the format validation, the checkstyle check, the spelling check and the newline check.

Additional notes

The scope of this PR is the repetition of one model call. It does not switch models, it does not replay tool calls, it does not own a persistent retry budget and it does not change the boundary of a streaming response that already produced output. The assembly of the retry behaviour as a lifecycle strategy, together with the routing and the fallback policies, belongs to the lifecycle chain and to the model policy work.

One message changes in an edge case: a failure that is not retryable and that happens on the last allowed attempt is now reported as a non retryable failure instead of an exhausted retry, because the reason of the stop is reported instead of the attempt count.

Diff: 650 lines (+487 / -163) across 8 files Reviewer: yuluo-yx Review duration: 4100m
All Vouch review confidence checks passed
Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 files
0.52
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
0.17
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
60%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.388
Shallow Review Depth shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #356"
general weight: 0.35
Reviewers
Assignees
Unassigned
Labels
risk: low confidence: 60.5% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 52% (MEDIUM) · Higher = larger blast radius
52%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 60.5% · Lower = rushed or shallow review
60.5%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 20.5% · Safe to merge
20.5%