Skip to content

fix(workflows): keep condition and router branch connections when an edit re-sends the branches - #10307

Merged
waleedlatif1 merged 2 commits into
stagingfrom
fix/condition-branch-ids-keep-edges
Nov 22, 2026
Merged

waleedlatif1 merged 2 commits into
stagingfrom
fix/condition-branch-ids-keep-edges

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Bug

An operations edit (v2 operations API, Copilot edit_workflow) that re-sends a condition block's conditions or a router's routes, for example to change one expression, disconnected branches the canvas had added. The canvas mints row ids like <blockId>-else-if-<timestamp>, and their edges are stored as condition-<rowId>. After the edit, the stored edge named no row. The branch still matched at run time but routed nowhere, because the executor follows only condition-<selectedOption>. After a canvas reorder, the edit could also move an edge onto a different branch's expression.

Root cause

normalizeConditionRouterIds reassigned every row id by position (-if, -else-if-N, -else, -routeN) on every edit and never looked at the stored rows or edges. Persistence keeps the stale edge as it is.

Fix

An edit that re-sends the branch list now keeps each branch's stored id. It first matches the stored row with the same expression, which covers branches inserted, removed or reordered around it. Otherwise it takes the stored row in the same slot (if / else-if-k / else / route-k, the positional handles that ops connections use). New rows get the canonical id, or a fresh one if a stored row already holds it. Edges from rows the edit removed are dropped in the same mutation. Adding a new block is unchanged.

Tests

apply-workflow-operations-branches.integration.ts runs against real Postgres through applyWorkflowOperations and reads the result back from the normalized tables. It covers:

  • a changed else-if expression
  • a canvas-reordered list
  • a removed last else-if
  • a removed middle else-if
  • an inserted middle else-if
  • an added else-if whose canonical id is already taken
  • a router route

All 7 fail on staging. Reverting each guard on its own (keep by slot, keep by expression, drop removed-row edges, id collision) turns at least one test red.

…edit re-sends the branches

An operations edit that re-sent a condition's conditions or a router's
routes reassigned every row id by position (<blockId>-if, -else-if-N,
-else, -routeN). Rows the canvas added have ids like
<blockId>-else-if-<timestamp>, and stored edges name rows as
condition-<id> / router-<id>, so the edit left those edges naming no row:
the branch matched at run time but routed nowhere. After a canvas reorder
the renamed ids could also attach an edge to another branch's expression.

Re-sent rows now keep the stored id of the same branch: the stored row
with the same expression first, then the row in the same slot. New rows
get the canonical id, or a fresh one when a stored row holds it. Edges
from rows the edit removed are dropped in the same mutation.
@vercel

vercel Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
docs Skipped Skipped Nov 22, 2026 6:03pm UTC

Request Review

@greptile-apps

greptile-apps Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no new actionable issues remain.

Summary

Keeps stored branch IDs when edits re-send condition or router rows, and removes edges for deleted rows.

  • Condition and router edits keep saved connections with their branches.

Reviews (2) · Last reviewed commit: "fix(workflows): reserve unchanged branch..." · Reviewed by Greptile

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 3 files

Reply with feedback, questions, or to request a fix.

Turn on auto-fix | Re-trigger cubic

…ndles, reject malformed condition rows

- An unchanged row (same slot, same expression) keeps its id before any
  row is matched by expression, so editing a branch to repeat a later
  branch's expression no longer takes that branch's id and connection.
- Condition and router handle resolution gives a row's own
  condition-<id> / router-<id> handle priority over another row's
  title or position alias, which can spell the same string after a
  reorder.
- A condition row that is not an object is refused as invalid input
  instead of crashing the lint pass.
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review

@cubic-dev-ai

cubic-dev-ai Bot commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 4 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Turn on auto-fix | Re-trigger cubic

@waleedlatif1
waleedlatif1 merged commit 96006f6 into staging Nov 22, 2026
84 checks passed
@waleedlatif1
waleedlatif1 deleted the fix/condition-branch-ids-keep-edges branch November 23, 2026 00:04

This branch was previously deployed

1 inactive deployment
Preview — ae6256b2 Deployed Nov 22, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant