Hmbown/CodeWhale · error
Thread engine not loaded
Error message
Thread engine not loaded
What it means
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.
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.
Example fix
// before runtime.submit_turn(thread_id, req)?; // engine never loaded // after runtime.ensure_engine_loaded(&thread).await?; runtime.submit_turn(thread_id, req)?;
Defensive patterns
Strategy: validation
Validate before calling
if !runtime.thread_engine_loaded(thread_id) {
runtime.ensure_engine_loaded(&thread).await?;
} Try / catch
match submit_turn(id, req).await {
Err(e) if e.to_string().contains("engine not loaded") => {
runtime.ensure_engine_loaded(&thread).await?;
retry(id, req).await
}
other => other,
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- Thread is not loaded
- Agent continuation target is no longer retained
- Agent not found
- Cloud agent sandbox disappeared before it was ready.
- unknown recording
AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22).
Data as JSON: /api/errors/9469225b365a790c.
Report an issue: GitHub.
Appendix: source
Thrown at crates/tui/src/runtime_threads.rs:10236
)
})
.transpose()?
.map(fd_lock::RwLock::new);
let operation_claim_guard = operation_claim
.as_mut()
.map(|claim| self.store.acquire_turn_operation_claim(claim))
.transpose()?;
// A concurrent exact retry may have crossed the first lookup
// before the original request committed its binding. Recheck
// under the same claim lock before inspecting active-turn state or
// persisting/sending anything.
if let Some(operation) = operation.as_ref()
&& let Some(original_turn) = self.replay_turn_for_operation(operation)?
{
return Ok((original_turn, true));
}
let Some(state) = active.engines.get_mut(thread_id) else {
bail!("Thread engine not loaded");
};
if state.active_turn.is_some() {
bail!("Thread already has an active turn");
}
let _goal_mutation = self.store.goal_mutation.lock();
if self.store.load_goal(thread_id)? != turn_goal {
bail!("Goal changed while preparing the turn; retry");
}
engine.restore_runtime_goal(turn_goal.as_ref())?;
let _thread_mutation = self.store.thread_mutation.lock();
let mut current_thread = self.store.load_thread(thread_id)?;
if !thread_execution_state_matches(&thread, ¤t_thread) {
bail!("Thread execution settings changed while preparing the turn; retry");
}
let previous_active_route = (state.route_identity.clone(), state.route_model.clone());
state.active_turn = Some(ActiveTurnState {
goal_id: turn_goal.as_ref().map(|goal| goal.goal_id.clone()),
turn_id: turn_id.clone(),View on GitHub (pinned to 73e0f67d83)