{"record":{"id":"7c8a101f0faa74c4","repo":"Hmbown/CodeWhale","slug":"task-not-found-task-id","errorCode":null,"errorMessage":"Task not found: {task_id}","messagePattern":"Task not found: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/task_manager.rs","lineNumber":1968,"sourceCode":"\n    /// Retrieve the exact owned task stamped onto a trusted runtime thread.\n    ///\n    /// The runtime thread supplies a full durable id rather than model input.\n    /// An ownerless task needs the current trusted execution scope. Legacy\n    /// ownerless tasks without that provenance still fail closed.\n    pub(crate) async fn get_task_for_active_runtime(&self, task_id: &str) -> Result<TaskRecord> {\n        let mut state = self.state.lock().await;\n        let _transaction = self.lock_store().await?;\n        self.refresh_locked(&mut state)?;\n        state\n            .tasks\n            .get(task_id)\n            .filter(|task| match task.execution_scope.as_deref() {\n                Some(scope) => scope == self.execution_scope(),\n                None => task.owner_session_id.is_some(),\n            })\n            .cloned()\n            .ok_or_else(|| anyhow!(\"Task not found: {task_id}\"))\n    }\n\n    async fn get_task_visible_to(\n        &self,\n        id_or_prefix: &str,\n        owner_session_id: Option<&str>,\n    ) -> Result<TaskRecord> {\n        let mut state = self.state.lock().await;\n        let _transaction = self.lock_store().await?;\n        self.refresh_locked(&mut state)?;\n        let id = resolve_task_id_visible_to(&state.tasks, id_or_prefix, owner_session_id)?;\n        state\n            .tasks\n            .get(&id)\n            .cloned()\n            .ok_or_else(|| anyhow!(\"Task not found: {id_or_prefix}\"))\n    }\n","sourceCodeStart":1950,"sourceCodeEnd":1986,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/task_manager.rs#L1950-L1986","documentation":"TaskManager::get_task_for_active_runtime throws this when a trusted runtime thread looks up a task by its full durable id and the record is either missing or fails the visibility filter: a scoped task whose execution_scope differs from the current scope, or an ownerless legacy task with no owner_session_id. Ownerless tasks without that provenance fail closed deliberately.","triggerScenarios":"Calling get_task_for_active_runtime(task_id) from a runtime thread when: the task id does not exist in state.tasks; the task's execution_scope string differs from self.execution_scope() (e.g. manager restarted, scope re-derived); or the task has execution_scope == None and owner_session_id == None (legacy unowned record).","commonSituations":"A resumed session or process restart changed the execution scope so previously valid task ids are now invisible; the runtime thread passes a stale id after the task was completed and pruned; a migrated pre-scoping task record has no owner/scope provenance and is hidden by design.","solutions":["Confirm the task_id is the full durable id stamped on the runtime thread, not a prefix or model-supplied value.","Re-create or re-scope the task so its execution_scope matches the current manager scope after a restart.","Stamp owner_session_id provenance onto legacy ownerless records so they no longer fail closed.","Re-check the task list immediately before lookup; retry with a fresh id if the task ended and was pruned."],"exampleFix":"// before\nlet task = manager.get_task_for_active_runtime(&stale_id).await?;\n// after\nlet task = match manager.get_task_for_active_runtime(&durable_id).await {\n    Ok(t) => t,\n    Err(e) => {\n        tracing::warn!(id = %durable_id, \"runtime task invisible or pruned\");\n        return Err(e);\n    }\n};","handlingStrategy":"validation","validationCode":"// Only pass full durable ids stamped onto the runtime thread, never prefixes.\nif !task_id.is_empty() && task_id.len() < FULL_ID_LEN { return Err(anyhow!(\"runtime requires full durable id\")); }","typeGuard":"fn is_full_durable_id(s: &str) -> bool { s.len() >= FULL_ID_LEN && s.chars().all(|c| c.is_ascii_alphanumeric() || c == '-') }","tryCatchPattern":"match manager.get_task_for_active_runtime(&task_id).await {\n    Ok(task) => proceed(task),\n    Err(e) => {\n        tracing::warn!(%task_id, \"task invisible to this runtime scope; re-scoping\");\n        re_bind_task_to_scope(task_id)\n    }\n}","preventionTips":["After a manager restart, re-derive or re-create tasks instead of reusing pre-restart ids.","Ensure legacy ownerless records get owner_session_id or execution_scope provenance stamped at migration time.","Verify execution_scope matches the manager's current scope before runtime lookups."],"tags":["task-management","not-found","execution-scope","rust","runtime"],"backgroundTag":"record-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"}