core/lib: carry a stored configuration across renames no single pin declares #1506
No reviewers
Labels
No labels
ambition
application-offering
ambition
configure-applications
ambition
front-end
ambition/install-applications
ambition
security
ambition
switch-host
ambition
update-applications
ambition
user-management
blocked
component
api-service
component
nixops4
component
panel
documentation
points
0
points
0.5
points
1
points
13
points
2
points
21
points
3
points
34
points
5
points
55
points
8
points
infinite
productisation
project-management
question
role
application-developer
role
application-operator
role
hosting-provider
role
maintainer
technical debt
testing
type
bug
type
deliverable
type
key-result
type
objective
type
task
type
unclear
type
user-story
user experience
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
fediversity/fediversity!1506
Loading…
Reference in a new issue
No description provided.
Delete branch "kiara/fediversity:schema-updates-automated"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Part of #629.
#1073 gave the api and the browser a rename table: every
Alias of {option}description a nixos module leaves behind becomes a{ from, to }entry,migrate_valuedeep-moves a stored value across it, andschema-for-source.nixprunes the legacy side out of the emitted schema so an alias never becomes a form field. That covers a rename an option tree declares about itself. #1384 introduced the kind of option it cannot see: one whose type is built from a published JSON Schema (core/lib/json-schema.nix'soptionType), which hides an entire upstream document behind a single option. A key upstream renames inside that document leaves no marker anywhere in the option tree, so a stored value on the old path is stranded and the next pin bump fails on rule 1 ofcore/lib/option-selection.nixnaming a key that is gone.The first gap is that the harvest never got that deep in the first place.
renames-for-source.nix's tree-walk stopped at every option node, so it saw only the top level of a configuration module -- a rename declared inside a nested submodule, garage'sensureBuckets.<name>.website -> serveAsWebsiteor anything reached throughapplications.*, was never recovered. The walk now descends through an option's own type withgetSubOptions, the same treeschema-for-source.nixhandsmoduleToSchema, so a recoveredfromlines up with the emitted schema by construction. The anchor comes from the node's ownlocrather than being threaded down, becauseattrsOf/listOf/functionToshift the prefix they hand their element type, and a rename crossing a level the migrator cannot range over --listOf's*,functionTo's<function body>-- is refused rather than emitted, sincemigrate.py's_expand_wildcardswould turn it into an invisible skip.removeAtPathlearns thenullwildcard step this makes reachable (descendingadditionalPropertiesoritems), and the prune fold now runs over a schema root wrapping the option map instead of the bare map, which is what makes it reach anything at all: a visiblemkAliasOptionModuleinside anattrsOfpreviously landed in the emitted schema and in itsrequired, so an old-shaped value failed validation against the very schema the form renders from.The second is the schema-carrying option type itself.
optionTypegainsrenamesandcontext, and puts the checked table infunctor.payload.jsonSchemaRenamesbesidejsonSchema-- the right home, because the renames are a fact about upstream's document andbinOpcompares the payload whole, so two types carrying the same schema must carry the same renames. The newcheckedRenamesexport collects the rules and throws once as a list against the narrowed schema.renames-for-source.nixreads the payload back out at each option node and anchors every entry at the option's own path, so both kinds of rename arrive in one table of the same shape.What those rules are follows from the table being a log across releases rather than a set of moves against one schema, since the pairing is a stored configuration at some one version against the pin of the moment. Upstream moves a key away and later brings the name back --
a -> bin one release,b -> ain the next -- and both are entries, so the first entry'sfromis a live key again by the time the table is read while a value still comes to rest where the schema has it. So afromis required to be gone only where the chain does not bring the value back to it, an earlier entry shadows a later one with the samefromonly where nothing in between restores that path, and chain resolution carries no visited set: the walk only looks at entries after the one it is at, so it terminates on the table's own length, and dropping the set is what makes it agree withmigrate_valueon a table where a path recurs. What stays refused is a wildcard segment, sincenarrowseals every object withadditionalProperties = falseand leaves no open level to range over, andfrom == to.The two halves of the table do not reach back equally far, though, and
core/renames-log.jsonis what fixes that. A harvested rename is read off a marker that is upstream's to retire -- dropped a few releases after the move, at which point the walk has nothing left to find -- while a declared one is ours, appended and never rewritten. So the harvested half is written down too: the log accumulates what each pin was seen to declare and is prepended to what the current walk finds, so a loggeda -> bmeets a freshly harvestedb -> cin the order upstream made them and one pass carries a value toc. Without it, a configuration older than the markers could only be reached by stepping it through the intermediate pins that still had them, one bump at a time. The log is kept current by the build: a rename this tree declares that the log does not carry failsapi-renames, naming the./core#renames-logcommand that records it, since the bump that retires a marker is the last build able to record what it said. Handing a log in is the claim that it covers the type walked, so the two travel together rather than the log being read from the tree unconditionally:services.fediversity-api.deployment.renamesLogdefaults to this tree's log, the one that pairs with the defaultdeployment.moduleType, and a type layered on from outside -- a deployer's extra modules, theapps-paneltest's worked example -- declares renames no log of ours could carry, so such a deployment supplies its own (recordInLogstamps it the same way) ornullfor no log, no history and no gate.A log reaching across releases cannot be read off the value alone, which is what makes the log versioned.
bar -> baz, thenfoo -> bar, thenbar -> boo:{"bar": 1}is the same JSON whichever side of the reuse it was saved on, and it belongs in a different place on each. So each recording stamps the entries it appends withsince, one version per batch, and a stored configuration carries the version it was last migrated through --renames_versionon the api's deployment row, accepted on submit and served bydeployment_get, since the forms island migrates a stored value client-side before rendering it and can be ahead of the row it came from.migrate_valuereplays only what was appended after that stamp, so a value saved when the log stood at 2 lands onbooand one saved before any of it lands onbaz, off the same table. An entry with nosincebelongs to no version and always applies: thepinEffectlift, which is how a build is assembled rather than a move upstream made. A row predating the stamp has the table replayed whole -- the oldest reading, the only one available for a value whose age nothing records.The panel keeps its own copy of that version,
Deployment.renames_version, because a value it saves was migrated in the browser and so can be ahead of the api row. The form carries it as a hidden input: the island migrates through only the entries after it, sets it tolatestVersionof the table (the version the api stamps), and save and deploy send it on. A blank input is a value of unknown age, which replays the whole log. fediversity/nix-module-form#61 givesmigrateValuethe same version filter, andnix-module-formis pinned to a revision that has it.POST /configuration/sectionsand itsget_forvariant take the samerenames_version, so thepathof a section follows only the renames newer than the stored value, and the renames of one section fromGET /schema/migrationskeep theirsince.A
pinEffected build puts two configuration shapes in circulation at once -- a value stored before the pin is tag-keyed, one stored after it is keyed from the root -- and the table'sdeployment-method.<tag>.<name> -> <name>bridge is a single wildcard step, so it reached a branch setting the operator holds directly but not a rename inside one. Each rename recovered under the pinned tag is now emitted a second time with the prefix stripped, after the lift rather than before it, so an old-shaped value is carried by the tag-keyed entry or the stripped one and a new-shaped value by the stripped one alone; a move out of the branch has no root-shaped reading, so only an entry with both sides under the tag is re-emitted. The schema prune needs the same second anchor for the mirror reason -- it runs after the union collapse, by which point the alias is already at the root -- so it asks for the table the pin actually serves rather than the bare type's.removeAtPathalso learns how a union is actually emitted.module-schemagives anattrTageach branch inlined atoneOf[i].properties.<tag>, so afromreaching underdeployment-methodmet a node withoneOfand nopropertiesand the step no-opped, leaving the legacy node in the served schema. A step now enters every in-place subschema branch as well -- in place being the distinction that matters, since such a branch describes the same instance location its parent does -- andjson-schema.nixgains that subset beside the lists it already classifies, being the file that owns the vocabulary every walk here shares.A key upstream removes is not a rename: it has no
to, so no entry can carry a value across it, rule 1 makes the bump throw, and a stored value still keyed on it fails validation. Rejecting it stays the whole of the response -- dropping it would discard operator data on a read path -- but the rejection now says why. The 400 lists every stored path the pinned source has no place for and names the remedy, that re-saving the form drops them, instead of jsonschema reporting one unexpected property with no indication of what became of it. Inside a union only a path no branch offers is listed: one a sibling branch offers is a wrong pick rather than a removal, and a branch that turned down an ancestor never looked inside, so it says nothing either way. Any other kind of validation failure keeps jsonschema's own message.The peertube schema comes from the
peertube-config-schemapin, which is the PeerTube release thatpkgs.peertubepackages:config/config-schema.jsonfirst ships in 8.3.0, and when the pin andpkgs.peertube.versiondiffer the evaluation fails and gives thenpins addcommand to run. The pin is read rather thanpkgs.peertube.src, because that is an import from derivation and the sandboxednix-unitchecks cannot build it. https://github.com/NixOS/nixpkgs/pull/565211 installs the file asshare/config-schema.json, but reading it from there would make each evaluation depend on the 1.5 GiB package output.Each component that gives an upstream schema to
optionType-- mastodon, peertube, pixelfed, authelia and lldap -- keeps asettings-renames.jsonbeside it and passes it asrenames. Pixelfed's entries use environment variable names, because its schema is keyed byx-env. All the tables ship as[]. Peertube's says why rather than leaving a reader to assume nobody looked: the releases that ship the schema, 8.3.0-rc.1, 8.3.0 and 8.3.1, ship the same document byte for byte, so no bump between them moves a key. Running the candidate tool over thedevelophistory finds exactly one rename,rates_limit.comments->rates_limit.create_comment, and no release ever carried the old name. Rate limits are the hosting provider's capacity decision, sorates_limitis absent fromoperatorSettingsandcheckedRenameswould refuse the entry on exactly that ground.Finding the first real entry by hand means diffing two 100k-line documents, so
nix run ./core#settings-rename-candidates -- OLD.json NEW.jsonranks which added key each removed one most likely became, scoring name similarity with the shape descriptor as a modifier and tie-breaking under the target the key's own parent was matched to. It diffs the raw upstream documents rather than the narrowed ones, because at the moment it is needed the selection is stale and the narrowed new schema cannot be evaluated at all. It is advice, not a gate: it exits 0 whatever it finds, writes nothing, and emitsupstreamas a placeholder so the suggested block cannot be pasted without a human recording what upstream did. The gates stay rule 1 andcheckedRenames. Resolving the old side from git is deliberately out of scope -- it would need agit show, a parse of npins' record shape and network fetches inside a tool whose value is being pure -- socore/lib/README.mdcarries the recipe instead, with the pin and the file of each schema: the new document is the pin as it stands, and the old one is the revision that the bump replaced. Where the application publishes the schema does not change that, since the old side is the release a previous revision of a pin had whether the document comes from the source, a package output or a pin of its own. Only the document being a file in this repository would remove the steps, which is a decision about vendoring upstream's schema rather than about the tool.#629 suggests string similarity by
fuzz.token_sort_ratio. The tool usesdifflib.SequenceMatcherfrom the standard library instead, so it adds no dependency. On an edit inside a name (enabled->enable,log.level->logging.level) the two measures give the same score.token_sort_ratiosorts the words before it compares, so it gives a higher score only when the same words change order and_,-or.separate them:max_file_size->file_size_maxscores 1.00 against 0.69 here. It does not split camelCase, somaxFileSize->fileSizeMaxgets 0.73 against 0.64 only because it lowercases. The cost of a sorted comparison is thata.b.candc.b.ascore 1.00, so a key and a sibling made of the same words become equal. The tool uses position in other ways: it scores the leaf name (weight 0.6) apart from the full path (weight 0.4), and the parent alignment settles the ties that a key moved under a renamed parent gives. These are the common upstream renames, and the tool ranks them first. A word reordering ranks lower, but it usually stays in the top 3 above the threshold of 0.5. If reorderings become a problem, the standard library can do the same: split the leaf on_,-,.and camelCase, and take the higher of the raw ratio and the ratio of the sorted words. #629's editable CSV review maps to the advice block with itsupstreamplaceholder, and the gate stayscheckedRenames.Nothing that ships moved:
api-renames.jsonandapi-schema.jsonbuild to the same store paths as onmain, since the real configuration type declares no rename at any depth and the shipped tables are empty.Verified locally on this tree:
treefmt,core-docs, thenix-unitsuiteslib,lib-application-schemas,lib-json-schema,lib-json-schema-suite,lib-option-selection,lib-renames-for-source,lib-nixos-service-options,components-autheliaandcomponents-mastodon-oidc,lib-settings-rename-candidates,api-python-tests,api-schema-parity,api-pinned-schema,panel-python-testsandpanel-js-tests.Closes #1503, #1504 and #1505. #629 stays open: its stable-release reconstruction sub-item is untouched.
Assisted-by: Claude:claude-opus-5-5
https://claude.ai/code/session_01JQTGNdhrToTVdVRm9QJwXw
@ -442,0 +457,4 @@The declared kind is checked at build time (`checkedRenames`) against thenarrowed schema the operator is offered, so an entry that could not migrateanything is a build failure rather than a silent no-op: the `to` path has to endat a key the form offers, the `from` path has to be gone from it, `upstream` hasthese seem naive: upstream changes will keep coming, which could even have things move back and forth, while an operator's configuration will be at one given version at a time, which as such can only match the restrictions imposed by a schema at one such version at a time as well
@ -442,0 +462,4 @@by following later entries' `from` -- the same thing list order makes`migrate_value` do. Wildcard segments are refused there, because `narrow` sealsevery object it emits with `additionalProperties: false` and so leaves no openlevel for a wildcard to range over. Each checked entry is emitted with thewait, what's this
narrowand could we not do this?core/lib: carry a stored configuration across a rename inside a pinned schemato WIP: core/lib: carry a stored configuration across a rename inside a pinned schema@ -0,0 +1 @@[]i'm not sure which peertube version we're on, but has this application not had changes to its schema prior to our version? it would probably be good to have actual data here, to make things more concrete.
developbranch only still... 🤦♀️subscribed for new releases
https://github.com/NixOS/nixpkgs/pull/565211
no renames document just yet i guess, let's see what we can do
@ -93,6 +93,17 @@ publishes (`core/lib/json-schema.nix`). Mastodon's and pixelfed's`upstream` rows judge their `.env` keys, which no NixOS module option reaches oneby one; those are recorded but not yet offered.A pinned schema moves on a dependency bump exactly as a nixpkgs option treei think there are some nuances here: the way we collect this for nixos is currently a snapshot, while for JSON-Schema, i think we may more easily get the historical changes between versions.
(sooner or later, we may need to consider how to reconcile these, as one may need to update gradually to be able to get from A to C thru B, if those change may be publish only separately, as would be the case at least for the NixOS option markers.)
@ -16,0 +54,4 @@Resolving the old side automatically is deliberately not the tool's job: itwould need a `git show`, a parse of npins' record shape and a network fetch,three couplings inside something whose value is being a pure function of twoJSON files.so, while nixpkgs unstable's peertube version currently lacks the json schema, in practice we expect to use application versions that do carry them. would that make this more viable?
32ae02f5ee5a6ff6df2fWIP: core/lib: carry a stored configuration across a rename inside a pinned schemato core/lib: carry a stored configuration across renames no single pin declares@ -175,2 +385,3 @@);indeclared ++ pinLift;history ++ pinLift ++ pinStripped;how would this history approach deal with situations with a historical rename log like this?
is it not too naive to deal with this still?
5a6ff6df2fd26507170f@ -122,0 +138,4 @@unversioned configuration is read as, so the two agree that nothing hasbeen passed yet."""return max((entry.get("since") or 0 for entry in renames), default=0)could/should we not use conventions w.r.t. order to make this faster (e.g. head/tail version)?
de10b5c8f703127277d4@ -517,0 +524,4 @@produces the entry, at whatever depth the module declares it.- **Value-space renames inside a schema-carrying option**, declared as databeside the application -- see`core/components/operator/peertube/settings-renames.json`. Where an option'sthis path seems hard-coded in a few places, but we may want to confirm the pattern generalizes to the other applications (once we have schemas for them)
@ -17,0 +33,4 @@which added key each removed one most likely became:```nix run ./core#settings-rename-candidates -- OLD.json NEW.jsonTODO actually try out this suggestion UX
this just prints suggestions in human or
--jsonshape71a68ddf78e98d3e3c63vulnix#2416e98d3e3c6349d689d868