This is an automated email from the ASF dual-hosted git repository. github-merge-queue[bot] pushed a commit to branch gh-readonly-queue/main/pr-9344-086a129a83a3e396c2aec769ea0a3da551339e5d in repository https://gitbox.apache.org/repos/asf/texera.git
commit 424b2a757ae2ff058d9d64696514f45d58e74531 Author: Eugene Gu <[email protected]> AuthorDate: Wed Nov 25 05:21:10 2026 +0000 fix(amber): surface synchronous region-advance failures (#9344) ### What changes were proposed in this PR? **Root cause.** `AdvanceRegionExecutionsHandler` reports a failed advance to the client through `.onFailure` on the future returned by `WorkflowExecutionManager.advanceRegionExecutions`. That method does work before any future exists: it eagerly maps `syncStatusAndTransitionRegionExecutionPhase()` over the unfinished regions, and entering a region's non-dependee phase runs `createOutputPortStorageObjects` synchronously, which throws when an output port's schema cannot be resolved or when the storage layer fails. Such an exception left the handler before `.onFailure` was attached. `AsyncRPCServer` caught it and returned a `ControlError` to the requester, but the requester is the coordinator itself (`PortCompletedHandler` sends the request and discards the reply), so nothing consumed the error: no `FatalError` reached the client and the execution stayed RUNNING with no region advancing. ```text Before: port completed -> advance RPC -> createOutputPortStorageObjects throws -> ControlError to coordinator (discarded) -> UI: Running forever After: port completed -> advance RPC -> createOutputPortStorageObjects throws -> failed future -> onFailure -> FatalError to client ``` **Change.** The call is wrapped as `Future(cp.workflowExecutionManager.advanceRegionExecutions(cp.actorService)).flatten`, so a synchronous throw becomes a failed future and takes the same `onFailure` path as an asynchronous failure. The handler still returns `EmptyReturn()` immediately without awaiting the advance. **Scope.** `PortCompletedHandler` still discards the reply by design (it must not await the advance in its own control round); the fix makes the handler self-sufficient instead of changing the caller. ### Any related issues, documentation, discussions? Closes #9343 ### How was this PR tested? Added to `AdvanceRegionExecutionsHandlerSpec`, with a `WorkflowExecutionManager` stub whose `advanceRegionExecutions` throws synchronously: - a `WorkflowRuntimeException` with a related worker id produces exactly one `FatalError(err, Some(workerId))` and the handler still returns `EmptyReturn`; - a plain `IllegalStateException` produces exactly one `FatalError(err, None)`; - dispatched through `processDCM` and the real `AsyncRPCServer`, the reply to the coordinator is the ordinary `ReturnInvocation(id, EmptyReturn())` rather than a `ControlError`, and exactly one message of any kind reaches the client, the `FatalError`; - a `WorkflowRuntimeException` with no related worker id produces exactly one `FatalError(err, None)`; - a fatal throwable (`LinkageError`) is not converted: it still escapes the handler, the RPC server answers the coordinator with a `ControlError`, and nothing is sent to the client, so the change only affects non-fatal failures. The existing tests for a failed future, a successful advance and the immediate reply are unchanged. ``` sbt "WorkflowExecutionService/testOnly org.apache.texera.amber.engine.architecture.coordinator.promisehandlers.AdvanceRegionExecutionsHandlerSpec org.apache.texera.amber.engine.architecture.coordinator.promisehandlers.PortCompletedHandlerSpec" ``` - Red (tests against unmodified source): sbt summary `succeeded 13, failed 4` across the two specs (AdvanceRegionExecutionsHandlerSpec 7 passed / 4 failed, PortCompletedHandlerSpec 6 passed / 0 failed; the LinkageError test passes either way because it pins the pre-existing fatal-throwable path); the RPC-dispatched case recorded `ReturnInvocation(11, ControlError("java.lang.IllegalStateException: Failed to resolve the output schema", ...))` and no client event. - Green (with this change): `succeeded 17, failed 0` (AdvanceRegionExecutionsHandlerSpec 11 / 0 with 5 new tests, PortCompletedHandlerSpec 6 / 0). - Mutation check: restoring the unwrapped call fails 4 of the 5 new tests (AdvanceRegionExecutionsHandlerSpec 7 passed / 4 failed; the LinkageError test is unaffected by design); restored afterwards. - `sbt WorkflowExecutionService/scalafmtCheck WorkflowExecutionService/Test/scalafmtCheck "WorkflowExecutionService/scalafix --check" "WorkflowExecutionService/Test/scalafix --check"`: all pass. ### Was this PR authored or co-authored using generative AI tooling? Yes. Generated-by: Claude Code (claude-fable-5-1). Co-authored with Claude; the author reviewed the change before submission. --- .../AdvanceRegionExecutionsHandler.scala | 5 +- .../AdvanceRegionExecutionsHandlerSpec.scala | 102 ++++++++++++++++++++- 2 files changed, 104 insertions(+), 3 deletions(-) diff --git a/amber/src/main/scala/org/apache/texera/amber/engine/architecture/coordinator/promisehandlers/AdvanceRegionExecutionsHandler.scala b/amber/src/main/scala/org/apache/texera/amber/engine/architecture/coordinator/promisehandlers/AdvanceRegionExecutionsHandler.scala index ec0e5b0030..11b55abbd9 100644 --- a/amber/src/main/scala/org/apache/texera/amber/engine/architecture/coordinator/promisehandlers/AdvanceRegionExecutionsHandler.scala +++ b/amber/src/main/scala/org/apache/texera/amber/engine/architecture/coordinator/promisehandlers/AdvanceRegionExecutionsHandler.scala @@ -47,8 +47,9 @@ trait AdvanceRegionExecutionsHandler { request: EmptyRequest, ctx: AsyncRPCContext ): Future[EmptyReturn] = { - cp.workflowExecutionManager - .advanceRegionExecutions(cp.actorService) + // `Future(...)` turns an exception thrown before the advance returns its future (e.g. while + // allocating output port storage) into a failed future, so both reach the handler below. + Future(cp.workflowExecutionManager.advanceRegionExecutions(cp.actorService)).flatten // The requester is the coordinator itself and discards this reply, so a failure has no // caller to propagate to. A fatal error is sent to the client, indicating that the region // cannot be scheduled. diff --git a/amber/src/test/scala/org/apache/texera/amber/engine/architecture/coordinator/promisehandlers/AdvanceRegionExecutionsHandlerSpec.scala b/amber/src/test/scala/org/apache/texera/amber/engine/architecture/coordinator/promisehandlers/AdvanceRegionExecutionsHandlerSpec.scala index a942c615aa..1502e417ba 100644 --- a/amber/src/test/scala/org/apache/texera/amber/engine/architecture/coordinator/promisehandlers/AdvanceRegionExecutionsHandlerSpec.scala +++ b/amber/src/test/scala/org/apache/texera/amber/engine/architecture/coordinator/promisehandlers/AdvanceRegionExecutionsHandlerSpec.scala @@ -39,6 +39,7 @@ import org.apache.texera.amber.engine.architecture.rpc.controlcommands.{ EmptyRequest } import org.apache.texera.amber.engine.architecture.rpc.controlreturns.{ + ControlError, EmptyReturn, ReturnInvocation } @@ -71,7 +72,9 @@ import scala.collection.mutable.ArrayBuffer * open; * - because nothing awaits the reply, a failing advance has no caller to propagate to and is * reported to the client as a `FatalError` instead — carrying the related worker id when the - * failure came from a worker RPC (`WorkflowRuntimeException`) and `None` for anything else. + * failure came from a worker RPC (`WorkflowRuntimeException`) and `None` for anything else; + * - an advance that throws before it returns a future is reported the same way, and the + * handler still replies normally to the requesting round. */ class AdvanceRegionExecutionsHandlerSpec extends TestKit(ActorSystem("AdvanceRegionExecutionsHandlerSpec", AmberRuntime.pekkoConfig)) @@ -97,16 +100,21 @@ class AdvanceRegionExecutionsHandlerSpec * worker RPC error — never a `WorkflowRuntimeException` carrying a worker id. This stub records * the advance calls and hands back a future the test controls, so the handler can be observed * both while the advance is still pending and after it has failed with either kind of cause. + * + * Setting `throwOnAdvance` makes the advance fail before any future exists, the way a storage + * or schema failure inside `syncStatusAndTransitionRegionExecutionPhase` does. */ private class PendingAdvanceExecutionManager( workflowExecution: WorkflowExecution, asyncRPCClient: AsyncRPCClient ) extends WorkflowExecutionManager(workflowExecution, coordinatorConfig, asyncRPCClient) { val advanceCalls: ArrayBuffer[PekkoActorService] = ArrayBuffer() + var throwOnAdvance: Option[Throwable] = None private val advance: Promise[Unit] = Promise[Unit]() override def advanceRegionExecutions(actorService: PekkoActorService): Future[Unit] = { advanceCalls += actorService + throwOnAdvance.foreach(failure => throw failure) advance } @@ -153,6 +161,13 @@ class AdvanceRegionExecutionsHandlerSpec Fixture(cp, new CoordinatorAsyncRPCHandlerInitializer(cp), sent) } + /** Like `newFixture`, but the execution manager's advance throws `failure` synchronously. */ + private def newThrowingFixture(failure: Throwable): Fixture = { + val fixture = newFixture() + fixture.manager.throwOnAdvance = Some(failure) + fixture + } + private def clientEvents(sent: ArrayBuffer[WorkflowFIFOMessage]): Seq[ClientEvent] = sent.toSeq.filter(_.channelId.toWorkerId == CLIENT).map(_.payload).collect { case event: ClientEvent => event @@ -244,4 +259,89 @@ class AdvanceRegionExecutionsHandlerSpec assert(clientEvents(fixture.sent).isEmpty) } + + it should "notify the client with the worker id when the advance throws before returning a future" in { + val failure = + new WorkflowRuntimeException("output port storage unavailable", Some(relatedWorker)) + val Fixture(_, init, sent) = newThrowingFixture(failure) + + val response = init.coordinatorInitiateAdvanceRegionExecutions(EmptyRequest(), ctx) + + // A throw from inside the advance is a failure like any other: the handler must still + // return its reply and the client must still hear about it. + assert(Await.result(response, awaitTimeout) == EmptyReturn()) + assert(clientEvents(sent) == Seq(FatalError(failure, Some(relatedWorker)))) + } + + it should "notify the client without a worker id when the advance throws a plain exception" in { + val failure = new IllegalStateException("Failed to resolve the output schema") + val Fixture(_, init, sent) = newThrowingFixture(failure) + + val response = init.coordinatorInitiateAdvanceRegionExecutions(EmptyRequest(), ctx) + + assert(Await.result(response, awaitTimeout) == EmptyReturn()) + assert(clientEvents(sent) == Seq(FatalError(failure, None))) + } + + it should "reply normally to the requesting round when the advance throws" in { + val failure = new IllegalStateException("Failed to resolve the output schema") + val Fixture(cp, _, sent) = newThrowingFixture(failure) + + // Dispatched by the real RPC server, as production does it. The reply to the coordinator + // must be the ordinary EmptyReturn, not a ControlError that nothing consumes, and the + // client must receive exactly one FatalError. + cp.processDCM( + ChannelIdentity(COORDINATOR, COORDINATOR, isControl = true), + ControlInvocation( + METHOD_COORDINATOR_INITIATE_ADVANCE_REGION_EXECUTIONS, + EmptyRequest(), + ctx, + advanceCommandId + ) + ) + + assert( + repliesToCoordinator(sent) == Seq( + ReturnInvocation(advanceCommandId, EmptyReturn()) + ) + ) + assert(clientEvents(sent) == Seq(FatalError(failure, None))) + // Exactly one message of any kind goes to the client: no second FatalError, no state update. + assert(sent.count(_.channelId.toWorkerId == CLIENT) == 1) + } + + it should "notify the client without a worker id when a WorkflowRuntimeException names no worker" in { + val failure = new WorkflowRuntimeException("region cannot be scheduled", None) + val Fixture(_, init, sent) = newThrowingFixture(failure) + + val response = init.coordinatorInitiateAdvanceRegionExecutions(EmptyRequest(), ctx) + + assert(Await.result(response, awaitTimeout) == EmptyReturn()) + assert(clientEvents(sent) == Seq(FatalError(failure, None))) + assert(sent.count(_.channelId.toWorkerId == CLIENT) == 1) + } + + it should "leave a fatal throwable to the RPC server instead of reporting it to the client" in { + // `Future(...)` only converts non-fatal exceptions; an Error still escapes the handler and + // the RPC server answers the coordinator with a ControlError. + val failure = new LinkageError("boom") + val Fixture(cp, _, sent) = newThrowingFixture(failure) + + cp.processDCM( + ChannelIdentity(COORDINATOR, COORDINATOR, isControl = true), + ControlInvocation( + METHOD_COORDINATOR_INITIATE_ADVANCE_REGION_EXECUTIONS, + EmptyRequest(), + ctx, + advanceCommandId + ) + ) + + val replies = repliesToCoordinator(sent) + assert(replies.size == 1) + assert(replies.head.commandId == advanceCommandId) + assert(replies.head.returnValue.isInstanceOf[ControlError]) + assert(clientEvents(sent).isEmpty) + assert(sent.count(_.channelId.toWorkerId == CLIENT) == 0) + } }
