Repository navigation
fix(contractspec): treat a new response enum value as additive - #5095
Conversation
The API contract rules say response enums gain values after the 1.0 lock and clients keep an unknown fallback, but the oasdiff policy rated response-property-enum-value-added as an error. Before the lock each such addition needed an approval entry; once contracts/api/v2/LOCKED exists it would fail with no override. Lower that one rule to INFO so it is reported but never breaking. Request enums stay closed: removing a request value is still breaking, and adding one was already INFO. The 14 approvals for the rule on main can no longer match a breaking change, so they go. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Warning Review limit reachedEnable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing. Next included review available in 7 minutes. View limit details
|
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Lowering response enum additions to INFO let two changes through that were caught before only because every addition was an error. A rename removes one response enum value and adds another, and oasdiff rates the removal INFO. A new tag value on one oneOf variant that a sibling already uses makes a response match both. Diff now keeps an addition breaking when the same operation, property, and status also lose a value. The spec lint requires the named variants of a oneOf to keep at least one shared enum tag disjoint. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
| for _, value := range v.Properties[name].Enum { | ||
| if value != nil && seen[value] { | ||
| disjoint = false | ||
| } | ||
| seen[value] = true |
There was a problem hiding this comment.
Object-valued enum entries crash the contract lint
Valid object or array enum values become maps or slices in []any, causing a panic when used as seen keys and aborting contract verification. Compare enum values in a way that supports non-comparable types.
Prompt for LLM
File internal/contractspec/lint.go, lines 430-434:
Object-valued enum entries crash the contract lint
JSON Schema permits object and array enum values, but unmarshaling them into `[]any` produces maps and slices that panic when used as `seen` map keys. A valid contract containing such a shared enum in named variants therefore aborts the contract verification instead of producing lint results.
Talk to Kody by mentioning @kody
Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.
| var tags []string | ||
| for _, name := range sortedKeys(variants[0].Properties) { | ||
| shared := true | ||
| for _, v := range variants { | ||
| if p := v.Properties[name]; p == nil || len(p.Enum) == 0 { |
There was a problem hiding this comment.
Composed variants bypass the new tag collision check
Variants expressed through allOf or component aliases can hide tag collisions, allowing an ambiguous oneOf to pass the diff and lint gates. Resolve composed and referenced variant properties before checking tags.
Prompt for LLM
File internal/contractspec/lint.go, lines 414-418:
Composed variants bypass the new tag collision check
Named variants expressed through `allOf` or a component alias have no direct `Properties`, so the shared-tag search silently skips them. Adding a tag value already used by another variant can then pass the additive diff and lint gates while creating an ambiguous `oneOf`; resolve composed and referenced variant properties before checking tags.
Talk to Kody by mentioning @kody
Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.
| for _, value := range v.Properties[name].Enum { | ||
| if value != nil && seen[value] { | ||
| disjoint = false | ||
| } | ||
| seen[value] = true |
There was a problem hiding this comment.
Nullable tag collisions pass the variant disjointness check
Two nullable variants can both accept null, allowing an ambiguous oneOf to pass linting. Treat null as an ordinary enum value when checking disjointness.
Prompt for LLM
File internal/contractspec/lint.go, lines 430-434:
Nullable tag collisions pass the variant disjointness check
Two nullable variants can both accept a tag value of `null`, but the overlap is ignored and the lint accepts the ambiguous `oneOf`. Treat `null` as an ordinary enum value when checking disjointness.
Suggested code:
if seen[value] {
disjoint = false
}
Talk to Kody by mentioning @kody
Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.
| if disjoint { | ||
| return | ||
| } |
There was a problem hiding this comment.
Optional tags are treated as proof that variants are disjoint
An object omitting an optional tag can satisfy multiple variants even when their tag enums are disjoint. Require the distinguishing tag in every variant before treating its enum values as proof of disjointness.
Prompt for LLM
File internal/contractspec/lint.go, lines 437-439:
Optional tags are treated as proof that variants are disjoint
Disjoint enum values do not distinguish variants when the tag property is optional: an object omitting it can satisfy multiple branches, but the lint returns successfully. Require the distinguishing tag in every variant before treating its enum values as proof of disjointness.
Talk to Kody by mentioning @kody
Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.
An optional enum that differs between variants can't tell a response apart, since the response may omit it. The variant tag lint now considers only enum members every variant requires. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
…tive Main's contract check (#5095) classes a new response enum value as additive, so the two approvals for the recommended row type match no change and fail the check as stale. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Problem
Related issue: N/A
Validation tasks: none
Other clients: Apple N/A (no client-visible change); Android N/A (no client-visible change); Roku N/A (no client-visible change)
The contract rules say a response enum may gain values after the 1.0 lock: AGENTS.md says "New functionality adds fields, enum values, or operations", and
docs/architecture/api-contract.mdsays response enums are additive and clients keep an unknown fallback. The contract checker disagreed. oasdiff ratesresponse-property-enum-value-addedas an error, andPolicytreats every error as breaking. Before the lock each new response enum value needs an approval entry; main carries 14 of them, all for this rule. Oncecontracts/api/v2/LOCKEDexists, approvals no longer apply, so any PR that adds a response enum value would failmake verify-apiv2-contractwithlocked contract: ... response-property-enum-value-added, with no way through.Approach
Diffnow builds the oasdiff config withchecker.WithSeverityLevels, lowering that one rule to INFO. The finding is still printed, but it is no longer breaking, before or after the lock. I dropped the pre-lock approval requirement for it on purpose: the rules call the change additive in both phases, and an approval that is required now and forbidden later only adds noise to the allowlist.Request enums stay closed. oasdiff already rates request enum additions as INFO and keeps removals as errors, and this leaves both alone. Response
oneOf/anyOfadditions also stay breaking. The doc calls discriminated response variants additive, but the spec has no discriminators today, and lowering those rules would also open up non-discriminated unions.Two changes stay blocked. They were caught before only because every addition was an error. A rename removes one response enum value and adds another, and oasdiff rates the removal alone as INFO, so
Diffkeeps an addition breaking when the same operation, property, and status also lose a value. A new tag value on oneoneOfvariant that a sibling already uses lets a response match both variants, so the spec lint now requires named variants to keep at least one shared, required enum tag disjoint. EveryoneOfin the spec passes.The 14 approval entries on main can no longer match a breaking change, so this removes them.
api-contract.mdnow states the checker's behavior for response enum additions.Validation
oneOfvariants that share akindvalue. It fails on main for the reported reason (unapprovedbefore the lock,locked contractafter) and passes on this branch. The rename and variant checks failed on the earlier heads of this PR and pass now.openapi.jsonchange with an empty allowlist and aLOCKEDmarker: main fails on all 14 enum additions; this branch prints them atinfoand passes.go test ./internal/contractspec/,make verify-apiv2-contract BASE_REF=origin/main, andmake lint-changedpass.Evidence: https://evidence.siloserver.org/r/silo-server/contract-response-enum-additive/
Risks
An open PR that added an approval for
response-property-enum-value-addedwill fail as a stale approval after this merges, and has to delete that entry. #4621 has 8 such entries. Such PRs already have to drop main's 14 when they rebase.A rename is matched by operation, property, and response status. oasdiff doesn't name the media type in its findings, so a value removed from one media type and another added to the same property in a second media type would read as a rename and fail. That errs toward blocking, and no current response has enums in more than one media type.
The gate does not check that each native client decodes a response enum with an unknown fallback. That stays a client-side rule, as before.
Checklist
Council review
Ran as a follow-up run, with one member at high effort. The plan round was skipped because the fix is mechanical.
Rounds: 2, last reviewed da6630a
Fixed: a response enum rename passed the locked gate; a
oneOfvariant tag shared with a sibling passed; an optional enum could stand in for the variant tag (fixed after round 2, not re-reviewed). Answered: a cross-media-type rename match errs toward blocking (see Risks). Neither round posted on the PR; findings came back to the run.AI Disclosure
Change. The background review's two findings are fixed (see Council review). The simplify pass changed nothing. See Council review for the background review.🤖 Generated with Claude Code
Note
Treat new response enum values as additive in contractspec diff and lint
response-property-enum-value-addedrule to INFO severity inadditiveRules, so a plain response enum addition no longer requires approval. In diff.go, additions are correlated with removals by operation, path, property, and status via the newenumPropertyKeyhelper; if the same response property also loses a value, the addition is reported at ERR severity (breaking).lintVariantTagscheck in lint.go that reportsoneOfschemas whose variants share values for every shared required enum tag. The former nullable-enum traversal is generalized intowalkSchema, which visits properties, items, additionalProperties, andoneOf/anyOf/allOfbranches.oneOfschemas lacking a disjoint required enum tag now produce a new lint finding. Renames (add+remove on the same property) remain breaking. Adds tests in diff_test.go and lint_test.go.Macroscope summarized a4a5ccf.