Repository navigation
Playbook Engine: Graph Traversal, NodeCollection, and Path Validation - #1011
Conversation
…ation (#1010) Implement dot-path expression resolution for the Playbook Engine's CEL evaluator and action binding system, enabling expressions like `node.story.epic.status` to walk relationships during condition evaluation and action execution. ## New files - `path_extractor.rs` — Walk cel-parser AST to extract dot-path references from CEL expressions (flat paths, comprehension/collection paths) - `graph_resolver.rs` — Resolve dot-paths by walking the data graph via NodeService with sync bridge (block_in_place) and segment caching - `mcp/handlers/playbook.rs` — get_workflow_state MCP tool for read-only condition evaluation against active playbook rules ## Key changes - `cel.rs` — evaluate_conditions accepts optional GraphResolver; paths are pre-resolved and injected as nested CEL Maps before evaluation - `actions.rs` — BindingContext uses GraphResolver for multi-hop dot-path resolution in action parameter bindings ({trigger.node.story.epic.title}) - `validation.rs` — Schema-aware path validation walks the schema graph to verify dot-path segments resolve to valid fields or relationships - `lifecycle.rs` — Path-aware schema drift detection checks condition paths that traverse through changed schemas, not just direct trigger references - `engine.rs` — RuleProcessor creates GraphResolver per work item ## Architecture decisions - Sync bridge via block_in_place in GraphResolver only (NodeService stays async) - Path extraction from cel-parser AST (cel-interpreter Value::member not extensible) - CEL collection macros (.exists/.all/.filter) work natively on pre-populated Lists - Schema path validation at save-time, data graph resolution at runtime Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Add 42 new Rust tests covering all previously untested modules:
- graph_resolver.rs: 19 tests — inject_resolved_paths (unit),
get_node_property (unit), resolve_path with single-hop, multi-hop,
cache hits, collections, scalars, empty segments, missing paths
- lifecycle.rs: 13 tests — activate/deactivate/disable, lookup_rules,
handle_schema_update with path-aware drift detection,
playbook_has_paths_through_schema, trigger_keys_for_event
- playbook.rs (MCP): 5 tests — parameter validation, missing nodes,
no matching playbooks, passing/failing condition evaluation
- validation.rs: 5 tests — valid multi-hop paths, broken unknown
segments, field-as-non-terminal, relationship without target_type,
single-hop skip
Also fixes bugs discovered by the tests:
- get_node_property now handles type-namespaced properties
({"task": {"status": "open"}} → finds "status")
- node_to_cel_value unwraps type namespace so CEL conditions can
use `node.status` instead of `node.task.status`
- parse_rules_from_properties checks inside "playbook" namespace
for DB-stored playbook nodes
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
malibio
left a comment
There was a problem hiding this comment.
Code Review: PR #1011 — Playbook Engine: Graph Traversal, NodeCollection, and Path Validation
Overall Assessment
This is a substantial and well-architected PR that adds graph traversal to the Playbook Engine's CEL evaluator, implementing Phases A through F of issue #1010. The second commit adds 42 new tests and fixes 3 real bugs related to how NodeSpace normalizes properties into a type-namespaced format after create_node. The approach of pre-populating CEL Value trees (rather than lazy resolution) is the correct architectural decision given cel-interpreter's synchronous Value::member(). The sync bridge via block_in_place is well-documented and safe for the single-RuleProcessor-task model.
The three bug fixes are correct in their intent and address real discrepancies between in-memory and DB-stored property formats. The test coverage is comprehensive and well-organized into unit tests (no DB), integration tests (with real NodeService), and the tests exercise meaningful scenarios rather than being trivial.
Verdict: Net positive. Approve with suggestions.
Findings
Suggested Improvements
1. [Improvement] get_node_property guard heuristic is fragile (graph_resolver.rs:273-278)
The guard condition !val.is_object() || obj.len() > 1 attempts to distinguish between a type-namespace wrapper and a legitimate property. However, it relies on obj.len() which creates a subtle edge case:
When properties = {"task": {"status": "open"}, "custom:priority": "high"} and key = "task":
obj.get("task")finds{"status": "open"}val.is_object()istrue, butobj.len() == 2soobj.len() > 1istrue- Guard evaluates to
!true || true=true, returning the entire type namespace object as a scalar
A more robust approach would be to check against the node_type directly:
if let Some(val) = obj.get(key) {
// Don't return the type namespace wrapper as a property
if key != node.node_type || !val.is_object() {
return Some(val.clone());
}
}This is clearer in intent and handles all obj.len() scenarios correctly. In practice the current code works because CEL paths wouldn't use the node_type as a property name, but explicit is better than implicit.
2. [Improvement] Missing test for parse_rules_from_properties namespace-nested format (types.rs:378-383)
The second commit added the "playbook": {"rules": [...]} fallback in parse_rules_from_properties, but neither the existing test_parse_rules_from_properties test (in tests.rs:240) nor any new test covers this code path. The existing test only exercises the top-level {"rules": [...]} format. A test for {"playbook": {"rules": [...]}} would prevent regression on this fix.
3. [Improvement] Missing test for get_node_property with type-namespaced properties (graph_resolver.rs:280-286)
The get_property_direct_key test uses flat properties {"status": "open"} and the get_property_with_namespace_prefix test uses colon-prefixed properties {"custom:amount": 1500}. Neither tests the actual DB-stored format that motivated the fix: {"task": {"status": "open"}}. Adding a test for this format would directly cover the bug that was fixed.
4. [Improvement] node_to_cel_value and get_node_property have parallel logic that could drift (cel.rs:174-192, graph_resolver.rs:270-298)
Both functions independently implement the same "unwrap type namespace, strip colon prefix" logic. If the property storage format changes, both need updating. Consider extracting a shared utility (e.g., iter_node_properties(node) -> impl Iterator<Item = (&str, &Value)>) that both functions call. This follows DRY and reduces the risk of these diverging.
Nitpicks
Nit: resolved_value_missing_is_default and resolved_value_scalar tests (graph_resolver.rs:579-588)
These tests verify that enum constructors work, which Rust's type system already guarantees. They add noise without meaningful coverage. Not blocking — the cost is trivial.
Nit: Comment accuracy in playbook_has_paths_through_schema (lifecycle.rs:299)
The comment says "heuristic: we extract paths from conditions and check if any segment matches the schema name" which is correct, but worth noting that action bindings (e.g., {trigger.node.story.epic.title}) are not checked. If an action binding references a path through a changed schema, the drift detection won't catch it. This is fine for now since action bindings are template strings not CEL expressions, but worth a TODO comment.
Summary
The three bug fixes are correct and address real issues with type-namespaced property storage. The test suite is comprehensive with good separation between unit and integration tests. The main suggestions are: (1) making the get_node_property guard more explicit by checking node.node_type directly instead of using obj.len(), (2) adding test coverage for the two new code paths that were fixed but not directly tested, and (3) extracting the duplicate property-iteration logic to prevent future drift. None of these are blockers.
malibio
left a comment
There was a problem hiding this comment.
Review Status: APPROVE (with suggestions)
All three bug fixes verified correct. 197 playbook tests pass. No blockers. See detailed review above for improvement suggestions.
- Replace fragile obj.len() heuristic in get_node_property with explicit key != node.node_type check (reviewer finding #1) - Add test for get_node_property with type-namespaced properties (the actual DB-stored format that motivated the fix) (#3) - Add test for parse_rules_from_properties with namespace-nested {"playbook": {"rules": [...]}} format (#2) - Add NOTE comment about action binding templates not being checked by drift detection (#6) - Add NOTE about parallel property-iteration logic between node_to_cel_value and get_node_property (#4 — comment over extraction) Skipped: #4 shared utility extraction (callsites have different return types — CEL Value vs JSON — making a shared iterator awkward for marginal benefit; comment noting the parallel is sufficient), #5 trivial enum constructor tests (cost of keeping is negligible). Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Review Feedback AddressedCommit: Addressed (4/6)
Skipped (2/6)
Test Results
|
…#1011) * feat: Playbook Engine graph traversal, NodeCollection, and path validation (#1010) Implement dot-path expression resolution for the Playbook Engine's CEL evaluator and action binding system, enabling expressions like `node.story.epic.status` to walk relationships during condition evaluation and action execution. ## New files - `path_extractor.rs` — Walk cel-parser AST to extract dot-path references from CEL expressions (flat paths, comprehension/collection paths) - `graph_resolver.rs` — Resolve dot-paths by walking the data graph via NodeService with sync bridge (block_in_place) and segment caching - `mcp/handlers/playbook.rs` — get_workflow_state MCP tool for read-only condition evaluation against active playbook rules ## Key changes - `cel.rs` — evaluate_conditions accepts optional GraphResolver; paths are pre-resolved and injected as nested CEL Maps before evaluation - `actions.rs` — BindingContext uses GraphResolver for multi-hop dot-path resolution in action parameter bindings ({trigger.node.story.epic.title}) - `validation.rs` — Schema-aware path validation walks the schema graph to verify dot-path segments resolve to valid fields or relationships - `lifecycle.rs` — Path-aware schema drift detection checks condition paths that traverse through changed schemas, not just direct trigger references - `engine.rs` — RuleProcessor creates GraphResolver per work item ## Architecture decisions - Sync bridge via block_in_place in GraphResolver only (NodeService stays async) - Path extraction from cel-parser AST (cel-interpreter Value::member not extensible) - CEL collection macros (.exists/.all/.filter) work natively on pre-populated Lists - Schema path validation at save-time, data graph resolution at runtime Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]> * test: comprehensive test coverage for graph traversal (#1010) Add 42 new Rust tests covering all previously untested modules: - graph_resolver.rs: 19 tests — inject_resolved_paths (unit), get_node_property (unit), resolve_path with single-hop, multi-hop, cache hits, collections, scalars, empty segments, missing paths - lifecycle.rs: 13 tests — activate/deactivate/disable, lookup_rules, handle_schema_update with path-aware drift detection, playbook_has_paths_through_schema, trigger_keys_for_event - playbook.rs (MCP): 5 tests — parameter validation, missing nodes, no matching playbooks, passing/failing condition evaluation - validation.rs: 5 tests — valid multi-hop paths, broken unknown segments, field-as-non-terminal, relationship without target_type, single-hop skip Also fixes bugs discovered by the tests: - get_node_property now handles type-namespaced properties ({"task": {"status": "open"}} → finds "status") - node_to_cel_value unwraps type namespace so CEL conditions can use `node.status` instead of `node.task.status` - parse_rules_from_properties checks inside "playbook" namespace for DB-stored playbook nodes Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]> * fix: address review feedback — heuristic fix, missing tests, docs - Replace fragile obj.len() heuristic in get_node_property with explicit key != node.node_type check (reviewer finding #1) - Add test for get_node_property with type-namespaced properties (the actual DB-stored format that motivated the fix) (#3) - Add test for parse_rules_from_properties with namespace-nested {"playbook": {"rules": [...]}} format (#2) - Add NOTE comment about action binding templates not being checked by drift detection (#6) - Add NOTE about parallel property-iteration logic between node_to_cel_value and get_node_property (#4 — comment over extraction) Skipped: #4 shared utility extraction (callsites have different return types — CEL Value vs JSON — making a shared iterator awkward for marginal benefit; comment noting the parallel is sufficient), #5 trivial enum constructor tests (cost of keeping is negligible). Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]> --------- Co-authored-by: Michael Libio <[email protected]> Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]>
Closes #1010