Repository navigation
fix(workflow-operator, v1.3): degrade instead of raising on malformed chat responses - #9208
Conversation
…responses (apache#8617) ### What changes were proposed in this PR? The text-generation and QA/ranking codegens read a chat provider's reply by indexing straight into it: return body["choices"][0]["message"]["content"] That assumes the response is a dict, that `choices` is non-empty, and that the first choice carries `message.content`. When a provider returns a 200 with anything else, the indexing raises, and since the parse step runs once per row, a single malformed response aborts the entire run. `TextGenCodegen` was the most exposed: it had no `isinstance` check either, so even a plain list body raised. All four extractions (one in `TextGenCodegen`, three in `QaRankingCodegen`) now guard on a truthy `choices` and use `.get` chaining, falling back to the raw JSON body. That is the same idiom `ImageTaskCodegen` adopted in apache#7920, and it matches how the native `hf-inference` shapes beside it already degrade via `body.get("answer", json.dumps(body))`. A bad response now lands in the result column as raw JSON instead of killing the run. ### Any related issues? Closes apache#8486 ### How was this PR tested? 145 tests pass in the Hugging Face suites, `PythonCodeRawInvalidTextSpec` py-compiles the generated Python for all 117 operators, and `scalafmtCheck` and `scalafix --check` are clean. Added a degradation test to `TextGenCodegenSpec` and `QaRankingCodegenSpec`, and updated the assertions in `HuggingFaceInferenceOpDescSpec` that pinned the old form. The emitted Python was also run directly against the failing shapes, comparing this branch with main across 33 task/response combinations: 16 of them raised before (`IndexError` on an empty `choices` list, `KeyError` on a missing `message`/`content`, `TypeError` on a list body) and none raise now. Well-formed chat responses and native `hf-inference` responses parse identically to before. ### Was this PR authored or co-authored using generative AI tooling? Yes, this PR was co-authored with Claude in compliance with ASF policy. --------- Co-authored-by: Meng Wang <[email protected]>
Backport auto-label reportThis
|
Automated Reviewer SuggestionsBased on the
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## release/v1.3 #9208 +/- ##
==================================================
- Coverage 94.10% 94.09% -0.02%
+ Complexity 4809 4807 -2
==================================================
Files 1194 1194
Lines 48648 48616 -32
Branches 5868 5864 -4
==================================================
- Hits 45780 45745 -35
- Misses 1411 1413 +2
- Partials 1457 1458 +1
*This pull request uses carry forward flags. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
| config | throughput | MB/s | latency | max Δ latest / 7d | |
|---|---|---|---|---|---|
| 🔴 | bs=10 sw=10 sl=64 | 572 | 0.349 | 17,400/21,365/21,365 us | 🔴 +17.0% / 🔴 +53.6% |
| 🟢 | bs=100 sw=10 sl=64 | 1,228 | 0.75 | 78,205/114,382/114,382 us | 🟢 -8.7% / 🔴 +18.8% |
| 🔴 | bs=1000 sw=10 sl=64 | 1,450 | 0.885 | 682,366/782,393/782,393 us | 🔴 +7.5% / 🟢 -22.3% |
Baseline details
Latest main f7394bf from same runner
| config | metric | PR | latest main | 7d avg | Δ latest | Δ 7d |
|---|---|---|---|---|---|---|
| bs=10 sw=10 sl=64 | throughput | 572 tuples/sec | 598 tuples/sec | 905.73 tuples/sec | -4.3% | -36.8% |
| bs=10 sw=10 sl=64 | MB/s | 0.349 MB/s | 0.365 MB/s | 0.553 MB/s | -4.4% | -36.9% |
| bs=10 sw=10 sl=64 | p50 | 17,400 us | 14,868 us | 11,331 us | +17.0% | +53.6% |
| bs=10 sw=10 sl=64 | p95 | 21,365 us | 25,399 us | 14,032 us | -15.9% | +52.3% |
| bs=10 sw=10 sl=64 | p99 | 21,365 us | 25,399 us | 17,338 us | -15.9% | +23.2% |
| bs=100 sw=10 sl=64 | throughput | 1,228 tuples/sec | 1,182 tuples/sec | 1,205 tuples/sec | +3.9% | +1.9% |
| bs=100 sw=10 sl=64 | MB/s | 0.75 MB/s | 0.721 MB/s | 0.735 MB/s | +4.0% | +2.0% |
| bs=100 sw=10 sl=64 | p50 | 78,205 us | 84,167 us | 89,237 us | -7.1% | -12.4% |
| bs=100 sw=10 sl=64 | p95 | 114,382 us | 125,246 us | 96,280 us | -8.7% | +18.8% |
| bs=100 sw=10 sl=64 | p99 | 114,382 us | 125,246 us | 111,344 us | -8.7% | +2.7% |
| bs=1000 sw=10 sl=64 | throughput | 1,450 tuples/sec | 1,473 tuples/sec | 1,239 tuples/sec | -1.6% | +17.1% |
| bs=1000 sw=10 sl=64 | MB/s | 0.885 MB/s | 0.899 MB/s | 0.756 MB/s | -1.6% | +17.1% |
| bs=1000 sw=10 sl=64 | p50 | 682,366 us | 679,397 us | 877,826 us | +0.4% | -22.3% |
| bs=1000 sw=10 sl=64 | p95 | 782,393 us | 727,978 us | 919,412 us | +7.5% | -14.9% |
| bs=1000 sw=10 sl=64 | p99 | 782,393 us | 727,978 us | 963,000 us | +7.5% | -18.8% |
Raw CSV
config_idx,batch_size,schema_width,string_len,num_batches,total_ms,total_tuples,total_bytes,tuples_per_sec,mb_per_sec,lat_p50_us,lat_p95_us,lat_p99_us
0,10,10,64,20,349.60,200,128000,572,0.349,17400.11,21364.97,21364.97
1,100,10,64,20,1628.08,2000,1280000,1228,0.750,78204.66,114381.63,114381.63
2,1000,10,64,20,13789.70,20000,12800000,1450,0.885,682365.88,782393.22,782393.22
What changes were proposed in this PR?
Manual backport of #8617 to
release/v1.3, replacing #8993, whose head branch lives in this repository and so could not be corrected by push.The automated cherry-pick conflicted in one file,
HuggingFaceCodegenBaseSpec.scala, and was committed with conflict markers. The cause is #8630, which is onmainbut not on this branch. #8630 appended three tests and achatContentHelperhelper to the end of that spec, and #8617 then appended its own test after them. Those three tests cover the candidate-labels feature that #8630 added, which this branch does not have, so they are left out. The spec here carries only the one test #8617 added.Everything else applied cleanly. Against
release/v1.3, each of the nine files carries exactly the change #8617 made onmain.Any related issues, documentation, discussions?
Backport of #8617. Originally linked #8486. Replaces #8993, which can be closed.
How was this PR tested?
The Hugging Face suites and
PythonCodeRawInvalidTextSpecon this branch: 147 tests across 14 suites, all passing. That includesHuggingFaceParseBehaviorSpec, which runs the generated parser against malformed chat responses. The generated Python of all 117 operators compiles.scalafmtCheckandscalafix --checkare clean for main and test.With the three source files reverted to
release/v1.3, 13 of those tests fail, all of them tests #8617 added or updated, so they exercise the fix on this branch.Was this PR authored or co-authored using generative AI tooling?
Yes, this PR was co-authored with Claude in compliance with ASF policy.