{"record":{"id":"3beaacff793eb7e6","repo":"Hmbown/CodeWhale","slug":"unsupported-sub-agent-state-schema","errorCode":null,"errorMessage":"Unsupported sub-agent state schema {}","messagePattern":"Unsupported sub-agent state schema (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/tools/subagent/mod.rs","lineNumber":4666,"sourceCode":"                    .join(\"state\")\n                    .join(SUBAGENT_STATE_FILE),\n            )?;\n            if legacy.exists() {\n                tracing::info!(\n                    target: \"subagent\",\n                    \"loading sub-agent state from legacy path for migration: {}\",\n                    legacy.display()\n                );\n                legacy\n            } else {\n                return Ok(());\n            }\n        };\n\n        let raw = read_subagent_state_file(&self.state_root, &path)?;\n        let state = serde_json::from_str::<PersistedSubAgentState>(&raw)?;\n        if state.schema_version != SUBAGENT_STATE_SCHEMA_VERSION {\n            return Err(anyhow!(\n                \"Unsupported sub-agent state schema {}\",\n                state.schema_version\n            ));\n        }\n\n        let mut coordination = state.coordination;\n        coordination\n            .validate_replay()\n            .map_err(|error| anyhow!(\"Invalid coordination ledger: {error}\"))?;\n        self.agents.clear();\n        self.worker_records.clear();\n        self.persist_sequence.store(\n            state.snapshot_sequence,\n            std::sync::atomic::Ordering::Relaxed,\n        );\n        self.coordination = coordination;\n        self.resume_targets = state.resume_targets;\n        for persisted in state.agents {","sourceCodeStart":4648,"sourceCodeEnd":4684,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/tools/subagent/mod.rs#L4648-L4684","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Run Codewhale with the version that matches the state file's schema_version (check release notes for the schema bump).","Delete or archive the stale sub-agent state under state_root so a fresh state is written with the current schema.","Back up the state file and let the current version recreate it; sub-agent history is not preserved.","If you must migrate manually, rewrite schema_version and adapt fields per the migration in the release notes."],"exampleFix":"// before: hand-editing the persisted file's version\n{ \"schema_version\": 2, ... }\n// after: start fresh / use matching binary\n$ codewhale --version  # ensure it matches the writer's version\n$ rm -rf .codewhale/subagent-state  # archive first","handlingStrategy":"validation","validationCode":"fn state_schema_supported(raw: &str, current: u32) -> bool {\n    serde_json::from_str::<serde_json::Value>(raw).ok()\n        .and_then(|v| v.get(\"schema_version\")?.as_u64())\n        .map(|v| v as u32 == current)\n        .unwrap_or(false)\n}","typeGuard":"fn is_current_schema(state: &PersistedSubAgentState, current: u32) -> bool {\n    state.schema_version == current\n}","tryCatchPattern":"match load_subagent_state(path) {\n    Err(e) if e.to_string().starts_with(\"Unsupported sub-agent state schema\") => {\n        warn!(\"state written by another version; starting fresh\");\n        fresh_state()\n    }\n    r => r?,\n}","preventionTips":["Keep the Codewhale binary version stable for a given workspace's state directory.","Archive sub-agent state before upgrading or downgrading.","Check the schema_version field in state files before manual edits or migrations."],"tags":["serialization","versioning","state"],"backgroundTag":"schema-validation-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"}