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-9239-2f5212d8fadc0d55aa60ac2ccc0ba2afb93fb5f9 in repository https://gitbox.apache.org/repos/asf/texera.git
commit b4c5ae1824e6b67b24ef55c708dceb6fa26ea9c9 Author: Xinyuan Lin <[email protected]> AuthorDate: Mon Nov 2 05:49:29 2026 +0000 refactor(agent-service): drop unused state and helper methods (#9239) ### What changes were proposed in this PR? Removes obsolete validation state management and unused helper methods in `agent-service`: - **`WorkflowState`**: - Drops internal validation state tracking (`validationErrors`, `workflowEmpty`, `validationChangedSubject`) and associated methods (`getValidationChangedStream`, `getValidationOutput`, `setValidationError`, `clearValidationError`, `setAllValidationErrors`, `updateWorkflowEmptyState`, `emitValidationChanged`). Property validation is handled directly by `WorkflowSystemMetadata.validateOperatorProperties` during tool execution. - Drops unused `updateOperatorInputPorts`, `getLink`, and `getFrontierOperators`. - **`TexeraAgent`**: - Drops unused helper `getStepsById()`. - **`WorkflowSystemMetadata`**: - Drops unused helper methods `getAllSchemasAsJson()` and `operatorTypeExists()`, along with private interface `OperatorSchemaInfo`. - **`types/workflow.ts`**: - Drops unused `OperatorDetail` interface. - **`WorkflowResultState`**: - Drops unused helper method `getOperatorInfo()`. ### Any related issues, documentation, discussions? Closes #9238 ### How was this PR tested? Tested with Bun test runner in `agent-service`: ```bash cd agent-service bun test ``` Output: ``` 313 pass 0 fail 765 expect() calls Ran 313 tests across 19 files. [2.10s] ``` ### Was this PR authored or co-authored using generative AI tooling? Generated-by: Antigravity 2.0 --- agent-service/src/agent/texera-agent.ts | 4 - .../src/agent/util/workflow-system-metadata.ts | 22 --- agent-service/src/agent/workflow-result-state.ts | 4 - agent-service/src/agent/workflow-state.spec.ts | 130 +---------------- agent-service/src/agent/workflow-state.ts | 162 --------------------- agent-service/src/types/workflow.ts | 9 -- 6 files changed, 4 insertions(+), 327 deletions(-) diff --git a/agent-service/src/agent/texera-agent.ts b/agent-service/src/agent/texera-agent.ts index b98c812b0b..db429b9ead 100644 --- a/agent-service/src/agent/texera-agent.ts +++ b/agent-service/src/agent/texera-agent.ts @@ -260,10 +260,6 @@ export class TexeraAgent { return chain; } - getStepsById(): Map<string, ReActStep> { - return this.stepsById; - } - getWorkflowResultState(): WorkflowResultState { return this.workflowResultState; } diff --git a/agent-service/src/agent/util/workflow-system-metadata.ts b/agent-service/src/agent/util/workflow-system-metadata.ts index 9269a0cff7..fc8c6261cd 100644 --- a/agent-service/src/agent/util/workflow-system-metadata.ts +++ b/agent-service/src/agent/util/workflow-system-metadata.ts @@ -26,12 +26,6 @@ const log = createLogger("WorkflowSystemMetadata"); export type { ValidationError, Validation } from "../../types/workflow"; -interface OperatorSchemaInfo { - properties: any; - required: any; - definitions: any; -} - interface CompactOperatorSchema { properties: Record<string, any>; required: string[]; @@ -202,26 +196,10 @@ export class WorkflowSystemMetadata { return getCompactSchema(schema); } - getAllSchemasAsJson(): string { - const result: Record<string, OperatorSchemaInfo> = {}; - for (const [type, schema] of this.schemas) { - result[type] = { - properties: filterObjectKeys(schema.properties, FILTERED_PROPERTY_KEYS), - required: schema.required, - definitions: filterObjectKeys(schema.definitions, FILTERED_DEFINITION_KEYS), - }; - } - return JSON.stringify(result, null, 2); - } - getOperatorCount(): number { return this.schemas.size; } - operatorTypeExists(operatorType: string): boolean { - return this.schemas.has(operatorType); - } - validateOperatorProperties(operatorType: string, properties: Record<string, any>): Validation { const schema = this.schemas.get(operatorType); if (!schema) { diff --git a/agent-service/src/agent/workflow-result-state.ts b/agent-service/src/agent/workflow-result-state.ts index e6f13c2301..60a539b77a 100644 --- a/agent-service/src/agent/workflow-result-state.ts +++ b/agent-service/src/agent/workflow-result-state.ts @@ -58,10 +58,6 @@ export class WorkflowResultState { return undefined; } - getOperatorInfo(operatorId: string): OperatorInfo | undefined { - return this.get(operatorId)?.operatorInfo; - } - getAllVisible(): Map<string, ResultEntry> { const result = new Map<string, ResultEntry>(); const path = this.getAncestorPath(); diff --git a/agent-service/src/agent/workflow-state.spec.ts b/agent-service/src/agent/workflow-state.spec.ts index 8dca5ee03e..4e8abc3aa0 100644 --- a/agent-service/src/agent/workflow-state.spec.ts +++ b/agent-service/src/agent/workflow-state.spec.ts @@ -19,7 +19,7 @@ import { describe, expect, test } from "bun:test"; import { WorkflowState } from "./workflow-state"; -import type { OperatorPredicate, OperatorLink, ValidationError, WorkflowContent } from "../types/workflow"; +import type { OperatorPredicate, OperatorLink, WorkflowContent } from "../types/workflow"; function makeOperator(id: string, overrides: Partial<OperatorPredicate> = {}): OperatorPredicate { return { @@ -90,16 +90,16 @@ describe("WorkflowState - operators", () => { }); describe("WorkflowState - links", () => { - test("add, get, and delete link", () => { + test("add and delete link", () => { const state = new WorkflowState(); state.addOperator(makeOperator("op1")); state.addOperator(makeOperator("op2")); const link = makeLink("l1", "op1", "op2"); state.addLink(link); - expect(state.getLink("l1")).toEqual(link); + expect(state.getAllLinks()).toEqual([link]); expect(state.deleteLink("l1")).toBe(true); - expect(state.getLink("l1")).toBeUndefined(); + expect(state.getAllLinks()).toEqual([]); }); test("getLinksConnectedToOperator returns both inbound and outbound", () => { @@ -238,21 +238,6 @@ describe("WorkflowState - traversal", () => { return state; } - test("getFrontierOperators returns the leaf operators at depth 1", () => { - // op3 is the only operator that is not the source of a link - expect(seedChain().getFrontierOperators(1)).toEqual(["op3"]); - }); - - test("getFrontierOperators expands one hop upstream per depth, topologically ordered", () => { - const state = seedChain(); - expect(state.getFrontierOperators(2)).toEqual(["op2", "op3"]); - expect(state.getFrontierOperators(3)).toEqual(["op1", "op2", "op3"]); - }); - - test("getFrontierOperators returns an empty list for an empty workflow", () => { - expect(new WorkflowState().getFrontierOperators(3)).toEqual([]); - }); - test("getSubDAG collects the target and every upstream operator and link", () => { const sub = seedChain().getSubDAG("op3"); expect(sub.operators.map(o => o.operatorID).sort()).toEqual(["op1", "op2", "op3"]); @@ -260,113 +245,6 @@ describe("WorkflowState - traversal", () => { }); }); -describe("WorkflowState - validation state", () => { - const err = (message: string): ValidationError => ({ isValid: false, messages: { general: message } }); - - test("setValidationError stores and getValidationOutput aggregates; clearValidationError removes", () => { - const state = new WorkflowState(); - - state.setValidationError("op1", err("bad")); - expect(state.getValidationOutput().errors).toEqual({ op1: err("bad") }); - - state.clearValidationError("op1"); - expect(state.getValidationOutput().errors).toEqual({}); - }); - - test("setAllValidationErrors replaces the map and recomputes the empty-state flag", () => { - const state = new WorkflowState(); - state.addOperator(makeOperator("op1")); - - state.setAllValidationErrors({ op1: err("x") }); - - const out = state.getValidationOutput(); - expect(out.errors).toEqual({ op1: err("x") }); - expect(out.workflowEmpty).toBe(false); // one enabled operator present - }); - - test("workflowEmpty is true with no operators and when every operator is disabled", () => { - const state = new WorkflowState(); - - state.setAllValidationErrors({}); - expect(state.getValidationOutput().workflowEmpty).toBe(true); - - state.addOperator(makeOperator("op1", { isDisabled: true })); - state.setAllValidationErrors({}); - expect(state.getValidationOutput().workflowEmpty).toBe(true); - }); - - test("getValidationChangedStream emits the aggregated output on every mutation", () => { - const state = new WorkflowState(); - const emitted: Array<ReturnType<WorkflowState["getValidationOutput"]>> = []; - state.getValidationChangedStream().subscribe(v => emitted.push(v)); - - state.setValidationError("op1", err("x")); - state.clearValidationError("op1"); - - expect(emitted).toHaveLength(2); - expect(emitted[0].errors).toEqual({ op1: err("x") }); - expect(emitted[1].errors).toEqual({}); - }); -}); - -describe("WorkflowState - updateOperatorInputPorts", () => { - test("rebuilds the input ports to the requested count, flagging the extras dynamic", () => { - const state = new WorkflowState(); - state.addOperator(makeOperator("op1")); - - expect(state.updateOperatorInputPorts("op1", 3)).toBe(true); - - const ports = state.getOperator("op1")!.inputPorts; - expect(ports.map(p => p.portID)).toEqual(["input-0", "input-1", "input-2"]); - expect(ports[0].isDynamicPort).toBe(false); // port 0 is static - expect(ports[1].isDynamicPort).toBe(true); // extra ports are dynamic - }); - - test("reducing the count drops the extra ports", () => { - const state = new WorkflowState(); - state.addOperator( - makeOperator("op1", { - inputPorts: [ - { portID: "input-0", displayName: "Input 0" }, - { portID: "input-1", displayName: "Input 1" }, - ], - }) - ); - - state.updateOperatorInputPorts("op1", 1); - - expect(state.getOperator("op1")!.inputPorts.map(p => p.portID)).toEqual(["input-0"]); - }); - - test("returns false for a missing operator", () => { - expect(new WorkflowState().updateOperatorInputPorts("missing", 2)).toBe(false); - }); - - test("removes links targeting input ports that are dropped", () => { - const state = new WorkflowState(); - - state.addOperator(makeOperator("src")); - state.addOperator( - makeOperator("op1", { - inputPorts: [ - { portID: "input-0", displayName: "Input 0" }, - { portID: "input-1", displayName: "Input 1" }, - ], - }) - ); - - state.addLink({ - linkID: "l1", - source: { operatorID: "src", portID: "output-0" }, - target: { operatorID: "op1", portID: "input-1" }, - }); - - state.updateOperatorInputPorts("op1", 1); - - expect(state.getAllLinks().map(l => l.linkID)).toEqual([]); - }); -}); - describe("WorkflowState - workflow content round-trip", () => { test("setWorkflowContent replaces the state and getWorkflowContent reflects it", () => { const state = new WorkflowState(); diff --git a/agent-service/src/agent/workflow-state.ts b/agent-service/src/agent/workflow-state.ts index 7d27427642..e91f78e97a 100644 --- a/agent-service/src/agent/workflow-state.ts +++ b/agent-service/src/agent/workflow-state.ts @@ -28,16 +28,8 @@ import type { Point, CommentBox, WorkflowSettings, - ValidationError, } from "../types/workflow"; -export type { ValidationError, Validation } from "../types/workflow"; - -interface ValidationOutput { - errors: Record<string, ValidationError>; - workflowEmpty: boolean; -} - const DEFAULT_WORKFLOW_SETTINGS: WorkflowSettings = { dataTransferBatchSize: 400, }; @@ -78,11 +70,6 @@ export class WorkflowState { newUnviewResultOps: string[]; }>(); - private validationErrors: Record<string, ValidationError> = {}; - private workflowEmpty: boolean = true; - - private readonly validationChangedSubject = new Subject<ValidationOutput>(); - private subscriptions: Subscription[] = []; getWorkflowChangedStream(): Observable<unknown> { @@ -173,38 +160,6 @@ export class WorkflowState { return true; } - updateOperatorInputPorts(operatorId: string, numInputPorts: number): boolean { - const operator = this.operators.get(operatorId); - if (!operator) return false; - - const newInputPorts: import("../types/workflow").PortDescription[] = []; - for (let i = 0; i < numInputPorts; i++) { - newInputPorts.push({ - portID: `input-${i}`, - displayName: `Input ${i}`, - disallowMultiInputs: true, - isDynamicPort: i > 0, - }); - } - - const updatedOperator: OperatorPredicate = { - ...operator, - inputPorts: newInputPorts, - }; - this.operators.set(operatorId, updatedOperator); - - const validInputPorts = new Set(newInputPorts.map(port => port.portID)); - - for (const link of this.getAllLinks()) { - if (link.target.operatorID === operatorId && !validInputPorts.has(link.target.portID)) { - this.deleteLink(link.linkID); - } - } - - this.operatorPropertyChangeSubject.next({ operator: updatedOperator }); - return true; - } - updateOperatorPosition(operatorId: string, position: Point): boolean { if (!this.operators.has(operatorId)) { return false; @@ -222,10 +177,6 @@ export class WorkflowState { this.linkAddSubject.next(link); } - getLink(linkId: string): OperatorLink | undefined { - return this.links.get(linkId); - } - getAllLinks(): OperatorLink[] { return Array.from(this.links.values()); } @@ -279,116 +230,6 @@ export class WorkflowState { return { operators: subDagOperators, links: subDagLinks }; } - getFrontierOperators(depth: number): string[] { - const allOperators = this.getAllOperators(); - if (allOperators.length === 0) return []; - - const sourceOperatorIds = new Set<string>(); - for (const link of this.getAllLinks()) { - sourceOperatorIds.add(link.source.operatorID); - } - - const leaves = allOperators.filter(op => !sourceOperatorIds.has(op.operatorID)).map(op => op.operatorID); - - if (leaves.length === 0) { - return allOperators.map(op => op.operatorID); - } - - const frontier = new Set<string>(leaves); - let currentLevel = new Set<string>(leaves); - - for (let d = 1; d < depth; d++) { - const nextLevel = new Set<string>(); - for (const opId of currentLevel) { - for (const link of this.getAllLinks()) { - if (link.target.operatorID === opId && !frontier.has(link.source.operatorID)) { - nextLevel.add(link.source.operatorID); - frontier.add(link.source.operatorID); - } - } - } - if (nextLevel.size === 0) break; - currentLevel = nextLevel; - } - - const frontierArray = Array.from(frontier); - const inDegree = new Map<string, number>(); - const children = new Map<string, string[]>(); - for (const opId of frontierArray) { - inDegree.set(opId, 0); - children.set(opId, []); - } - for (const link of this.getAllLinks()) { - if (frontier.has(link.source.operatorID) && frontier.has(link.target.operatorID)) { - children.get(link.source.operatorID)!.push(link.target.operatorID); - inDegree.set(link.target.operatorID, (inDegree.get(link.target.operatorID) ?? 0) + 1); - } - } - - const queue: string[] = frontierArray.filter(opId => (inDegree.get(opId) ?? 0) === 0); - const sorted: string[] = []; - while (queue.length > 0) { - const node = queue.shift()!; - sorted.push(node); - for (const child of children.get(node) ?? []) { - const newDeg = (inDegree.get(child) ?? 1) - 1; - inDegree.set(child, newDeg); - if (newDeg === 0) queue.push(child); - } - } - - if (sorted.length < frontierArray.length) { - for (const opId of frontierArray) { - if (!sorted.includes(opId)) sorted.push(opId); - } - } - - return sorted; - } - - getValidationChangedStream(): Observable<ValidationOutput> { - return this.validationChangedSubject.asObservable(); - } - - getValidationOutput(): ValidationOutput { - return { - errors: { ...this.validationErrors }, - workflowEmpty: this.workflowEmpty, - }; - } - - setValidationError(operatorId: string, error: ValidationError): void { - this.validationErrors[operatorId] = error; - this.emitValidationChanged(); - } - - clearValidationError(operatorId: string): void { - delete this.validationErrors[operatorId]; - this.emitValidationChanged(); - } - - setAllValidationErrors(errors: Record<string, ValidationError>): void { - this.validationErrors = { ...errors }; - this.updateWorkflowEmptyState(); - this.emitValidationChanged(); - } - - private updateWorkflowEmptyState(): void { - const operators = this.getAllOperators(); - this.workflowEmpty = operators.length === 0; - - if (!this.workflowEmpty) { - this.workflowEmpty = operators.every(op => op.isDisabled); - } - } - - private emitValidationChanged(): void { - this.validationChangedSubject.next({ - errors: { ...this.validationErrors }, - workflowEmpty: this.workflowEmpty, - }); - } - getWorkflowContent(): WorkflowContent { const positionsObj: { [key: string]: Point } = {}; for (const [id, pos] of this.operatorPositions) { @@ -482,8 +323,6 @@ export class WorkflowState { this.settings = { ...DEFAULT_WORKFLOW_SETTINGS }; this.formBinding = undefined; this.operatorsToViewResult.clear(); - this.validationErrors = {}; - this.workflowEmpty = true; } destroy(): void { @@ -499,7 +338,6 @@ export class WorkflowState { this.linkDeleteSubject.complete(); this.disabledOperatorChangedSubject.complete(); this.viewResultOperatorChangedSubject.complete(); - this.validationChangedSubject.complete(); this.reset(); } diff --git a/agent-service/src/types/workflow.ts b/agent-service/src/types/workflow.ts index e6f9b0c15c..cc564db6cf 100644 --- a/agent-service/src/types/workflow.ts +++ b/agent-service/src/types/workflow.ts @@ -132,15 +132,6 @@ export type PortSchema = readonly SchemaAttribute[]; export type OperatorPortSchemaMap = Record<string, PortSchema | undefined>; -export interface OperatorDetail { - operatorId: string; - operatorType: string; - customDisplayName?: string; - operatorProperties: Record<string, any>; - inputPorts: PortDescription[]; - outputPorts: PortDescription[]; -} - export type ValidationError = { isValid: false; messages: Record<string, string>;
