Skip to content

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

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

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 <mengw15@uci.edu>
@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

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant