{"record":{"id":"e9b9143dbb4ce593","repo":"Hmbown/CodeWhale","slug":"failed-to-register-sub-agent-work-err","errorCode":null,"errorMessage":"failed to register sub-agent work: {err}","messagePattern":"failed to register sub-agent work: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/tui/src/tools/subagent/mod.rs","lineNumber":2969,"sourceCode":"        let external = format!(\"worker:{agent_id}\");\n        let lifecycle = Self {\n            work,\n            session_id,\n            external,\n        };\n        lifecycle\n            .work\n            .register_operation(\n                &lifecycle.session_id,\n                OperationIntent::new(\n                    lifecycle.external.clone(),\n                    title,\n                    true,\n                    \"agent\",\n                    format!(\"agent:{agent_id}:spawn\"),\n                ),\n            )\n            .map_err(|err| anyhow!(\"failed to register sub-agent work: {err}\"))?;\n\n        // A root Operate verification lease is provenance, not delegated\n        // authority. Nested workers cannot inherit this bit.\n        if runtime.accept_verification && runtime.spawn_depth == 1 {\n            let reference = format!(\"operate-verification:{agent_id}\");\n            if let Err(err) = lifecycle.work.record_operation_approval(\n                &lifecycle.session_id,\n                &lifecycle.external,\n                &reference,\n                \"agent\",\n                &format!(\"agent:{agent_id}:approval\"),\n            ) {\n                let _ = lifecycle.reconcile_state(OwnerState::Failed, 1, None);\n                return Err(anyhow!(\n                    \"failed to record sub-agent verification approval: {err}\"\n                ));\n            }\n        }","sourceCodeStart":2951,"sourceCodeEnd":2987,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/433685b2024e7bc4c99e1e2e326bcad39b4d9d65/crates/tui/src/tools/subagent/mod.rs#L2951-L2987","documentation":"After creating a sub-agent lifecycle, the runtime records the delegated work item in the work ledger (lifecycle.work record with kind \"agent\" and reference agent:{id}:spawn). If that ledger write fails, the spawn is aborted and the underlying error is wrapped in this message.","triggerScenarios":"Spawning a sub-agent when the work-ledger/store call fails — e.g. storage backend error, I/O failure writing the record, or a ledger invariant violation for the agent:{agent_id}:spawn reference.","commonSituations":"Disk full or permission problems on the state directory; corrupted or locked session state store; a bug in the ledger's record_work API; concurrent writers conflicting on the same session.","solutions":["Read the wrapped inner {err} — it names the real ledger/storage failure","Check disk space and write permissions for the session state directory","Retry the spawn; transient store contention usually clears on a second attempt","If it persists, inspect/repair the session state store or start a fresh session"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// before spawning, verify the ledger is writable\nif let Err(e) = std::fs::metadata(&state_dir) {\n    return Err(anyhow!(\"state dir unavailable: {e}\"));\n}","typeGuard":null,"tryCatchPattern":"match lifecycle.work.record_work(/* agent spawn record */) {\n    Ok(_) => { /* continue spawn */ }\n    Err(err) => {\n        log::error!(\"sub-agent work registration failed: {err}\");\n        return Err(anyhow!(\"failed to register sub-agent work: {err}\"));\n    }\n}","preventionTips":["Monitor disk space and permissions on the session state directory","Retry transient ledger write failures once before failing the spawn","Back up or rotate session state stores to avoid corruption","Validate the ledger API contract when changing record shapes"],"tags":["subagent","persistence","ledger"],"backgroundTag":"database-write-failed","analyzedSha":"433685b2024e7bc4c99e1e2e326bcad39b4d9d65","analyzedAt":"2026-09-15T12:24:24.634Z","contentChangedAt":"2026-09-15T12:24:24.634Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}