Repository navigation
Closed
Labels
Description
Overview
Implement graph traversal for the Playbook Engine's CEL evaluator and action binding resolver. This enables dot-path expressions like node.story.epic.status to walk relationships during condition evaluation and action execution. Also adds NodeCollection operators and schema-aware path validation.
Parent issue: #995 (Playbook Engine Architecture — Phases 0-7 complete)
Architecture spec: playbook-engine.md Section 3 — CEL Evaluation
Background
Issue #995 implemented the full playbook engine pipeline (Phases 0-7), but graph traversal was deferred because cel-interpreter's Program::execute() is synchronous while NodeService is async. Architectural review (by senior-architect-reviewer agent) determined:
cel-interpreter'sValue::member()is hardcoded — no custom resolver hook exists- CEL Value trees must be pre-populated before evaluation, not lazily resolved
- The recommended approach: parse CEL ASTs to extract dot-paths → resolve against graph → build nested CEL Maps → evaluate
- Sync bridging via
tokio::task::block_in_placein a dedicatedGraphResolver(NOT on NodeService) - The path extractor is the shared foundation for three features: save-time validation, runtime resolution, and schema drift detection
Implementation Plan
Phase A: Path Extractor (foundation)
-
path_extractor.rs— Walkcel-parserAST to extract dot-path references from compiled CEL programs- Extract flat paths:
node.story.epic.status→["node", "story", "epic", "status"] - Extract sub-expression paths inside collection operators:
node.tasks.any(item.status == "done")→ collection path["node", "tasks"]+ item path["item", "status"] - Handle nested collection paths recursively
- Extract flat paths:
- Write tests: path extraction from various CEL expression patterns
Phase B: GraphResolver (runtime resolution)
-
graph_resolver.rs— Resolves dot-paths by walking the data graph via NodeServiceGraphResolver::new(node_service: Arc<NodeService>)— created per rule evaluationresolve_path(root_node, segments) -> ResolvedValue— walks segments, property-first then relationship fallback- Sync bridge via
tokio::task::block_in_place+Handle::current().block_on()(safe: multi-threaded runtime, single RuleProcessor task) - Segment cache:
HashMap<Vec<String>, ResolvedValue>— prevents redundant DB queries for overlapping paths across conditions in the same rule ResolvedValueenum:Node(Node),Collection(Vec<Node>),Scalar(Value)
- Enrich CEL context —
build_condition_contextinjects resolved paths as nestedValue::Mapstructures - Update
evaluate_conditionsincel.rsto accept&mut GraphResolverand pre-resolve paths before evaluation - Update
engine.rsRuleProcessor — createGraphResolverper work item, pass to CEL evaluation - Write tests: single-hop resolution, multi-hop chains, property vs. relationship precedence, segment cache hit/miss, missing path → false
Phase C: NodeCollection operators
-
NodeCollection— resolved asValue::Listof node Maps (pre-fetched by GraphResolver) - Register custom CEL functions:
.count— property on List, returns integer.any(expr)— returns bool (true if any item matches).all(expr)— returns bool (true if ALL items match; empty → false per spec).none(expr)— returns bool (true if no items match).where(expr)— returns filtered List (chainable)
- Sub-expression resolution — paths inside
.any()/.where()lambdas are extracted by path_extractor, resolved in batch for all collection items - Empty collection → false (deliberate departure from vacuous truth per spec)
- Write tests: collection operators, empty collections, chained
.where().any(), nested relationship paths in sub-expressions
Phase D: Action binding graph traversal
- Update
BindingContextinactions.rs—{trigger.node.story.epic.title}resolves via GraphResolver - Live state resolution — bindings resolve against current graph (not snapshot), so action 0's
create_nodeis visible to action 1's binding -
for_eachcollection resolution —for_each: "trigger.node.tasks"uses GraphResolver to fetch the collection - Write tests: multi-hop binding resolution, live state visibility across actions, for_each with graph-resolved collections
Phase E: Schema-aware path validation (save-time + drift)
- Schema-level path validation in
validation.rs— reuse path_extractor, walk the schema graph (not data graph) to verify every segment resolves to a field or relationshipnode.status→ "status" is a field on trigger's schema ✓node.story→ "story" is a relationship on trigger's schema ✓node.story.epic→ "epic" is a relationship on story's target schema ✓node.story.epic.status→ "status" is a field on epic's target schema ✓
- Schema drift with path awareness — upgrade
handle_schema_updatefrom "does playbook reference this node_type?" to "do any paths still resolve after the schema change?"- When a schema changes: re-extract paths from all active playbooks, re-validate against updated schema graph
- Broken path → disable playbook + log node explaining which path broke and why
- Write tests: valid paths pass, broken intermediate relationship fails, removed field fails, schema update triggers re-validation
Phase F: get_workflow_state MCP tool
- MCP handler — shares CEL evaluation infrastructure (condition results without action execution)
- Returns: which conditions passed/failed for a given node against active playbook rules
- Write tests: workflow state query, condition evaluation results
Architecture Decisions
| Decision | Choice | Why |
|---|---|---|
| Sync bridging | block_in_place in GraphResolver |
cel-interpreter is sync; multi-threaded runtime makes this safe |
| Sync methods on NodeService? | No — sync bridge lives in GraphResolver only |
NodeService stays purely async; sync bridging is a playbook-engine concern |
| Path extraction | Walk cel-parser AST |
Required by cel-interpreter's non-extensible Value::member() |
| Collection representation | Value::List of node Maps |
Pre-fetched by GraphResolver; collection operators as custom CEL functions |
| Path validation target | Schema graph (save-time), Data graph (runtime) | Same path extractor, different resolution backends |
Files to create/modify
New files:
packages/core/src/playbook/path_extractor.rspackages/core/src/playbook/graph_resolver.rs
Modified files:
packages/core/src/playbook/cel.rs—evaluate_conditionsgains GraphResolver; enriched context buildingpackages/core/src/playbook/engine.rs— RuleProcessor creates GraphResolver per work itempackages/core/src/playbook/actions.rs— BindingContext uses GraphResolver for dot-path resolutionpackages/core/src/playbook/validation.rs— schema-level path validationpackages/core/src/playbook/lifecycle.rs—handle_schema_updateuses path-aware drift detectionpackages/core/src/playbook/mod.rs— add new modulespackages/core/src/mcp/handlers/— newget_workflow_statehandler
References
- Playbook Engine Architecture — Section 3 (CEL Evaluation), Section 4 (Action Executor)
- Playbook System Spec — Dot-Path Traversal
- Parent issue: Playbook Engine Architecture #995 (Phases 0-7 complete)
- PR Playbook Engine Phase 0: EventEnvelope + enriched NodeUpdated #996 (current implementation)
cel-interpretercrate v0.10 — objects.rsValue::member()confirms no custom resolver hookcel-parsercrate — AST types for path extraction
🤖 Generated with Claude Code
Activity
malibio commentedon Apr 2, 2026
Test Baseline (Issue #1010)\n\nFrontend tests: 119 files, 3748 tests all passing\nDuration: 38.42s\nBranch: main (e9c9575)\n\nStarting implementation.
feat: Playbook Engine graph traversal, NodeCollection, and path valid…
test: comprehensive test coverage for graph traversal (#1010)
Playbook Engine: Graph Traversal, NodeCollection, and Path Validation (…
Playbook Engine: Graph Traversal, NodeCollection, and Path Validation (…