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-8936-713834a553dc2214b597caa5ce6c4b31ec60dd01 in repository https://gitbox.apache.org/repos/asf/texera.git
commit cc179d58559824db72ba4f40b63751d8240a0e0b Author: Eugene Gu <[email protected]> AuthorDate: Mon Nov 16 02:54:13 2026 +0000 fix(frontend): reset the run state when its unit is lost (#8936) ### What changes were proposed in this PR? **Root cause.** The frontend learns that a run has ended only from the engine, over the selected unit's websocket. When the selected unit is terminated from the unit dropdown, drops out of the unit list, or stays selected but reports Failed, as an evicted or crash-looping Kubernetes unit does, that message can never arrive and nothing resets the execution state, so the run keeps being reported as running. On top of that, the Kill button's gate exempted `NoComputingUnit` from its socket check, so Kill stayed enabled although its request could no longer be delivered. #3400 (a910bcfd5) added the socket check to Kill together with that exemption, copying the Run button's translation of the old single-mode flag `!environment.computingUnitManagerEnabled`; that mode no longer exists. ``` Before: unit terminated mid-run -> no end-of-run message -> state stays Running: clock counts, Form View says "Running", Kill enabled but dead After: unit terminated mid-run -> socket down, selection drops to none -> run reset: clock stopped, Form View idle, Kill disabled; console and results kept ``` Both screenshots: a run was in flight on "Analytics Unit", which was then terminated from the unit dropdown. | Before | After | | --- | --- | | <img width="1512" height="805" alt="kill-button-2-after-terminate-kill-still-enabled" src="https://github.com/user-attachments/assets/e0919b87-0c2b-4138-a30b-12295b749175" /> | <img width="1456" height="829" alt="kill-button-4-after-fix-terminated-kill-disabled-canvas-relocked" src="https://github.com/user-attachments/assets/729eb0df-d01a-4e4c-90e4-e2c4ac684398" /> | | Kill is still enabled, and clicking it does nothing; the clock keeps counting. | Kill is greyed out; the clock is back at 0:00:00. The info message comes from the separate check described under "Scope boundary". | Form View after the same steps no longer reports a run: <img width="1456" height="829" alt="kill-button-6-after-fix-form-view-not-running" src="https://github.com/user-attachments/assets/bd68cdd3-161c-4479-a2c2-889a74b5d2d8" /> **Changes.** 1. `ExecuteWorkflowService` calls its existing `resetExecutionAndWorkers()` when an execution is in flight, the workflow websocket is down, and the selected unit is either gone or reports Failed. It combines the selected-unit stream with the websocket's connection-status stream, so the reset fires on whichever of the two happens last. That puts the execution back to Uninitialized, which Form View and the canvas lock already follow, clears the worker ids and stops the clock. It is the narrower of the two existing resets: console messages and results stay, unlike the `connectionReset` path a manual unit switch takes. 2. The Kill button is disabled whenever the websocket is down, without the `NoComputingUnit` exemption. This is defense in depth: with change 1, a run that is still in flight with no unit and no socket should not occur any more, and if it does, Kill no longer looks usable. 3. `isExecutionInFlight` takes the state and `updateWorkflowActionLock` calls it, so the reset and the canvas lock share one list of in-flight states. What does and does not trigger the reset in change 1: | Situation | Selected unit | Socket | Reset by this check | | --- | --- | --- | --- | | Unit terminated from the dropdown | gone | down | yes | | Kubernetes unit evicted or crash-looping | still selected, Failed | down | yes | | Another tab disconnects a local unit | gone | still up | no: the shared engine is still running it and Kill still works over this tab's socket; yes once that socket drops | | Socket drops and reconnects on a healthy unit | Running | down, then up | no | | Direct switch from one unit to another | the new unit | down, then up | no; the existing `connectionReset` path handles the switch | | Unit reports Pending, Unknown or Terminating | still selected | down | no | **Scope boundary.** The canvas can be locked again right away by a second, independent check, which this PR leaves unchanged. Whenever the selected unit changes, including when it drops to none, `ComputingUnitSelectionComponent.updateWorkflowModificationStatus` asks the database for Running or Initializing executions of the workflow. If it finds any, it disables modification and shows "There are ongoing executions on this workflow. Modification of the workflow is currently disabled." At that moment the lost unit's execution row is still RUNNING, because disconnecting a local unit does not stop the shared engine, which keeps running the execution. The lock is accurate, and the check passes again on the first reload or unit selection after that execution finishes. Also not changed here: on a dropdown terminate, the existing `clearStatus()` call in `ComputingUnitStatusService.terminateComputingUnit` resets the operators' colors, while their port row counts keep the last values. When the unit is lost any other way, for example an evicted unit that reports Failed or a terminate from another tab, nothing resets the colors, so the operators keep their last state after the reset. Not covered: a unit that is lost without reporting Failed or leaving this tab's unit list. A unit whose pod state cannot be determined reports Unknown, and a pod deleted outside Texera is polled as Pending until this tab next refreshes its unit list; in both the run keeps showing as running. ### Any related issues, documentation, discussions? Closes #8934 Related: - #8618: a stuck non-terminal execution row keeps its unit off the idle sweep. - #8853, fixed by #8855: a clean websocket close never marks the socket disconnected; the Kill gate and the reset both rely on `isConnected` being accurate. ### How was this PR tested? New tests in `frontend/src/app/workspace/service/execute-workflow/execute-workflow.service.spec.ts`: - keeps the run when the socket drops on a healthy unit, then ends it once the selection empties - keeps the run when the selection empties with the socket still up, then ends it once the socket drops - ends the run when the selected unit reports Failed with the socket down - keeps the run when the selected unit reports Failed with the socket still up - ends a later run as well when its unit is lost too - ends a run that is Initializing, Running, Pausing, Paused, Resuming or Recovering when its unit is lost, one case per state - leaves a run that is Uninitialized, Completed, Terminated, Failed or Killed untouched when its unit is lost, one case per state - keeps the run with the socket down when switching straight from one unit to another, when a unit is first selected, and when the selected unit is still Running or reports Pending, Unknown or Terminating, one case each New tests in `frontend/src/app/workspace/component/menu/menu.component.spec.ts`, one table for the Kill button: | Execution | Unit status | Socket | Kill | | --- | --- | --- | --- | | Running | No Computing Unit | down | disabled | | Running | No Computing Unit | up | enabled | | Running | Running | down | disabled | | Running | Running | up | enabled | | Completed | Running | down | disabled | | Completed | Running | up | disabled | The shared `beforeEach` of the service spec now installs a `BehaviorSubject` for the selected-unit stream and one for the connection-status stream before the service is constructed, since the service subscribes in its constructor. Form View needs no test of its own: it reads `isRunning` from the execution state stream that `resetExecutionAndWorkers()` already broadcasts. `ExecuteWorkflowService` does not inject the console or result services, so this change cannot clear them. ``` cd frontend npx ng test --watch=false --include src/app/workspace/service/execute-workflow/execute-workflow.service.spec.ts # 79 passed npx ng test --watch=false --include src/app/workspace/component/menu/menu.component.spec.ts # 150 passed npx ng test --watch=false # 253 files, 7206 passed | 1 skipped npx tsc --noEmit -p tsconfig.json # clean npx eslint <changed files> # clean npx prettier --check <changed files> # clean ``` Mutation check: each of these makes at least one test fail: restoring the `NoComputingUnit` exemption, dropping the socket condition, dropping the Failed condition, dropping the empty-selection condition, resetting regardless of the execution state, resetting on any non-Running unit status, reading the socket state only when the selection changes, reading the selection only when the socket state changes, using `resetExecutionState()` instead of `resetExecutionAndWorkers()`, a reset that forgets to clear the worker ids, letting only the first lost unit reset, moving any one of the eleven states across the in-flight split, and swapping the enable and disable branches of the canvas lock. Manual check in Chrome, 1512x861 viewport, against a build of this branch on the local-dev stack with local computing units: 1. Workflow: Text Input -> Python UDF whose `process_tuple` does `time.sleep(900)`. 2. Select a unit and a warehouse, click Run, and wait until the UDF operator is running. 3. Open the unit dropdown, click the trash icon of the selected unit, confirm "Disconnect", then click Kill. 4. Before: Kill stays enabled and does nothing; the clock keeps counting; Form View keeps saying "Running"; operators cannot be moved. After: the execution is back to Uninitialized, the clock reads 0:00:00, Kill is disabled, and Form View no longer reports a run; console and results stay. The canvas is locked again right away with the info message quoted under "Scope boundary", because the shared local engine is still running the execution. ### Was this PR authored or co-authored using generative AI tooling? Yes. Generated-by: Claude Code (claude-fable-5-1, claude-fable-5-2, claude-opus-5-5). Co-authored with Claude; the author reviewed the change before submission. --------- Co-authored-by: Kunwoo (Chris) <[email protected]> --- .../workspace/component/menu/menu.component.html | 3 +- .../component/menu/menu.component.spec.ts | 29 +++++ .../execute-workflow.service.spec.ts | 138 ++++++++++++++++++++- .../execute-workflow/execute-workflow.service.ts | 55 +++++--- 4 files changed, 203 insertions(+), 22 deletions(-) diff --git a/frontend/src/app/workspace/component/menu/menu.component.html b/frontend/src/app/workspace/component/menu/menu.component.html index acef7bbb9e..1e38e72c7f 100644 --- a/frontend/src/app/workspace/component/menu/menu.component.html +++ b/frontend/src/app/workspace/component/menu/menu.component.html @@ -452,8 +452,7 @@ executionState === ExecutionState.Completed || executionState === ExecutionState.Killed || executionState === ExecutionState.Failed || - (!workflowWebsocketService.isConnected && - computingUnitStatus !== ComputingUnitState.NoComputingUnit) + !workflowWebsocketService.isConnected " nz-button nzDanger diff --git a/frontend/src/app/workspace/component/menu/menu.component.spec.ts b/frontend/src/app/workspace/component/menu/menu.component.spec.ts index 2bf03c3e5e..5d80b9d513 100644 --- a/frontend/src/app/workspace/component/menu/menu.component.spec.ts +++ b/frontend/src/app/workspace/component/menu/menu.component.spec.ts @@ -402,6 +402,35 @@ describe("MenuComponent", () => { }); }); + describe("kill button enablement", () => { + const killButton = () => fixture.nativeElement.querySelector("button[nzdanger]") as HTMLButtonElement; + const setConnected = (connected: boolean) => + Object.defineProperty(component.workflowWebsocketService, "isConnected", { + get: () => connected, + configurable: true, + }); + + it.each([ + [ExecutionState.Running, ComputingUnitState.NoComputingUnit, false, true], + [ExecutionState.Running, ComputingUnitState.NoComputingUnit, true, false], + [ExecutionState.Running, ComputingUnitState.Running, false, true], + [ExecutionState.Running, ComputingUnitState.Running, true, false], + [ExecutionState.Completed, ComputingUnitState.Running, false, true], + [ExecutionState.Completed, ComputingUnitState.Running, true, true], + ])( + "execution %s, unit status %s, socket connected %s: disabled %s", + (executionState, computingUnitStatus, connected, disabled) => { + component.executionState = executionState; + component.computingUnitStatus = computingUnitStatus; + setConnected(connected); + + fixture.detectChanges(); + + expect(killButton().disabled).toBe(disabled); + } + ); + }); + describe("getRunButtonBehavior", () => { it("returns 'Invalid Workflow' when the workflow is invalid", () => { component.isWorkflowValid = false; diff --git a/frontend/src/app/workspace/service/execute-workflow/execute-workflow.service.spec.ts b/frontend/src/app/workspace/service/execute-workflow/execute-workflow.service.spec.ts index 6e20b0c880..906dcd6fe4 100644 --- a/frontend/src/app/workspace/service/execute-workflow/execute-workflow.service.spec.ts +++ b/frontend/src/app/workspace/service/execute-workflow/execute-workflow.service.spec.ts @@ -30,7 +30,7 @@ import { UndoRedoService } from "../undo-redo/undo-redo.service"; import { OperatorMetadataService } from "../operator-metadata/operator-metadata.service"; import { StubOperatorMetadataService } from "../operator-metadata/stub-operator-metadata.service"; import { JointUIService } from "../joint-ui/joint-ui.service"; -import { of, Subject } from "rxjs"; +import { BehaviorSubject, of, Subject } from "rxjs"; import { WorkflowWebsocketService } from "../workflow-websocket/workflow-websocket.service"; import { WorkflowStatusService } from "../workflow-status/workflow-status.service"; import { NotificationService } from "../../../common/service/notification/notification.service"; @@ -63,6 +63,8 @@ import { sessionGetObject, sessionSetObject } from "../../../common/util/storage describe("ExecuteWorkflowService", () => { let service: ExecuteWorkflowService; let mockDocument: Document; + let selectedUnit$: BehaviorSubject<DashboardWorkflowComputingUnit | null>; + let connected$: BehaviorSubject<boolean>; beforeEach(() => { mockDocument = { @@ -91,6 +93,16 @@ describe("ExecuteWorkflowService", () => { ], }); + // Install the selected-unit and connection streams before the service is constructed. The socket + // starts out up, so no run is reset until a test drops it. + selectedUnit$ = new BehaviorSubject<DashboardWorkflowComputingUnit | null>(null); + vi.spyOn(TestBed.inject(ComputingUnitStatusService), "getSelectedComputingUnit").mockReturnValue( + selectedUnit$.asObservable() + ); + connected$ = new BehaviorSubject<boolean>(true); + vi.spyOn(TestBed.inject(WorkflowWebsocketService), "getConnectionStatusStream").mockReturnValue( + connected$.asObservable() + ); service = TestBed.inject(ExecuteWorkflowService); }); @@ -238,6 +250,130 @@ describe("ExecuteWorkflowService", () => { }); }); + describe("losing the selected computing unit mid-run", () => { + const unit = (cuid: number, status: DashboardWorkflowComputingUnit["status"] = "Running") => + ({ computingUnit: { cuid }, status }) as unknown as DashboardWorkflowComputingUnit; + + // The usual order: the socket errors at once, the unit list catches up on its next poll. + it("keeps the run when the socket drops on a healthy unit, then ends it once the selection empties", () => { + const enable = vi.spyOn(service["workflowActionService"], "enableWorkflowModification"); + const seen: ExecutionState[] = []; + service.getExecutionStateStream().subscribe(({ current }) => seen.push(current.state)); + emitWsEvent({ type: "WorkflowStateEvent", state: ExecutionState.Running }); + emitWsEvent({ type: "WorkerAssignmentUpdateEvent", operatorId: "op1", workerIds: ["w1", "w2"] }); + selectedUnit$.next(unit(7)); + enable.mockClear(); + + connected$.next(false); + expect(service.getExecutionState().state).toBe(ExecutionState.Running); + + selectedUnit$.next(null); + expect(service.getExecutionState().state).toBe(ExecutionState.Uninitialized); + expect(service.getWorkerIds("op1")).toEqual([]); + expect(enable).toHaveBeenCalled(); + expect(seen).toEqual([ExecutionState.Running, ExecutionState.Uninitialized]); + }); + + // Another tab disconnecting a local unit empties this tab's selection while this tab's socket + // to the engine, and so Kill, still work. + it("keeps the run when the selection empties with the socket still up, then ends it once the socket drops", () => { + emitWsEvent({ type: "WorkflowStateEvent", state: ExecutionState.Running }); + selectedUnit$.next(unit(7)); + + selectedUnit$.next(null); + expect(service.getExecutionState().state).toBe(ExecutionState.Running); + + connected$.next(false); + expect(service.getExecutionState().state).toBe(ExecutionState.Uninitialized); + }); + + // An evicted or crash-looping unit stays selected and reports Failed instead of leaving the list. + it("ends the run when the selected unit reports Failed with the socket down", () => { + emitWsEvent({ type: "WorkflowStateEvent", state: ExecutionState.Running }); + selectedUnit$.next(unit(7)); + connected$.next(false); + + selectedUnit$.next(unit(7, "Failed")); + + expect(service.getExecutionState().state).toBe(ExecutionState.Uninitialized); + }); + + it("keeps the run when the selected unit reports Failed with the socket still up", () => { + emitWsEvent({ type: "WorkflowStateEvent", state: ExecutionState.Running }); + selectedUnit$.next(unit(7)); + + selectedUnit$.next(unit(7, "Failed")); + + expect(service.getExecutionState().state).toBe(ExecutionState.Running); + }); + + it("ends a later run as well when its unit is lost too", () => { + emitWsEvent({ type: "WorkflowStateEvent", state: ExecutionState.Running }); + selectedUnit$.next(unit(7)); + connected$.next(false); + selectedUnit$.next(null); + selectedUnit$.next(unit(8)); + connected$.next(true); + emitWsEvent({ type: "WorkflowStateEvent", state: ExecutionState.Running }); + + connected$.next(false); + selectedUnit$.next(null); + + expect(service.getExecutionState().state).toBe(ExecutionState.Uninitialized); + }); + + it.each([ + ExecutionState.Initializing, + ExecutionState.Running, + ExecutionState.Pausing, + ExecutionState.Paused, + ExecutionState.Resuming, + ExecutionState.Recovering, + ])("ends a run that is %s when its unit is lost", state => { + (service as any).currentState = { state }; + selectedUnit$.next(unit(7)); + connected$.next(false); + + selectedUnit$.next(null); + + expect(service.getExecutionState().state).toBe(ExecutionState.Uninitialized); + }); + + it.each([ + ExecutionState.Uninitialized, + ExecutionState.Completed, + ExecutionState.Terminated, + ExecutionState.Failed, + ExecutionState.Killed, + ])("leaves a run that is %s untouched when its unit is lost", state => { + const before = { state }; + (service as any).currentState = before; + selectedUnit$.next(unit(7)); + connected$.next(false); + + selectedUnit$.next(null); + + expect(service.getExecutionState()).toBe(before); + }); + + it.each([ + ["switching straight from one unit to another", unit(7), unit(8)], + ["a unit is first selected", null, unit(7)], + ["the selected unit is still Running", unit(7), unit(7)], + ["the selected unit reports Pending", unit(7), unit(7, "Pending")], + ["the selected unit reports Unknown", unit(7), unit(7, "Unknown")], + ["the selected unit reports Terminating", unit(7), unit(7, "Terminating")], + ])("keeps the run with the socket down when %s", (_case, selected, next) => { + connected$.next(false); + selectedUnit$.next(selected); + emitWsEvent({ type: "WorkflowStateEvent", state: ExecutionState.Running }); + + selectedUnit$.next(next); + + expect(service.getExecutionState().state).toBe(ExecutionState.Running); + }); + }); + it("resetExecutionAndWorkers() clears the execution state and worker assignments", () => { (service as any).currentState = { state: ExecutionState.Running }; (service as any).assignedWorkerIds.set("op1", ["w1", "w2"]); diff --git a/frontend/src/app/workspace/service/execute-workflow/execute-workflow.service.ts b/frontend/src/app/workspace/service/execute-workflow/execute-workflow.service.ts index 21519374f9..6ef22669e5 100644 --- a/frontend/src/app/workspace/service/execute-workflow/execute-workflow.service.ts +++ b/frontend/src/app/workspace/service/execute-workflow/execute-workflow.service.ts @@ -18,7 +18,7 @@ */ import { Inject, Injectable, DOCUMENT } from "@angular/core"; -import { BehaviorSubject, interval, Observable, Subject, Subscription } from "rxjs"; +import { BehaviorSubject, combineLatest, interval, Observable, Subject, Subscription } from "rxjs"; import { WorkflowActionService } from "../workflow-graph/model/workflow-action.service"; import { WorkflowGraphReadonly } from "../workflow-graph/model/workflow-graph"; import { @@ -140,6 +140,17 @@ export class ExecuteWorkflowService { } } }); + + // Ends an in-flight run once its unit is gone or Failed and the socket is down; console and results are kept. + combineLatest([ + computingUnitStatusService.getSelectedComputingUnit(), + workflowWebsocketService.getConnectionStatusStream(), + ]).subscribe(([unit, connected]) => { + const unitLost = unit === null || unit.status === "Failed"; + if (!connected && unitLost && this.isExecutionInFlight(this.currentState.state)) { + this.resetExecutionAndWorkers(); + } + }); } public handleReconfigurationEvent(event: TexeraWebsocketEvent) { @@ -496,6 +507,26 @@ export class ExecuteWorkflowService { this.anchorDuration(0, false); } + private isExecutionInFlight(state: ExecutionState): boolean { + switch (state) { + case ExecutionState.Initializing: + case ExecutionState.Running: + case ExecutionState.Pausing: + case ExecutionState.Paused: + case ExecutionState.Resuming: + case ExecutionState.Recovering: + return true; + case ExecutionState.Uninitialized: + case ExecutionState.Completed: + case ExecutionState.Terminated: + case ExecutionState.Failed: + case ExecutionState.Killed: + return false; + default: + return exhaustiveGuard(state); + } + } + private updateExecutionState(stateInfo: ExecutionStateInfo): void { if (isEqual(this.currentState, stateInfo)) { return; @@ -515,24 +546,10 @@ export class ExecuteWorkflowService { * enables or disables workflow action service based on execution state */ private updateWorkflowActionLock(stateInfo: ExecutionStateInfo): void { - switch (stateInfo.state) { - case ExecutionState.Completed: - case ExecutionState.Terminated: - case ExecutionState.Failed: - case ExecutionState.Uninitialized: - case ExecutionState.Killed: - this.workflowActionService.enableWorkflowModification(); - return; - case ExecutionState.Paused: - case ExecutionState.Pausing: - case ExecutionState.Recovering: - case ExecutionState.Resuming: - case ExecutionState.Running: - case ExecutionState.Initializing: - this.workflowActionService.disableWorkflowModification(); - return; - default: - return exhaustiveGuard(stateInfo); + if (this.isExecutionInFlight(stateInfo.state)) { + this.workflowActionService.disableWorkflowModification(); + } else { + this.workflowActionService.enableWorkflowModification(); } }
