Skip to content

fix(workflow-operator): degrade instead of raising on malformed chat responses - #8617

Merged
mengw15 merged 11 commits into
apache:mainfrom
PG1204:fix/hf-chat-response-degrade
Oct 15, 2026
Merged

mengw15 merged 11 commits into
apache:mainfrom
PG1204:fix/hf-chat-response-degrade

Conversation

@PG1204

@PG1204 PG1204 commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

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 #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 #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.

@Yicong-Huang Yicong-Huang added the release/v1.3 back porting to release/v1.3 label Sep 21, 2026
@github-actions
github-actions Bot requested a review from mengw15 September 21, 2026 00:10
@github-actions

Copy link
Copy Markdown
Contributor

Backport auto-label report

This fix: PR was checked against each actively-supported release branch. A release/* label nominates a backport target; the branch's release manager approving this PR is what sends the fix there. The required Backport Approvals check stays red until every label below is approved, so each manager either approves or removes their own label — which is why the labels left on a merged PR are exactly the branches it reached.

Release branch Analysis
✅ release/v1.3 Change detected on this branch — label added; this fix is queued to backport here. @mengw15 decides: approving sends the fix here, removing this label declines it. The merge waits on one or the other. Review requested.
⚠️ release/v1.2 Not labeled automatically — none of the files this PR modifies exist on this branch (common/workflow-operator/src/main/scala/org/apache/texera/amber/operator/huggingFace/codegen/QaRankingCodegen.scala, common/workflow-operator/src/main/scala/org/apache/texera/amber/operator/huggingFace/codegen/TextGenCodegen.scala, common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/huggingFace/HuggingFaceInferenceOpDescSpec.scala, common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/huggingFace/codegen/QaRankingCodegenSpec.scala, common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/huggingFace/codegen/TextGenCodegenSpec.scala). The fix may target code that isn't on this release, or the files were moved/renamed after the branch was cut. Please check and add release/v1.2 by hand if this fix should be backported here — its release manager then has to approve before this PR can merge.

Auto-label run.

@github-actions

Copy link
Copy Markdown
Contributor

Automated Reviewer Suggestions

Based on the git blame history of the changed files, we recommend the following reviewers:

  • Contributors with relevant context: @EmilySun621
    You can notify them by mentioning @EmilySun621 in a comment.

@PG1204

PG1204 commented Sep 21, 2026

Copy link
Copy Markdown
Contributor Author

/request-review @Ma77Ball

@codecov-commenter

codecov-commenter commented Sep 21, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.29%. Comparing base (40ced5b) to head (3fca4b3).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #8617      +/-   ##
============================================
- Coverage     92.31%   92.29%   -0.02%     
  Complexity     5049     5049              
============================================
  Files          1259     1255       -4     
  Lines         53924    53569     -355     
  Branches       6722     6653      -69     
============================================
- Hits          49778    49442     -336     
+ Misses         2485     2474      -11     
+ Partials       1661     1653       -8     
Flag Coverage Δ *Carryforward flag
access-control-service 77.38% <ø> (ø)
agent-service 99.16% <ø> (ø) Carriedforward from 8bfe034
amber 87.32% <ø> (ø)
computing-unit-managing-service 60.48% <ø> (ø)
config-service 87.37% <ø> (ø)
file-service 82.00% <ø> (ø)
frontend 96.56% <ø> (+0.01%) ⬆️ Carriedforward from 8bfe034
notebook-migration-service 83.73% <ø> (ø)
pyamber 98.58% <ø> (+0.08%) ⬆️ Carriedforward from 8bfe034
workflow-compiling-service 72.43% <ø> (ø)

*This pull request uses carry forward flags. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions

github-actions Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Benchmark changes need a look

🟢 4 better · 🔴 4 worse · ⚪ 7 noise (<±5%) · 0 without baseline

Compared against main 40ced5b benchmarked on this same runner, so the delta is largely free of cross-runner hardware noise. The "7d avg" column still reflects the gh-pages dashboard. Treat <±5% as noise unless repeated.

Dashboard · Run

config throughput MB/s latency max Δ latest / 7d
🔴 bs=10 sw=10 sl=64 543 0.331 18,090/25,038/25,038 us 🟢 -11.7% / 🔴 +61.9%
🔴 bs=100 sw=10 sl=64 1,158 0.707 85,947/112,501/112,501 us 🟢 -13.0% / 🟢 -11.8%
⚪ bs=1000 sw=10 sl=64 1,399 0.854 715,946/760,540/760,540 us ⚪ within ±5% / 🟢 +27.3%
Baseline details

Latest main 40ced5b from same runner

config metric PR latest main 7d avg Δ latest Δ 7d
bs=10 sw=10 sl=64 throughput 543 tuples/sec 585 tuples/sec 822.11 tuples/sec -7.2% -34.0%
bs=10 sw=10 sl=64 MB/s 0.331 MB/s 0.357 MB/s 0.502 MB/s -7.3% -34.0%
bs=10 sw=10 sl=64 p50 18,090 us 16,378 us 12,129 us +10.5% +49.1%
bs=10 sw=10 sl=64 p95 25,038 us 28,363 us 15,469 us -11.7% +61.9%
bs=10 sw=10 sl=64 p99 25,038 us 28,363 us 18,357 us -11.7% +36.4%
bs=100 sw=10 sl=64 throughput 1,158 tuples/sec 1,194 tuples/sec 1,058 tuples/sec -3.0% +9.5%
bs=100 sw=10 sl=64 MB/s 0.707 MB/s 0.729 MB/s 0.646 MB/s -3.0% +9.5%
bs=100 sw=10 sl=64 p50 85,947 us 79,760 us 97,399 us +7.8% -11.8%
bs=100 sw=10 sl=64 p95 112,501 us 129,312 us 104,184 us -13.0% +8.0%
bs=100 sw=10 sl=64 p99 112,501 us 129,312 us 117,615 us -13.0% -4.3%
bs=1000 sw=10 sl=64 throughput 1,399 tuples/sec 1,431 tuples/sec 1,099 tuples/sec -2.2% +27.3%
bs=1000 sw=10 sl=64 MB/s 0.854 MB/s 0.873 MB/s 0.671 MB/s -2.2% +27.3%
bs=1000 sw=10 sl=64 p50 715,946 us 700,210 us 946,743 us +2.2% -24.4%
bs=1000 sw=10 sl=64 p95 760,540 us 784,767 us 985,437 us -3.1% -22.8%
bs=1000 sw=10 sl=64 p99 760,540 us 784,767 us 1,012,622 us -3.1% -24.9%
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,368.66,200,128000,543,0.331,18090.09,25038.34,25038.34
1,100,10,64,20,1727.81,2000,1280000,1158,0.707,85947.20,112501.06,112501.06
2,1000,10,64,20,14298.34,20000,12800000,1399,0.854,715945.75,760540.11,760540.11

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Nested malformed values can still produce request errors instead of the promised raw-JSON fallback.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 4 Medium severity

Open (4)
What changed in this PR

Improves Hugging Face code-generated parsers so malformed chat responses fall back to raw JSON.

Changes:

  • Guards chat response extraction in text-generation and QA/ranking tasks.
  • Updates generated-code assertions and regression tests.
File Description
common/​workflow-operator/​src/​test/​scala/​org/​apache/​texera/​amber/​operator/​huggingFace/​HuggingFaceInferenceOpDescSpec.scala Updates generated-parser assertions.
common/​workflow-operator/​src/​test/​scala/​org/​apache/​texera/​amber/​operator/​huggingFace/​codegen/​TextGenCodegenSpec.scala Adds text-generation degradation coverage.
common/​workflow-operator/​src/​test/​scala/​org/​apache/​texera/​amber/​operator/​huggingFace/​codegen/​QaRankingCodegenSpec.scala Adds QA/ranking degradation coverage.
common/​workflow-operator/​src/​main/​scala/​org/​apache/​texera/​amber/​operator/​huggingFace/​codegen/​TextGenCodegen.scala Adds guarded text response parsing.
common/​workflow-operator/​src/​main/​scala/​org/​apache/​texera/​amber/​operator/​huggingFace/​codegen/​QaRankingCodegen.scala Adds guarded QA/ranking response parsing.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@mengw15 mengw15 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@PG1204
PG1204 requested a review from mengw15 September 24, 2026 19:56

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PG1204

PG1204 commented Oct 5, 2026

Copy link
Copy Markdown
Contributor Author

@mengw15 I want to follow up with you regarding the review of this PR. I have applied all changes to all of the recent suggestions. Requesting your review on the changes.

@mengw15
mengw15 added this pull request to the merge queue Oct 5, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to no response for status checks Oct 5, 2026
@mengw15
mengw15 added this pull request to the merge queue Oct 5, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to no response for status checks Oct 5, 2026
@mengw15
mengw15 added this pull request to the merge queue Oct 13, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to no response for status checks Oct 13, 2026
@mengw15
mengw15 enabled auto-merge October 13, 2026 19:03
@mengw15
mengw15 added this pull request to the merge queue Oct 15, 2026
Merged via the queue into apache:main with commit 65a748a Oct 15, 2026
33 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

Backport PR opened: draft #8993 (#8993) to release/v1.3, assigned to @PG1204 — needs manual work because the cherry-pick conflicts.

renovate-bot pushed a commit to renovate-bot/apache-_-texera that referenced this pull request Nov 25, 2026
)

### What changes were proposed in this PR?

Remove unused imports, bindings, helpers and fields, and settings that
repeat a default or another entry, from the Amber Python runtime, the
Python test resources of the workflow compiler and operators, the `bin/`
licensing, local-dev and observability scripts, repository
configuration, and three GitHub workflows (**+102/-172 lines**). There
is no behavior change.

- **Amber Python runtime:** `StatisticsManager` uses `defaultdict`
instead of the deprecated `typing.DefaultDict`, and
`BroadcastPartitioner` builds its batch with `[]`.
`LargeBinaryOutputStream` raises and documents `OSError` (which
`IOError` aliases), wraps its best-effort cleanup delete in
`contextlib.suppress`, and drops the `pass` after `flush`'s docstring.
- **Operator verification test resources:** `py_op_driver.py` drops ten
`pytexera` imports and `RAW_TYPE_MAPPING` that it never reads. User code
runs in its own namespace seeded by `from pytexera import *`, so the
"used dynamically" note on those imports did not hold. `compare.py`
drops the uncalled `_string_columns` helper and two dict copies of
`double_kinds_a`/`double_kinds_e`, and `hf_parse_probe.py` drops unused
`io` and `re` imports. Quoted annotations, `open(..., "r")`,
`startswith` plus a slice, and a placeholder-free f-string take their
plain forms here and in `standalone_worker.py`, `py_compile_worker.py`
and `hf_binary_value_probe.py`.
- **`bin/` scripts:** the licensing tools use a tuple `startswith`, read
the one regex group they need instead of unpacking all four, print plain
strings where f-strings had no placeholders, return a `bool` expression
directly, drop annotation quotes under `from __future__ import
annotations`, use `removesuffix`, and name unused loop values `_`. Two
licensing tests drop `# noqa: E402` comments that suppress nothing under
Ruff, and `test_local_dev_tui.py` drops the never-passed `version`
parameter of `_seed_jvm_layout` together with the docstring sentence
about a jar it never wrote. `bin/observability/smoke_test.py` stops
returning an unread status from `_post`, builds the trace id from one
`uuid4().hex` (the first 32 hex digits of two concatenated ones were
always the first), and drops a `leaked = False` that both branches of
the following `try` overwrite.
- **Repository configuration:** `amber/pyproject.toml` drops
`line-length = 88` and `max-complexity = 10`, which are Ruff's defaults
(and `C901` is not selected). `.dockerignore` drops a root
`user-resources/` entry that its first rule, `**/user-resources/`,
already covers. `bin/fix-format.sh` drops the `""` case that
`TARGET="${1:-all}"` makes unreachable, and `bin/frontend-proto-gen.sh`
drops a `--proto_path` that repeats its `-I`.
`bin/k8s/templates/aws/.gitkeep` goes, since the folder holds
`s3-credentials-secret.yaml`. `bin/y-websocket-server/package.json`
drops npm-init's `main` and placeholder `test` script (the image runs
`npx y-websocket`), and a `bin/observability/docker-compose.yml` comment
stops pointing at a `start_app.sh` that the repository does not have.
- **GitHub workflows:** `comment-commands.yml` drops `github.event_name
== 'issue_comment' && github.event.action == 'created'` from three job
conditions, because the workflow only runs on `issue_comment:
[created]`. `pr-assignment.yml` drops a `|| ''` that follows a `typeof
... === 'string'` guard. `benchmarks-pr-comment.yml` stops storing
per-benchmark commit and date, a sample count and delta labels that
nothing reads, takes each row's status from the deltas it already
computed instead of a second `deltaInfo` pass, reuses each metric's
7-day delta, and builds the PR-only CSV table only when there is no
comparison to show.

| Event | PR / Commit |
| --- | --- |
| Introduced by | Amber Python runtime: apache#1891 (2023-05-01), apache#3262
(2025-02-18), apache#4100 (2025-12-15), apache#4707 (2026-05-03), apache#5249
(2026-06-06), apache#8260 (2026-11-18); test resources: apache#7207 (2026-08-14),
apache#8617 (2026-10-15), apache#9306 (2026-11-10), apache#8357 (2026-11-17), apache#8358
(2026-11-18), apache#8359 (2026-11-19); `bin/` scripts: apache#4387 (2026-04-29),
apache#4668 (2026-05-02), apache#4693 (2026-05-02), apache#4711 (2026-05-03), apache#5057
(2026-05-15), apache#5417 (2026-06-10), apache#5961 (2026-06-28), apache#5377
(2026-10-28); configuration: apache#3019 (2024-11-20), apache#3335 (2025-03-23),
apache#3441 (2025-05-19), apache#3890 (2025-10-14), apache#4005 (2025-10-29), apache#4105
(2025-12-05), apache#5757 (2026-06-24); workflows: apache#4885 (2026-05-03), apache#4986
(2026-05-08), apache#5148 (2026-05-22), apache#5557 (2026-06-11), apache#5639 (2026-06-12)
|
| Usage removed by | `issue_comment` checks: apache#4899 (2026-05-04, `ci:
drop the triage label, use is:open no:assignee filter`) moved `/take`
out of `issue-triage.yml`, which also ran on `issues` events, into a
workflow that only runs on created comments, and apache#4986 and apache#5148 copied
the checks into two new jobs; `aws/.gitkeep`: apache#5932 (2026-07-01,
`feat(k8s): make app-tier object storage configurable via storage.s3`)
added the folder's first template; PR-only CSV table: apache#5639 (2026-06-12,
`ci: compare benchmark PRs with main`) shows it only when there is no
comparison; everything else: unused or redundant since introduction |

As of 2026-11-23, the unread test-resource code is under a week old, the
`.gitkeep` placeholder and the unread benchmark fields have been
redundant for about 5 months, the `issue_comment` checks for over 6
months, and the duplicate `.dockerignore` entry and `--proto_path` for
20 and 24 months.

### Any related issues, documentation, discussions?

Closes apache#9676.

### How was this PR tested?

Ran on `525f8ce3fb` and on `main` at `89a492f97e` (Windows 11, Python
3.12 with CI's pinned `ruff` 0.14.7, `pytest` 9.0.3 and `textual` 8.2.8,
JDK 17):

```bash
cd amber
ruff check src/main/python src/test/python
ruff format --check src/main/python src/test/python
pytest -m "not integration"
cd ..
ruff check $(git diff --name-only origin/main -- '*.py' ':!amber/')
python -m pytest bin/ -v --tb=short
sbt "WorkflowCompilingService/testOnly org.apache.texera.amber.translator.verify.ComparatorSpec org.apache.texera.amber.translator.verify.HarnessSpec org.apache.texera.amber.translator.verify.PyOpExecHarnessSpec org.apache.texera.amber.translator.verify.VisualizationJsonComparatorSpec"
sbt "WorkflowOperator/testOnly org.apache.texera.amber.operator.huggingFace.codegen.HuggingFaceBinaryValueBehaviorSpec org.apache.texera.amber.operator.huggingFace.codegen.HuggingFaceParseBehaviorSpec org.apache.texera.amber.util.PythonCodeRawInvalidTextSpec"
```

- Ruff: passed on `amber/` (218 files already formatted) and on the 14
changed Python files outside `amber/`.
- `pytest -m "not integration"` in `amber/` (JUnit XML): each of the
1,524 tests has the same outcome as on `main`: 1,496 passed, 10 skipped,
and the same 18 platform-dependent tests (Iceberg catalog on PostgreSQL
and `s3fs`, time zones, object reprs) fail on this Windows machine on
both.
- `python -m pytest bin/` (JUnit XML): each of the 196 tests has the
same outcome as on `main`: 186 passed, and nine `bin/mounter` tests plus
`test_stamp_dir_for_matches_shell_sha1`, which assume POSIX paths and
shells, fail on Windows on both.
- sbt (JUnit XML, `UDF_PYTHON_PATH` set to Python 3.12 because Windows
has no `python3`): these seven suites load the edited test resources.
`WorkflowCompilingService` passed 52 of 52 in 4 suites and
`WorkflowOperator` 11 of 11 in 3 suites, with 0 canceled, the same as on
`main`.
- Licensing scripts: `concat_license_binary.py` writes byte-identical
combined licenses for the Python and frontend images, and
`check_binary_deps.py jar` prints byte-identical reports and exit codes
for a synthetic lib folder with missing, extra and version-mismatched
jars, with and without `--ignore-transitive-version`.
- Workflows: the three edited workflows run only from the default branch
(`issue_comment`, `pull_request_target` and `workflow_run`), so this
PR's CI cannot run them. Each edited `github-script` body ran before and
after under Node with recording stubs for `github`, `core`, `fs` and
`fetch`, over 496 fixtures (missing or malformed CSV and baseline data,
failed API calls, body edits with and without closing references). Every
API call, comment body and log line is identical, and a one-line change
to each script does show up in its traces. The `comment-commands.yml`
conditions differ from `main` only by the two removed checks.
- `bash -n` passes on `bin/fix-format.sh` and
`bin/frontend-proto-gen.sh`, and the edited YAML, TOML and JSON files
parse.
- After review, `f84888ca6c` changes only three docstrings in
`large_binary_output_stream.py` and inlines one local in
`py_op_driver.py`. On it, Ruff passes as above, each of the 1,524
`amber` tests again has the same outcome as on `main`, the four
`WorkflowCompilingService` suites pass 52 of 52, and `_jsonify` returns
the same strings as on `525f8ce3fb` for seven `BINARY` inputs, with and
without the pickle marker.

### Was this PR authored or co-authored using generative AI tooling?

Generated-by: Claude Code (Claude Opus 5.5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

common fix release/v1.3 back porting to release/v1.3

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Malformed chat responses abort the run in the text-generation and QA codegens

5 participants