Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package ai.docling.serve.api.convert.response;

import org.jspecify.annotations.Nullable;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;

import ai.docling.serve.api.task.response.FailureCategory;

/**
* Represents an individual error produced during document conversion.
*
Expand Down Expand Up @@ -42,6 +46,28 @@ public class ErrorItem {
@JsonProperty("module_name")
private String moduleName;

/**
* Semantic category of the error, for filtering.
*
* <p>Absent from responses produced by Docling Serve versions predating this field.
*
* @param category the error category, or null if not reported
* @return the error category, or null if not reported
*/
@JsonProperty("category")
@Nullable
private FailureCategory category;

/**
* 1-indexed page the error is attributable to, or null for document-scoped errors.
*
* @param pageNo the page number, or null if not applicable
* @return the page number, or null if not applicable
*/
@JsonProperty("page_no")
@Nullable
private Integer pageNo;

/**
* Builder for creating {@link ErrorItem} instances.
* Generated by Lombok's {@code @Builder} annotation.
Expand All @@ -51,6 +77,8 @@ public class ErrorItem {
* <li>{@code componentType(String)} - Set the component type</li>
* <li>{@code errorMessage(String)} - Set the error message</li>
* <li>{@code moduleName(String)} - Set the module name</li>
* <li>{@code category(FailureCategory)} - Set the error category</li>
* <li>{@code pageNo(Integer)} - Set the page number</li>
* </ul>
*/
public static class Builder {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package ai.docling.serve.api.task.response;

import com.fasterxml.jackson.annotation.JsonEnumDefaultValue;
import com.fasterxml.jackson.annotation.JsonProperty;

/**
* Semantic category of a task or document failure reported by Docling Serve.
*
* <p>Shared by {@link TaskFailureInfo} (task scope) and document/page-scope errors.
* Upstream documents this category as extensible, so {@link #UNKNOWN} is also the
* default value used when an unrecognized category is encountered during
* deserialization. This graceful fallback is enabled by default on the JSON mappers
* used by {@code docling-serve-client}; a consumer supplying its own Jackson 2 or
* Jackson 3 mapper must enable the equivalent "read unknown enum as default" feature
* itself to get the same behavior instead of a hard deserialization failure.
*
* <ul>
* <li>{@code POLICY}: The request violated a service policy (e.g. an unreachable or disallowed source).</li>
* <li>{@code CAPACITY}: The service ran out of capacity while processing the task.</li>
* <li>{@code SOURCE_UNAVAILABLE}: The source document could not be reached.</li>
* <li>{@code TARGET_UNAVAILABLE}: The result could not be written to the requested target.</li>
* <li>{@code TIMEOUT}: The task exceeded the allowed execution time.</li>
* <li>{@code INTERNAL}: An internal service defect caused the failure.</li>
* <li>{@code BACKEND_FAILURE}: A document/page-scope backend processing failure.</li>
* <li>{@code INFERENCE_FAILURE}: A document/page-scope model inference failure.</li>
* <li>{@code UNKNOWN}: The failure could not be categorized, including categories unrecognized by this version of the library.</li>
* </ul>
*/
public enum FailureCategory {
@JsonProperty("policy")
POLICY,
@JsonProperty("capacity")
CAPACITY,
@JsonProperty("source_unavailable")
SOURCE_UNAVAILABLE,
@JsonProperty("target_unavailable")
TARGET_UNAVAILABLE,
@JsonProperty("timeout")
TIMEOUT,
@JsonProperty("internal")
INTERNAL,
@JsonProperty("backend_failure")
BACKEND_FAILURE,
@JsonProperty("inference_failure")
INFERENCE_FAILURE,
@JsonProperty("unknown")
@JsonEnumDefaultValue
UNKNOWN;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package ai.docling.serve.api.task.response;

import com.fasterxml.jackson.annotation.JsonEnumDefaultValue;
import com.fasterxml.jackson.annotation.JsonProperty;

/**
* Processing phase in which a task failure occurred, as reported in {@link TaskFailureInfo}.
*
* <ul>
* <li>{@code ADMISSION}: The failure occurred while admitting the task (e.g. a document exceeded service limits).</li>
* <li>{@code SOURCE_ENUMERATION}: The failure occurred while resolving or fetching the source document.</li>
* <li>{@code EXECUTION}: The failure occurred while executing the conversion pipeline.</li>
* <li>{@code ORCHESTRATION}: The failure occurred in task orchestration, outside a specific document-processing phase.</li>
* <li>{@code UNKNOWN}: The phase could not be determined. Not an upstream value; added by this library as a
* forward-compatibility fallback for phases unrecognized by this version of the library.</li>
* </ul>
*/
public enum FailurePhase {
@JsonProperty("admission")
ADMISSION,
@JsonProperty("source_enumeration")
SOURCE_ENUMERATION,
@JsonProperty("execution")
EXECUTION,
@JsonProperty("orchestration")
ORCHESTRATION,
@JsonProperty("unknown")
@JsonEnumDefaultValue
UNKNOWN;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package ai.docling.serve.api.task.response;

import java.util.Map;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;

/**
* Structured failure information reported by Docling Serve for a failed task.
*
* <p>Only populated when the backing Docling Serve deployment uses the Ray orchestrator
* (available since Docling Serve v1.25.0); other orchestrators report only
* {@link TaskStatusPollResponse#getErrorMessage()}.
*
* <p>Serialization uses {@link JsonInclude.Include#NON_EMPTY}, so nulls and empty
* collections are omitted from JSON output.
*/
@JsonInclude(JsonInclude.Include.NON_EMPTY)
@lombok.extern.jackson.Jacksonized
@lombok.Builder(toBuilder = true)
@lombok.Getter
@lombok.ToString
public class TaskFailureInfo {
/**
* Semantic category of the failure.
*
* @param category the failure category
* @return the failure category
*/
@JsonProperty("category")
private FailureCategory category;

/**
* Human-readable description of the failure, more specific than the task's
* generic error message for the same failure.
*
* @param message the failure message
* @return the failure message
*/
@JsonProperty("message")
private String message;

/**
* Whether the task can be resubmitted with a reasonable chance of success.
*
* @param retryable whether the failure is retryable
* @return whether the failure is retryable
*/
@JsonProperty("retryable")
private boolean retryable;

/**
* Processing phase in which the failure occurred.
*
* @param phase the failure phase
* @return the failure phase
*/
@JsonProperty("phase")
private FailurePhase phase;

/**
* Additional structured details about the failure.
*
* @param details the failure details, keyed by detail name
* @return the failure details, keyed by detail name
*/
@JsonProperty("details")
private Map<String, String> details;

/**
* Builder for creating {@link TaskFailureInfo} instances.
* Generated by Lombok's {@code @Builder} annotation.
*
* <p>Builder methods:
* <ul>
* <li>{@code category(FailureCategory)} - Set the failure category</li>
* <li>{@code message(String)} - Set the failure message</li>
* <li>{@code retryable(boolean)} - Set whether the failure is retryable</li>
* <li>{@code phase(FailurePhase)} - Set the failure phase</li>
* <li>{@code details(Map<String, String>)} - Set the failure details</li>
* </ul>
*/
public static class Builder {
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package ai.docling.serve.api.task.response;

import org.jspecify.annotations.Nullable;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;

Expand All @@ -21,6 +23,7 @@
* - {@code numDocs}: The total number of documents associated with the task.
* - {@code numProcessed}: The number of documents that have been processed.
* - {@code numSucceeded}: The number of documents that were successfully processed.
* - {@code numPartiallySucceeded}: The number of documents that were partially processed successfully.
* - {@code numFailed}: The number of documents that failed processing.
*/
@JsonInclude(JsonInclude.Include.NON_EMPTY)
Expand All @@ -32,37 +35,53 @@ public class TaskStatusMetadata {
/**
* Total number of documents in the task.
*
* @param numDocs the total number of documents
* @return the total number of documents
* @param numDocs the total number of documents, or null if not reported
* @return the total number of documents, or null if not reported
*/
@JsonProperty("num_docs")
@Nullable
private Long numDocs;

/**
* Number of documents processed so far.
*
* @param numProcessed the number of processed documents
* @return the number of processed documents
* @param numProcessed the number of processed documents, or null if not reported
* @return the number of processed documents, or null if not reported
*/
@JsonProperty("num_processed")
@Nullable
private Long numProcessed;

/**
* Number of documents that succeeded.
*
* @param numSucceeded the number of successful documents
* @return the number of successful documents
* @param numSucceeded the number of successful documents, or null if not reported
* @return the number of successful documents, or null if not reported
*/
@JsonProperty("num_succeeded")
@Nullable
private Long numSucceeded;

/**
* Number of documents that were partially processed successfully.
*
* <p>Absent from responses produced by Docling Serve versions predating this field.
*
* @param numPartiallySucceeded the number of partially successful documents, or null if not reported
* @return the number of partially successful documents, or null if not reported
*/
@JsonProperty("num_partially_succeeded")
@Nullable
private Long numPartiallySucceeded;

/**
* Number of documents that failed.
*
* @param numFailed the number of failed documents
* @return the number of failed documents
* @param numFailed the number of failed documents, or null if not reported
* @return the number of failed documents, or null if not reported
*/
@JsonProperty("num_failed")
@Nullable
private Long numFailed;

/**
Expand All @@ -74,6 +93,7 @@ public class TaskStatusMetadata {
* <li>{@code numDocs(Long)} - Set the total number of documents</li>
* <li>{@code numProcessed(Long)} - Set the number of processed documents</li>
* <li>{@code numSucceeded(Long)} - Set the number of successful documents</li>
* <li>{@code numPartiallySucceeded(Long)} - Set the number of partially successful documents</li>
* <li>{@code numFailed(Long)} - Set the number of failed documents</li>
* </ul>
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
* - {@code taskPosition}: A numerical representation of the task's position in the processing queue.
* - {@code taskStatusMetadata}: Metadata providing detailed statistics and progress information (optional).
* - {@code errorMessage}: The error message reported by Docling Serve when the task failed (optional).
* - {@code failure}: Structured failure information reported by Docling Serve when the task failed (optional).
*/
@JsonInclude(JsonInclude.Include.NON_EMPTY)
@lombok.extern.jackson.Jacksonized
Expand Down Expand Up @@ -90,6 +91,19 @@ public class TaskStatusPollResponse {
@Nullable
private String errorMessage;

/**
* Structured failure information reported by Docling Serve when the task failed.
*
* <p>Only populated by deployments using the Ray orchestrator; other orchestrators
* report only {@link #getErrorMessage()}.
*
* @param failure the structured failure information, or null if not available
* @return the structured failure information, or null if not available
*/
@JsonProperty("failure")
@Nullable
private TaskFailureInfo failure;

/**
* Builder for creating {@link TaskStatusPollResponse} instances.
* Generated by Lombok's {@code @Builder} annotation.
Expand All @@ -102,6 +116,7 @@ public class TaskStatusPollResponse {
* <li>{@code taskPosition(Long)} - Set the queue position</li>
* <li>{@code taskStatusMetadata(TaskStatusMetadata)} - Set the task metadata</li>
* <li>{@code errorMessage(String)} - Set the error message</li>
* <li>{@code failure(TaskFailureInfo)} - Set the structured failure information</li>
* </ul>
*/
public static class Builder {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import org.junit.jupiter.api.Test;

import ai.docling.serve.api.task.response.FailureCategory;

/**
* Unit tests for {@link ErrorItem}.
*/
Expand All @@ -14,16 +16,22 @@ void createErrorItemWithAllFields() {
String componentType = "parser";
String errorMessage = "Failed to parse document structure";
String moduleName = "docling.core.parser";
FailureCategory category = FailureCategory.BACKEND_FAILURE;
Integer pageNo = 3;

ErrorItem errorItem = ErrorItem.builder()
.componentType(componentType)
.errorMessage(errorMessage)
.moduleName(moduleName)
.category(category)
.pageNo(pageNo)
.build();

assertThat(errorItem.getComponentType()).isEqualTo(componentType);
assertThat(errorItem.getErrorMessage()).isEqualTo(errorMessage);
assertThat(errorItem.getModuleName()).isEqualTo(moduleName);
assertThat(errorItem.getCategory()).isEqualTo(category);
assertThat(errorItem.getPageNo()).isEqualTo(pageNo);
}

@Test
Expand All @@ -33,6 +41,8 @@ void createErrorItemWithNullFields() {
assertThat(errorItem.getComponentType()).isNull();
assertThat(errorItem.getErrorMessage()).isNull();
assertThat(errorItem.getModuleName()).isNull();
assertThat(errorItem.getCategory()).isNull();
assertThat(errorItem.getPageNo()).isNull();
}

@Test
Expand Down
Loading