Commit 354b01b
authored
Enable default model retries (#4620)
## Summary
Enable provider retries for Electric Agents model calls by default.
Transient LLM/provider failures now get two provider-level retry
attempts before the run fails, while callers can still opt out with
`modelMaxRetries: 0`.
## Root Cause
The agent runtime already threaded `modelMaxRetries` through to `pi-ai`
provider stream calls, but its default was `0`. That meant
normal/default agent runs did not retry retryable provider failures such
as transient server errors, rate limits, or network blips unless each
agent explicitly configured retries.
## Approach
- Change the runtime default from no retries to two provider retries:
```ts
const DEFAULT_MODEL_MAX_RETRIES = 2
```
- Keep the existing `modelMaxRetries` option behavior intact. Because
the runtime still uses nullish coalescing, explicit values continue to
override the default, including `modelMaxRetries: 0` for no-retry
behavior.
- Add coverage for the default options passed into provider stream
calls.
- Update existing option-forwarding tests to use `modelMaxRetries: 5`,
so they clearly verify explicit overrides rather than matching the new
default by coincidence.
## Key Invariants
- Default provider stream calls receive `{ timeoutMs: 30_000,
maxRetries: 2 }`.
- Explicit `modelMaxRetries` values override the default.
- Explicit `modelMaxRetries: 0` remains a valid way to disable retries.
- Existing stream options, especially `AbortSignal`, continue to be
preserved when timeout/retry options are injected.
## Non-goals
- This does not add Electric-runtime-level retry orchestration around
failed assistant messages.
- This does not change model provider error classification.
- This does not alter run/event replay semantics or retry after
partially emitted model output.
## Trade-offs
This is the smallest safe mitigation: retries happen in the
provider/pi-ai layer before the Electric runtime observes a failed
stream. That avoids introducing replay or duplicate-event semantics in
this PR.
The trade-off is that transient failures may now take longer to surface,
because the provider call can retry before failing. Users who prefer
fail-fast behavior can set `modelMaxRetries: 0`.
## Verification
```bash
cd packages/agents-runtime
pnpm exec vitest run test/pi-adapter.test.ts test/model-provider-error.test.ts --pool-options.threads.maxThreads=2
```
Result:
```txt
✓ test/pi-adapter.test.ts (30 tests)
✓ test/model-provider-error.test.ts (11 tests)
Test Files 2 passed
Tests 41 passed
```
## Files changed
- `.changeset/enable-agent-model-retries.md` — Adds a patch changeset
for `@electric-ax/agents-runtime` describing the default retry behavior
and opt-out.
- `packages/agents-runtime/src/pi-adapter.ts` — Changes the default
model retry count from `0` to `2`.
- `packages/agents-runtime/test/pi-adapter.test.ts` — Adds default
option coverage and strengthens explicit override assertions.1 parent 9d063e4 commit 354b01b
3 files changed
Lines changed: 64 additions & 5 deletions
File tree
- .changeset
- packages/agents-runtime
- src
- test
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
86 | 86 | | |
87 | 87 | | |
88 | 88 | | |
89 | | - | |
| 89 | + | |
90 | 90 | | |
91 | 91 | | |
92 | 92 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
127 | 127 | | |
128 | 128 | | |
129 | 129 | | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
130 | 184 | | |
131 | 185 | | |
132 | 186 | | |
| |||
158 | 212 | | |
159 | 213 | | |
160 | 214 | | |
161 | | - | |
| 215 | + | |
162 | 216 | | |
163 | 217 | | |
164 | 218 | | |
| |||
180 | 234 | | |
181 | 235 | | |
182 | 236 | | |
183 | | - | |
| 237 | + | |
184 | 238 | | |
185 | 239 | | |
186 | 240 | | |
| |||
214 | 268 | | |
215 | 269 | | |
216 | 270 | | |
217 | | - | |
| 271 | + | |
218 | 272 | | |
219 | 273 | | |
220 | 274 | | |
221 | | - | |
| 275 | + | |
222 | 276 | | |
223 | 277 | | |
224 | 278 | | |
| |||
0 commit comments