diff --git a/.github/reconcile-models/RULES.md b/.github/reconcile-models/RULES.md index 48ace7f1..33d36475 100644 --- a/.github/reconcile-models/RULES.md +++ b/.github/reconcile-models/RULES.md @@ -17,7 +17,7 @@ What a reconcile-models run changes, what it skips and why, and what it hands to 5. **Only what the report can list.** Change only values a report field covers, so an existing `Description` stays as it is. A new model's `Description` comes from its vendor's own pages. 6. **Append-only.** Adding a model never edits an existing entry: ordering, succession and price tiers are derived when the catalogue is read, and a newer model in a series is a new entry. Adding a regional copy extends its family, and may re-route the family's bare names only as new-copy-offered-region says. A retired model keeps its entry, so old usage stays priceable. 7. **No questions, little prose.** No person takes part in a CI run, so the bot never stops to ask: a case that needs a person becomes a `needs_human` row with its Ask's fixed question. A hand run asks the person that question instead. The report's only free text is three short sentences on a `needs_human` row (`why`, `rule_when` and `rule_does`, in plain characters; see Report values): every other value is an ID, a field, a skip reason, a short value or a URL on a named host, and code writes the rest of the PR's notes. Every row names the rule that gives its outcome: a `changes` row names the Default for its field, and a `skipped` or `needs_human` row its Default or Ask, or no-rule when none does. Skip an offering only when a rule leaves it out, and never beside a `needs_human` row for it, so a skip always means something. A `no_catalog_field` row leaves out one fact, not the offering, so it can stand beside the offering's other rows. -8. **Recorded decisions.** Read `.github/reconcile-models/decisions.yaml` before proposing changes, and don't change a decided value, so later runs don't reopen what a review settled. Still report the rows the rules call for; the PR shows a row a decision answers as held, linked to the decision. Each decision names one offering and field, its kind (keep or hold), a public reason and a `review_by` date, and never widens sources, paths or checks; a case that would need many decisions becomes a rule here instead. Decisions change only in reviewed PRs. +8. **Recorded decisions.** Read `.github/reconcile-models/decisions.yaml` before proposing changes, so later runs don't reopen what a review settled. A keep fixes a value, or only the parts its `keys` name: don't change it. A hold on `new_model` or `new_copy` keeps that model or copy out; a hold on another field leaves the value out while its `rule` still asks, and never stops a change another rule makes. A decision that names a `rule` answers only that rule's questions. Still report the rows the rules call for; the PR shows a row a decision answers as held, linked to the decision. Each decision names one offering and field, its kind, a public reason and a `review_by` date, and never widens sources, paths or checks. `review_by` is three months after `decided`, or a year for a decision that records a lasting choice rather than a wait for a fix; its reason then says so. A case that covers many models becomes a rule here instead; one model's case may take a decision for each of its IDs. Decisions change only in reviewed PRs. ## Report values diff --git a/.github/reconcile-models/decisions.yaml b/.github/reconcile-models/decisions.yaml index 2566902c..2c082d80 100644 --- a/.github/reconcile-models/decisions.yaml +++ b/.github/reconcile-models/decisions.yaml @@ -1,7 +1,78 @@ # Review decisions for reconcile-models runs; RULES.md (Principles) says how they work. # Public file: no people, customers, internal systems or ticket keys. # An offering is :. A keep's lock uses the field's shape in -# catalog/snapshot.json; a hold is on new_model or new_copy with no lock. +# catalog/snapshot.json, or only the parts its keys name. A hold takes no lock; +# on a field other than new_model or new_copy it names the rule whose question +# it answers, never no-rule, and on those two no rule. The PR that closes a held +# gap deletes its hold. +# review_by is three months after decided; a decision that records a lasting +# choice, not a wait for a fix, gets a year, and its reason says so. The check +# refuses a date more than a year out; the three months are the reviewer's to +# check. # TestDecisionsHold fails on a contradiction and prints the current value to # paste as a lock. -decisions: [] +decisions: + - id: DEC-001 + offering: bedrock:global.amazon.nova-2-lite-v1:0 + field: price + kind: hold + rule: out-of-reach + reason: "AWS prices Nova 2 Lite profile calls by the calling region, but the catalogue holds one rate per profile and a profile's reply doesn't name that region, so these rates wait for SDK support." + decided: 2026-11-17 + review_by: 2027-02-17 + - id: DEC-002 + offering: bedrock:eu.amazon.nova-2-lite-v1:0 + field: price + kind: hold + rule: out-of-reach + reason: "AWS prices Nova 2 Lite profile calls by the calling region, but the catalogue holds one rate per profile and a profile's reply doesn't name that region, so these rates wait for SDK support." + decided: 2026-11-17 + review_by: 2027-02-17 + - id: DEC-003 + offering: bedrock:us.amazon.nova-2-lite-v1:0 + field: capability + kind: hold + rule: reasoning-unsendable + reason: "Nova 2 Lite takes reasoning efforts through reasoningConfig, but the SDK's Bedrock code sends reasoning only in Anthropic's format, so the efforts stay out until it sends reasoningConfig." + decided: 2026-11-17 + review_by: 2027-02-17 + - id: DEC-004 + offering: bedrock:eu.amazon.nova-2-lite-v1:0 + field: capability + kind: hold + rule: reasoning-unsendable + reason: "Nova 2 Lite takes reasoning efforts through reasoningConfig, but the SDK's Bedrock code sends reasoning only in Anthropic's format, so the efforts stay out until it sends reasoningConfig." + decided: 2026-11-17 + review_by: 2027-02-17 + - id: DEC-005 + offering: bedrock:global.amazon.nova-2-lite-v1:0 + field: capability + kind: hold + rule: reasoning-unsendable + reason: "Nova 2 Lite takes reasoning efforts through reasoningConfig, but the SDK's Bedrock code sends reasoning only in Anthropic's format, so the efforts stay out until it sends reasoningConfig." + decided: 2026-11-17 + review_by: 2027-02-17 + - id: DEC-006 + offering: bedrock:jp.amazon.nova-2-lite-v1:0 + field: capability + kind: hold + rule: reasoning-unsendable + reason: "Nova 2 Lite takes reasoning efforts through reasoningConfig, but the SDK's Bedrock code sends reasoning only in Anthropic's format, so the efforts stay out until it sends reasoningConfig." + decided: 2026-11-17 + review_by: 2027-02-17 + - id: DEC-007 + offering: fireworks:accounts/fireworks/models/deepseek-v4p1-flash + field: capability + kind: hold + rule: reasoning-unsendable + reason: "Fireworks documents a hard thinking budget for DeepSeek V4.1 only on Chat Completions, but the SDK calls these models through Messages, which has none, so the budget stays out until the SDK can send it." + decided: 2026-11-17 + review_by: 2027-02-17 + - id: DEC-008 + offering: fireworks:accounts/fireworks/models/deepseek-v4p1-flash-1017 + field: capability + kind: hold + rule: reasoning-unsendable + reason: "Fireworks documents a hard thinking budget for DeepSeek V4.1 only on Chat Completions, but the SDK calls these models through Messages, which has none, so the budget stays out until the SDK can send it." + decided: 2026-11-17 + review_by: 2027-02-17 diff --git a/REVIEW.md b/REVIEW.md index 715021b0..a6682000 100644 --- a/REVIEW.md +++ b/REVIEW.md @@ -141,10 +141,15 @@ To review one: row covers needs a new rule. - Settle each question in "Open questions" as its Decide line says, or record a decision in `.github/reconcile-models/decisions.yaml`, in a PR to the base - branch. A decision stops the question coming back. You may also merge with a - question open; the next run asks it again. + branch. A decision stops the question coming back. For a gap the SDK can't + fill yet, record a `hold` that names the question's rule; the PR that adds + the support deletes it. You may also merge with a question open; the next + run asks it again. - In "Held by decisions", each value should still match its entry in - `.github/reconcile-models/decisions.yaml`. + `.github/reconcile-models/decisions.yaml`. The line that counts recorded + decisions also names any decision that names a rule, on a model the + catalogue carries, and answered no question this run. A run can miss a + question, so delete it only if its reason no longer holds. - Approve a move in "Routing changes" only if every caller of that name can take the new profile and its price. - Read the files under "Code changed" as code before marking the PR ready: that diff --git a/cmd/catalog-report/report.go b/cmd/catalog-report/report.go index f7a4e4da..c1b75e43 100644 --- a/cmd/catalog-report/report.go +++ b/cmd/catalog-report/report.go @@ -911,8 +911,9 @@ func (base Base) questionBlock(q numbered) string { // principle 8). func (base Base) decide(q numbered) string { item, n := q.row, len(q.offerings) - // decisions.yaml takes no decision on a location, and a keep on a fact - // the catalogue lacks has nothing to lock, so a rule stops those too. + // decisions.yaml takes no decision on a location, and a fact the + // catalogue lacks can take neither a keep (nothing to lock) nor a hold + // (it can't name no-rule), so a rule stops those too. added := item.Field == reconcile.FieldNewCopy || item.Field == reconcile.FieldNewModel none := !added && strings.EqualFold(item.Catalogue, "none") stop := func(kind string) string { @@ -951,11 +952,15 @@ func sameOffering(reported, provider, decided string) bool { } // hold takes the needs_human and skipped rows a decision already answers out -// of the report, and returns the rest with the held table's rows. -func (base Base) hold(report Report, provider string) (Report, []string) { - find := func(offering string, wanted ...string) (reconcile.Decision, bool) { +// of the report, and returns the rest with the held table's rows and the IDs +// of the decisions that answered one. A decision that names a rule answers +// only that rule's rows. +func (base Base) hold(report Report, provider string) (Report, []string, map[string]bool) { + answered := map[string]bool{} + find := func(offering, rule string, wanted ...string) (reconcile.Decision, bool) { for _, d := range base.Decisions { - if slices.Contains(wanted, d.Field) && sameOffering(offering, provider, d.Offering) { + if slices.Contains(wanted, d.Field) && sameOffering(offering, provider, d.Offering) && d.Answers(rule) { + answered[d.ID] = true return d, true } } @@ -973,7 +978,7 @@ func (base Base) hold(report Report, provider string) (Report, []string) { var needs []NeedsHuman for _, item := range report.NeedsHuman { - if d, ok := find(item.Offering, item.Field); ok { + if d, ok := find(item.Offering, item.Rule, item.Field); ok { held = append(held, row(d, item.Offering, valueList(rowValues(item)))) } else { needs = append(needs, item) @@ -983,7 +988,7 @@ func (base Base) hold(report Report, provider string) (Report, []string) { var skipped []Skipped for _, item := range report.Skipped { - if d, ok := find(item.Offering, reconcile.FieldNewModel, reconcile.FieldNewCopy); ok { + if d, ok := find(item.Offering, item.Rule, reconcile.FieldNewModel, reconcile.FieldNewCopy); ok { held = append(held, row(d, item.Offering, item.Reason)) } else { skipped = append(skipped, item) @@ -992,7 +997,7 @@ func (base Base) hold(report Report, provider string) (Report, []string) { report.NeedsHuman, report.Skipped = needs, skipped - return report, held + return report, held, answered } // byRule groups change rows by rule, in RULES.md's order so every run lists @@ -1156,8 +1161,10 @@ func (base Base) splitWaiting(report Report) (Report, []Skipped) { } // summary is one line about decisions.yaml itself: how many decisions it -// holds, and which are past their review date. It shows on every run. -func (base Base) summary() string { +// holds, which are past their review date, and which of those that name a +// rule answered no question in a run that checked them. It shows on every +// run. +func (base Base) summary(parts []vendorPart) string { if len(base.Decisions) == 0 { return "" } @@ -1175,8 +1182,58 @@ func (base Base) summary() string { due = strings.Join(overdue, ", ") + " (still enforced)." } - return fmt.Sprintf("Recorded decisions: %d, in %s. Past their review date: %s\n\n", + line := fmt.Sprintf("Recorded decisions: %d, in %s. Past their review date: %s", len(base.Decisions), base.fileLink("decisions.yaml", reconcile.DecisionsPath, 0), due) + if ids := base.unanswered(parts); len(ids) > 0 { + line += fmt.Sprintf(" Answered no question this run: %s. A run can miss a question, so delete %s only if its reason no longer holds.", + strings.Join(ids, ", "), plural(len(ids), "it", "one")) + } + + return line + "\n\n" +} + +// unanswered names each decision that names a rule, on an offering the +// catalogue carries, that answered no question in the run of its model's +// publisher. Each vendor's catalogue holds every offering, so any one will +// do; a vendor whose patch changed nothing brings none, and when none did, +// nothing is named. A decision with no rule is never named: a keep may stop +// a change a Default would make, which raises no question, and a hold on +// new_model or new_copy ends when its offering is added (TestDecisionsHold +// fails) or at its review date. +func (base Base) unanswered(parts []vendorPart) []string { + var catalogue *reconcile.Snapshot + + // answered holds, for each vendor whose run didn't fail, the decisions + // that answered one of its questions. + answered := map[string]map[string]bool{} + + for _, part := range parts { + if catalogue == nil { + catalogue = part.Before + } + + if !part.Failed { + answered[part.Name] = part.answered + } + } + + if catalogue == nil { + return nil + } + + var ids []string + + for _, d := range base.Decisions { + offering, found := catalogue.Offering(reconcile.PackageOf(d.Offering, "")) + model, _ := offering["model"].(string) + publisher, _ := catalogue.Facts[model]["publisher"].(string) + + if used, ran := answered[publisher]; found && ran && d.Rule != "" && !used[d.ID] { + ids = append(ids, d.ID) + } + } + + return ids } // Vendor is one vendor's part of the PR: its report, and the catalogue @@ -1207,6 +1264,7 @@ type vendorPart struct { base Base shown Report held []string + answered map[string]bool waiting []Skipped asks []question unreported []string @@ -1217,7 +1275,7 @@ type vendorPart struct { func (base Base) part(vendor Vendor) vendorPart { part := vendorPart{Vendor: vendor, base: base} part.base.Before, part.base.After = vendor.Before, vendor.After - part.shown, part.held = part.base.hold(vendor.Report, vendor.Name) + part.shown, part.held, part.answered = part.base.hold(vendor.Report, vendor.Name) part.shown, part.waiting = part.base.splitWaiting(part.shown) part.asks = questions(part.shown.NeedsHuman) // Held and waiting rows still count as rows here. @@ -1265,7 +1323,7 @@ func (base Base) render(vendors []Vendor, codeFiles []string, hasDiff bool) (str body.WriteString("## Catalogue drift: " + strings.Join(names, ", ") + "\n\n") if rows == 0 && !failed && !hasDiff { - body.WriteString("No drift found.\n\n" + base.summary()) + body.WriteString("No drift found.\n\n" + base.summary(parts)) return body.String(), nil } @@ -1292,7 +1350,7 @@ func (base Base) render(vendors []Vendor, codeFiles []string, hasDiff bool) (str // says why (plan.sh, carry.sh); REVIEW.md has the details. body.WriteString("You can push commits here: the bot never removes them. It doesn't read comments.\n\n") - body.WriteString(base.summary()) + body.WriteString(base.summary(parts)) // What the PR asks of people takes a share of the room like a vendor's // section, so many questions can't push every Changes table out of a diff --git a/cmd/catalog-report/report_test.go b/cmd/catalog-report/report_test.go index 5d63a193..cb11618a 100644 --- a/cmd/catalog-report/report_test.go +++ b/cmd/catalog-report/report_test.go @@ -436,6 +436,14 @@ func TestRender(t *testing.T) { holdCopy.Field = reconcile.FieldNewCopy otherField := keepLimit otherField.Field = "price" + otherRule := keepLimit + otherRule.Rule = "out-of-reach" + sameRule := keepLimit + sameRule.Rule = reconcile.JudgmentRule + gapHold := reconcile.Decision{ + ID: "DEC-003", Offering: "anthropic:claude-sonnet-5-5", Field: "limit", Kind: reconcile.KindHold, Rule: reconcile.JudgmentRule, + Reason: "The SDK can't send it yet.", ReviewBy: "2027-01-13", Line: 20, + } // #259's copies in India, which Bedrock doesn't offer, and one in a second region. waiting := []Skipped{ {Offering: "bedrock:in.anthropic.claude-opus-5", Reason: "region_not_offered", Rule: "region-not-offered"}, @@ -831,6 +839,26 @@ func TestRender(t *testing.T) { contains: []string{"### Open questions (1)"}, notContains: []string{"### Held by decisions"}, }, + { + name: "a decision on another rule holds nothing", + report: validReport(), + base: Base{URL: baseURL, Decisions: []reconcile.Decision{otherRule}, Today: "2026-10-14"}, + contains: []string{"### Open questions (1)"}, + notContains: []string{"### Held by decisions"}, + }, + { + name: "a decision on the question's rule holds it", + report: validReport(), + base: Base{URL: baseURL, Decisions: []reconcile.Decision{sameRule}, Today: "2026-10-14"}, + contains: []string{"### Held by decisions (1)"}, + }, + { + name: "a hold on a field holds its rule's question", + report: validReport(), + base: Base{URL: baseURL, Decisions: []reconcile.Decision{gapHold}, Today: "2026-10-14"}, + contains: []string{"| [DEC-003](" + decisionsURL + "#L20) | `claude-sonnet-5-5` | limit | `65535`, `65536` | The SDK can't send it yet. |"}, + notContains: []string{"### Open questions"}, + }, { name: "an overdue decision is named even with no drift", report: Report{}, @@ -884,6 +912,62 @@ func TestRender(t *testing.T) { } } +// TestRenderUnansweredDecisions checks that the decisions line names a +// decision that answered no question in a run of its model's vendor, so a +// record whose case is gone gets deleted. +func TestRenderUnansweredDecisions(t *testing.T) { + t.Parallel() + + snap, err := reconcile.ParseSnapshot([]byte(`{ + "facts": {"anthropic/claude-sonnet-5-5": {"publisher": "anthropic"}, "anthropic/claude-opus-5-5": {"publisher": "anthropic"}}, + "providers": [{"provider": "anthropic", "offerings": [ + {"id": "claude-sonnet-5-5", "model": "anthropic/claude-sonnet-5-5"}, + {"id": "claude-opus-5-5", "model": "anthropic/claude-opus-5-5"}]}]}`)) + require.NoError(t, err) + + stale := keepLimit + stale.ID, stale.Offering, stale.Rule = "DEC-002", "anthropic:claude-opus-5-5", "out-of-reach" + // A keep with no rule may stop a Default's change, which raises no + // question, so answering none says nothing about it. + guard := keepLimit + guard.ID, guard.Offering, guard.Field = "DEC-003", "anthropic:claude-opus-5-5", "price" + base := Base{Decisions: []reconcile.Decision{keepLimit, stale, guard}, Today: "2026-10-14"} + const named = "Answered no question this run: DEC-002. A run can miss a question, so delete it only if its reason no longer holds." + + tests := []struct { + name string + vendors []Vendor + want string + }{ + { + "names a decision its vendor's run didn't use", + []Vendor{{Name: "anthropic", Report: validReport(), Before: &snap, After: &snap}}, + named, + }, + { + "reads another vendor's catalogue when this one changed nothing", + []Vendor{{Name: "anthropic", Report: validReport()}, {Name: "openai", Before: &snap, After: &snap}}, + named, + }, + {"names none when no vendor brings a catalogue", []Vendor{{Name: "anthropic", Report: validReport()}}, ""}, + {"names none for a failed run", []Vendor{{Name: "anthropic", Failed: true}, {Name: "openai", Before: &snap, After: &snap}}, ""}, + {"names none for another vendor's run", []Vendor{{Name: "openai", Report: validReport(), Before: &snap, After: &snap}}, ""}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + + body := Render(tt.vendors, "", nil, base) + if tt.want == "" { + assert.NotContains(t, body, "Answered no question") + return + } + + assert.Contains(t, body, tt.want) + }) + } +} + // TestRenderCarried checks the line under the checks line (proposal 12): each // commit people pushed that the carry job carried, and that such commits get // fewer checks than the bot's own (carry.sh). diff --git a/cmd/catalog-report/rules_test.go b/cmd/catalog-report/rules_test.go index 1c7afef6..9fb5f8d5 100644 --- a/cmd/catalog-report/rules_test.go +++ b/cmd/catalog-report/rules_test.go @@ -76,6 +76,10 @@ func TestRulesFile(t *testing.T) { // keep must be listed as something only the agent does. assert.Contains(t, string(raw), "kept every Vertex location the model page or the locations table still lists", "Not checked by code must name location-follow's keep") + // A hold on a field answers one rule's question. If it stopped another + // rule's change, a closed SDK gap would stay out of the catalogue. + assert.Contains(t, string(raw), "never stops a change another rule makes", "principle 8 must keep a hold on a field to its rule") + unlisted := Report{NeedsHuman: []NeedsHuman{{ Offering: "vertex:claude-sonnet-5", Field: "location", Page: "us-east5", SourceURLs: []string{"https://docs.cloud.google.com/gemini-enterprise-agent-platform/resources/locations"}, Rule: "location-unlisted", diff --git a/cmd/catalog-snapshot/decisions_check_test.go b/cmd/catalog-snapshot/decisions_check_test.go index a18f13fb..134571ec 100644 --- a/cmd/catalog-snapshot/decisions_check_test.go +++ b/cmd/catalog-snapshot/decisions_check_test.go @@ -18,6 +18,7 @@ import ( "encoding/json" "fmt" "regexp" + "slices" "strings" "github.com/redpanda-data/ai-sdk-go/catalog" @@ -26,8 +27,9 @@ import ( // lockedKeys lists, for each field in RULES.md's Field table, the snapshot // keys a lock covers: "key" or "key.subkey" on the offering, or "facts.key" -// on its model. A field with one key locks that value; one with several locks -// an object of those present, keyed by their last part. +// on its model. A field with one key locks that value; one with several, or a +// decision's own keys, lock an object of those present, keyed by their last +// part. var lockedKeys = map[string][]string{ reconcile.FieldNewModel: nil, reconcile.FieldNewCopy: nil, @@ -46,8 +48,8 @@ var lockedKeys = map[string][]string{ var decisionID = regexp.MustCompile(`^DEC-[0-9]{3}$`) // checkDecisions returns one problem per decision that is malformed or that -// the snapshot contradicts. -func checkDecisions(file, snapshotJSON []byte) []string { +// the snapshot contradicts. asks maps each RULES.md Ask to its question. +func checkDecisions(file, snapshotJSON []byte, asks map[string]string) []string { entries, err := reconcile.ParseDecisions(file) if err != nil { return []string{"decisions.yaml: " + err.Error()} @@ -60,36 +62,44 @@ func checkDecisions(file, snapshotJSON []byte) []string { var problems []string - ids, keys := map[string]bool{}, map[string]string{} + ids, taken := map[string]bool{}, map[string][]reconcile.Decision{} for _, d := range entries { key := d.Offering + " " + d.Field + // Two decisions on one offering and field clash when one answers a + // question the other does, so the run would pick by file order. + clash := slices.IndexFunc(taken[key], func(o reconcile.Decision) bool { + return o.Answers(d.Rule) || d.Answers(o.Rule) + }) - switch problem := malformed(d); { + switch problem := malformed(d, asks); { case problem != "": problems = append(problems, d.ID+": "+problem) continue case ids[d.ID]: problems = append(problems, d.ID+": duplicate ID") continue - case keys[key] != "": - problems = append(problems, d.ID+": "+keys[key]+" already covers "+key) + case clash >= 0: + problems = append(problems, d.ID+": "+taken[key][clash].ID+" already covers "+key) continue } - ids[d.ID], keys[key] = true, d.ID + ids[d.ID], taken[key] = true, append(taken[key], d) pkg, id, _ := strings.Cut(d.Offering, ":") offering, exists := snap.Offering(pkg, id) where := fmt.Sprintf("%s %s %s %s: ", d.ID, d.Kind, d.Offering, d.Field) + // A hold on new_model or new_copy keeps the offering out; every + // other decision is about an offering the catalogue carries. + out := d.Kind == reconcile.KindHold && adds(d.Field) switch { - case d.Kind == reconcile.KindHold && exists: + case out && exists: problems = append(problems, where+"the offering is in the catalogue") - case d.Kind == reconcile.KindKeep && !exists: + case !out && !exists: problems = append(problems, where+"the offering is missing") case d.Lock != nil: - if got, want := canonical(lockedPart(d.Field, offering, snap.Facts)), canonical(d.Lock); got != want { + if got, want := canonical(lockedPart(d, offering, snap.Facts)), canonical(d.Lock); got != want { problems = append(problems, where+"got "+got+", locked "+want) } } @@ -98,12 +108,10 @@ func checkDecisions(file, snapshotJSON []byte) []string { return problems } -func malformed(d reconcile.Decision) string { +func malformed(d reconcile.Decision, asks map[string]string) string { pkg, id, _ := strings.Cut(d.Offering, ":") _, knownField := lockedKeys[d.Field] - _, decidedErr := catalog.ParseDate(d.Decided) - _, reviewErr := catalog.ParseDate(d.ReviewBy) - added := d.Field == reconcile.FieldNewModel || d.Field == reconcile.FieldNewCopy + added := adds(d.Field) switch { case !decisionID.MatchString(d.ID): @@ -118,23 +126,96 @@ func malformed(d reconcile.Decision) string { return "unknown field " + d.Field case d.Field == "location": return "location takes no decision yet: served locations are not in the snapshot" - case d.Kind == reconcile.KindHold && !added: - return "a hold applies only to new_model or new_copy" + case d.Kind == reconcile.KindHold && !added && d.Rule == "": + return "a hold on " + d.Field + " names the rule whose question it answers" case added && d.Lock != nil: return d.Field + " takes no lock" - case !added && d.Lock == nil: + case added && d.Rule != "": + // It answers every question and skip about its offering, whatever + // rule raised it; skipped rows name Defaults, which a decision can't. + return d.Field + " takes no rule" + case d.Kind == reconcile.KindHold && d.Rule == reconcile.JudgmentRule: + return "a hold can't name no-rule: it would hide every question no rule covers on " + d.Field + ", so add a rule to RULES.md" + case d.Kind == reconcile.KindHold && d.Lock != nil: + return "a hold takes no lock" + case d.Kind == reconcile.KindKeep && !added && d.Lock == nil: return "a keep needs a lock" + case d.Rule != "" && asks[d.Rule] == "": + return "rule " + d.Rule + " asks no question" + case len(d.Keys) > 0 && (d.Kind != reconcile.KindKeep || added): + return "only a keep on a value names keys" case d.Reason == "": return "a decision needs a reason" + } + + if problem := badDates(d); problem != "" { + return problem + } + + return badKeys(d) +} + +// badDates returns what is wrong with a decision's dates: decided and +// review_by are dates, and review_by is at most a year after decided. +func badDates(d reconcile.Decision) string { + decided, decidedErr := catalog.ParseDate(d.Decided) + reviewBy, reviewErr := catalog.ParseDate(d.ReviewBy) + + switch { case decidedErr != nil || reviewErr != nil: return "decided and review_by are YYYY-MM-DD dates" + case !reviewBy.After(decided) || reviewBy.After(decided.AddDate(1, 0, 0)): + return "review_by is after decided, and at most a year after it" + } + + return "" +} + +// badKeys returns what is wrong with a keep's keys: each is part of its +// field, and no two lock the same name. +func badKeys(d reconcile.Decision) string { + names := map[string]string{} + + for _, key := range d.Keys { + name := key[strings.LastIndex(key, ".")+1:] + + switch { + case !inField(d.Field, key): + return "key " + key + " isn't part of " + d.Field + ": name one of its snapshot keys, or one level under one" + case names[name] != "": + return "keys " + names[name] + " and " + key + " would both lock " + name + } + + names[name] = key } return "" } -// lockedPart returns the part of the snapshot a field locks (see lockedKeys). -func lockedPart(field string, offering map[string]any, facts map[string]map[string]any) any { +// adds reports whether a field is about an offering the catalogue doesn't +// carry yet: a new model, or a new copy of one. +func adds(field string) bool { + return field == reconcile.FieldNewModel || field == reconcile.FieldNewCopy +} + +// inField reports whether key is one of field's snapshot keys (lockedKeys), +// or one level under one that is a whole offering key, as lockedPart's +// lookup reads it. +func inField(field, key string) bool { + parent, child, nested := strings.Cut(key, ".") + + for _, path := range lockedKeys[field] { + if key == path || nested && parent == path && child != "" && !strings.Contains(child, ".") { + return true + } + } + + return false +} + +// lockedPart returns the part of the snapshot a decision locks: the parts +// its keys name, or else its field's (see lockedKeys). +func lockedPart(d reconcile.Decision, offering map[string]any, facts map[string]map[string]any) any { model, _ := offering["model"].(string) lookup := func(path string) (any, bool) { first, rest, nested := strings.Cut(path, ".") @@ -152,8 +233,10 @@ func lockedPart(field string, offering map[string]any, facts map[string]map[stri return value, ok } - paths := lockedKeys[field] - if len(paths) == 1 { + paths := lockedKeys[d.Field] + if len(d.Keys) > 0 { + paths = d.Keys + } else if len(paths) == 1 { value, _ := lookup(paths[0]) return value } diff --git a/cmd/catalog-snapshot/decisions_test.go b/cmd/catalog-snapshot/decisions_test.go index b197080e..99f51981 100644 --- a/cmd/catalog-snapshot/decisions_test.go +++ b/cmd/catalog-snapshot/decisions_test.go @@ -39,10 +39,15 @@ func TestDecisionsHold(t *testing.T) { file, err := os.ReadFile(filepath.Join("..", "..", ".github", "reconcile-models", "decisions.yaml")) require.NoError(t, err) + raw, err := os.ReadFile(filepath.Join("..", "..", reconcile.RulesPath)) + require.NoError(t, err) + + rules, _ := reconcile.ParseRules(raw) + var generated bytes.Buffer require.NoError(t, snapshot.Encode(&generated, allCatalogs()...)) - assert.Empty(t, checkDecisions(file, generated.Bytes()), + assert.Empty(t, checkDecisions(file, generated.Bytes(), rules.Questions), "the catalogue contradicts a recorded decision: change the code back, or update the decision in the same PR") } @@ -81,6 +86,15 @@ func TestCheckDecisions(t *testing.T) { keepGA := keep("lifecycle", `{"stage": "ga"}`) hold := item("DEC-002", reconcile.FieldNewModel, reconcile.KindHold) holdCopy := item("DEC-002", reconcile.FieldNewCopy, reconcile.KindHold) + gap := item("DEC-002", "capability", reconcile.KindHold, "rule: reasoning-unsendable") + keyed := func(keys, lock string) string { + return item("DEC-001", "capability", reconcile.KindKeep, "keys: "+keys, "lock: "+lock) + } + asks := map[string]string{ + "reasoning-unsendable": "Add support, or leave them out?", "out-of-reach": "Make it by hand?", + reconcile.JudgmentRule: "Add a rule?", + } + reviewBy := func(date string) string { return strings.Replace(keepGA, "2027-01-13", date, 1) } tests := []struct { name string @@ -104,20 +118,42 @@ func TestCheckDecisions(t *testing.T) { {"unknown key", keepGA + " colour: red\n", fable, "decisions.yaml"}, {"duplicate ID", keepGA + keepGA, fable, "DEC-001: duplicate ID"}, {"two decisions on one field", keepGA + item("DEC-004", "lifecycle", reconcile.KindKeep, `lock: {"stage": "ga"}`), fable, "DEC-004: DEC-001 already covers"}, + {"two rules share a field", gap + item("DEC-004", "capability", reconcile.KindHold, "rule: out-of-reach"), fable, ""}, + {"one rule twice on a field", gap + item("DEC-004", "capability", reconcile.KindHold, "rule: reasoning-unsendable"), fable, "DEC-004: DEC-002 already covers"}, + {"no rule beside a rule", gap + keyed(`[capabilities.tools]`, `{"tools": true}`), fable, "DEC-001: DEC-002 already covers"}, + {"a rule beside no rule", keyed(`[capabilities.tools]`, `{"tools": true}`) + gap, fable, "DEC-002: DEC-001 already covers"}, {"keep without a lock", keep("lifecycle", "null"), fable, "a keep needs a lock"}, {"lock on new_model", item("DEC-003", reconcile.FieldNewModel, reconcile.KindKeep, `lock: {"stage": "ga"}`), fable, "new_model takes no lock"}, {"lock on new_copy", item("DEC-003", reconcile.FieldNewCopy, reconcile.KindKeep, `lock: {"stage": "ga"}`), fable, "new_copy takes no lock"}, - {"hold on another field", item("DEC-002", "price", reconcile.KindHold), fable, "a hold applies only to new_model or new_copy"}, + {"hold on a field answers its rule", gap, fable, ""}, + {"hold on a field needs its rule", item("DEC-002", "price", reconcile.KindHold), fable, "DEC-002: a hold on price names the rule whose question it answers"}, + {"hold on a field needs the offering", gap, `{}`, "DEC-002 hold bedrock:eu.anthropic.claude-fable-5 capability: the offering is missing"}, + {"hold on a field takes no lock", gap + ` lock: {"capabilities": {"tools": true}}` + "\n", fable, "DEC-002: a hold takes no lock"}, + {"rule that asks no question", strings.Replace(gap, "reasoning-unsendable", "price-follow", 1), fable, "DEC-002: rule price-follow asks no question"}, + {"hold naming no-rule", strings.Replace(gap, "reasoning-unsendable", reconcile.JudgmentRule, 1), fable, "DEC-002: a hold can't name no-rule"}, + {"rule on a held model", hold + " rule: out-of-reach\n", `{}`, "DEC-002: new_model takes no rule"}, + {"rule on a kept copy", item("DEC-003", reconcile.FieldNewCopy, reconcile.KindKeep, "rule: out-of-reach"), fable, "DEC-003: new_copy takes no rule"}, + {"keep that answers one rule", keepGA + " rule: out-of-reach\n", fable, ""}, + {"keys lock only their part", keyed(`[capabilities.tools]`, `{"tools": true}`), fable, ""}, + {"a missing part locks as empty", keyed(`[reasoning]`, `{}`), fable, ""}, + {"a locked part moved", keyed(`[capabilities.tools]`, `{"tools": false}`), fable, `DEC-001 keep bedrock:eu.anthropic.claude-fable-5 capability: got {"tools":true}`}, + {"keys that lock one name", keyed(`[capabilities.reasoning, reasoning]`, `{}`), fable, "DEC-001: keys capabilities.reasoning and reasoning would both lock reasoning"}, + {"a key outside its field", keyed(`[pricing]`, `{}`), fable, "DEC-001: key pricing isn't part of capability"}, + {"a key too deep", keyed(`[capabilities.tools.x]`, `{}`), fable, "DEC-001: key capabilities.tools.x isn't part of capability"}, + {"keys on a hold", gap + " keys: [reasoning]\n", fable, "DEC-002: only a keep on a value names keys"}, {"keep on location", keep("location", `["global"]`), fable, "DEC-001: location takes no decision yet: served locations are not in the snapshot"}, {"hold on location", item("DEC-002", "location", reconcile.KindHold), `{}`, "DEC-002: location takes no decision yet: served locations are not in the snapshot"}, {"unknown package", strings.Replace(keepGA, "bedrock:", "azure:", 1), fable, "unknown package azure"}, - {"bad date", strings.Replace(keepGA, "2027-01-13", "soon", 1), fable, "review_by"}, + {"bad date", reviewBy("soon"), fable, "review_by"}, + {"review a year out", reviewBy("2027-10-13"), fable, ""}, + {"review more than a year out", reviewBy("2027-10-14"), fable, "DEC-001: review_by is after decided, and at most a year after it"}, + {"review before decided", reviewBy("2026-10-01"), fable, "DEC-001: review_by is after decided, and at most a year after it"}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { t.Parallel() - problems := checkDecisions([]byte("decisions:\n"+tt.decisions), []byte(tt.snapshot)) + problems := checkDecisions([]byte("decisions:\n"+tt.decisions), []byte(tt.snapshot), asks) if tt.wantProblem == "" { assert.Empty(t, problems) return diff --git a/internal/reconcile/decisions.go b/internal/reconcile/decisions.go index 3c0da9cf..9194b381 100644 --- a/internal/reconcile/decisions.go +++ b/internal/reconcile/decisions.go @@ -27,8 +27,8 @@ import ( // reconcile run must not reopen (RULES.md, Principles). const DecisionsPath = ".github/reconcile-models/decisions.yaml" -// The two kinds of decision, and the fields a hold applies to: a model the -// catalogue doesn't carry yet, and another copy of one it does. +// The two kinds of decision, and the two fields about an offering the +// catalogue doesn't carry yet: a new model, and another copy of one it has. const ( KindKeep = "keep" KindHold = "hold" @@ -37,23 +37,33 @@ const ( ) // Decision is one entry in decisions.yaml. A keep pins one field of an offering to Lock, -// written in that field's catalog/snapshot.json shape; a hold keeps an -// offering out of the catalogue. +// written in that field's catalog/snapshot.json shape, or only the parts Keys +// names; a hold keeps an offering out of the catalogue, or on another field +// leaves the vendor's value out while Rule still asks about it. With a Rule, +// a decision answers only that rule's questions. type Decision struct { - ID string `yaml:"id"` - Offering string `yaml:"offering"` - Field string `yaml:"field"` - Kind string `yaml:"kind"` - Lock any `yaml:"lock"` - Reason string `yaml:"reason"` - Decided string `yaml:"decided"` - ReviewBy string `yaml:"review_by"` - PR int `yaml:"pr"` + ID string `yaml:"id"` + Offering string `yaml:"offering"` + Field string `yaml:"field"` + Kind string `yaml:"kind"` + Rule string `yaml:"rule"` + Keys []string `yaml:"keys"` + Lock any `yaml:"lock"` + Reason string `yaml:"reason"` + Decided string `yaml:"decided"` + ReviewBy string `yaml:"review_by"` + PR int `yaml:"pr"` // Line is where the entry starts in the file, so a PR can link to it. Line int `yaml:"-"` } +// Answers reports whether d answers a question raised by rule on its +// offering and field: every one when d names no rule, else its rule's. +func (d Decision) Answers(rule string) bool { + return d.Rule == "" || d.Rule == rule +} + // ParseDecisions decodes decisions.yaml strictly, so an unknown key is an error. func ParseDecisions(data []byte) ([]Decision, error) { var doc struct { diff --git a/internal/reconcile/decisions_test.go b/internal/reconcile/decisions_test.go index dccef84f..895ee815 100644 --- a/internal/reconcile/decisions_test.go +++ b/internal/reconcile/decisions_test.go @@ -59,6 +59,15 @@ decisions: assert.Equal(t, 12, entries[1].Line) }) + t.Run("reads the rule a decision answers and the keys it locks", func(t *testing.T) { + t.Parallel() + + entries, err := ParseDecisions([]byte(file + " rule: reasoning-unsendable\n keys: [reasoning.efforts]\n")) + require.NoError(t, err) + assert.Equal(t, "reasoning-unsendable", entries[1].Rule) + assert.Equal(t, []string{"reasoning.efforts"}, entries[1].Keys) + }) + t.Run("rejects an unknown key", func(t *testing.T) { t.Parallel()