{"record":{"id":"7b89788a6aff48e2","repo":"Hmbown/CodeWhale","slug":"error-runtime-preset-rollback-also-failed-provider-setup","errorCode":null,"errorMessage":"{error:#}; runtime preset rollback also failed: {}","messagePattern":"(.+?); runtime preset rollback also failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"crates/tui/src/tui/ui/provider_setup.rs","lineNumber":76,"sourceCode":"                }\n            },\n        }\n    }\n}\n\npub(crate) fn runtime_preset_error_with_rollback(\n    error: anyhow::Error,\n    snapshots: &[&RuntimePresetFileSnapshot],\n) -> anyhow::Error {\n    let rollback_errors = snapshots\n        .iter()\n        .filter_map(|snapshot| snapshot.restore().err())\n        .map(|error| format!(\"{error:#}\"))\n        .collect::<Vec<_>>();\n    if rollback_errors.is_empty() {\n        error\n    } else {\n        anyhow::anyhow!(\n            \"{error:#}; runtime preset rollback also failed: {}\",\n            rollback_errors.join(\"; \")\n        )\n    }\n}\n","sourceCodeStart":58,"sourceCodeEnd":82,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/tui/ui/provider_setup.rs#L58-L82","documentation":"Compound error produced by runtime_preset_error_with_rollback: applying a runtime preset failed, the code attempted to restore previously captured runtime snapshots, and at least one restore also failed. The original error is formatted with `{error:#}` (its full anyhow chain) and appended with all rollback errors joined by \"; \", so the developer sees both the primary failure and how much state may now be inconsistent.","triggerScenarios":"apply_setup_runtime_preset fails (invalid preset values, provider/model not available) AND snapshot.restore() on one or more captured runtime snapshots errors while rolling back — leaving the runtime in a partially modified state.","commonSituations":"Selecting a preset referencing a model/provider removed in a config or registry change; snapshots taken across a runtime version change so restore expects fields that no longer exist; concurrent modification of runtime state while the preset apply is in flight.","solutions":["Read the leading `{error:#}` chain first — it names why the preset apply failed; fix that (e.g. correct the preset's provider/model).","Treat the runtime state as suspect: restart the TUI or reload config to rebuild clean snapshots instead of trusting the partial rollback.","Validate preset values (provider exists, model supported) before applying; use a dry-run or preview if available.","If restores consistently fail, the snapshot format may be stale — regenerate state from the current config files."],"exampleFix":"// before\napply_setup_runtime_preset(app, config, preset)?; // compound rollback error\n// after: validate the preset before mutating runtime state\nvalidate_preset_against_registry(config, &preset)?;\nlet snapshots = capture_snapshots(app);\nif let Err(err) = apply_preset(app, config, &preset) {\n    for s in &snapshots { let _ = s.restore(); } // log restore errors individually\n    return Err(err);\n}","handlingStrategy":"validation","validationCode":"// validate the preset against the current registry before applying\nfn preset_applicable(config: &Config, preset: &Preset) -> Result<()> {\n    let provider = config.provider(&preset.provider)\n        .ok_or_else(|| anyhow::anyhow!(\"unknown provider {}\", preset.provider))?;\n    anyhow::ensure!(\n        provider.supports_model(&preset.model),\n        \"provider {} does not support model {}\",\n        preset.provider, preset.model\n    );\n    Ok(())\n}","typeGuard":null,"tryCatchPattern":"if let Err(e) = apply_setup_runtime_preset(app, config, &preset) {\n    let msg = format!(\"{e:#}\");\n    if msg.contains(\"rollback also failed\") {\n        // runtime state is inconsistent — rebuild rather than continue\n        reload_runtime_from_config(app, config)?;\n        return Err(anyhow::anyhow!(\"preset apply failed; runtime reloaded: {msg}\"));\n    }\n    return Err(e);\n}","preventionTips":["Validate preset provider/model against the registry before applying.","Capture snapshots and verify restore() succeeds once before relying on rollback.","Restart or reload the runtime whenever a rollback error appears — never continue on partially restored state.","Regenerate snapshots after config format or runtime version changes."],"tags":["config","preset","rollback","state"],"backgroundTag":"invalid-config-value","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"}