Hmbown/CodeWhale · error

worker task changed before it could be restarted

Error message

worker {worker_id} task changed before it could be restarted

What it means

restart_worker lost a race: the worker's leased task changed between state inspection and the restart commit inside the coordination guard, so the prepared restart generation is abandoned rather than restarting against the wrong task.

Solutions

  1. Retry the restart; the task lease changed concurrently and the next attempt re-reads the current lease.
  2. Avoid concurrent restart/cancel operations on the same worker.
Defensive patterns

Strategy: retry

When it happens

Trigger: Thrown at crates/tui/src/fleet/manager.rs:1129 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22). Data as JSON: /api/errors/973d48d0ff7f546a. Report an issue: GitHub.

Appendix: source

Thrown at crates/tui/src/fleet/manager.rs:1129

            task.entry.attempts,
            || {
                if let Some(guard) = coordination_guard.as_mut() {
                    let task_spec = run
                        .task_specs
                        .iter()
                        .find(|spec| spec.id == task.entry.task_id)
                        .ok_or_else(|| {
                            anyhow!("Fleet task {} does not exist", task.entry.task_id)
                        })?;
                    self.prepare_registered_restart_generation(
                        guard, &state, task, task_spec, worker_id,
                    )?;
                }
                Ok(())
            },
        )?;
        if !restarted {
            bail!("worker {worker_id} task changed before it could be restarted");
        }
        self.ledger
            .update_run_status(&task.entry.run_id, FleetRunStatus::Running, &timestamp())?;
        Ok(FleetRestartReport {
            run_id: task.entry.run_id.clone(),
            max_workers,
            inspection: self.inspect_worker(worker_id)?,
        })
    }

    /// Prepare or consume the exact durable launch generation for one Fleet
    /// retry. The persisted one-generation-ahead record is the prepare marker:
    /// it is not launchable while the ledger remains on the old attempt, but a
    /// retry after a crash may validate and consume it idempotently.
    fn prepare_registered_restart_generation(
        &self,
        coordination: &mut SubAgentManager,
        state: &FleetLedgerState,

View on GitHub (pinned to 73e0f67d83)