{"record":{"id":"da02a4900012423d","repo":"Hmbown/CodeWhale","slug":"thread-is-not-loaded","errorCode":null,"errorMessage":"Thread is not loaded","messagePattern":"Thread is not loaded","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/runtime_threads.rs","lineNumber":10339,"sourceCode":"                engine.clone(),\n                ClaimedTurnKind::Message,\n            )\n        };\n\n        let turn = acceptance_rx\n            .await\n            .map_err(|_| anyhow!(\"Turn lifecycle task ended before acknowledgement\"))?\n            .map_err(anyhow::Error::msg)?;\n        Ok((turn, false))\n        })\n        .await\n    }\n\n    pub async fn interrupt_turn(&self, thread_id: &str, turn_id: &str) -> Result<TurnRecord> {\n        {\n            let mut active = self.active.lock().await;\n            let Some(active_thread) = active.engines.get_mut(thread_id) else {\n                bail!(\"Thread is not loaded\");\n            };\n            let Some(active_turn) = active_thread.active_turn.as_mut() else {\n                bail!(\"No active turn on thread {thread_id}\");\n            };\n            if active_turn.turn_id != turn_id {\n                bail!(\"Turn {turn_id} is not active on thread {thread_id}\");\n            }\n            active_turn.interrupt_requested = true;\n            // Wake the monitor's approval wait so it can consume the Engine's\n            // terminal receipt. Revoke only this turn's minted capabilities.\n            // Registration takes the same active lock, so a late event cannot\n            // install a new waiter after this sweep.\n            self.pending_approvals.lock().retain(|_, entry| {\n                entry.thread_id != thread_id || entry.request.turn_id != turn_id\n            });\n            if let Some(compaction_id) = active_turn.compaction_id.as_deref() {\n                active_thread.engine.cancel_compaction(compaction_id)?;\n            } else {","sourceCodeStart":10321,"sourceCodeEnd":10357,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/runtime_threads.rs#L10321-L10357","documentation":"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.","triggerScenarios":"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.","commonSituations":"Cancelling from UI after the session was closed; interrupting after an idle-unload evicted the engine; stale UI state referencing a removed thread.","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."],"exampleFix":"// before\nruntime.interrupt_turn(thread_id, turn_id)?; // thread already closed\n// after\nif runtime.thread_engine_loaded(thread_id) {\n    runtime.interrupt_turn(thread_id, turn_id)?;\n}","handlingStrategy":"type-guard","validationCode":"fn interruptable(active: &ActiveEngines, thread_id: &str, turn_id: &str) -> bool {\n    active.engines.get(thread_id)\n        .and_then(|s| s.active_turn.as_ref())\n        .is_some_and(|t| t.turn_id == turn_id)\n}","typeGuard":"fn is_thread_loaded(active: &ActiveEngines, thread_id: &str) -> bool { active.engines.contains_key(thread_id) }","tryCatchPattern":"match interrupt_turn(id, tid).await {\n    Err(e) if e.to_string().contains(\"not loaded\") => Ok(()), // nothing to interrupt\n    other => other,\n}","preventionTips":["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."],"tags":["interrupt","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"}