Skip to content

config: a corrupt config.json is silently overwritten with defaults when the CLI records its managed Python #515

Open

Description

@rominf

Current behavior

RocmCliConfig::load deliberately distinguishes a missing config (returns defaults) from an unreadable one (returns an error). record_managed_python_config (apps/rocm/src/therock.rs) collapses the two and then saves:

let mut config = RocmCliConfig::load(paths).unwrap_or_default();
config.tools.insert("python".to_owned(), …);
config.save(paths)

Both callers discard the result with let _ =. So a config that is merely unreadable is replaced on disk with an otherwise-empty one, and nothing is reported.

What is lost

Everything the user configured: the active and default runtime, the TheRock folder setting, providers, the permissions mode, engine preferences, and dashboard chat settings. The next command sees a valid, empty config and carries on.

Expected behavior

An unreadable config is reported, not replaced. Recording the managed Python should either fail loudly or leave the file untouched.

How a user gets here

The config only has to be unreadable at the moment the CLI bootstraps its own Python — the first rocm install sdk or update on a machine whose system Python cannot create a virtual environment (common on Windows, and on Linux without python3-venv).

A config becomes unreadable more easily than it should, because RocmCliConfig::save uses a plain fs::write, which truncates before writing. A full disk during a multi-gigabyte install produces precisely a truncated config.json. Every corruption class tested is wiped: a truncated write, a non-finite number serialised as null, a field of the wrong type, and an out-of-range value load rejects.

Steps to reproduce

Truncate config.json to one byte, then trigger managed-Python recording. The file afterwards loads cleanly as defaults.

Related, same root

  • configured_managed_root_from_config reads the same file with .ok()?, so when the config is unreadable the data directory silently falls back to the default. A user who installed with --prefix then sees no runtimes — and once the wipe above erases setup.therock_venv, the relocation becomes permanent.
  • Dashboard tick fields are f64; serde_json writes NaN/±inf as null, which load rejects. The legacy rocm-dash TOML migration copies those ticks unchecked, so discovery_tick = nan in an old config migrates into a config.json that cannot be loaded — and then the wipe above discards the migrated settings, while migration never runs again because config.json now exists.
  • Several other writes (save_runtime_manifest, write_active_runtime_marker) are not atomic either, while the least important file, the startup update-check cache, is written atomically.

Environment

  • Built from main. Platform-independent.

How it was found

Property-testing persisted-state round-trips: the property "corruption is never silently converted into a different valid state" failed for every corruption class.

Activity

  1. 7 remaining items

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions