|
10 | 10 |
|
11 | 11 | import io.a2a.server.tasks.PushNotificationSender; |
12 | 12 | import io.a2a.server.tasks.TaskManager; |
| 13 | +import io.a2a.server.tasks.TaskPersistenceException; |
| 14 | +import io.a2a.server.tasks.TaskSerializationException; |
13 | 15 | import io.a2a.server.tasks.TaskStore; |
14 | 16 | import io.a2a.spec.A2AError; |
15 | 17 | import io.a2a.spec.A2AServerException; |
|
41 | 43 | * <b>Note:</b> This bean is eagerly initialized by {@link MainEventBusProcessorInitializer} |
42 | 44 | * to ensure the background thread starts automatically when the application starts. |
43 | 45 | * </p> |
| 46 | + * |
| 47 | + * <h2>Exception Handling</h2> |
| 48 | + * TaskStore persistence failures are caught and handled gracefully: |
| 49 | + * <ul> |
| 50 | + * <li>{@link TaskSerializationException} - Data corruption or schema mismatch. |
| 51 | + * Logged at ERROR level, distributed as {@link InternalError} to clients.</li> |
| 52 | + * <li>{@link TaskPersistenceException} - Database/storage system failure. |
| 53 | + * Logged at ERROR level, distributed as {@link InternalError} to clients.</li> |
| 54 | + * </ul> |
| 55 | + * |
| 56 | + * <p>Processing continues after errors - the failed event is distributed as InternalError |
| 57 | + * to all ChildQueues, and the MainEventBusProcessor continues consuming subsequent events.</p> |
44 | 58 | */ |
45 | 59 | @ApplicationScoped |
46 | 60 | public class MainEventBusProcessor implements Runnable { |
@@ -293,11 +307,26 @@ private boolean updateTaskStore(String taskId, Event event, boolean isReplicated |
293 | 307 | LOGGER.debug("TaskStore updated via TaskManager.process() for task {}: {} (final: {}, replicated: {})", |
294 | 308 | taskId, event.getClass().getSimpleName(), isFinal, isReplicated); |
295 | 309 | return isFinal; |
| 310 | + |
| 311 | + } catch (TaskSerializationException e) { |
| 312 | + // Data corruption or schema mismatch - ALWAYS permanent |
| 313 | + LOGGER.error("Task {} event serialization failed - data corruption detected: {}", |
| 314 | + taskId, e.getMessage(), e); |
| 315 | + throw new InternalError("Failed to serialize task " + taskId + ": " + e.getMessage()); |
| 316 | + |
| 317 | + } catch (TaskPersistenceException e) { |
| 318 | + // Database/storage failure |
| 319 | + LOGGER.error("Task {} event persistence failed: {}", taskId, e.getMessage(), e); |
| 320 | + throw new InternalError("Storage failure for task " + taskId + ": " + e.getMessage()); |
| 321 | + |
296 | 322 | } catch (InternalError e) { |
| 323 | + // Already an InternalError from TaskManager validation - pass through |
297 | 324 | LOGGER.error("Error updating TaskStore via TaskManager for task {}", taskId, e); |
298 | 325 | // Rethrow to prevent distributing unpersisted event to clients |
299 | 326 | throw e; |
| 327 | + |
300 | 328 | } catch (Exception e) { |
| 329 | + // Unexpected exception type - treat as permanent failure |
301 | 330 | LOGGER.error("Unexpected error updating TaskStore for task {}", taskId, e); |
302 | 331 | // Rethrow to prevent distributing unpersisted event to clients |
303 | 332 | throw new InternalError("TaskStore persistence failed: " + e.getMessage()); |
|
0 commit comments