nikivdev/code · error

no previous task found for this project

Error message

no previous task found for this project

What it means

The rerun command re-executes the most recent task record saved for the current project directory; when history::load_last_record_for_project returns None there is nothing to replay, so rerun bails. It means the project simply has no recorded task history yet.

Source

Thrown at src/main.rs:859

        | Some(Commands::Publish(_))
        | Some(Commands::Clone(_))
        | Some(Commands::TaskShortcut(_))
        | Some(Commands::Agents(_))
        | Some(Commands::Hive(_)) => StartupPolicy::SECRETS_ONLY,
        Some(Commands::Undo(_)) => StartupPolicy::NONE,
    }
}

fn rerun(opts: RerunOpts) -> Result<()> {
    let project_root = if opts.config.is_absolute() {
        opts.config.parent().unwrap_or(Path::new(".")).to_path_buf()
    } else {
        std::env::current_dir().unwrap_or_else(|_| Path::new(".").to_path_buf())
    };

    let record = history::load_last_record_for_project(&project_root)?;
    let Some(rec) = record else {
        bail!("no previous task found for this project");
    };

    // Parse user_input to extract task name and args (respecting shell quoting)
    let parts = shell_words::split(&rec.user_input).unwrap_or_else(|_| vec![rec.task_name.clone()]);
    let task_name = parts.first().cloned().unwrap_or(rec.task_name.clone());
    let args: Vec<String> = parts.into_iter().skip(1).collect();

    println!("Re-running: {}", rec.user_input);

    tasks::run(TaskRunOpts {
        config: opts.config,
        delegate_to_hub: false,
        hub_host: IpAddr::from([127, 0, 0, 1]),
        hub_port: 9050,
        name: task_name,
        args,
    })
}

View on GitHub (pinned to a747e741ae)

Solutions

  1. Run the desired task normally once — it will be recorded and rerun will then work.
  2. Use the flag/argument to rerun against the correct project root where history exists.
  3. Check where the history file is stored and confirm it was not deleted or moved.

Example fix

# before
flow rerun                 # in a fresh repo -> no previous task
# after
flow build && flow test    # run tasks first
flow rerun                 # now replays the last one
Defensive patterns

Strategy: fallback

Validate before calling

fn has_history(project_root: &Path) -> bool {
    history::load_last_record_for_project(project_root)
        .map(|r| r.is_some())
        .unwrap_or(false)
}
if !has_history(&project_root) {
    eprintln!("no previous task recorded; run a task first");
    return;
}

Type guard

fn previous_task_known(rec: Option<history::Record>) -> bool {
    rec.is_some()
}

Try / catch

match rerun(opts) {
    Err(e) if e.to_string() == "no previous task found for this project" => {
        eprintln!("Nothing to rerun. Run a task first, e.g. `flow build`");
        std::process::exit(1);
    }
    other => other?,
}

Prevention

When it happens

Trigger: Running `flow rerun` (without a project flag resolving to another directory) in a directory where no task was ever run, or after the history store was cleared/reset.

Common situations: Fresh clone of a repo without the local history file; running in a different subdirectory than where previous tasks ran (project root mismatch); deleting ~/.local/share-style history data.

Related errors


AI-assisted analysis of nikivdev/code@a747e741ae (2026-09-01). Data as JSON: /api/errors/eb327976bbc881c7. Report an issue: GitHub.