fix(controlplane): rewrite stored contracts with a null spec to `spec: {}`
Since v1.135.3, the control plane and the CLI reject a YAML contract that has an empty spec: line:
v2 Contract format error: error unmarshalling raw message: :6:6 spec: value is required (required)
The cause is the update of buf.build/go/protoyaml from v0.7.0 to v0.8.0 (#3816). protoyaml v0.8.0 leaves a message field unset when its YAML value is null (bufbuild/protoyaml-go#72). v0.7.0 set an empty message.
The v0.8.0 behavior is the correct one: in the protobuf JSON mapping, null for a message field means "not set", and protojson already rejected "spec": null. So we keep it, and we update the stored data instead.
This change adds a migration that rewrites the null top-level spec of stored YAML contracts (spec:, spec: null or spec: ~) to spec: {}. This keeps the meaning of the stored text, and the control plane and the CLI can read these contracts again. It also uses spec: {} in the empty contract example of the docs, which had an empty spec:.
Behavior
| Contract text | Up to v1.135.2 | v1.135.3 and v1.135.4 | With this change |
|---|---|---|---|
Stored with spec:, spec: null or spec: ~ | valid, empty spec | invalid on each read | rewritten to spec: {}, valid |
New, with spec: | valid | invalid | invalid |
New, with spec: {} | valid | valid | valid |
JSON with "spec": null | invalid | invalid | invalid |
Migration
- It changes only rows with the
yamlformat, and only a nullspecat the top level of the document. Aspecwith fields, a nestedspeckey and JSON rows do not change. - It keeps a comment on the
spec:line and the line endings of the document. - It skips a row that is not valid UTF-8, so the migration cannot fail on such a row.
- A second run changes nothing.
raw_bodyis immutable in the application. The migration changes the stored text of past contract revisions, but it does not change what they mean.
FAQ
Why not keep the v0.7.0 behavior in the parser?
It is not correct by the protobuf JSON mapping, and it is not consistent with JSON. We can keep the strict parser if we update the stored data once.
What must users do?
Update the control plane, so that the migration runs. A contract file that a user keeps in a repository with an empty spec: is now rejected on create and update: change it to spec: {}. The release notes must say this.
Do CLI v1.135.3 and v1.135.4 still fail?
No. They parse the contract that the control plane sends, and after the migration that text has spec: {}.
This change was made with AI assistance (Claude Code).