Hmbown/CodeWhale · error

Unsupported sub-agent state schema

Error message

Unsupported sub-agent state schema {}

What it means

Persisted sub-agent state files carry a schema_version field. When loading a snapshot whose schema_version does not match SUBAGENT_STATE_SCHEMA_VERSION, the library refuses to interpret it, because field layouts and semantics may have changed between releases. This prevents silently misreading old or newer state files.

Solutions

  1. Run Codewhale with the version that matches the state file's schema_version (check release notes for the schema bump).
  2. Delete or archive the stale sub-agent state under state_root so a fresh state is written with the current schema.
  3. Back up the state file and let the current version recreate it; sub-agent history is not preserved.
  4. If you must migrate manually, rewrite schema_version and adapt fields per the migration in the release notes.

Example fix

// before: hand-editing the persisted file's version
{ "schema_version": 2, ... }
// after: start fresh / use matching binary
$ codewhale --version  # ensure it matches the writer's version
$ rm -rf .codewhale/subagent-state  # archive first
Defensive patterns

Strategy: validation

Validate before calling

fn state_schema_supported(raw: &str, current: u32) -> bool {
    serde_json::from_str::<serde_json::Value>(raw).ok()
        .and_then(|v| v.get("schema_version")?.as_u64())
        .map(|v| v as u32 == current)
        .unwrap_or(false)
}

Type guard

fn is_current_schema(state: &PersistedSubAgentState, current: u32) -> bool {
    state.schema_version == current
}

Try / catch

match load_subagent_state(path) {
    Err(e) if e.to_string().starts_with("Unsupported sub-agent state schema") => {
        warn!("state written by another version; starting fresh");
        fresh_state()
    }
    r => r?,
}

Prevention

When it happens

Trigger: Calling the sub-agent state restore/load path on a state file written by a different Codewhale version (older schema after upgrade, or newer schema after downgrade).

Common situations: Upgrading Codewhale over an existing workspace; downgrading to an older build; copying a state directory between machines with different versions; a partially migrated state root.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22). Data as JSON: /api/errors/3beaacff793eb7e6. Report an issue: GitHub.

Appendix: source

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

                    .join("state")
                    .join(SUBAGENT_STATE_FILE),
            )?;
            if legacy.exists() {
                tracing::info!(
                    target: "subagent",
                    "loading sub-agent state from legacy path for migration: {}",
                    legacy.display()
                );
                legacy
            } else {
                return Ok(());
            }
        };

        let raw = read_subagent_state_file(&self.state_root, &path)?;
        let state = serde_json::from_str::<PersistedSubAgentState>(&raw)?;
        if state.schema_version != SUBAGENT_STATE_SCHEMA_VERSION {
            return Err(anyhow!(
                "Unsupported sub-agent state schema {}",
                state.schema_version
            ));
        }

        let mut coordination = state.coordination;
        coordination
            .validate_replay()
            .map_err(|error| anyhow!("Invalid coordination ledger: {error}"))?;
        self.agents.clear();
        self.worker_records.clear();
        self.persist_sequence.store(
            state.snapshot_sequence,
            std::sync::atomic::Ordering::Relaxed,
        );
        self.coordination = coordination;
        self.resume_targets = state.resume_targets;
        for persisted in state.agents {

View on GitHub (pinned to 73e0f67d83)