{"record":{"id":"02f5c8fe278dae7a","repo":"Hmbown/CodeWhale","slug":"failed-to-durably-register-write-capable-sub-agent","errorCode":null,"errorMessage":"failed to durably register write-capable sub-agent before launch: {error}","messagePattern":"failed to durably register write-capable sub-agent before launch: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/tools/subagent/mod.rs","lineNumber":7286,"sourceCode":"            }\n            self.agents.insert(agent_id.clone(), agent);\n            let persist_result = self.persist_state_synchronously();\n            agent = self\n                .agents\n                .remove(&agent_id)\n                .expect(\"pre-launch agent remains registered under manager lock\");\n            if let Err(error) = persist_result {\n                if let Some(source) = continuation_from.as_ref() {\n                    self.resume_targets.remove(source);\n                }\n                let (worker_records, coordination) = durable_launch_snapshot\n                    .expect(\"durable launch captured a registration snapshot\");\n                self.worker_records = worker_records;\n                self.coordination = coordination;\n                if let Some(lifecycle) = agent.work_lifecycle.as_ref() {\n                    let _ = lifecycle.reconcile_state(OwnerState::Failed, 1, None);\n                }\n                return Err(anyhow!(\n                    \"failed to durably register write-capable sub-agent before launch: {error}\"\n                ));\n            }\n        }\n\n        if let Some(mb) = runtime.mailbox.as_ref() {\n            let _ = mb.send(MailboxMessage::started(&agent_id, agent_type.clone()));\n        }\n\n        if let Some(event_tx) = runtime.event_tx.clone() {\n            let _ = event_tx.try_send(Event::AgentSpawned {\n                owner_session_id: runtime.context.state_namespace.clone(),\n                id: agent_id.clone(),\n                prompt: prompt.clone(),\n                worker_status: self\n                    .worker_record_by_ref(&agent_id)\n                    .map(|(_, record)| record.status),\n                parent_run_id: runtime.parent_agent_id.clone(),","sourceCodeStart":7268,"sourceCodeEnd":7304,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/tools/subagent/mod.rs#L7268-L7304","documentation":"Before a write-capable sub-agent is launched, it must be durably registered in the coordination state (so a crash after launch leaves a record). If that durable pre-launch registration fails, the agent's work lifecycle is marked Failed and the launch is aborted with this error. This prevents launching workers that the durable ledger would not know about.","triggerScenarios":"Spawning a write-capable sub-agent (or one with a continuation_from source) when the pre-launch durable registration step (persisting worker_records/coordination) returns an error.","commonSituations":"State file unwritable (permissions, disk full, missing parent directory); corrupted coordination state causing the persist/registration call to fail; filesystem errors on the session state path.","solutions":["Inspect the embedded {error} and fix the state-persistence failure (permissions, disk space, path validity), then retry the spawn.","Verify the coordination state file and its parent directory exist and are writable.","If the state is corrupted, restore or recreate the coordination state before launching write-capable agents."],"exampleFix":"// before\n$ test -w $SESSION_DIR/subagents.json || echo \"not writable\"\nnot writable\n// after\n$ chmod u+w $SESSION_DIR/subagents.json && retry spawn","handlingStrategy":"validation","validationCode":"// pre-flight before write-capable spawn\nif (!canWrite(stateDir)) throw new Error(`state dir ${stateDir} not writable: fix before launching`);","typeGuard":null,"tryCatchPattern":"if (err.message.startsWith(\"failed to durably register\")) {\n  // embedded cause is in the message tail; fix persistence, then retry\n  repair_state_storage(); retry_spawn();\n}","preventionTips":["Verify the coordination state file and parent directory exist and are writable before spawning write-capable agents.","Keep the state path on a local, non-read-only filesystem.","Validate coordination state integrity at session start to avoid mid-spawn registration failures."],"tags":["subagent","durable-registration","persistence","pre-launch"],"backgroundTag":"file-write-failed","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"}