{"record":{"id":"99b72f0a9b706459","repo":"BigPizzaV3/CodexPlusPlus","slug":"session-index-cleanup-task-failed-error","errorCode":null,"errorMessage":"session index cleanup task failed: {error}","messagePattern":"session index cleanup task failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"apps/codex-plus-manager/src-tauri/src/commands.rs","lineNumber":3261,"sourceCode":"            json!({\n                \"snapshotSha256\": preview.snapshot_sha256,\n                \"candidates\": preview.candidates,\n            }),\n        ),\n        Err(error) => failed(&format!(\"预览失效任务索引失败：{error}\"), json!({})),\n    }\n}\n\n#[tauri::command]\npub async fn apply_session_index_cleanup(\n    snapshot_sha256: String,\n    thread_ids: Vec<String>,\n) -> CommandResult<Value> {\n    let result = tauri::async_runtime::spawn_blocking(move || {\n        codex_plus_data::apply_session_index_cleanup(None, &snapshot_sha256, &thread_ids)\n    })\n    .await\n    .map_err(|error| anyhow::anyhow!(\"session index cleanup task failed: {error}\"));\n    match result {\n        Ok(Ok(cleanup)) => ok(\n            &format!(\n                \"已清理 {} 条失效任务索引；原索引已完整备份。\",\n                cleanup.pruned_entries\n            ),\n            json!({\n                \"prunedEntries\": cleanup.pruned_entries,\n                \"backupDir\": cleanup.backup_dir,\n            }),\n        ),\n        Ok(Err(error)) => {\n            let backup_hint = error\n                .backup_dir\n                .as_ref()\n                .map(|path| format!(\" 备份目录：{}。\", path.to_string_lossy()))\n                .unwrap_or_default();\n            failed(","sourceCodeStart":3243,"sourceCodeEnd":3279,"githubUrl":"https://github.com/BigPizzaV3/CodexPlusPlus/blob/b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6/apps/codex-plus-manager/src-tauri/src/commands.rs#L3243-L3279","documentation":"apply_session_index_cleanup runs codex_plus_data::apply_session_index_cleanup(None, &snapshot_sha256, &thread_ids) on a blocking thread via tauri::async_runtime::spawn_blocking. A JoinError from awaiting the handle (task panicked or was cancelled) is mapped into this error; it is the outer failure, distinct from an inner cleanup Result error which is handled separately in the match.","triggerScenarios":"The spawn_blocking closure for apply_session_index_cleanup panicked (e.g. while pruning/rewriting the index or writing the backup) or the JoinHandle resolved to Err(JoinError) due to runtime cancellation.","commonSituations":"Panic while writing the index backup or rewriting session index files (disk full, permission denied on an unwrap path), corrupted snapshot_sha256/thread_ids payloads causing panics in the cleanup logic, or app exit cancelling the task mid-run.","solutions":["Read the wrapped JoinError message to locate the panic in apply_session_index_cleanup","Verify the index directory is writable and has free space (backup write failures are a common panic trigger)","Check that snapshot_sha256 matches the preview's snapshot; stale snapshots can lead downstream into bad state","Convert panic paths (unwrap/expect) in the cleanup data layer into returned errors, then retry the cleanup"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// 执行前确认 snapshot 仍与当前索引匹配，避免过期快照导致清理路径异常\nif !snapshot_matches_current_index(&snapshot_sha256) {\n    return Err(anyhow::anyhow!(\"索引快照已过期，请重新执行预览\"));\n}","typeGuard":null,"tryCatchPattern":"match tauri::async_runtime::spawn_blocking(move || {\n    codex_plus_data::apply_session_index_cleanup(None, &snapshot_sha256, &thread_ids)\n}).await {\n    Ok(Ok(cleanup)) => { /* 汇报清理结果 */ }\n    Ok(Err(data_err)) => eprintln!(\"cleanup failed: {data_err}（原索引有备份，可恢复）\"),\n    Err(join_err) => eprintln!(\"cleanup task panicked or was cancelled: {join_err}\"),\n}","preventionTips":["Verify index directory writability and free disk space before cleanup (backup writes are a common panic trigger)","Always run preview immediately before apply so snapshot_sha256 is fresh","Convert unwrap/expect panics in apply_session_index_cleanup into returned errors","Keep cleanup tasks short-lived and avoid triggering them at app exit"],"tags":["rust","tauri","spawn-blocking","join-error","session-index"],"backgroundTag":"thread-interrupted","analyzedSha":"b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6","analyzedAt":"2026-09-19T23:35:21.129Z","contentChangedAt":"2026-09-19T23:35:21.129Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}