You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix: keep waiting in TaskClient.result() when a rule rejects a result - #2012
TaskClient.result() and resultAsync() ignore ResultRejected notifications and keep waiting, since a rejected result is not terminal. The ignored rejection is logged at debug level.
Fix the TaskNotification javadoc, which said notifications are published only at terminal states, and document the behavior on TaskClient.result.
History check: resultAsync (#1457) predates ResultRejected. Before #1525 a rule rejection failed the task, so result() threw TaskException.Failed. #1525 made rejection non-terminal and added TaskException.ResultRejected, but did not update resultAsync, and nothing throws that exception. The Unexpected notification type branch was not a deliberate choice for rejections.
Ignoring the rejection does not hide a failure: the task still ends in FAILED after the iteration limit, and result() then throws TaskException.Failed. A rejection is also visible in the notification stream. This matches the documented contract that result() waits for COMPLETED, FAILED or CANCELLED. I added a debug log so an ignored rejection leaves a trace.
Not changed here: the final Failed reason does not include the last rule rejection.
I have confirmed that this is a real issue. The solution looks good.
🤖 review
Review: fix/task-result-rejected-not-terminal
Update notifications.adoc (lines 148-150). It still says the task entity publishes "on every terminal transition" and that non-terminal transitions publish nothing. That contradicts the corrected TaskNotification javadoc. State that the entity also publishes ResultRejected, that it is not terminal, and that the agent retries. The ResultRejected table row can say the same.
Bound the wait in shouldFailResultAfterRepeatedRuleRejections. It calls result() with no timeout, so a regression that makes the wait hang would hang the suite instead of failing the test. Use resultAsync(...).toCompletableFuture().get(15, TimeUnit.SECONDS) and assert on the cause. A JUnit @Timeout in its default mode does not help, because it interrupts the thread and result() blocks in CompletableFuture.join(), which ignores interrupts.
Add unit tests to TaskClientImplSpec. The integration tests depend on timing to catch a regression, so the spec is the place for deterministic coverage.
Register classOf[TaskNotification.ResultRejected] in the spec serializer. It only registers the three terminal types today.
ResultRejected then Completed returns the result.
ResultRejected then Failed fails with TaskException.Failed.
A task already RESULT_REJECTED at subscribe time returns the result on the next Completed.
The existing mockEntityClient(state, notificationSource) helper accepts a Source with several notifications.
Suggestions
Replace the 1 second sleep in shouldAwaitResultAcrossRuleRejection with a gate. The Awaitility.await().pollDelay(...) call is a sleep. If subscribing ever takes longer than a second, the test still passes but stops covering the fix. A gate ties the order to the call instead of to time, and removes the supplyAsync wrapper. This sketch is not run:
varresultRequested = newCompletableFuture<Void>().orTimeout(10, TimeUnit.SECONDS);
agentModel
.whenMessage(msg -> msg.contains("Do something"))
.reply(
input -> {
resultRequested.join(); // released after the test calls resultAsyncreturnnewTestModelProvider.AiResponse(
completeTask(newTestTasks.TestResult("low quality", 3)));
});
// second reply and runSingleTask as beforevarresult = componentClient.forTask(taskId).resultAsync(TestTasks.VALIDATED_TASK);
resultRequested.complete(null);
assertThat(result.toCompletableFuture().get(15, TimeUnit.SECONDS).value())
.isEqualTo("improved result");
Consider ignoring every non-terminal notification, not only ResultRejected (TaskClientImpl.scala:151). The default branch still throws, so the next non-terminal notification type repeats this bug. The runtime's consumer of the same stream ignores anything that is not terminal (TaskProcessing.handleDependencyNotification). The trade-off is that a future terminal type that nobody handles would hang instead of fail.
Nit
.map { notification => notification match { ... } } can be .map { case ... } (TaskClientImpl.scala:140).
notifications.adoc now says the entity also publishes ResultRejected when a rule rejects a result, that it is not terminal, and that resultAsync keeps waiting. The table row says the same.
The failing-path test waits with resultAsync(...).get(15, SECONDS) and asserts the TaskException.Failed cause.
Added three cases to TaskClientImplSpec: rejected then completed, rejected then failed, and a task already RESULT_REJECTED at subscribe. The first two fail without the fix. The third passes either way, because an already rejected task has no rejection notification to ignore, so it only pins that the wait continues.
The sleep is replaced with a gate that is released after resultAsync is called. Both integration tests fail without the fix.
Not changed. Ignoring only ResultRejected keeps an unknown notification type loud: a future non-terminal type fails with the existing IllegalStateException instead of making result() wait until the caller gives up. I can switch to ignoring everything non-terminal, like handleDependencyNotification, if you prefer.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
TaskClient.result()andresultAsync()ignoreResultRejectednotifications and keep waiting, since a rejected result is not terminal. The ignored rejection is logged at debug level.TaskNotificationjavadoc, which said notifications are published only at terminal states, and document the behavior onTaskClient.result.Fixes #2011
Test plan
shouldAwaitResultAcrossRuleRejectionfails without the fix withUnexpected notification type ... ResultRejectedand passes with it.shouldFailResultAfterRepeatedRuleRejections:result()still throwsTaskException.Failedwhen the iteration limit is reached.TaskClientImplSpeccover rejected then completed, rejected then failed, and an already rejected task.TaskRuleIntegrationTestpasses.javafmtCheckAll,headerCheckAll,scalafmtCheckAll, scalafixOrganizeImports,additionalValidation.