{"record":{"id":"8bfee37dee9e277b","repo":"Hmbown/CodeWhale","slug":"cannot-queue-a-parent-message-for-agent-agent-id","errorCode":null,"errorMessage":"Cannot queue a parent message for agent {agent_id}: status is {} (only running children accept messages)","messagePattern":"Cannot queue a parent message for agent (.+?): status is (.+?) \\(only running children accept messages\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/tools/subagent/mod.rs","lineNumber":5812,"sourceCode":"        })\n    }\n\n    /// Queue-only message entrypoint for live children. Terminal records are\n    /// immutable receipts, not mailboxes, so the message surface fails closed\n    /// instead of acknowledging undeliverable work.\n    pub fn queue_running_parent_message(\n        &mut self,\n        agent_ref: &str,\n        text: String,\n    ) -> Result<ParentMailReceipt> {\n        let agent_id = self.resolve_agent_ref(agent_ref)?;\n        let status = self\n            .agents\n            .get(&agent_id)\n            .map(|agent| agent.status.clone())\n            .ok_or_else(|| anyhow!(\"Agent {agent_id} not found\"))?;\n        if status != SubAgentStatus::Running {\n            return Err(anyhow!(\n                \"Cannot queue a parent message for agent {agent_id}: status is {} (only running children accept messages)\",\n                subagent_status_name(&status)\n            ));\n        }\n        self.queue_parent_message(&agent_id, text, false)\n    }\n\n    pub(crate) fn queue_running_parent_message_for_session(\n        &mut self,\n        active_session_id: &str,\n        agent_ref: &str,\n        text: String,\n    ) -> Result<ParentMailReceipt> {\n        let agent_id = self.resolve_agent_ref_for_session(active_session_id, agent_ref)?;\n        self.queue_running_parent_message(&agent_id, text)\n    }\n\n    /// Queue mail and attempt a live wake (`agents/followup`).","sourceCodeStart":5794,"sourceCodeEnd":5830,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/tools/subagent/mod.rs#L5794-L5830","documentation":"Parent messages are only accepted by agents whose status is exactly Running. When a resolved agent exists but is in any other state (Completed, Failed, Cancelled, BudgetExhausted, etc.), queueing would silently lose the message, so the library rejects it with this error naming the current status.","triggerScenarios":"Calling the queue-parent-message API on an agent whose SubAgentStatus is anything other than Running — typically after the child returned its result, failed, was cancelled, or exhausted its budget.","commonSituations":"A parent sends a follow-up just after the child finished; automation racing agent completion; retry logic re-sending to an agent that already errored out.","solutions":["Check the agent's status before sending and consume its final result instead of queueing more mail.","If follow-up work is needed, spawn a new sub-agent with the additional message.","Add race handling: catch this error and fall back to reading the agent's terminal result.","Adjust orchestration so messages are sent before the child can terminate (e.g. during a wait barrier)."],"exampleFix":"// before: unconditional queue\nmanager.queue_parent_message(&id, text)?;\n// after: only queue while running, else read result\nmatch manager.agent_status(&id) {\n    SubAgentStatus::Running => manager.queue_parent_message(&id, text)?,\n    status => println!(\"agent done ({status:?}); skipping message\"),\n}","handlingStrategy":"validation","validationCode":"fn accepts_parent_mail(mgr: &SubAgentManager, agent_ref: &str) -> bool {\n    mgr.resolve_agent_ref(agent_ref).ok()\n        .and_then(|id| mgr.find_agent(&id).map(|a| a.status == SubAgentStatus::Running))\n        .unwrap_or(false)\n}","typeGuard":"fn is_running(a: &SubAgent) -> bool { a.status == SubAgentStatus::Running }","tryCatchPattern":"match manager.queue_parent_message(&id, text) {\n    Err(e) if e.to_string().contains(\"only running children accept messages\") => {\n        let result = manager.collect_result(&id)?;\n        info!(\"agent already terminal: {result:?}\");\n    }\n    r => r?,\n}","preventionTips":["Check agent status equals Running before every parent-message send.","Design orchestration so follow-up messages are sent before the child can reach a terminal state.","On this error, read the child's final result instead of resending."],"tags":["subagent","messaging","lifecycle"],"backgroundTag":"invalid-state-transition","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"}