Skip to content

fix(workflow-operator, v1.3): degrade instead of raising on malformed chat responses - #8993

Closed
github-actions[bot] wants to merge 1 commit into
release/v1.3from
backport/8617-degrade-instead-of-raising-on-malformed-v1.3
Closed

github-actions[bot] wants to merge 1 commit into
release/v1.3from
backport/8617-degrade-instead-of-raising-on-malformed-v1.3

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

What changes were proposed in this PR?

Automated backport of #8617 to release/v1.3.

Source: 65a748a · automation run

Any related issues, documentation, discussions?

Backport of #8617. Originally linked #8486.

How was this PR tested?

Release-branch CI runs on this branch once the conflicts are resolved and this PR is marked ready for review.

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

No.

…responses (#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 #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.

---------

(backported from commit 65a748a)

Co-authored-by: Meng Wang <[email protected]>
@github-actions

Copy link
Copy Markdown
Contributor Author

The cherry-pick conflicted and was committed with conflict markers. Resolve the conflicts on this branch, then mark this PR ready for review.

Conflicting files:

  • common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/huggingFace/codegen/HuggingFaceCodegenBaseSpec.scala

@mengw15

mengw15 commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

@PG1204 the cherry-pick of #8617 conflicts in HuggingFaceCodegenBaseSpec.scala. This branch lives in apache/texera, so you can't push to it; could you open a PR with the same title against release/v1.3 from your fork, with the conflict resolved (as #7905 did for v1.2)? I'll close this one once yours is up.

@github-actions

Copy link
Copy Markdown
Contributor Author

Automated Reviewer Suggestions

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

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

@PG1204

PG1204 commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

@PG1204 the cherry-pick of #8617 conflicts in HuggingFaceCodegenBaseSpec.scala. This branch lives in apache/texera, so you can't push to it; could you open a PR with the same title against release/v1.3 from your fork, with the conflict resolved (as #7905 did for v1.2)? I'll close this one once yours is up.

@mengw15 thanks, done in #9208 (from my fork, against release/v1.3, same title).

@mengw15 mengw15 closed this Oct 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants