{"record":{"id":"4b35b8c10ccae946","repo":"Hmbown/CodeWhale","slug":"failed-to-sync-thread-session-e","errorCode":null,"errorMessage":"Failed to sync thread session: {e}","messagePattern":"Failed to sync thread session: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/runtime_threads.rs","lineNumber":11084,"sourceCode":"                .map(|s| SystemPrompt::Text(s.clone()));\n            if !session_messages.is_empty() || sys_prompt.is_some() {\n                engine\n                    .send(Op::SyncSession {\n                        session_id: thread.session_id.clone(),\n                        messages: session_messages,\n                        system_prompt: sys_prompt,\n                        system_prompt_override: thread.system_prompt.is_some(),\n                        model: route_model.clone(),\n                        workspace: thread.workspace.clone(),\n                        mode: RuntimePolicyProjection::from_persisted(\n                            &thread.mode,\n                            thread.permission_posture.as_deref(),\n                            thread.auto_approve,\n                        )\n                        .mode,\n                    })\n                    .await\n                    .map_err(|e| anyhow!(\"Failed to sync thread session: {e}\"))?;\n            }\n\n            let mut active = self.active.lock().await;\n            if let Some(winner) = active\n                .engines\n                .get(&thread.id)\n                .map(|state| state.engine.clone())\n            {\n                touch_lru(&mut active.lru, &thread.id);\n                drop(active);\n                engine.cancel_with_reason(crate::core::engine::CancelReason::Internal);\n                let _ = engine.try_send(Op::Shutdown);\n                return Ok(winner);\n            }\n\n            // Atomically compare the record used for construction with the latest\n            // durable record while holding the same active -> thread lock order as\n            // updates. A concurrent workspace/model/session/policy change makes","sourceCodeStart":11066,"sourceCodeEnd":11102,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/runtime_threads.rs#L11066-L11102","documentation":"Raised while loading a thread when restoring its persisted history onto a freshly spawned engine fails: the runtime sends an `Op::SyncSession` message (restored session messages, optional system prompt, model, workspace, mode) and the engine's channel send returns Err. That happens only when the engine's receiver is gone — the just-spawned engine task already terminated — or the send otherwise fails with error `{e}`.","triggerScenarios":"Opening/reloading a thread whose restored session messages or system prompt are non-empty, when `engine.send(Op::SyncSession {...}).await` returns Err because the engine worker died immediately after spawn (panic at startup, invalid engine config) or the channel was closed.","commonSituations":"Engine worker panics during initialization (bad tools config, invalid exec policy engine); app shutting down while threads are being opened; resource exhaustion (OOM) killing the freshly spawned task; a config reload spawning an engine that fails to start.","solutions":["Read `{e}` for the underlying send failure; check logs for an engine startup panic and fix its config cause.","Retry opening the thread — a new engine is spawned on the next attempt.","Validate tools/advisor/exec-policy settings in the config that the engine consumes at startup.","Avoid opening threads during application shutdown; free memory if OOM killed the worker."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"match open_thread(&thread_id).await {\n    Err(e) if e.to_string().contains(\"Failed to sync thread session\") => {\n        // engine died at startup: check logs, fix config, then reopen the thread\n    }\n    r => r?,\n}","preventionTips":["Validate tools/advisor/exec-policy engine config that runs at engine startup.","Fix any engine startup panics in logs before reopening threads.","Do not open threads while the app is shutting down.","Watch memory usage so fresh engine tasks are not OOM-killed."],"tags":["session-restore","engine","channel-closed","async"],"backgroundTag":"broken-pipe","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"}