From ea4cf7033b71b7ddfb7e72d9fb4c70a347be8a3e Mon Sep 17 00:00:00 2001 From: Bryan Helmkamp Date: Wed, 1 Apr 2026 21:39:17 -0700 Subject: [PATCH] Restore rewound run metadata from the store --- .../fabro-cli/src/commands/run/rewind.rs | 30 +++++++++++++++++-- lib/crates/fabro-cli/tests/it/cmd/rewind.rs | 1 + 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/lib/crates/fabro-cli/src/commands/run/rewind.rs b/lib/crates/fabro-cli/src/commands/run/rewind.rs index 410739c76..c42ac6387 100644 --- a/lib/crates/fabro-cli/src/commands/run/rewind.rs +++ b/lib/crates/fabro-cli/src/commands/run/rewind.rs @@ -107,7 +107,29 @@ async fn reset_rewound_run_state( run_id: &fabro_types::RunId, run_dir: &std::path::Path, ) -> Result<()> { - let run_record = RunRecord::load(run_dir)?; + let existing_run_store = durable_store + .open_run_reader(run_id) + .await + .map_err(|err| anyhow::anyhow!("failed to open durable store run before rewind: {err}"))?; + let store_run_record = if let Some(run_store) = existing_run_store.as_ref() { + run_store.get_run().await.ok().flatten() + } else { + None + }; + let store_start_record = if let Some(run_store) = existing_run_store.as_ref() { + run_store.get_start().await.ok().flatten() + } else { + None + }; + let store_graph = if let Some(run_store) = existing_run_store.as_ref() { + run_store.get_graph().await.ok().flatten() + } else { + None + }; + + let run_record = store_run_record + .or_else(|| RunRecord::load(run_dir).ok()) + .context("failed to restore run record after rewind: missing run metadata")?; let checkpoint = MetadataStore::read_checkpoint(git_store.repo_dir(), &run_id.to_string())? .context("rewound metadata branch is missing checkpoint.json")?; checkpoint.save(&run_dir.join("checkpoint.json"))?; @@ -136,13 +158,15 @@ async fn reset_rewound_run_state( .put_run(&run_record) .await .map_err(|err| anyhow::anyhow!("failed to restore run record after rewind: {err}"))?; - if let Ok(start_record) = StartRecord::load(run_dir) { + if let Some(start_record) = store_start_record.or_else(|| StartRecord::load(run_dir).ok()) { run_store .put_start(&start_record) .await .map_err(|err| anyhow::anyhow!("failed to restore start record after rewind: {err}"))?; } - if let Ok(dot_source) = std::fs::read_to_string(run_dir.join("workflow.fabro")) { + if let Some(dot_source) = + store_graph.or_else(|| std::fs::read_to_string(run_dir.join("workflow.fabro")).ok()) + { run_store .put_graph(&dot_source) .await diff --git a/lib/crates/fabro-cli/tests/it/cmd/rewind.rs b/lib/crates/fabro-cli/tests/it/cmd/rewind.rs index 2e1f186c3..0b59449e8 100644 --- a/lib/crates/fabro-cli/tests/it/cmd/rewind.rs +++ b/lib/crates/fabro-cli/tests/it/cmd/rewind.rs @@ -85,6 +85,7 @@ fn rewind_target_updates_metadata_and_resume_hint() { let mut cmd = context.command(); cmd.current_dir(&setup.repo_dir); + std::fs::remove_file(setup.run.run_dir.join("run.json")).unwrap(); cmd.args(["rewind", &setup.run.run_id, "@1", "--no-push"]); let (snapshot, output) = run_and_format(&mut cmd, &git_filters(&context));