{"record":{"id":"3b0113d8a4d8c9b3","repo":"Hmbown/CodeWhale","slug":"failed-to-persist-steer-error-cleanup-also-fai","errorCode":null,"errorMessage":"Failed to persist steer: {error}; cleanup also failed: {cleanup_error}","messagePattern":"Failed to persist steer: (.+?); cleanup also failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/runtime_threads.rs","lineNumber":10470,"sourceCode":"                if turn.status != RuntimeTurnStatus::InProgress {\n                    bail!(\"Turn {turn_id} is no longer in progress and cannot be steered\");\n                }\n                self.store.save_item(&item)?;\n                // `steer_count` counts steers the model actually received, so\n                // it rises in the settlement path, not here.\n                if !turn.item_ids.iter().any(|id| id == &item.id) {\n                    turn.item_ids.push(item.id.clone());\n                }\n                self.store.save_turn(&turn)?;\n                Ok(turn)\n            })();\n            let turn = match persistence {\n                Ok(turn) => turn,\n                Err(error) => {\n                    let cleanup = self.store.remove_item(&item.id);\n                    return match cleanup {\n                        Ok(()) => Err(error),\n                        Err(cleanup_error) => Err(anyhow!(\n                            \"Failed to persist steer: {error}; cleanup also failed: {cleanup_error}\"\n                        )),\n                    };\n                }\n            };\n            // The reserved send has no await/failure point. From here the\n            // engine and durable record agree even if the API caller drops.\n            let outcome_rx = permit.send_with_outcome(prompt.clone());\n            touch_lru(&mut active.lru, thread_id);\n            queued_turn = turn.clone();\n            self.spawn_steer_settlement(turn, item, prompt, outcome_rx)\n        };\n\n        // The settler owns the verdict; this is only an observation of it.\n        // Steering a streaming turn settles in milliseconds, so the caller\n        // almost always gets the truth in-band. Behind a long tool call the\n        // engine will not look at its mailbox for minutes, and an API request\n        // must not hang that long — so the wait is bounded and the caller","sourceCodeStart":10452,"sourceCodeEnd":10488,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/runtime_threads.rs#L10452-L10488","documentation":"Raised in the steer path when persisting the steer item/turn update fails (`store.load_turn`, `save_item`, or `save_turn`) AND the compensating cleanup (`store.remove_item` of the queued steer item) also fails. Both errors are chained into a single anyhow message so the operator sees the write failure and the orphaned-record failure together.","triggerScenarios":"Calling the steer API while the persistence closure returns Err (e.g. store write error, turn no longer InProgress race lost) and `store.remove_item(&item.id)` for the queued steer item also returns Err.","commonSituations":"Disk full / I/O failure during a steer; the turn reached terminal status between the pre-checks and the write, and cleanup then hit the same storage fault; contention on the store's turn mutation lock from another process.","solutions":["Fix the underlying storage problem named by `{error}` first (disk space, permissions, corrupt store).","Manually remove the orphaned steer item (`{cleanup_error}` shows removal failed) from the thread store.","Retry the steer once the store is healthy; the failed steer was rolled back only if cleanup succeeded.","If the turn became non-InProgress, re-check turn status — the steer may be obsolete anyway."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"match runtime.steer_turn(&thread_id, &turn_id, text).await {\n    Err(e) if e.to_string().contains(\"cleanup also failed\") => {\n        // storage fault: free space / repair store, remove orphaned steer item, retry\n    }\n    r => r?,\n}","preventionTips":["Keep free disk headroom on the data directory.","Avoid concurrent writers to the same thread store.","Verify turn status is InProgress before steering.","Back up the store so post-failure cleanup is safe."],"tags":["persistence","steering","storage","rust"],"backgroundTag":"database-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"}