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
- 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
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
- 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
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
- ; additionally failed to persist contention receipt
- failed to durably register write-capable sub-agent before…
- failed to record sub-agent verification approval
- sub-agent transcript history shrank from
- agent action=claim widens an enforced write scope, and the…
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)