invoke-ai/InvokeAI · error · RuntimeError
Failed to load and migrate v3 config file {config_path}: {e}
Error message
Failed to load and migrate v3 config file {config_path}: {e} What it means
load_and_migrate_config upgrades a v3 config file: it validates the loaded dict with DefaultInvokeAIAppConfig, writes the migrated file, and on any exception restores the .yaml.bak backup and re-raises as RuntimeError 'Failed to load and migrate v3 config file {path}: {e}'. This keeps the original config intact while signaling that migration failed.
Source
Thrown at invokeai/app/services/config/config_default.py:626
if loaded_config_dict["schema_version"] == "4.0.0":
migrated = True
loaded_config_dict = migrate_v4_0_0_to_4_0_1_config_dict(loaded_config_dict)
if loaded_config_dict["schema_version"] == "4.0.1":
migrated = True
loaded_config_dict = migrate_v4_0_1_to_4_0_2_config_dict(loaded_config_dict)
if loaded_config_dict["schema_version"] == "4.0.2":
migrated = True
loaded_config_dict = migrate_v4_0_2_to_4_0_3_config_dict(loaded_config_dict)
if migrated:
shutil.copy(config_path, config_path.with_suffix(".yaml.bak"))
try:
# load and write without environment variables
migrated_config = DefaultInvokeAIAppConfig.model_validate(loaded_config_dict)
migrated_config.write_file(config_path)
except Exception as e:
shutil.copy(config_path.with_suffix(".yaml.bak"), config_path)
raise RuntimeError(f"Failed to load and migrate v3 config file {config_path}: {e}") from e
try:
# Meta is not included in the model fields, so we need to validate it separately
config = InvokeAIAppConfig.model_validate(loaded_config_dict)
assert config.schema_version == CONFIG_SCHEMA_VERSION, (
f"Invalid schema version, expected {CONFIG_SCHEMA_VERSION}: {config.schema_version}"
)
return config
except Exception as e:
raise RuntimeError(f"Failed to load config file {config_path}: {e}") from e
def load_external_api_keys(api_keys_file_path: Path) -> dict[str, str]:
"""Load external provider config (API keys and base URLs) from a dedicated YAML file."""
if not api_keys_file_path.exists():
return {}
with open(api_keys_file_path, "rt", encoding=locale.getpreferredencoding()) as file:View on GitHub (pinned to 0b6a024f2f)
Solutions
- Read the inner '{e}' message to find the exact validation failure and fix that key in the YAML
- Restore the automatic backup (config_path.yaml.bak was copied back) and fix types/keys before retrying
- Rename or move the old config and let InvokeAI generate a fresh one, then re-add settings incrementally
- Ensure the config directory is writable so write_file can persist the migrated config
Example fix
// before (invokeai.yaml, v3) generation_devices: cuda:0 # invalid type for new schema // after generation_devices: - cuda:0
Defensive patterns
Strategy: try-catch
Validate before calling
import yaml
data = yaml.safe_load(open('invokeai.yaml'))
from invokeai.app.services.config.config_default import DefaultInvokeAIAppConfig
DefaultInvokeAIAppConfig.model_validate(data) # surfaces errors before migration writes Try / catch
try:
config = load_and_migrate_config(path)
except RuntimeError as e:
logger.error(f"Config migration failed: {e}; .yaml.bak was restored")
# fix the offending key reported in the chained exception, then retry Prevention
- Keep a manual copy of invokeai.yaml before upgrading
- Fix validation errors reported by pydantic before re-running migration
- Ensure the config directory is writable
- Re-add old config values incrementally rather than carrying the whole v3 file forward
When it happens
Trigger: Running InvokeAI (or update_runtime_config/get_config) with a v3-era invokeai.yaml that fails model_validate — unknown/invalid keys, wrong types, malformed YAML values, or a write_file failure (permissions, read-only volume) — triggering the except branch.
Common situations: Upgrading InvokeAI across major versions with an old hand-edited config; config entries typed incorrectly (string where list expected, e.g. generation_devices); migrating configs in containers with read-only config mounts.
Related errors
- JWT secret not found in database. This should have been crea
- Invalid regex: {e}
- Invalid generation_devices value '{v}'. Use 'auto' or a list
- generation_devices cannot be an empty list. Use 'auto' or a
- base_url must not start with reserved path segment '/{first_
AI-assisted analysis of invoke-ai/InvokeAI@0b6a024f2f (2026-08-29).
Data as JSON: /api/errors/ad22808ca7bbf47d.
Report an issue: GitHub.