Skip to content

CAMEL-24528: camel-huggingface - surface Python inference errors in four task predictors - #25854

Merged
Croway merged 1 commit into
apache:mainfrom
oscerd:fix/CAMEL-24528
Aug 28, 2026
Merged

CAMEL-24528: camel-huggingface - surface Python inference errors in four task predictors#25854
Croway merged 1 commit into
apache:mainfrom
oscerd:fix/CAMEL-24528

Conversation

@oscerd

@oscerd oscerd commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Issue

CAMEL-24528

Problem

Ten task predictors delegate to a Python inference script and read the result via output.getAsString("data").
Six of them guard the output before using it:

String resultJson = output.getAsString("data");
if (resultJson.contains("\"error\"")) {
    throw new RuntimeCamelException("Python inference failed: " + resultJson);
}

Four do not: TextGenerationPredictor, SummarizationPredictor, QuestionAnsweringPredictor
and TextToImagePredictor. When the Python script fails and returns a JSON error payload
({"error": ...}), these four set it as the successful result:

  • text generation / summarization / question answering return the raw error JSON as the body;
  • text-to-image serves the error JSON bytes to the caller as image/png.

Fix

Add the same error guard to the four predictors. For text-to-image (whose output is raw image bytes)
the returned bytes are decoded to a string to check for the error marker before the image body is set.

Testing

  • New PredictorErrorHandlingTest asserts each of the four predictors throws on an error payload, and
    that a successful text-generation result is still passed through.
  • mvn -Psourcecheck validate green.

Claude Code on behalf of oscerd

…our task predictors

TextGenerationPredictor, SummarizationPredictor, QuestionAnsweringPredictor and
TextToImagePredictor set the returned data as the successful result without
checking whether the Python script had returned an error payload. The six other
task predictors guard the output with
`if (result.contains("\"error\"")) throw new RuntimeCamelException(...)`, so a
failed inference in these four was silently delivered as a success. For
text-to-image the JSON error text was served as image/png bytes.

Add the same guard to the four predictors. Text-to-image decodes the returned
bytes to a string to check for the error marker before setting the image body.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Signed-off-by: Andrea Cosentino <ancosen@gmail.com>
@oscerd oscerd added the bug Something isn't working label Aug 28, 2026
@oscerd oscerd added this to the 4.23.0 milestone Aug 28, 2026
@oscerd
oscerd requested review from Croway and davsclaus August 28, 2026 04:49
@github-actions

Copy link
Copy Markdown
Contributor

🌟 Thank you for your contribution to the Apache Camel project! 🌟
🤖 CI automation will test this PR automatically.

🐫 Apache Camel Committers, please review the following items:

  • First-time contributors require MANUAL approval for the GitHub Actions to run
  • You can use the command /component-test (camel-)component-name1 (camel-)component-name2.. to request a test from the test bot although they are normally detected and executed by CI.
  • You can label PRs using skip-tests and test-dependents to fine-tune the checks executed by this PR.
  • Build and test logs are available in the summary page. Only Apache Camel committers have access to the summary.

⚠️ Be careful when sharing logs. Review their contents before sharing them publicly.

@github-actions

Copy link
Copy Markdown
Contributor

🧪 CI tested the following changed modules:

  • components/camel-ai/camel-huggingface

🔬 Scalpel shadow comparison — Scalpel: 9 tested, 28 compile-only — current: 9 all tested

Maveniverse Scalpel detected 37 affected modules (current approach: 9).

⚠️ Modules only in Scalpel (28)
  • apache-camel
  • camel-allcomponents
  • camel-catalog
  • camel-catalog-console
  • camel-catalog-maven
  • camel-catalog-suggest
  • camel-componentdsl
  • camel-csimple-maven-plugin
  • camel-endpointdsl
  • camel-endpointdsl-support
  • camel-itest
  • camel-jbang-core
  • camel-jbang-it
  • camel-jbang-main
  • camel-jbang-plugin-edit
  • camel-jbang-plugin-generate
  • camel-jbang-plugin-kubernetes
  • camel-jbang-plugin-test
  • camel-kamelet-main
  • camel-launcher
  • camel-report-maven-plugin
  • camel-route-parser
  • camel-yaml-dsl
  • camel-yaml-dsl-deserializers
  • camel-yaml-dsl-maven-plugin
  • coverage
  • docs
  • dummy-component

