fix(graph_workflow): make to_json/from_json node types round-trip (#1839) - #1898
Open
aayushbaluni wants to merge 1 commit into
Open
fix(graph_workflow): make to_json/from_json node types round-trip (#1839)#1898aayushbaluni wants to merge 1 commit into
aayushbaluni wants to merge 1 commit into
Conversation
to_json serialized the node type with str(node.type), which renders a NodeType as 'NodeType.AGENT'. from_json parses it with NodeType(n['type']), which only accepts the enum value ('agent'), so every node raised "'NodeType.AGENT' is not a valid NodeType".
That exception was swallowed by the per-node try/except in the deserialize loop, so all nodes were silently dropped and the subsequent edge restore failed with "Source node 'alpha' does not exist in GraphWorkflow" - a confusing error that points at the edges rather than the actual serialization defect.
Serialize the enum value instead, and parse through a helper that also accepts the legacy 'NodeType.X' spelling so workflows exported before this fix still load.
|
Hello there, thank you for opening an PR ! 🙏🏻 The team was notified and they will get back to you asap. |
3 tasks
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
GraphWorkflow.to_json()→GraphWorkflow.from_json()round trip is broken: it raises and loses the entire graph. This fixes the serialization defect that causes it.to_jsonwrites the node type withstr(node.type), which renders aNodeTypeas"NodeType.AGENT".from_jsonparses it withNodeType(n["type"]), which only accepts the enum value ("agent"):Because the deserialize loop wraps each node in
try/except ... continue, thatValueErroris swallowed per node and every node is silently dropped. The failure then surfaces on the edges, pointing away from the real cause:Reproduced on
master(3ff3475) with a two-agent workflow and one edge.Fix
to_jsonemits the enum value ("agent").Node.typeis not coerced in__init__, sogetattr(node.type, "value", node.type)also tolerates a plain string.from_jsonparses via a small_parse_node_typehelper that additionally accepts the legacy"NodeType.X"spelling, so workflows exported before this fix still load.The change is confined to the two lines that serialize/deserialize the node type, plus the helper. I deliberately left
export_summary'sstr(node.type)alone: it is display-only and never parsed back.Issue
Fixes the first half of #1839.
Scope note: #1839 also reports that
from_jsonreconstructs agents as plain dicts. That is real and still present —Agenthasto_dict()but nofrom_dict()inverse, so restoring liveAgentobjects is a design decision rather than a bug fix, and it belongs in a separate PR. The issue additionally proposes deleting the ~495-line JSON path; that is a maintainer call on public API, so this PR only repairs the defect. With this change the round trip preserves ids, node types and edges instead of collapsing to an exception.Tests
Added 3 tests to
tests/structs/test_graph_workflow.py(there were previously none covering the JSON path, which is how this shipped):test_to_json_node_type_round_trips— serialized type is"agent"and parses backtest_parse_node_type_accepts_legacy_and_canonical_forms— canonical, legacy and enum inputs; invalid input still raisestest_from_json_reconstructs_nodes_and_edges— topology survives the round tripVerification
pytest tests/structs/test_graph_workflow.py→ 51 passed, 11 skipped (48 passed on unmodifiedmaster, so +3 and no regressions)to_jsontostr(node.type)failstest_to_json_node_type_round_trips; disabling the legacy branch in_parse_node_typefails the legacy test. The tests measure the fix rather than decorating it.black --checkclean;ruff checkreports 215 errors on these two files both before and after my change (all pre-existing, repo-wideUP006/I001style), so this adds none.Dependencies
None.
Tag maintainer
@kyegomez