{"record":{"id":"9469225b365a790c","repo":"Hmbown/CodeWhale","slug":"thread-engine-not-loaded","errorCode":null,"errorMessage":"Thread engine not loaded","messagePattern":"Thread engine not loaded","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/runtime_threads.rs","lineNumber":10236,"sourceCode":"                    )\n                })\n                .transpose()?\n                .map(fd_lock::RwLock::new);\n            let operation_claim_guard = operation_claim\n                .as_mut()\n                .map(|claim| self.store.acquire_turn_operation_claim(claim))\n                .transpose()?;\n            // A concurrent exact retry may have crossed the first lookup\n            // before the original request committed its binding. Recheck\n            // under the same claim lock before inspecting active-turn state or\n            // persisting/sending anything.\n            if let Some(operation) = operation.as_ref()\n                && let Some(original_turn) = self.replay_turn_for_operation(operation)?\n            {\n                return Ok((original_turn, true));\n            }\n            let Some(state) = active.engines.get_mut(thread_id) else {\n                bail!(\"Thread engine not loaded\");\n            };\n            if state.active_turn.is_some() {\n                bail!(\"Thread already has an active turn\");\n            }\n            let _goal_mutation = self.store.goal_mutation.lock();\n            if self.store.load_goal(thread_id)? != turn_goal {\n                bail!(\"Goal changed while preparing the turn; retry\");\n            }\n            engine.restore_runtime_goal(turn_goal.as_ref())?;\n            let _thread_mutation = self.store.thread_mutation.lock();\n            let mut current_thread = self.store.load_thread(thread_id)?;\n            if !thread_execution_state_matches(&thread, &current_thread) {\n                bail!(\"Thread execution settings changed while preparing the turn; retry\");\n            }\n            let previous_active_route = (state.route_identity.clone(), state.route_model.clone());\n            state.active_turn = Some(ActiveTurnState {\n                goal_id: turn_goal.as_ref().map(|goal| goal.goal_id.clone()),\n                turn_id: turn_id.clone(),","sourceCodeStart":10218,"sourceCodeEnd":10254,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/runtime_threads.rs#L10218-L10254","documentation":"During the turn-preparation critical section, the runtime looks up the thread's engine state in the active-engines map. If the engine for that thread_id was never loaded (or was unloaded between preflight and this section), the turn cannot proceed and this error is thrown.","triggerScenarios":"Submitting a turn for a thread_id whose engine was never ensured (ensure_engine_loaded not called or failed), or whose engine was evicted/closed concurrently before the mutation-lock section.","commonSituations":"A thread closed/expired by the user while a queued request fired; calling the internal turn path directly without loading the engine; an earlier ensure_engine_loaded error silently swallowed upstream.","solutions":["Call ensure_engine_loaded(&thread) before submitting the turn for that thread.","Check that the thread_id is valid and the thread was not closed/unloaded.","Reload the thread/session in the UI before issuing the turn again."],"exampleFix":"// before\nruntime.submit_turn(thread_id, req)?; // engine never loaded\n// after\nruntime.ensure_engine_loaded(&thread).await?;\nruntime.submit_turn(thread_id, req)?;","handlingStrategy":"validation","validationCode":"if !runtime.thread_engine_loaded(thread_id) {\n    runtime.ensure_engine_loaded(&thread).await?;\n}","typeGuard":null,"tryCatchPattern":"match submit_turn(id, req).await {\n    Err(e) if e.to_string().contains(\"engine not loaded\") => {\n        runtime.ensure_engine_loaded(&thread).await?;\n        retry(id, req).await\n    }\n    other => other,\n}","preventionTips":["Always call ensure_engine_loaded before any turn API on a thread.","Don't submit turns for threads already closed or unloaded.","Handle engine-load failures visibly instead of continuing to the turn call."],"tags":["engine-lifecycle","thread-state","resource-not-found"],"backgroundTag":"resource-not-found","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"}