Repository navigation
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
A moderate active issue remains because synchronous setup failures can occur before the terminal exception handler is attached, leaving those failures without the claimed logging protection.
1 open issue
What changed in this PR
Fixes asynchronous cleanup task retries by capturing the request-scoped principal before dispatch and logging terminal task failures.
Changes:
- Preserves the principal across retry attempts.
- Logs exhausted task failures.
- Adds CDI retry coverage and a changelog entry.
| File | Description |
|---|---|
| runtime/service/src/test/java/org/apache/polaris/service/task/TaskExecutorRetryCdiTest.java | Adds CDI-backed coverage verifying that all retry attempts execute. |
| runtime/service/src/main/java/org/apache/polaris/service/task/TaskExecutorImpl.java | Captures and reuses the principal across retries and logs terminal failures. |
| changelog.d/async-task-retry-principal.md | Documents the asynchronous retry principal fix. |
Review effort: Lite
| tryHandleTask(taskEntityId, clone, principalClone, eventMetadata, null, 1) | ||
| .exceptionally(t -> { | ||
| LOGGER.error("Task entity id {} was not handled", taskEntityId, t); | ||
| return null; | ||
| }); |
There was a problem hiding this comment.
PolarisCallContext.copy() resolves the realm identifier eagerly and returns () -> realmId, so the getRealmContext().getRealmIdentifier() call in tryHandleTask reads off that snapshot and cannot fail.
The copy and the principal clone both happen in addTaskHandlerContext before the handler is attached, so a throw there propagates to the caller rather than being dropped — that is already the loud path. The handler covers the path that was silent: a retry re-enters tryHandleTask from inside exceptionallyComposeAsync, where a synchronous throw completes the composed future exceptionally, and that future is the one that was discarded.
orca-review-bot
left a comment
There was a problem hiding this comment.
Nice catch. The diagnosis checks out: retries re-enter tryHandleTask on the CDI-cleared task-executor, so dereferencing the request-scoped principal proxy there was failing before the attempt began. Cloning it once next to callContext.copy() is the right minimal fix. The new CDI test fails without the fix, since an untyped task throws a retryable TaskHandlerNotFoundException and attempt 3 is only reached once retries work. spotlessJavaCheck passes locally. Two small things outside the diff: can you tick the checklist that applies and link an issue, or say there isn't one? And can the test drop its task entity at the end so it doesn't leak into the shared store?
🤖 AI-generated review comment — agents make mistakes, so please verify before acting on it.
| tryHandleTask(taskEntityId, clone, eventMetadata, null, 1); | ||
| tryHandleTask(taskEntityId, clone, principalClone, eventMetadata, null, 1) | ||
| .exceptionally(t -> { | ||
| LOGGER.error("Task entity id {} was not handled", taskEntityId, t); |
There was a problem hiding this comment.
When a task runs out of attempts, or hits a FileDeletionTimeoutException, the same throwable has already been logged at WARN in tryHandleTask. This ERROR then prints the full stack a second time. Can we drop the t here, or make it a one-line 'gave up on task {}' message?
🤖 AI-generated review comment — agents make mistakes, so please verify before acting on it.
There was a problem hiding this comment.
The duplicate is real, but the handler exists for throwables that have no other log line: a synchronous throw inside the retry composition reaches it with nothing logged, which is the failure this PR is about. Dropping t would lose the stack in exactly that case, so I'd keep it.
| private @NonNull CompletableFuture<Void> tryHandleTask( | ||
| long taskEntityId, | ||
| CallContext callContext, | ||
| PolarisPrincipal principal, |
There was a problem hiding this comment.
Retries call this on a thread with CDI context cleared, and that's how the bug got in. Can we add a one-line comment saying tryHandleTask must only use what it's passed, and never polarisPrincipal or other request-scoped fields?
🤖 AI-generated review comment — agents make mistakes, so please verify before acting on it.
| callContext.getPolarisCallContext(), null, taskEntity); | ||
| assertThat(created.isSuccess()) | ||
| .describedAs("task entity create: %s", created.getReturnStatus()) | ||
| .isTrue(); |
There was a problem hiding this comment.
Once all three attempts fail, this task entity stays persisted in the shared DefaultProfile store. Can we drop it at the end of the test so later tests in the same Quarkus app don't find a stray task?
🤖 AI-generated review comment — agents make mistakes, so please verify before acting on it.
There was a problem hiding this comment.
Done, the test now drops the entity in a finally so it goes even if the assertion fails.
TaskExecutorImpl retries a failed task up to three times, but only the first attempt ever ran. Every attempt cloned the injected PolarisPrincipal inside tryHandleTask, and a retry re-enters that method from exceptionallyComposeAsync on the task-executor ManagedExecutor, which is built with cleared(ThreadContext.CDI). PolarisPrincipal is produced @RequestScoped by PolarisPrincipalHolder, so dereferencing its client proxy there finds no active request context and the attempt died before reaching the task body. Nothing reported it. addTaskHandlerContext discards the returned future, so a dropped table's data, manifest and metadata files were left behind with no log line past the first attempt's warning. handleTaskWithTracing is annotated @ActivateRequestContext and runs in a fresh request context, so the task body itself was never affected; only tryHandleTask sits outside that scope. Clone the principal once in addTaskHandlerContext, next to the CallContext clone that exists for the same reason, and pass it to each attempt. Also complete the discarded future with a terminal handler that logs. The suppression on addTaskHandlerContext reads "it _should_ be okay in this particular case", and this bug is what that assumption cost: any throwable raised before CompletableFuture.runAsync, or inside the retry composition itself, vanished without a trace. The handler changes no behaviour, since the future was already ignored, and it also records the outcome when a task exhausts its attempts. TaskExecutorImplTest constructs the task executor directly, so the principal it holds is an ordinary instance rather than a client proxy and its retry test cannot reach this path; that test also asserts only that at least one attempt ran. The new test drives the real CDI container and asserts the last attempt reported is the third.
8954e23 to
3409b38
Compare

TaskExecutorImplis written to retry a failed task up to three times, but onlythe first attempt ever ran.
Every attempt cloned the injected
PolarisPrincipalinsidetryHandleTask, anda retry re-enters that method from
exceptionallyComposeAsyncon thetask-executor
ManagedExecutor, which is built withcleared(ThreadContext.CDI).PolarisPrincipalis produced@RequestScopedbyPolarisPrincipalHolder, so dereferencing its client proxy on that thread findsno active request context, and the attempt died before it reached the task body.
Nothing reported it.
addTaskHandlerContextdiscards the future it gets back, soafter a drop with purge a transient failure left the table's data, manifest and
metadata files behind, with no log line past the first attempt's warning.
handleTaskWithTracingis annotated@ActivateRequestContextand runs in afresh request context, so the task body itself was never affected; only
tryHandleTasksits outside that scope. This clones the principal once inaddTaskHandlerContext, next to theCallContextclone that is already therefor the same reason, and passes it to each attempt.
It also completes the discarded future with a terminal handler that logs. The
existing suppression on
addTaskHandlerContextreads "it should be okay inthis particular case", and this bug is what that assumption cost: any throwable
raised before
CompletableFuture.runAsync, or inside the retry compositionitself, vanished without a trace. The handler changes no behaviour, since the
future was already ignored, and it also records the outcome when a task
exhausts its attempts.
Checklist
changelog.d/(if needed, seechangelog.d/README.md)site/content/in-dev/unreleased(if needed)CONTRIBUTING.md)