Hmbown/CodeWhale · critical
Failed to persist compaction
Error message
Failed to persist compaction: {persistence_error}; cleanup also failed: {cleanup_error} What it means
The cleanup-failed variant of the compaction persistence error: the compaction turn could not be persisted AND `cleanup_unaccepted_turn_records` also failed, so orphaned records for the unaccepted turn_id may remain on disk. Both errors are chained into one anyhow message so neither is lost; the in-memory active-turn state is still rolled back.
Solutions
- Fix the storage fault named by `{persistence_error}` first — it is the root cause.
- Inspect the store for the orphaned turn (`turn_id` from logs) and delete it manually or rely on startup recovery.
- Retry compaction after storage is healthy; if a stale unaccepted compaction turn blocks the thread ("Thread already has an active turn"), clear the orphan first.
- Check for competing codewhale processes and close them.
Defensive patterns
Strategy: try-catch
Try / catch
match runtime.compact_thread(&thread_id, req).await {
Err(e) if e.to_string().contains("cleanup also failed") => {
// systemic storage fault: fix root cause, then purge orphaned turn_id records manually
}
r => r?,
} Prevention
- Treat repeated storage failures as an environment emergency — both write and cleanup are failing.
- Free disk space at the first persistence warning, not after cleanup fails too.
- Keep exclusive ownership of the data directory per process.
- Rely on startup recovery, but verify orphaned unaccepted turns are gone before re-compacting.
When it happens
Trigger: Calling `compact_thread` when `save_turn`/`save_thread` fails and `cleanup_unaccepted_turn_records(&turn_id, None, None)` also returns Err — usually a systemic storage fault (disk full, corrupted store, lock held).
Common situations: Disk full for an extended period (write and cleanup both fail); corrupted store where deletes also fail; external process holding an exclusive lock on the store during compaction.
Related errors
- Failed to persist compaction
- Failed to persist turn
- Failed to persist steer
- Failed to persist turn
- Archive this pet recording before accepting more telemetry.
AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22).
Data as JSON: /api/errors/f4f0d5e92711d58f.
Report an issue: GitHub.
Appendix: source
Thrown at crates/tui/src/runtime_threads.rs:10650
state.route_identity = route_identity;
state.route_model = route_model;
let persistence_result = (|| -> Result<()> {
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, None, None)
.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 compaction: {persistence_error}")),
Some(cleanup_error) => Err(anyhow!(
"Failed to persist compaction: {persistence_error}; cleanup also failed: {cleanup_error}"
)),
};
}
self.register_runtime_usage_sink(&turn_id);
let policy = RuntimePolicyProjection::from_persisted(
¤t_thread.mode,
current_thread.permission_posture.as_deref(),
current_thread.auto_approve,
);
engine.publish_turn_authority(
policy.mode,
current_thread.allow_shell,
current_thread.trust_mode,
policy.auto_approve(),
policy.permission,
configured_sandbox_mode,View on GitHub (pinned to 73e0f67d83)