-
Notifications
You must be signed in to change notification settings - Fork 3.2k
test(whaleflow): replay dogfood workflow from recorded trace #2852
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Hmbown
merged 1 commit into
codex/v0.9.0-stewardship
from
codex/v090-whaleflow-dogfood-replay
Jun 6, 2026
+197
−4
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -416,7 +416,13 @@ fn workflow_builtins(builder: &mut GlobalsBuilder) { | |
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
| use crate::{AgentType, ControlNodeKind, MockWorkflowExecutor, WorkflowRunStatus}; | ||
| use std::collections::BTreeMap; | ||
|
|
||
| use crate::{ | ||
| AgentType, ControlNodeKind, LeafResult, MockWorkflowExecutor, ReplayControlRecord, | ||
| ReplayLeafRecord, WorkflowReplayExecutor, WorkflowReplayTrace, WorkflowRunStatus, | ||
| compute_leaf_input_hash, | ||
| }; | ||
|
|
||
| #[test] | ||
| fn starlark_compiles_to_ir() { | ||
|
|
@@ -464,6 +470,187 @@ mod tests { | |
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn rlm_cache_change_workflow_replays_from_recorded_mock_trace() { | ||
| let source = include_str!("../../../workflows/rlm_cache_change.star"); | ||
| let workflow = compile_starlark_workflow("rlm_cache_change.star", source) | ||
| .expect("example should compile"); | ||
| let execution = MockWorkflowExecutor::new() | ||
| .with_predicate_results("implement-until-tests-pass", vec![true]) | ||
| .run(&workflow) | ||
| .expect("dogfood workflow should run with mock leaves"); | ||
| let trace = replay_trace_from_execution("trace-rlm-cache", &workflow, &execution); | ||
|
|
||
| let replayed = WorkflowReplayExecutor::new(trace) | ||
| .run(&workflow) | ||
| .expect("recorded dogfood trace should replay"); | ||
|
|
||
| assert_eq!(replayed.status, WorkflowRunStatus::Succeeded); | ||
| assert!( | ||
| replayed | ||
| .leaf_results | ||
| .iter() | ||
| .any(|result| result.leaf_id == "regression-tests") | ||
| ); | ||
| assert!( | ||
| replayed | ||
| .control_node_results | ||
| .iter() | ||
| .any(|result| result.node_id == "teacher-review") | ||
| ); | ||
| assert!( | ||
| replayed | ||
| .control_node_results | ||
| .iter() | ||
| .any(|result| result.node_id == "summarize-cache-change") | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn rlm_cache_change_replay_diverges_when_record_missing() { | ||
| let source = include_str!("../../../workflows/rlm_cache_change.star"); | ||
| let workflow = compile_starlark_workflow("rlm_cache_change.star", source) | ||
| .expect("example should compile"); | ||
| let execution = MockWorkflowExecutor::new() | ||
| .with_predicate_results("implement-until-tests-pass", vec![true]) | ||
| .run(&workflow) | ||
| .expect("dogfood workflow should run with mock leaves"); | ||
| let mut trace = | ||
| replay_trace_from_execution("trace-rlm-cache-missing", &workflow, &execution); | ||
| trace | ||
| .leaf_records | ||
| .retain(|record| record.leaf_id != "regression-tests"); | ||
|
|
||
| let replayed = WorkflowReplayExecutor::new(trace) | ||
| .run(&workflow) | ||
| .expect("missing dogfood leaf record should be a replay result"); | ||
|
|
||
| assert_eq!(replayed.status, WorkflowRunStatus::ReplayDiverged); | ||
| assert!(replayed.leaf_results.iter().any(|result| { | ||
| result.leaf_id == "regression-tests" | ||
| && result.status == WorkflowRunStatus::ReplayDiverged | ||
| })); | ||
| } | ||
|
|
||
| fn replay_trace_from_execution( | ||
| trace_id: &str, | ||
| workflow: &WorkflowSpec, | ||
| execution: &crate::WorkflowExecution, | ||
| ) -> WorkflowReplayTrace { | ||
| let mut resolved_outputs = BTreeMap::new(); | ||
| let mut leaf_records = Vec::new(); | ||
| collect_leaf_records( | ||
| trace_id, | ||
| workflow, | ||
| &workflow.nodes, | ||
| &execution.leaf_results, | ||
| &mut resolved_outputs, | ||
| &mut leaf_records, | ||
| ); | ||
| let control_records = execution | ||
| .control_node_results | ||
| .iter() | ||
| .cloned() | ||
| .map(|result| ReplayControlRecord { | ||
| trace_id: trace_id.to_string(), | ||
| node_id: result.node_id.clone(), | ||
| kind: result.kind, | ||
| result, | ||
| generated_nodes: Vec::new(), | ||
| }) | ||
| .collect(); | ||
|
|
||
| WorkflowReplayTrace { | ||
| trace_id: trace_id.to_string(), | ||
| leaf_records, | ||
| control_records, | ||
| } | ||
| } | ||
|
|
||
| fn collect_leaf_records( | ||
| trace_id: &str, | ||
| workflow: &WorkflowSpec, | ||
| nodes: &[WorkflowNode], | ||
| results: &[LeafResult], | ||
| resolved_outputs: &mut BTreeMap<String, Option<String>>, | ||
| records: &mut Vec<ReplayLeafRecord>, | ||
| ) { | ||
| for node in nodes { | ||
| match node { | ||
| WorkflowNode::BranchSet(branch) => collect_leaf_records( | ||
| trace_id, | ||
| workflow, | ||
| &branch.children, | ||
| results, | ||
| resolved_outputs, | ||
| records, | ||
| ), | ||
| WorkflowNode::Leaf(leaf) => { | ||
| let result = results | ||
| .iter() | ||
| .find(|result| result.leaf_id == leaf.id) | ||
| .expect("mock execution should record every declared leaf") | ||
| .clone(); | ||
| let resolved_inputs = leaf | ||
| .depends_on_results | ||
| .iter() | ||
| .map(|dependency| { | ||
| ( | ||
| dependency.clone(), | ||
| resolved_outputs.get(dependency).cloned().unwrap_or(None), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| ) | ||
| }) | ||
| .collect(); | ||
| records.push(ReplayLeafRecord { | ||
| trace_id: trace_id.to_string(), | ||
| leaf_id: leaf.id.clone(), | ||
| input_hash: compute_leaf_input_hash(workflow, leaf, &resolved_inputs) | ||
| .expect("leaf input hash should serialize"), | ||
| result: result.clone(), | ||
| }); | ||
| resolved_outputs.insert(leaf.id.clone(), result.output); | ||
| } | ||
| WorkflowNode::Sequence(sequence) => collect_leaf_records( | ||
| trace_id, | ||
| workflow, | ||
| &sequence.children, | ||
| results, | ||
| resolved_outputs, | ||
| records, | ||
| ), | ||
| WorkflowNode::LoopUntil(loop_until) => collect_leaf_records( | ||
| trace_id, | ||
| workflow, | ||
| &loop_until.children, | ||
| results, | ||
| resolved_outputs, | ||
| records, | ||
| ), | ||
| WorkflowNode::Cond(cond) => { | ||
| collect_leaf_records( | ||
| trace_id, | ||
| workflow, | ||
| &cond.then_nodes, | ||
| results, | ||
| resolved_outputs, | ||
| records, | ||
| ); | ||
| collect_leaf_records( | ||
| trace_id, | ||
| workflow, | ||
| &cond.else_nodes, | ||
| results, | ||
| resolved_outputs, | ||
| records, | ||
| ); | ||
| } | ||
| WorkflowNode::Expand(_) | ||
| | WorkflowNode::Reduce(_) | ||
| | WorkflowNode::TeacherReview(_) => {} | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #[test] | ||
| fn starlark_repair_loop() { | ||
| let source = r#" | ||
|
|
||
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Limitation in Trace Reconstruction for Loops / Multiple Executions
The
collect_leaf_recordshelper statically traverses the workflow AST (&workflow.nodes) to reconstruct the replay trace.Because it performs a static traversal:
Leafnode once, even if that leaf is executed multiple times (e.g., inside aLoopUntilblock with multiple iterations)..find()call on line 590 will always retrieve the first execution result of that leaf, ignoring subsequent iterations.This means any workflow containing loops that execute more than once will produce an incomplete or incorrect replay trace, leading to
ReplayDivergederrors during replay. Consider refactoring this helper to map directly over the dynamic execution results (execution.leaf_results) and resolve their dependencies dynamically, or document this limitation if it is strictly intended for single-iteration test scenarios.