Commit 2572980
authored
fix(ollama): soft-fail on empty response in generate_from_raw (#1161)
* fix(ollama): soft-fail on empty response body; remove stale xfail (#599)
Ollama returns HTTP 200 with an empty `response` field when the first
sampled token is EOS (runner.go:546-552). This is real but vanishingly
rare — 4 400 requests across 1 100 trials showed zero occurrences once
the primary cause (return_exceptions=True in asyncio.gather, PR #1163)
was removed.
This PR adds belt-and-braces handling for that genuine-but-rare path:
warm the model in isolation runs, detect an HTTP-200-with-empty-body
response and log a warning rather than silently returning an empty
string. The stale xfail on test_generate_from_raw (which was passing
cleanly after #1163) is removed.
Three unit tests cover the soft-fail branch directly without needing a
live Ollama server.
Assisted-by: Claude Code
Signed-off-by: Nigel Jones <jonesn@uk.ibm.com>
* docs(agents): add asyncio.gather return_exceptions footgun to common issues
Lesson from #599 investigation: return_exceptions=True silently converts
exceptions to empty values in batch backends.
Assisted-by: Claude Code
Signed-off-by: Nigel Jones <jonesn@uk.ibm.com>
* docs(ollama): document soft-fail contract in generate_from_raw Returns
Addresses reviewer nit on PR #1161: the removed `Raises:` block left
callers with no way to discover that empty done responses now soft-fail
(``value=""``, error stashed in ``_generate_log.extra["error"]``) rather
than propagate, while network-level exceptions still propagate all-or-nothing.
Assisted-by: Claude Code
Signed-off-by: Nigel Jones <jonesn@uk.ibm.com>
* docs(ollama): correct generate_from_raw soft-fail/error wording
Self-review fixes on the prior docstring update:
- "raw response" -> "serialized response dict" (it is response.model_dump())
- move the gather all-or-nothing behaviour to a Note: an exception
propagates (the call raises) rather than returning an empty list, and
successful sibling requests are discarded
- drop the inaccurate "Ollama client exceptions (e.g. ConnectionError)"
framing (ConnectionError is not an ollama type)
Assisted-by: Claude Code
Signed-off-by: Nigel Jones <jonesn@uk.ibm.com>
* docs(ollama): note sibling actions unaffected by empty-response soft-fail
Restores the per-action isolation point from Paul's review suggestion:
an empty-response soft-fail only affects that action's thunk; other
actions in the batch still produce normal results.
Assisted-by: Claude Code
Signed-off-by: Nigel Jones <jonesn@uk.ibm.com>
* test(ollama): use mock_ollama_backend fixture for #599 tests
After rebasing onto main, the shared mock_ollama_backend factory fixture
(test/backends/conftest.py) is now the canonical way to build a patched
backend. Convert the three generate_from_raw empty-response tests from the
local _make_backend helper (which no longer exists post-rebase) to the
fixture, matching the rest of the file.
Assisted-by: Claude Code
Signed-off-by: Nigel Jones <jonesn@uk.ibm.com>
---------
Signed-off-by: Nigel Jones <jonesn@uk.ibm.com>1 parent 006485c commit 2572980
4 files changed
Lines changed: 180 additions & 79 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
119 | 119 | | |
120 | 120 | | |
121 | 121 | | |
| 122 | + | |
122 | 123 | | |
123 | 124 | | |
124 | 125 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
47 | | - | |
| 47 | + | |
48 | 48 | | |
49 | 49 | | |
50 | | - | |
| 50 | + | |
51 | 51 | | |
52 | | - | |
| 52 | + | |
53 | 53 | | |
54 | 54 | | |
55 | | - | |
| 55 | + | |
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
61 | | - | |
62 | | - | |
| 61 | + | |
| 62 | + | |
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
| |||
281 | 281 | | |
282 | 282 | | |
283 | 283 | | |
284 | | - | |
| 284 | + | |
285 | 285 | | |
286 | | - | |
| 286 | + | |
287 | 287 | | |
288 | 288 | | |
289 | 289 | | |
| |||
293 | 293 | | |
294 | 294 | | |
295 | 295 | | |
296 | | - | |
| 296 | + | |
297 | 297 | | |
298 | 298 | | |
299 | 299 | | |
300 | 300 | | |
301 | | - | |
| 301 | + | |
302 | 302 | | |
303 | 303 | | |
304 | 304 | | |
| |||
334 | 334 | | |
335 | 335 | | |
336 | 336 | | |
337 | | - | |
| 337 | + | |
338 | 338 | | |
339 | 339 | | |
340 | 340 | | |
| |||
345 | 345 | | |
346 | 346 | | |
347 | 347 | | |
348 | | - | |
| 348 | + | |
349 | 349 | | |
350 | 350 | | |
351 | 351 | | |
| |||
502 | 502 | | |
503 | 503 | | |
504 | 504 | | |
505 | | - | |
506 | | - | |
507 | | - | |
508 | | - | |
509 | | - | |
510 | | - | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
511 | 517 | | |
512 | 518 | | |
513 | 519 | | |
| |||
549 | 555 | | |
550 | 556 | | |
551 | 557 | | |
552 | | - | |
553 | | - | |
554 | | - | |
555 | | - | |
556 | | - | |
557 | | - | |
558 | | - | |
559 | | - | |
560 | | - | |
561 | | - | |
562 | | - | |
563 | | - | |
564 | | - | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
565 | 589 | | |
566 | | - | |
567 | | - | |
| 590 | + | |
568 | 591 | | |
569 | 592 | | |
570 | 593 | | |
| |||
582 | 605 | | |
583 | 606 | | |
584 | 607 | | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
585 | 612 | | |
586 | 613 | | |
587 | 614 | | |
| |||
624 | 651 | | |
625 | 652 | | |
626 | 653 | | |
627 | | - | |
| 654 | + | |
628 | 655 | | |
629 | | - | |
| 656 | + | |
630 | 657 | | |
631 | 658 | | |
632 | 659 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
| 11 | + | |
10 | 12 | | |
11 | 13 | | |
12 | 14 | | |
| |||
16 | 18 | | |
17 | 19 | | |
18 | 20 | | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
19 | 45 | | |
20 | 46 | | |
21 | 47 | | |
| |||
101 | 127 | | |
102 | 128 | | |
103 | 129 | | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | 130 | | |
108 | 131 | | |
109 | 132 | | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | 133 | | |
114 | 134 | | |
115 | 135 | | |
| |||
0 commit comments