Fix race condition between fabro run --detach and fabro logs -f

Write id.txt and touch empty progress.jsonl in detach_run() before
spawning the child process so that `fabro logs -f ULID` can resolve
the run and tail the file immediately.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Bryan Helmkamp 2026-03-15 13:37:48 -04:00
parent 0bd012acb6
commit ea6aa93c22
No known key found for this signature in database
2 changed files with 7 additions and 1 deletions

View file

@ -218,6 +218,8 @@ fn detach_run(args: fabro_workflows::cli::RunArgs) -> Result<()> {
))
});
std::fs::create_dir_all(&run_dir)?;
std::fs::write(run_dir.join("id.txt"), &run_id)?;
std::fs::File::create(run_dir.join("progress.jsonl"))?;
let log_file = std::fs::File::create(run_dir.join("detach.log"))?;

View file

@ -161,8 +161,12 @@ pub fn scan_runs(base: &Path) -> Result<Vec<RunInfo>> {
.map(|t| -> DateTime<Utc> { t.into() });
let mtime = mtime_dt.map(|dt| dt.to_rfc3339()).unwrap_or_default();
let run_id = std::fs::read_to_string(path.join("id.txt"))
.map(|s| s.trim().to_string())
.unwrap_or_else(|_| dir_name.clone());
runs.push(RunInfo {
run_id: dir_name.clone(),
run_id,
dir_name,
workflow_name: "[no manifest]".to_string(),
workflow_slug: None,