{"record":{"id":"7e65dee9d17aa0e4","repo":"Hmbown/CodeWhale","slug":"failed-to-promote-staged-task-task-id-promote-err","errorCode":null,"errorMessage":"Failed to promote staged task {task.id}: {promote_err}","messagePattern":"Failed to promote staged task (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/task_manager.rs","lineNumber":1834,"sourceCode":"                {\n                    tracing::warn!(\n                        task_id = %task.id,\n                        error = %cleanup_err,\n                        \"failed to remove ignored staged task after queue write failure\"\n                    );\n                }\n                return Err(err);\n            }\n            if let Err(promote_err) = tokio::fs::rename(&staged_task_path, &task_path).await {\n                let rollback_error = self.persist_queue_locked(&state.queue).err();\n                let cleanup_error = if recover_stage {\n                    None\n                } else {\n                    tokio::fs::remove_file(&staged_task_path).await.err()\n                };\n                let mut message =\n                    format!(\"Failed to promote staged task {}: {promote_err}\", task.id);\n                if let Some(rollback_error) = rollback_error {\n                    message.push_str(&format!(\"; queue rollback also failed: {rollback_error:#}\"));\n                }\n                if let Some(cleanup_error) = cleanup_error {\n                    message.push_str(&format!(\n                        \"; ignored staged-file cleanup also failed: {cleanup_error}\"\n                    ));\n                }\n                bail!(message);\n            }\n            state.queue = next_queue;\n            state.tasks.insert(task.id.clone(), task.clone());\n        }\n        self.notify.notify_one();\n        Ok(task)\n    }\n\n    /// List tasks, newest first.\n    pub async fn list_tasks(&self, limit: Option<usize>) -> Result<Vec<TaskSummary>> {","sourceCodeStart":1816,"sourceCodeEnd":1852,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/task_manager.rs#L1816-L1852","documentation":"Promoting a staged (queued) task from its staging file into the active queue failed. Task_manager stages a task to disk first, then atomically promotes it; if promotion errors, it attempts a queue rollback and staged-file cleanup, and folds every secondary failure into one message so no failure is silently dropped. The task remains staged (or partially rolled back) — it was not activated.","triggerScenarios":"`promote` of a staged task at task_manager.rs fails (queue write error, IO error on the queue file); the subsequent `tokio::fs::remove_file(&staged_task_path)` or queue rollback may also fail, each appending to the message.","commonSituations":"The queue store is locked by a concurrent writer; the staged file was deleted or renamed externally between staging and promotion; permission or disk-full errors; the staged task JSON no longer matches the queue's expected schema after an upgrade.","solutions":["Read the chained promote_err (plus rollback/cleanup notes) to identify the failing step.","Check whether the staged task file still exists at the staged_task_path shown/derived from the queue directory.","Fix the underlying cause (disk space, permissions, concurrent writer) and re-run promotion.","If the staged file is orphaned and the queue is intact, remove the stale staged file manually and re-enqueue the task.","Verify the queue schema version matches after a Codewhale upgrade."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// before promoting, confirm the staged file exists and the queue is writable\nif !tokio::fs::try_exists(&staged_task_path).await.unwrap_or(false) {\n    // staged file missing: re-stage or abort promotion\n}\nlet md = tokio::fs::metadata(&queue_path).await?;\nif md.permissions().readonly() {\n    // promotion would fail\n}","typeGuard":null,"tryCatchPattern":"// Rust\nmatch task_manager.promote(task_id).await {\n    Err(e) if e.to_string().contains(\"Failed to promote staged task\") => {\n        // check rollback/cleanup notes in message; clear stale staged file; re-enqueue\n    }\n    other => other?,\n}","preventionTips":["Do not delete or rename files in the task queue directory while the manager runs.","Ensure a single writer owns the queue at a time.","Keep disk space and permissions healthy on the queue directory.","Re-verify staged task schema after upgrading."],"tags":["task-queue","persistence","staging","filesystem"],"backgroundTag":"file-write-failed","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"}