{"record":{"id":"973d48d0ff7f546a","repo":"Hmbown/CodeWhale","slug":"worker-worker-id-task-changed-before-it-could-be","errorCode":null,"errorMessage":"worker {worker_id} task changed before it could be restarted","messagePattern":"worker (.+?) task changed before it could be restarted","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/fleet/manager.rs","lineNumber":1129,"sourceCode":"            task.entry.attempts,\n            || {\n                if let Some(guard) = coordination_guard.as_mut() {\n                    let task_spec = run\n                        .task_specs\n                        .iter()\n                        .find(|spec| spec.id == task.entry.task_id)\n                        .ok_or_else(|| {\n                            anyhow!(\"Fleet task {} does not exist\", task.entry.task_id)\n                        })?;\n                    self.prepare_registered_restart_generation(\n                        guard, &state, task, task_spec, worker_id,\n                    )?;\n                }\n                Ok(())\n            },\n        )?;\n        if !restarted {\n            bail!(\"worker {worker_id} task changed before it could be restarted\");\n        }\n        self.ledger\n            .update_run_status(&task.entry.run_id, FleetRunStatus::Running, &timestamp())?;\n        Ok(FleetRestartReport {\n            run_id: task.entry.run_id.clone(),\n            max_workers,\n            inspection: self.inspect_worker(worker_id)?,\n        })\n    }\n\n    /// Prepare or consume the exact durable launch generation for one Fleet\n    /// retry. The persisted one-generation-ahead record is the prepare marker:\n    /// it is not launchable while the ledger remains on the old attempt, but a\n    /// retry after a crash may validate and consume it idempotently.\n    fn prepare_registered_restart_generation(\n        &self,\n        coordination: &mut SubAgentManager,\n        state: &FleetLedgerState,","sourceCodeStart":1111,"sourceCodeEnd":1147,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/fleet/manager.rs#L1111-L1147","documentation":"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.","triggerScenarios":"Thrown at crates/tui/src/fleet/manager.rs:1129 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Retry the restart; the task lease changed concurrently and the next attempt re-reads the current lease.","Avoid concurrent restart/cancel operations on the same worker."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}