Hmbown/CodeWhale · error
Failed to persist turn: {persistence_error}; cleanup also fa
Error message
Failed to persist turn: {persistence_error}; cleanup also failed: {cleanup_error} What it means
Raised in submit_turn after the durable-store closure (save_item/save_turn/save_thread) returned Err for a newly constructed user turn. It is a compound sentinel: the primary persistence_error says why the store write failed, and cleanup_error is appended only because the compensating cleanup_unaccepted_turn_records call that tries to roll back the half-written item/turn also failed, leaving the store possibly inconsistent.
Source
Thrown at crates/tui/src/runtime_threads.rs:6147
state.route_model.clone_from(&model);
let persistence_result = (|| -> Result<()> {
self.store.save_item(&user_item)?;
self.store.save_turn(&turn)?;
current_thread.latest_turn_id = Some(turn_id.clone());
current_thread.updated_at = now;
self.store.save_thread(¤t_thread)
})();
if let Err(persistence_error) = persistence_result {
let cleanup_error = self
.cleanup_unaccepted_turn_records(&turn_id, Some(&user_item_id))
.err();
state.active_turn = None;
state.route_identity = previous_active_route.0;
state.route_model = previous_active_route.1;
return match cleanup_error {
None => Err(anyhow!("Failed to persist turn: {persistence_error}")),
Some(cleanup_error) => Err(anyhow!(
"Failed to persist turn: {persistence_error}; cleanup also failed: {cleanup_error}"
)),
};
}
self.register_runtime_usage_sink(&turn_id);
// Sending through an owned permit cannot await or fail. From this
// point the engine owns the operation and the spawned task owns
// lifecycle events, monitoring, and terminal cleanup even if the
// HTTP/client future is dropped.
engine.publish_turn_authority(
mode,
allow_shell,
trust_mode,
auto_approve,
policy.permission,
configured_sandbox_mode,
);View on GitHub (pinned to 0c42157ee5)
Solutions
- Inspect persistence_error first (disk full, store lock, schema corruption) and fix that root cause; the cleanup error is secondary noise from the rollback attempt
- If cleanup also failed, check the store for orphaned records with the reported turn id / user_item id and delete them manually before retrying the turn
- Verify the store directory is writable and not concurrently locked by another Codewhale process, then resubmit the turn
Defensive patterns
Strategy: fallback
When it happens
Trigger: Thrown at crates/tui/src/runtime_threads.rs:6147 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of Hmbown/CodeWhale@0c42157ee5 (2026-08-20).
Data as JSON: /api/errors/97f6750a04716cbb.
Report an issue: GitHub.