• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

KusionStack / karpor / 39578577111
65%

Build:
DEFAULT BRANCH: main
Ran 21 Oct 2026 09:39AM UTC
Jobs 1
Files 68
Run time 1min
Badge
Embed ▾
README BADGES
x

If you need to use a raster PNG badge, change the '.svg' to '.png' in the link

Markdown

Textile

RDoc

HTML

Rst

21 Oct 2026 09:38AM UTC coverage: 64.035% (+0.2%) from 63.801%
39578577111

push

github

web-flow
fix(ai): don't panic on an empty or short Hugging Face response (#865)

## What type of PR is this?

/kind bug

## What this PR does / why we need it:

`HuggingfaceClient.Generate` returns
`resp[0].GeneratedText[len(prompt):]`. That expression panics in two
cases and is wrong in a third:

- the Inference API answers with an empty list (`[]`): `resp[0]` is out
of range;
- `generated_text` is shorter than the prompt, for example a model that
returns only the completion: the slice bounds are out of range;
- `generated_text` is longer than the prompt but does not start with it:
the first `len(prompt)` characters of the answer are silently cut off.

The method now returns an error (`huggingface returned no generated
text`) for an empty list, and removes the prompt with
`strings.TrimPrefix`, so the echoed prompt is dropped when it is there
and the text is kept whole when it is not. `GenerateStream` calls
`Generate`, so the streaming path gets the same behaviour; it already
reports errors through the `ERROR:` message.

`pkg/infra/ai/huggingface_test.go` (new) answers the Inference API
through a stub `RoundTripper` and checks three cases: a response that
echoes the prompt (unchanged: `" Hi there"`), a response without the
prompt (kept whole) and an empty list (error, no panic). Two of the
three fail on `master` (the empty list panics, the short text panics)
and all pass with this change; `go test ./pkg/infra/ai/` passes.

## Which issue(s) this PR fixes:

None.

This change was made with Claude Code.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

4 of 4 new or added lines in 1 file covered. (100.0%)

4412 of 6890 relevant lines covered (64.03%)

0.7 hits per line

Jobs
ID Job ID Ran Files Coverage
1 39578577111.1 21 Oct 2026 09:39AM UTC 68
64.03
GitHub Action Run
Source Files on build 39578577111
  • Tree
  • List 68
  • Changed 2
  • Source Changed 0
  • Coverage Changed 2
Coverage ∆ File Lines Relevant Covered Missed Hits/Line
  • Back to Repo
  • 218d019f on github
  • Prev Build on main (#39356401477)
  • Next Build on main (#39579317773)
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc