Hmbown/CodeWhale · error
Thread is not loaded
Error message
Thread is not loaded
What it means
interrupt_turn requires the thread's engine to be present in the active-engines map. If the thread has no loaded engine there is nothing to interrupt, so the call fails with this error before even looking at active turns.
Solutions
- Verify the thread is open and its engine is loaded before interrupting.
- Handle the not-loaded case as a no-op: nothing is running, cleanup local UI state instead.
- Reload/reopen the thread first if interruption of a persisted turn record is required.
Example fix
// before
runtime.interrupt_turn(thread_id, turn_id)?; // thread already closed
// after
if runtime.thread_engine_loaded(thread_id) {
runtime.interrupt_turn(thread_id, turn_id)?;
} Defensive patterns
Strategy: type-guard
Validate before calling
fn interruptable(active: &ActiveEngines, thread_id: &str, turn_id: &str) -> bool {
active.engines.get(thread_id)
.and_then(|s| s.active_turn.as_ref())
.is_some_and(|t| t.turn_id == turn_id)
} Type guard
fn is_thread_loaded(active: &ActiveEngines, thread_id: &str) -> bool { active.engines.contains_key(thread_id) } Try / catch
match interrupt_turn(id, tid).await {
Err(e) if e.to_string().contains("not loaded") => Ok(()), // nothing to interrupt
other => other,
} Prevention
- Track which threads currently have loaded engines in the client.
- Treat interrupt of an unloaded thread as a no-op, not an error path.
- Clean up interrupt buttons when a session/thread is closed.
When it happens
Trigger: Calling interrupt_turn(thread_id, turn_id) for a thread whose engine was never loaded or has been unloaded/closed; passing a mistyped thread_id.
Common situations: Cancelling from UI after the session was closed; interrupting after an idle-unload evicted the engine; stale UI state referencing a removed thread.
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 engine not loaded
- Agent continuation target is no longer retained
- Agent not found
- Cloud agent sandbox disappeared before it was ready.
- Refusing to interrupt root. agents/interrupt fails closed…
AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22).
Data as JSON: /api/errors/da02a4900012423d.
Report an issue: GitHub.
Appendix: source
Thrown at crates/tui/src/runtime_threads.rs:10339
engine.clone(),
ClaimedTurnKind::Message,
)
};
let turn = acceptance_rx
.await
.map_err(|_| anyhow!("Turn lifecycle task ended before acknowledgement"))?
.map_err(anyhow::Error::msg)?;
Ok((turn, false))
})
.await
}
pub async fn interrupt_turn(&self, thread_id: &str, turn_id: &str) -> Result<TurnRecord> {
{
let mut active = self.active.lock().await;
let Some(active_thread) = active.engines.get_mut(thread_id) else {
bail!("Thread is not loaded");
};
let Some(active_turn) = active_thread.active_turn.as_mut() else {
bail!("No active turn on thread {thread_id}");
};
if active_turn.turn_id != turn_id {
bail!("Turn {turn_id} is not active on thread {thread_id}");
}
active_turn.interrupt_requested = true;
// Wake the monitor's approval wait so it can consume the Engine's
// terminal receipt. Revoke only this turn's minted capabilities.
// Registration takes the same active lock, so a late event cannot
// install a new waiter after this sweep.
self.pending_approvals.lock().retain(|_, entry| {
entry.thread_id != thread_id || entry.request.turn_id != turn_id
});
if let Some(compaction_id) = active_turn.compaction_id.as_deref() {
active_thread.engine.cancel_compaction(compaction_id)?;
} else {View on GitHub (pinned to 73e0f67d83)