Skip to content

fix(flows): route a condition node only along its own edges - #1748

Merged
sung17 merged 1 commit into
mainfrom
fix/condition-duplicate-case-ids
Nov 18, 2026
Merged

sung17 merged 1 commit into
mainfrom
fix/condition-duplicate-case-ids

Conversation

@sung17

@sung17 sung17 commented Nov 18, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • A Condition node sent contacts down the wrong branch after a Condition node in the same flow had been duplicated. Reported case: a contact whose source is "Livestream comments" ran the actions of another Condition node's branch.
  • Cause: Duplicate kept the copy's case ids and otherwiseId. Those ids are the edge source handles. The worker found the next node by handle id alone (seekConnectedNode), so when two nodes shared a case id it could pick the other node's edge.
  • The worker now also matches the edge's source node. Flows that already contain shared ids route correctly after deploy, without editing or republishing them. Duplicate now gives every case and the otherwise handle a new id.

Changes

  • apps/worker/src/integration/handlers/flow-utils.ts: seekConnectedNode takes an optional sourceNodeId. New findNodeIdContainingStep helper.
  • apps/worker/src/integration/handlers/condition.ts: looks up the next node from this condition node's own edges.
  • apps/builder/src/features/flows/react-flow/toolbar/duplicate-node-data.ts: gives condition case ids and otherwiseId new ids on Duplicate. Split-traffic cases have no id and are unchanged.
  • Tests:
    • condition-handler.test.ts: regression for two nodes that share a case id. It fails without the worker fix.
    • duplicate-node-data.test.ts: the duplicated condition gets new ids and keeps its conditions.

Other step handlers keep the handle-only lookup. Their handle ids (state, button, option ids) were already given new ids on Duplicate. Analytics does not read condition case ids.

Test plan

  • vitest condition-handler + flow (seekConnectedNode) in worker
  • vitest duplicate-node-data in builder
  • pnpm --filter worker check-types, pnpm --filter builder check-types
  • ultracite on the changed files
  • pnpm lint (full) in CI
  • Manual: duplicate a Condition node, publish, and check that each copy follows its own branches

🤖 Generated with Claude Code

Duplicating a condition node kept its case ids and otherwiseId, which are
the edge source handles. The worker resolved the next node by handle id
alone, so with two nodes sharing a case id it could follow the other
node's edge and send the contact down a branch it never matched.

The condition handler now also matches the edge's source node, so flows
that already hold duplicated ids route correctly without being edited.
Duplicate now gives every case and the otherwise handle a new id.
@github-actions github-actions Bot added the bug Something isn't working as expected label Nov 18, 2026
@sung17
sung17 merged commit 0d143f8 into main Nov 18, 2026
15 checks passed
hello-jackytruong referenced this pull request in hello-jackytruong/ChatWorkAI Nov 22, 2026
Duplicating a condition node kept its case ids and otherwiseId, which are
the edge source handles. The worker resolved the next node by handle id
alone, so with two nodes sharing a case id it could follow the other
node's edge and send the contact down a branch it never matched.

The condition handler now also matches the edge's source node, so flows
that already hold duplicated ids route correctly without being edited.
Duplicate now gives every case and the otherwise handle a new id.

Co-authored-by: Deathgiver <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working as expected

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant