Repository navigation
Commit c8d81ad
authored
fix(sse): reconnect when a stream drops instead of reporting failure (#291)
## Summary
A dropped operation stream ended `monitor_operation` as `FAILED` while
the operation kept running, so a caller could retry a write that was
still in progress. The client now reconnects and returns the operation's
real result.
## Changes
- **`SSEClient` and `AsyncSSEClient`:**
- A mid-stream drop, a clean close before the operation finishes, and a
`429` or `5xx` now go through the retry path. A deploy can cause any of
these.
- Other refusals, such as a `401`, still emit `error` without retrying.
- `stream_end` still stops without reconnecting.
- **Retry budget:** it now resets only when a real event arrives. The
server sends `connected` on every open, so resetting on open or on that
event would let a stream that opens and ends retry forever.
- **`OperatorClient`:** it sets `max_retries=0`. Its `/status` polling
already covers a lost stream, and retrying first would delay that by
about 31 seconds.
- **Connections:** a reconnect now releases the previous connection
first. The async client also honors a `close()` during backoff.
- **`clients/README.md`:** describes the new behavior.
**Worth a close look:** a stream that keeps closing with no result used
to raise `ended before a terminal event` straight away. It now retries,
and when the retries run out it returns `FAILED` with the error, the
same as other lost connections. A `stream_end` with no result, which is
what a paused operation sends, still raises as before.
## Compatibility
Fix only: no export or signature changes. Runtime behavior changes in
the case above, and in `max_retries_exceeded` now firing for drops that
used to emit `error`. Both correct false failures, so this fits a patch
or minor, not a major.
## Testing
- The pre-commit checks passed, including tests (747 passed, 17
skipped), with new coverage for drops, clean closes, 503s, refused
credentials, `stream_end`, the retry budget and the async client.
- Reproduced before and after against a local mock server that drops the
first connection: `failed` after 1 connection before, `completed` after
2 connections with the fix.
- Not run against a live API or through a real deploy.
🤖 Generated with [Claude Code](https://claude.com/claude-code)5 files changed
Lines changed: 277 additions & 19 deletions
File tree
- robosystems_client/clients
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
114 | 114 | | |
115 | 115 | | |
116 | 116 | | |
117 | | - | |
| 117 | + | |
118 | 118 | | |
119 | | - | |
| 119 | + | |
120 | 120 | | |
121 | 121 | | |
122 | 122 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
246 | 246 | | |
247 | 247 | | |
248 | 248 | | |
249 | | - | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
250 | 256 | | |
251 | 257 | | |
252 | 258 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
74 | 74 | | |
75 | 75 | | |
76 | 76 | | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
77 | 89 | | |
78 | 90 | | |
79 | 91 | | |
| |||
104 | 116 | | |
105 | 117 | | |
106 | 118 | | |
| 119 | + | |
107 | 120 | | |
108 | 121 | | |
109 | 122 | | |
| |||
126 | 139 | | |
127 | 140 | | |
128 | 141 | | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
129 | 146 | | |
130 | 147 | | |
131 | 148 | | |
| |||
136 | 153 | | |
137 | 154 | | |
138 | 155 | | |
139 | | - | |
140 | 156 | | |
141 | 157 | | |
142 | 158 | | |
143 | 159 | | |
144 | 160 | | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
145 | 165 | | |
146 | 166 | | |
147 | 167 | | |
| |||
200 | 220 | | |
201 | 221 | | |
202 | 222 | | |
203 | | - | |
| 223 | + | |
204 | 224 | | |
205 | | - | |
| 225 | + | |
206 | 226 | | |
207 | 227 | | |
208 | 228 | | |
| |||
214 | 234 | | |
215 | 235 | | |
216 | 236 | | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
217 | 242 | | |
218 | 243 | | |
219 | 244 | | |
| |||
252 | 277 | | |
253 | 278 | | |
254 | 279 | | |
| 280 | + | |
| 281 | + | |
255 | 282 | | |
256 | 283 | | |
257 | 284 | | |
| |||
308 | 335 | | |
309 | 336 | | |
310 | 337 | | |
311 | | - | |
312 | | - | |
313 | | - | |
314 | | - | |
| 338 | + | |
| 339 | + | |
315 | 340 | | |
316 | 341 | | |
317 | 342 | | |
| |||
324 | 349 | | |
325 | 350 | | |
326 | 351 | | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
327 | 356 | | |
328 | 357 | | |
329 | 358 | | |
| |||
348 | 377 | | |
349 | 378 | | |
350 | 379 | | |
| 380 | + | |
351 | 381 | | |
352 | 382 | | |
353 | 383 | | |
| |||
370 | 400 | | |
371 | 401 | | |
372 | 402 | | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
373 | 407 | | |
374 | 408 | | |
375 | 409 | | |
| |||
380 | 414 | | |
381 | 415 | | |
382 | 416 | | |
383 | | - | |
384 | 417 | | |
385 | 418 | | |
386 | 419 | | |
387 | 420 | | |
388 | 421 | | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
389 | 426 | | |
390 | 427 | | |
391 | 428 | | |
| |||
444 | 481 | | |
445 | 482 | | |
446 | 483 | | |
447 | | - | |
| 484 | + | |
448 | 485 | | |
449 | | - | |
| 486 | + | |
450 | 487 | | |
451 | 488 | | |
452 | 489 | | |
| |||
458 | 495 | | |
459 | 496 | | |
460 | 497 | | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
461 | 503 | | |
462 | 504 | | |
463 | 505 | | |
| |||
496 | 538 | | |
497 | 539 | | |
498 | 540 | | |
| 541 | + | |
| 542 | + | |
499 | 543 | | |
500 | 544 | | |
501 | 545 | | |
| |||
512 | 556 | | |
513 | 557 | | |
514 | 558 | | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
515 | 563 | | |
516 | 564 | | |
517 | 565 | | |
| |||
546 | 594 | | |
547 | 595 | | |
548 | 596 | | |
549 | | - | |
550 | | - | |
551 | | - | |
552 | | - | |
| 597 | + | |
| 598 | + | |
553 | 599 | | |
554 | 600 | | |
555 | 601 | | |
| |||
562 | 608 | | |
563 | 609 | | |
564 | 610 | | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
565 | 615 | | |
566 | 616 | | |
567 | 617 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
| 13 | + | |
12 | 14 | | |
13 | 15 | | |
14 | 16 | | |
| |||
442 | 444 | | |
443 | 445 | | |
444 | 446 | | |
445 | | - | |
| 447 | + | |
446 | 448 | | |
447 | 449 | | |
448 | 450 | | |
449 | | - | |
| 451 | + | |
| 452 | + | |
450 | 453 | | |
451 | 454 | | |
452 | 455 | | |
453 | 456 | | |
454 | 457 | | |
455 | 458 | | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
456 | 489 | | |
457 | 490 | | |
458 | 491 | | |
| |||
0 commit comments