You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Model workflow edge direction by condition presence - #938
Fixes a set of edge-direction bugs in the hand-written workflows-as-code builder, bringing it in line with the six new-language SDKs (Rust/Ruby/PHP/.NET already landed). A loaded workflow edge can carry only a forward condition, only a backward one, or both, and a transition exists only in the direction whose condition is present — the builder previously assumed a forward transition always exists.
Details
Validation (validate.py): the forward routing checks (edge_into_start, end-has-outgoing, tool/result) now run only when a forward_condition is present, and the same checks run in the reverse direction when a backward_condition is present. Previously a backward condition could point into the start node, leave an end node, or leave a tool node without a result condition, all unflagged.
Reachability (validate.pydepths_from): an edge is followed forward only when it has a forward_condition (the reverse pass already required a backward one), so a loaded backward-only edge no longer invents a forward transition or suppresses unreachable_node.
Serialization (workflow.py_to_wire): an edge joins its source's edge_order only when it has a forward_condition (its target's only when backward_condition), so a loaded backward-only edge isn't re-attached forward on save.
insert_between on a bidirectional edge can't preserve the original target's reverse route, so it now rejects with a new cannot_insert_bidirectional issue instead of silently dropping/misattaching it.
position is accepted for node kinds with no dedicated field map (graph.py), e.g. generated say/update_state, instead of recording invalid_option.
These are behaviour fixes to the shipped builder; no generated code changes. The same fixes are in the Rust/Ruby/PHP/.NET PRs. Follow-up: lock these behaviours into the shared golden fixtures so all SDKs stay identical.
Testing
pytest tests/agent_workflows/ — 59 passed (8 shared fixtures + hand-written suite + 4 new TestEdgeDirectionModel cases covering bidirectional-insert rejection, backward-out-of-end, position on an unmapped node kind, and a loaded backward-only edge's edge_order).
…onal insert
Brings the workflows-as-code builder's edge model in line with the six new
SDKs. A loaded edge can carry only a forward or only a backward condition,
and a transition exists only in the direction whose condition is present:
- validate(): the forward routing checks (edge_into_start, end outgoing,
tool/result) run only when a forward condition is present, and the same
checks now also run in the reverse direction for a backward condition
(previously a backward condition could leave an end node, point into
start, or leave a tool without a result unflagged).
- depths_from(): follow an edge forward only when it has a forward
condition.
- _to_wire(): add an edge to its source's outgoing edge_order only when it
has a forward condition (to the target's only when backward), so a loaded
backward-only edge is not re-attached forward.
insert_between() on a bidirectional edge can't preserve the original
target's reverse route, so reject it (cannot_insert_bidirectional) instead
of dropping it. And position is accepted for node kinds without a dedicated
field map (e.g. generated say/update_state).
Co-Authored-By: Claude Opus 4.8 <[email protected]>
Medium Risk
Changes core workflow graph validation, layout, and serialization semantics for loaded or bidirectional edges; incorrect behavior could alter reachability or saved edge order but is confined to the workflows-as-code builder with new tests.
Overview
Treats workflow transitions as directional: a move exists only when the corresponding forward_condition or backward_condition is set on an edge, instead of assuming every edge has a forward transition.
Validation runs start/end/tool routing rules on the forward leg only when forward_condition is present, and applies the same rules to the reverse leg (target → source) when backward_condition is present. Reachability layout follows an edge forward only if it has a forward_condition, so backward-only loaded edges no longer fake forward paths or hide unreachable nodes. Wire serialization puts edges in a node’s edge_order only for outgoing transitions that actually exist (source for forward, target for backward).
insert_between now fails with cannot_insert_bidirectional when splitting an edge that still has a backward condition, rather than dropping the reverse route. Node updates accept position for kinds without a dedicated field map (e.g. say), avoiding spurious invalid_option errors.
Reviewed by Cursor Bugbot for commit 8b13a16. Bugbot is set up for automated code reviews on this repo. Configure here.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
The new cannot_insert_bidirectional issue code is missing from the exported WorkflowIssueCode literal, creating a type mismatch for callers and leaving exhaustive handlers incomplete.
This PR updates the hand-written workflow builder so transitions exist only in directions with a condition, aligning validation and serialization with the other SDKs.
Changes:
Makes routing validation, reachability, and outgoing edge order respect condition presence.
Rejects insertion into edges with backward conditions and accepts positions on unmapped node kinds.
Adds regression tests and shared fixtures for edge-direction behavior.
File
Description
tests/agent_workflows/test_workflow.py
Adds four edge-direction and position regression tests.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
The serialization test would still pass without the new guard because it lacks a backward-only edge case asserting that an otherwise isolated target remains unreachable.
This test checks serialization, but all its nodes are already reachable through forward edges, so removing the new depths_from condition guard still passes it. Add a case with a reachable source and an otherwise isolated target connected by a backward-only edge, and assert unreachable_node for the target. That locks down the false-reachability bug this PR fixes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes a set of edge-direction bugs in the hand-written workflows-as-code builder, bringing it in line with the six new-language SDKs (Rust/Ruby/PHP/.NET already landed). A loaded workflow edge can carry only a forward condition, only a backward one, or both, and a transition exists only in the direction whose condition is present — the builder previously assumed a forward transition always exists.
Details
validate.py): the forward routing checks (edge_into_start, end-has-outgoing, tool/result) now run only when aforward_conditionis present, and the same checks run in the reverse direction when abackward_conditionis present. Previously a backward condition could point into the start node, leave an end node, or leave a tool node without a result condition, all unflagged.validate.pydepths_from): an edge is followed forward only when it has aforward_condition(the reverse pass already required a backward one), so a loaded backward-only edge no longer invents a forward transition or suppressesunreachable_node.workflow.py_to_wire): an edge joins its source'sedge_orderonly when it has aforward_condition(its target's only whenbackward_condition), so a loaded backward-only edge isn't re-attached forward on save.insert_betweenon a bidirectional edge can't preserve the original target's reverse route, so it now rejects with a newcannot_insert_bidirectionalissue instead of silently dropping/misattaching it.positionis accepted for node kinds with no dedicated field map (graph.py), e.g. generatedsay/update_state, instead of recordinginvalid_option.These are behaviour fixes to the shipped builder; no generated code changes. The same fixes are in the Rust/Ruby/PHP/.NET PRs. Follow-up: lock these behaviours into the shared golden fixtures so all SDKs stay identical.
Testing
pytest tests/agent_workflows/— 59 passed (8 shared fixtures + hand-written suite + 4 newTestEdgeDirectionModelcases covering bidirectional-insert rejection, backward-out-of-end, position on an unmapped node kind, and a loaded backward-only edge'sedge_order).ruff format --checkclean on the changed files.🤖 Generated with Claude Code