Skip-tests mode would test 9 modules (1 direct + 8 downstream), skip tests for 28 (generated code, meta-modules)

Modules Scalpel would test (9)
  • camel-huggingface
  • camel-jbang-mcp
  • camel-jbang-plugin-mcp
  • camel-jbang-plugin-route-parser
  • camel-jbang-plugin-tui
  • camel-jbang-plugin-validate
  • camel-launcher-container
  • camel-yaml-dsl-validator
  • camel-yaml-dsl-validator-maven-plugin
Modules with tests skipped (28)
  • apache-camel
  • camel-allcomponents
  • camel-catalog
  • camel-catalog-console
  • camel-catalog-maven
  • camel-catalog-suggest
  • camel-componentdsl
  • camel-csimple-maven-plugin
  • camel-endpointdsl
  • camel-endpointdsl-support
  • camel-itest
  • camel-jbang-core
  • camel-jbang-it
  • camel-jbang-main
  • camel-jbang-plugin-edit
  • camel-jbang-plugin-generate
  • camel-jbang-plugin-kubernetes
  • camel-jbang-plugin-test
  • camel-kamelet-main
  • camel-launcher
  • camel-report-maven-plugin
  • camel-route-parser
  • camel-yaml-dsl
  • camel-yaml-dsl-deserializers
  • camel-yaml-dsl-maven-plugin
  • coverage
  • docs
  • dummy-component

ℹ️ Shadow mode — Scalpel observes but does not affect test execution. Learn more

All tested modules (37 modules)
  • Camel :: AI :: Hugging Face
  • Camel :: All Components Sync point
  • Camel :: Assembly
  • Camel :: Catalog :: CSimple Maven Plugin (deprecated)
  • Camel :: Catalog :: Camel Catalog
  • Camel :: Catalog :: Camel Report Maven Plugin
  • Camel :: Catalog :: Camel Route Parser
  • Camel :: Catalog :: Console
  • Camel :: Catalog :: Dummy Component
  • Camel :: Catalog :: Maven
  • Camel :: Catalog :: Suggest
  • Camel :: Component DSL
  • Camel :: Coverage
  • Camel :: Docs
  • Camel :: Endpoint DSL
  • Camel :: Endpoint DSL :: Support
  • Camel :: Integration Tests
  • Camel :: JBang :: Core
  • Camel :: JBang :: Integration tests
  • Camel :: JBang :: MCP
  • Camel :: JBang :: Main
  • Camel :: JBang :: Plugin :: Edit
  • Camel :: JBang :: Plugin :: Generate
  • Camel :: JBang :: Plugin :: Kubernetes
  • Camel :: JBang :: Plugin :: MCP
  • Camel :: JBang :: Plugin :: Route Parser
  • Camel :: JBang :: Plugin :: TUI
  • Camel :: JBang :: Plugin :: Testing
  • Camel :: JBang :: Plugin :: Validate
  • Camel :: Kamelet Main
  • Camel :: Launcher
  • Camel :: Launcher :: Container
  • Camel :: YAML DSL
  • Camel :: YAML DSL :: Deserializers
  • Camel :: YAML DSL :: Maven Plugins
  • Camel :: YAML DSL :: Validator
  • Camel :: YAML DSL :: Validator Maven Plugin

⚙️ View full build and test results

@gnodet gnodet 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.

Clean and consistent fix. The four predictors that were missing error guards (TextGenerationPredictor, SummarizationPredictor, QuestionAnsweringPredictor, TextToImagePredictor) now follow the same error-detection pattern used by the other six predictors.

Key observations:

  • The error-detection pattern (result.contains("\"error\"")) is consistent with the existing codebase across all ten predictors.
  • Tests cover all four error scenarios plus a happy-path case.
  • The component exists on camel-4.22.x where the bug is present — backport is worth considering.

LGTM 👍


AI-generated review on behalf of Guillaume Nodet — verify any suggestions before applying.

@Croway

Croway commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

I wonder if result.contains("\"error\"") is the correct approach. Maybe can be improved, I'll merge it anyway, and open an issue about it

@Croway
Croway merged commit a53ceb1 into apache:main Aug 28, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working components components-ai

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants