{"record":{"id":"143e976aee4057cf","repo":"Hmbown/CodeWhale","slug":"failed-to-persist-compaction-persistence-error","errorCode":null,"errorMessage":"Failed to persist compaction: {persistence_error}","messagePattern":"Failed to persist compaction: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/runtime_threads.rs","lineNumber":10649,"sourceCode":"            });\n            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,","sourceCodeStart":10631,"sourceCodeEnd":10667,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/runtime_threads.rs#L10631-L10667","documentation":"Raised in the compaction preparation path when the durable store fails to persist the compaction turn record or update the thread pointer (`save_turn`/`save_thread`), and the subsequent cleanup (`cleanup_unaccepted_turn_records`) succeeds. The active-turn slot and route identity are rolled back; the store is left consistent, so the compaction can simply be retried.","triggerScenarios":"Calling `compact_thread` when the persistence closure returns Err (disk full, store lock contention, corrupt store) while cleanup of the unaccepted turn records succeeds.","commonSituations":"Disk full during a compaction; SQLite/file-store corruption after a crash; another process holding the thread mutation lock; read-only data directory.","solutions":["Read `{persistence_error}` — fix the storage root cause (free disk space, fix permissions, repair store).","Retry the compaction once storage is healthy; state was fully rolled back.","If the store is corrupt, back it up and rebuild the thread store.","Check for competing processes locking the codewhale data directory."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"match runtime.compact_thread(&thread_id, req).await {\n    Err(e) if e.to_string().contains(\"Failed to persist compaction\")\n        && !e.to_string().contains(\"cleanup also failed\") => {\n        // state rolled back cleanly; fix storage then retry\n    }\n    r => r?,\n}","preventionTips":["Ensure free disk space before long compaction-heavy sessions.","Keep the data directory writable and on healthy storage.","Avoid competing processes on the same data directory.","Repair or rebuild a corrupt store promptly."],"tags":["persistence","compaction","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"}