Skip to content

feat(api): map the failure field of the task status response - #835

Open
edeandrea wants to merge 2 commits into
docling-project:mainfrom
edeandrea:feat/778-map-failure-field
Open

edeandrea wants to merge 2 commits into
docling-project:mainfrom
edeandrea:feat/778-map-failure-field

Conversation

@edeandrea

Copy link
Copy Markdown
Contributor

Summary

  • Add FailureCategory (9 values) and FailurePhase (4 values, plus a library-added UNKNOWN) enums to ai.docling.serve.api.task.response, mirroring upstream docling.datamodel.base_models.FailureCategory / docling.datamodel.service.responses.FailurePhase. Both carry a @JsonEnumDefaultValue UNKNOWN constant so a value added upstream after this library's enum was last updated deserializes gracefully instead of failing.
  • Enable READ_UNKNOWN_ENUM_VALUES_USING_DEFAULT_VALUE (Jackson 2) / EnumFeature.READ_UNKNOWN_ENUM_VALUES_USING_DEFAULT_VALUE (Jackson 3) by default in DoclingServeJackson2Client and DoclingServeJackson3Client, next to the existing FAIL_ON_UNKNOWN_PROPERTIES configuration. This is the first time the repo needs an unknown-enum-value policy; consumers supplying their own Jackson mapper need to enable the equivalent feature themselves to get the same graceful fallback (documented on the enums' Javadoc).
  • Add TaskFailureInfo (category, message, retryable, phase, details) and wire it into TaskStatusPollResponse.failure. Only populated by Docling Serve deployments using the Ray orchestrator (v1.25.0+); other orchestrators continue to report only errorMessage, which is left unchanged.
  • Fold in two related upstream-drift gaps flagged in the issue: TaskStatusMetadata.numPartiallySucceeded and ErrorItem.category/ErrorItem.pageNo.
  • Update docs/src/doc/docs/whats-new.md.

Test plan

  • ./gradlew --no-daemon :docling-serve-api:test :docling-serve-client:test
  • ./gradlew --no-daemon spotlessCheck
  • New tests: TaskFailureInfoTests, TaskStatusMetadataTests, TaskStatusPollResponseTests, extended ErrorItemTests, and FailureDeserializationTests (verifies known and unrecognized FailureCategory/FailurePhase values deserialize correctly with both Jackson 2 and Jackson 3 default mappers, including the UNKNOWN fallback).

Refs #778

Assisted-By: Claude Code noreply@anthropic.com

TaskStatusPollResponse now exposes failure (TaskFailureInfo), the
structured category/message/retryable/phase/details Docling Serve
reports for a failed task when the Ray orchestrator is in use.
FailureCategory and FailurePhase are modeled as extensible enums
with an UNKNOWN default so a value added upstream after this
library's enum was last updated deserializes gracefully instead of
failing, when using the default docling-serve-client JSON mappers.

Also fold in two related upstream-drift gaps: TaskStatusMetadata
gains numPartiallySucceeded, and ErrorItem gains category and
pageNo.

Refs docling-project#778

Assisted-By: Claude Code <noreply@anthropic.com>
Signed-off-by: Eric Deandrea <eric.deandrea@ibm.com>
Copilot AI balanced review requested due to automatic review settings December 1, 2026 22:33

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.

🟡 Changes recommended

The new fields can be null in older-server responses but advertise non-null getter contracts under @NullMarked, exposing callers to runtime NPEs unless annotated @Nullable.

2 open issues
What changed in this PR

Adds structured task-failure information to the Java API for Ray-backed Docling Serve deployments, addressing #778 while preserving existing errorMessage behavior.

Changes:

  • Adds TaskFailureInfo and failure enums, with unknown-value fallback in both default Jackson clients.
  • Maps error categories, page numbers, and partially successful document counts.
  • Adds model and deserialization tests, updates existing expectations, and documents the additions.
File Description
docs/​src/​doc/​docs/​whats-new.md Documents new fields and enum fallback behavior.
docling-serve/​docling-serve-client/​src/​test/​java/​ai/​docling/​serve/​client/​FailureDeserializationTests.java Tests known and unknown failure values with both Jackson versions.
docling-serve/​docling-serve-client/​src/​test/​java/​ai/​docling/​serve/​client/​AbstractDoclingServeClientTests.java Updates the expected metadata string.
docling-serve/​docling-serve-client/​src/​main/​java/​ai/​docling/​serve/​client/​DoclingServeJackson3Client.java Enables default-value fallback for unknown enums.
docling-serve/​docling-serve-client/​src/​main/​java/​ai/​docling/​serve/​client/​DoclingServeJackson2Client.java Enables default-value fallback for unknown enums.
docling-serve/​docling-serve-api/​src/​test/​java/​ai/​docling/​serve/​api/​task/​response/​TaskStatusPollResponseTests.java Tests responses with and without structured failures.
docling-serve/​docling-serve-api/​src/​test/​java/​ai/​docling/​serve/​api/​task/​response/​TaskStatusMetadataTests.java Tests metadata fields, including partial successes.
docling-serve/​docling-serve-api/​src/​test/​java/​ai/​docling/​serve/​api/​task/​response/​TaskFailureInfoTests.java Tests failure fields and empty details.
docling-serve/​docling-serve-api/​src/​test/​java/​ai/​docling/​serve/​api/​convert/​response/​ErrorItemTests.java Extends tests for category and page number.
docling-serve/​docling-serve-api/​src/​main/​java/​ai/​docling/​serve/​api/​task/​response/​TaskStatusPollResponse.java Exposes optional structured failure information.
docling-serve/​docling-serve-api/​src/​main/​java/​ai/​docling/​serve/​api/​task/​response/​TaskStatusMetadata.java Maps the partially successful document count.
docling-serve/​docling-serve-api/​src/​main/​java/​ai/​docling/​serve/​api/​task/​response/​TaskFailureInfo.java Defines structured failure data, including retryability.
docling-serve/​docling-serve-api/​src/​main/​java/​ai/​docling/​serve/​api/​task/​response/​FailurePhase.java Defines failure phases and an unknown fallback.
docling-serve/​docling-serve-api/​src/​main/​java/​ai/​docling/​serve/​api/​task/​response/​FailureCategory.java Defines failure categories and an unknown fallback.
docling-serve/​docling-serve-api/​src/​main/​java/​ai/​docling/​serve/​api/​convert/​response/​ErrorItem.java Maps error category and page number.

Review effort: Balanced

Comment on lines +55 to +56
@JsonProperty("category")
private FailureCategory category;
Comment on lines +60 to +67
/**
* Number of documents that were partially processed successfully.
*
* @param numPartiallySucceeded the number of partially successful documents
* @return the number of partially successful documents
*/
@JsonProperty("num_partially_succeeded")
private Long numPartiallySucceeded;
Satisfies the spotless formatting rules, which rejected the wrapped
form of the constant.

Assisted-By: Claude Code <noreply@anthropic.com>
Signed-off-by: Eric Deandrea <eric.deandrea@ibm.com>
Copilot AI balanced review requested due to automatic review settings December 1, 2026 22:38

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.

🔵 Needs a closer look

The tests use independent mappers rather than default-built clients, leaving the production unknown-enum fallback unprotected against regression.

2 open issues
1 previously missed issue

In code that hasn't changed since last review

Medium severity Test unknown-enum fallback with default-built Jackson clients

docling-serve/​docling-serve-client/​src/​test/​java/​ai/​docling/​serve/​client/​FailureDeserializationTests.java:46

These tests configure independent mappers, so removing either production builder's unknown-enum feature flag would still leave all four tests passing. Add regression tests that deserialize through default-built DoclingServeJackson2Client and DoclingServeJackson3Client instances without supplying custom mappers; their protected readValue methods are accessible from this test package. This will cover the promised default UNKNOWN fallback for unfamiliar categories and phases.

Review effort: Balanced

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.

2 participants