Repository navigation
fix(agent-service): check operator edits before changing the workflow - #8981
ShawnGarello wants to merge 4 commits into
Conversation
addOperator and modifyOperator change the workflow before they check the input ports and source operators, so a call that returns an error can leave a new operator, a partial link, or changed properties with the operator's incoming links removed. Add three tests that assert the workflow is unchanged after such an error. They fail on main and are meant to pass once the tools check everything before changing the workflow. Generated-by: Claude Code (Opus 5.5)
addOperator and modifyOperator now check every input port index and source operator before they add the operator, apply properties or delete links, so a call that returns an error leaves the workflow as it was. Closes apache#8979 Generated-by: Claude Code (Opus 5.5)
Automated Reviewer SuggestionsBased on the
|
Backport auto-label reportThis
|
|
/request-review @aglinxinyuan |
bobbai00
left a comment
There was a problem hiding this comment.
🟡 0 must-fix · 2 advisory · 0 polish: a clean root-cause fix with good red-first tests; two optional follow-ups in the new helper.
Correctness (2)
workflow-crud-tools.ts:85: add and modify now handle a self-referencing source differently (advisory, see inline)workflow-crud-tools.ts:73:parseIntmaps keys like"1abc"to port 1 (advisory, see inline)
Verification trace
Every [ERROR] return in both tools now comes before the first WorkflowState write (addOperator: line 194 before 196; modifyOperator: line 282 before 288), and resolveInputLinks only reads, so a failed call emits nothing to getWorkflowChangedStream. Error strings, link order and link-ID order match main. Locally in agent-service, main's workflow-crud-tools.ts with this spec fails exactly the 4 changed or new tests; this head passes all 313, and typecheck and format are clean.
bobbai00
left a comment
There was a problem hiding this comment.
Thanks for the PR! Please check my comments. Please also add more test cases
Applies the review suggestions on apache#8981. resolveInputLinks now rejects an operator that names itself as a source (modifyOperator used to store a self-loop) and port keys that are not all digits (parseInt read "1abc" as port 1). Adds tests for both, plus a failed modify on a later port, no change events after a failed call, a two-port add and a retry after a failed add. Generated-by: Claude Code (Opus 5.5)
|
/request-review @bobbai00 |
What changes were proposed in this PR?
When the agent calls
modifyOperatorwith a source operator that doesn't exist, the tool reports an error, but the operator's properties and name have already changed and its input links are gone.addOperatorhas the same problem: a bad port index or source leaves the new operator (and links for earlier ports) in the workflow, and a retry with the same id then fails with "already exists".Both tools now run every input check (port index, source operator) first, through one small helper,
resolveInputLinks, and only then add the operator, apply properties and name, or replace links. A failed call leaves the workflow as it was. Error messages and success results are unchanged.Why this approach (option A in #8979) and not snapshot/restore (B): it's a reorder with no new
WorkflowStateAPI, and a failed call now emits no change events, so nothing half-applied reaches the canvas or the 500 ms auto-persist. B would restore withsetWorkflowContent, which emits no events, after the failed edit had already emitted some. I'm happy to switch to B if reviewers prefer it.The existing test "returns an error when an input port index is not a number" (from #7026) asserted the half-applied result: the failed modify had dropped the operator's input link. It now asserts that the link is kept and the operator isn't renamed.
After review, both tools also reject an operator that names itself as a source (
modifyOperatorused to store a self-loop link), and an input port key must be all digits (parseIntread"1abc"as port 1).Out of scope: the model isn't told that the call failed (
isErroris always false for these results). I'll open a separate issue for that.Any related issues, documentation, discussions?
Closes #8979
Backport: the bug is on both release branches (
workflow-crud-tools.tsis identical onrelease/v1.3andrelease/v1.2), so I'd suggest both. Onrelease/v1.2the spec fileworkflow-crud-tools.spec.tsdoesn't exist yet, so that cherry-pick will need the test changes dropped or adapted.How was this PR tested?
In
agent-service, afterbun install --frozen-lockfile:[ERROR]result (one formodifyOperator, two foraddOperator). Without the fix,bun testgives 310 pass, 3 fail: exactly those three.bun testgives 313 pass, 0 fail (run twice).bun run format:checkandbun run typecheckare clean.bun test --coverage: all new lines inworkflow-crud-tools.tsare covered (229/230 lines; the one uncovered line is the existingcatchindeleteOperator).bun testgives 324 pass, 0 fail. With only the two new checks reverted, exactly their 6 tests fail; withmain'sworkflow-crud-tools.ts, 14 fail.Was this PR authored or co-authored using generative AI tooling?
Generated-by: Claude Code (Opus 5.5)