{"record":{"id":"f4f0d5e92711d58f","repo":"Hmbown/CodeWhale","slug":"failed-to-persist-compaction-persistence-error-f4f0d5","errorCode":null,"errorMessage":"Failed to persist compaction: {persistence_error}; cleanup also failed: {cleanup_error}","messagePattern":"Failed to persist compaction: (.+?); cleanup also failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"crates/tui/src/runtime_threads.rs","lineNumber":10650,"sourceCode":"            state.route_identity = route_identity;\n            state.route_model = route_model;\n\n            let persistence_result = (|| -> Result<()> {\n                self.store.save_turn(&turn)?;\n                current_thread.latest_turn_id = Some(turn_id.clone());\n                current_thread.updated_at = now;\n                self.store.save_thread(&current_thread)\n            })();\n            if let Err(persistence_error) = persistence_result {\n                let cleanup_error = self\n                    .cleanup_unaccepted_turn_records(&turn_id, None, None)\n                    .err();\n                state.active_turn = None;\n                state.route_identity = previous_active_route.0;\n                state.route_model = previous_active_route.1;\n                return match cleanup_error {\n                    None => Err(anyhow!(\"Failed to persist compaction: {persistence_error}\")),\n                    Some(cleanup_error) => Err(anyhow!(\n                        \"Failed to persist compaction: {persistence_error}; cleanup also failed: {cleanup_error}\"\n                    )),\n                };\n            }\n\n            self.register_runtime_usage_sink(&turn_id);\n            let policy = RuntimePolicyProjection::from_persisted(\n                &current_thread.mode,\n                current_thread.permission_posture.as_deref(),\n                current_thread.auto_approve,\n            );\n            engine.publish_turn_authority(\n                policy.mode,\n                current_thread.allow_shell,\n                current_thread.trust_mode,\n                policy.auto_approve(),\n                policy.permission,\n                configured_sandbox_mode,","sourceCodeStart":10632,"sourceCodeEnd":10668,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/runtime_threads.rs#L10632-L10668","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"match runtime.compact_thread(&thread_id, req).await {\n    Err(e) if e.to_string().contains(\"cleanup also failed\") => {\n        // systemic storage fault: fix root cause, then purge orphaned turn_id records manually\n    }\n    r => r?,\n}","preventionTips":["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."],"tags":["persistence","compaction","cleanup","storage"],"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"}