Hmbown/CodeWhale · error · anyhow::Error

failed to register sub-agent work

Error message

failed to register sub-agent work: {err}

What it means

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.

Solutions

  1. Read the wrapped inner {err} — it names the real ledger/storage failure
  2. Check disk space and write permissions for the session state directory
  3. Retry the spawn; transient store contention usually clears on a second attempt
  4. If it persists, inspect/repair the session state store or start a fresh session
Defensive patterns

Strategy: try-catch

Validate before calling

// before spawning, verify the ledger is writable
if let Err(e) = std::fs::metadata(&state_dir) {
    return Err(anyhow!("state dir unavailable: {e}"));
}

Try / catch

match lifecycle.work.record_work(/* agent spawn record */) {
    Ok(_) => { /* continue spawn */ }
    Err(err) => {
        log::error!("sub-agent work registration failed: {err}");
        return Err(anyhow!("failed to register sub-agent work: {err}"));
    }
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@433685b202 (2026-09-15). Data as JSON: /api/errors/e9b9143dbb4ce593. Report an issue: GitHub.

Appendix: source

Thrown at crates/tui/src/tools/subagent/mod.rs:2969

        let external = format!("worker:{agent_id}");
        let lifecycle = Self {
            work,
            session_id,
            external,
        };
        lifecycle
            .work
            .register_operation(
                &lifecycle.session_id,
                OperationIntent::new(
                    lifecycle.external.clone(),
                    title,
                    true,
                    "agent",
                    format!("agent:{agent_id}:spawn"),
                ),
            )
            .map_err(|err| anyhow!("failed to register sub-agent work: {err}"))?;

        // A root Operate verification lease is provenance, not delegated
        // authority. Nested workers cannot inherit this bit.
        if runtime.accept_verification && runtime.spawn_depth == 1 {
            let reference = format!("operate-verification:{agent_id}");
            if let Err(err) = lifecycle.work.record_operation_approval(
                &lifecycle.session_id,
                &lifecycle.external,
                &reference,
                "agent",
                &format!("agent:{agent_id}:approval"),
            ) {
                let _ = lifecycle.reconcile_state(OwnerState::Failed, 1, None);
                return Err(anyhow!(
                    "failed to record sub-agent verification approval: {err}"
                ));
            }
        }

View on GitHub (pinned to 433685b202)