Skip to content

config: load a configuration whatever version wrote it - #947

Merged
techomancer merged 2 commits into
mainfrom
gui-legacy-prefs-migration
Dec 1, 2026
Merged

techomancer merged 2 commits into
mainfrom
gui-legacy-prefs-migration

Conversation

@danifunker

Copy link
Copy Markdown
Collaborator

Installing the latest nightly over an August-or-earlier install left the front end
with an empty library and no way to create a machine: every machine in gui.json
failed to migrate with

invalid type: null, expected any valid TOML value at line 28 column 25

and migration_pending then locks the library. The cause is one missing
skip_serializing_if: ScsiDeviceConfig::size_mb wrote "size_mb": null for
every disk, and legacy_scsi: Option<toml::Table> cannot hold a JSON null,
because TOML has no null. Any install with a disk was affected, on every
platform, including the August Mac App Store build.

Rather than fix that one key, this makes reading an old configuration lenient by
construction, since MachineConfig is both today's strict schema and the
migration target for every file ever written.

Reading preferences (iris-gui/core/src/model/settings.rs)

load_in() — the single migration entry point all four front ends share — now
reads gui.json by three rules instead of one strict from_str:

  • JSON nulls are stripped before deserializing, so a serialized None can never
    again reject a file.
  • A machine whose payload carries a key nothing claims has that key dropped, with
    a warning, and the machine loads. Bounded at 32 keys.
  • A machine that still will not read is quarantined by name: the library opens,
    the other machines work, and the failure is reported against the retained
    original with the reason.

Version stamping (src/config.rs)

New iris::config::SCHEMA (= 1) and an optional schema key on MachineConfig.
Nothing writes it yet; both readers check it, so a file from a future IRIS says
"update IRIS to open it" instead of failing on whichever key it happens to hit
first. 20 bare Option fields gained skip_serializing_if so they stop writing
nulls at all.

Two defects the audit turned up

  • [audio] cpal_buffer_frames was silently discarded on load; it now folds to
    latency_ms (frames ÷ 48, one 48 kHz period).
  • [o2] control_port was refused without naming a replacement; it now points at
    ci = true and iris-ci.

Guards

  • iris-gui/core/tests/legacy/ holds real preference files as literal text —
    a June nightly, an August App Store install, and synthetic unknown-key,
    one-bad-machine and newer-schema cases. Fixtures are never written by
    serializing today's structs; README.md there says so.
  • tools/config-compat.py <rev> reads the config structs at a past revision and
    reports any key that would now stop a file loading without saying why. It
    understands rename, alias, skip, skip_serializing and per-struct
    deny_unknown_fields. Exit 1 on a lockout.

Verification

  • cargo test -p iris-gui-core --lib model::settings — 14 passed, 0 failed,
    including the two real-world fixtures.
  • tools/config-compat.py against June, August and 14 November — no lockouts.
  • cargo check --tests -p iris -p iris-gui-core — clean.

The iris crate's own unit tests are type-checked but were not run locally:
the test binary needs more memory than this machine can give it safely. They need
CI.

🤖 Generated with Claude Code

danifunker and others added 2 commits November 30, 2026 21:12
A machine holds the retired `[scsi.N]` tables as a `toml::Table`, and
TOML's value model has no null, so the `"size_mb": null` every pre-TOML
front end wrote for a disk with no scratch size made the whole
preferences file unreadable: the library stayed empty and New Machine
refused, on every platform and in the sandboxed Mac build alike.

Parse the preferences to a `serde_json::Value` and drop null members
before deserializing. Every field in `GuiSettings` and `MachineConfig`
has a serde default, so an absent member and a null member mean the
same thing.

The suite missed this because the migration fixtures are built by
serializing today's structs, and `legacy_scsi` is `skip_serializing` —
so no fixture could contain the key the fold exists for. The new test
writes the legacy JSON as literal text instead.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
`MachineConfig` is both the live schema and the migration target for
every file any version ever wrote, and it is `deny_unknown_fields`, so
each schema change silently redefined which older files still load and
turned the ones that didn't into a locked-out front end. That shipped
twice: the retired `[impact]` section, and a disk's `size_mb: null`.

The legacy JSON path is now lenient, because nothing hand-wrote it: a
null means absent, each machine is read on its own, and a key no fold
claims is dropped and named in the log instead of costing the file.
Folding stays how a retired key keeps its meaning; the drop is the net
under it. Quarantining a machine rather than the whole file means
`migration_pending` -- which blocks every save -- now means only that
the preferences file itself cannot be read or written. A machine that
would not read is named in the library, with its settings still in
`gui.json.pre-toml.bak`.

Nothing writes a null into a configuration any more: the twenty bare
`Option` fields that would have serialized one now skip. TOML omits
`None` either way, so this only ever mattered on the JSON side, which
is the legacy direction.

Configurations take a `schema` version. Nothing writes it, by design:
an older build refuses a key it has never seen, so a build must read
the stamp a release before any build may write one. A file stamped
newer now says to update IRIS instead of failing on whichever key that
build did not recognise.

Two findings from auditing August 2026 forward. `[audio]
cpal_buffer_frames` was being silently discarded, because
`AudioConfig` is not `deny_unknown_fields`; it folds into `latency_ms`
now, 960 frames being 20 ms at 48 kHz. `[o2] control_port` was refused
without naming a replacement, and now names one. Nothing else from
August hard-fails once `alias`, the `legacy_*` renames and per-struct
`deny_unknown_fields` are accounted for.

Two guards so this stops recurring. `iris-gui/core/tests/legacy/` holds
preferences as shipped versions actually wrote them, as literal text --
building a fixture by serializing today's structs is exactly how the
null got past the suite, since the retired `[scsi.N]` tables are a
`skip_serializing` field and so can never appear in a generated one.
And `tools/config-compat.py` reads the structs at a past revision and
names every key that version could write and this one would refuse,
separating silent breakage from a `refuse()` that names its
replacement.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@techomancer
techomancer force-pushed the gui-legacy-prefs-migration branch from 9e2f691 to 2cabb35 Compare December 1, 2026 05:25
@techomancer
techomancer merged commit f277903 into main Dec 1, 2026
9 checks passed
@jamesbraid

Copy link
Copy Markdown
Collaborator

nice, thanks for doing this!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants