S5b security #5 revised: another connection within the same rule
Hosted CI's headless C5 Review tests caught the first fix: reading "equal rank" as equal room let Engineering's own Claude account review whenever it had a reading and the other had none. Equal rank is the same §7 rule: in each family group preference, subscription and metered stay in order, and within the rule that yields candidates another connection than Engineering's comes first, then room. S3's Review cases are back as they were. Budget reasons shortened under 200 bytes.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
6 files changed,
+63
−40
.rastrillo/budgets.txt+3 −3docs/superpowers/plans/S5B-MODELS-PROGRESS.md+11 −7internal/runner/thin/models_test.go+2 −2internal/schedule/models_test.go+20 −15internal/schedule/schedule.go+19 −3internal/schedule/schedule_test.go+8 −10
CI passed — run details
diff --git a/.rastrillo/budgets.txt b/.rastrillo/budgets.txt| index 18bca0aa..87d37435 100644 |
| --- a/.rastrillo/budgets.txt |
| +++ b/.rastrillo/budgets.txt |
| @@ -15,7 +15,7 @@ time internal/equipo/team 60s Plan 3 loaded CI measured 45.985s; niced serial re |
| time internal/equipotest 300s Final fix package rerun measured 187.035s (review 172.4s); 300s gives 60 percent headroom for HTTP, sandbox, authority and final regression coverage. |
| size internal/equipo 19321 - The instance web layer: pages, handlers, templates and copy for every screen, the Usage page and the models list included. Measured 19321 source lines. |
| -size internal/wire 5810 - The runner and person API protocol: every frame, resource and its downgrade up to protocol 18 (16 publishing, 17 OpenCode Go, 18 models chosen per step), one package so Encode sees every type. Measured 5810 source lines. |
| +size internal/wire 5810 - The runner and person API protocol: every frame, resource and downgrade up to protocol 18 (models per step), one package so Encode sees every type. Measured 5810 source lines. |
| size internal/equipotest - 13400 Task 21 repairs historical migration and conversation fixtures after Plan 3. Measured 13024 test lines; the 300s time ceiling is unchanged. |
| time internal/runner/checks 90s CI worker measured 44.553s (44.6s rounded); |
| time internal/runner 330s Plan 3 CI repair measured 292.120s for the full package (controller CI 472.184s). |
| @@ -38,7 +38,7 @@ time internal/runner/provider 15s Plan 3 CI repair measured 10.346s for the full |
| perf GET /releases/* skip Verified runner release file downloads, not browser GET screens. |
| perf GET /install.sh skip Mac runners: the one-line bootstrap a terminal pipes to sh, not a browser screen. |
| time internal/runner/containment 15s Plan 3 loaded CI measured 10.817s; |
| -size internal/runner/thin 23736 15802 The thin runner: steps, link, coordinator, Mac worker, previews, merges, metered connections, Research, scheduler, Codex reading probe, site host, OpenCode, models chosen per step. Measured 23736 source and 15802 test lines. |
| +size internal/runner/thin 23736 15802 The thin runner: steps, link, coordinator, Mac worker, previews, merges, metered connections and their models, Research, scheduler, site host, OpenCode. Measured 23736 source and 15802 test lines. |
| time internal/thintest 180s Contract tests for Mac runners, transitions and the thin core share one instance harness; loaded CI needs 180s. |
| time internal/runner/mac 30s Mac runners (Darwin worker): real process groups killed after a grace and proven gone (SIGTERM, SIGKILL, the marker sweep), and the probes run end to end with fake srt and xcodebuild, P6 killing. |
| time internal/runner/thin 45s Thin v1 slice 4 review: real git repositories for the merge and squash checks, a stalled fetch, and a 16 MiB candidate streamed through the review diff and the checks pack (about 5s). |
| @@ -53,7 +53,7 @@ perf GET /api/v1/notebook skip Thin v1 person API: bearer-only JSON for devices; |
| perf GET /api/v1/thinking skip Thin v1 person API: bearer-only JSON for devices; the browser reads thinking words on /settings/thinking. |
| perf GET /api/v1/tasks skip Thin v1 person API: bearer-only JSON for devices; the browser reads tasks through /tasks. |
| perf GET /api/v1/tasks/{id} skip Thin v1 person API: bearer-only JSON for devices; the browser reads a task through /tasks/{id}. |
| -size internal/equipo/chat 22550 - The instance store: tasks, steps, cards, merge authority, housekeeping, placement, metered connections and their allowed models, Research, scheduler, usage, advice, site publishing. Measured 22550 source lines. |
| +size internal/equipo/chat 22550 - The instance store: tasks, steps, cards, merge authority, housekeeping, placement, metered connections and models, Research, scheduler, usage, advice, sites. Measured 22550 source lines. |
| perf GET /api/v1/questions/{id} skip Thin v1 person API: bearer-only JSON for devices; the browser reads questions on /tasks/{id}. |
| perf GET /api/v1/steps/{id}/log skip Thin v1 person API: bearer-only JSON for devices; the browser shows the log tail on /tasks/{id}. |
| perf GET /api/v1/connections/preference skip Connections slice 1 person API: bearer-only JSON for devices; the browser shows the preference on /conversation/connections. |
diff --git a/docs/superpowers/plans/S5B-MODELS-PROGRESS.md b/docs/superpowers/plans/S5B-MODELS-PROGRESS.md| index f8c09d6b..12513bcf 100644 |
| --- a/docs/superpowers/plans/S5B-MODELS-PROGRESS.md |
| +++ b/docs/superpowers/plans/S5B-MODELS-PROGRESS.md |
| @@ -317,11 +317,15 @@ ruled by the controller (accept and state). |
| applied set. `TestModelsWritesCheckOwnerRosterAndRevision`, |
| `TestContractModels`, `TestModelsFrame` (a refused set stays at the |
| revision held). |
| -5. Review's three groups (`schedule/schedule.go`): two family groups, |
| - §7's order in each; another connection than Engineering's wins only |
| - at equal rank (subscriptions' room, metered fill), in either group. |
| - S3's two cases that assumed the three groups now hold room equal. |
| - `TestDecidePairs`, `TestDecideReviewFamily`. |
| +5. Review's three groups (`schedule/schedule.go`): two family groups; |
| + in each, §7's rules in order (preference, subscription, metered), and |
| + within the rule that yields candidates another connection than |
| + Engineering's first, then room. "Equal rank" is read as the same |
| + rule, as the scheduler did before (Review runs away from |
| + Engineering's account): the first fix read it as equal room, and the |
| + hosted headless C5 tests (Review on a second Claude account) caught |
| + it, since Engineering's account has a reading and the other none. |
| + `TestDecidePairs`, `TestDecideReviewFamily` (S3's cases as they were). |
| 6. A mismatch retried by time (`metered/models.go`): `model_mismatch` is |
| never retryable; it stays until Check again. `TestModelRetryable`. |
| 7. (Design) OpenCode's ACP usage names no model: accepted and stated in |
| @@ -353,8 +357,8 @@ Mutations observed: |
| - S3b: a connection with no list allowed to grow its set -> same (a model added with no list of the key's) |
| - S4a: hello's applied revision maxed with what the instance held (as it was) -> TestModelsWritesCheckOwnerRosterAndRevision (a hello behind was maxed away). The test failed before the fix, observed first |
| - S4b: the models frame's ack taken as applied (as it was) -> same (an ack showed the set applied), TestContractModels (an ack showed the set applied) |
| -- S5a: Review's three groups (other family, same family elsewhere, Engineering's own; as it was) -> TestDecidePairs (room before another connection: ran on u), TestDecideReviewFamily (room before another account). The tests failed before the fix, observed first. S3's two cases that assumed the three groups now hold room equal |
| -- S5b: the equal-rank tie rule off -> TestDecidePairs (same family elsewhere at equal room: ran on t), TestDecideReviewFamily |
| +- S5a: Review's three groups (as it was) -> TestDecidePairs (subscription before metered: ran on u; the preference before another connection). The test failed before the fix, observed first |
| +- S5c: Engineering's own connection kept in a rule while another is there (room alone deciding, the first fix) -> TestDecidePairs (same family elsewhere at the same rule: ran on t), TestDecideReviewFamily (another account next). Hosted CI's TestHeadlessConnections C5_review_failover and C5_review_auth failed on that first fix |
| - S6: a model_mismatch retried after a day (as it was) -> TestModelRetryable (a mismatch retried by time). The test failed before the fix, observed first |
| - S8a: the first-use probe run without the step's admission (nil admit) -> TestModelsProbeRunsInsideTheAdmission (no admission row at the probe's request), TestModelsProbeNeedsTheAdmission (the probe ran though leave to spend was withdrawn before the admission). Before these tests, TestModelsEngineeringProbesThenRunsTheStrongest passed with it, as the finding says (its admission check comes after the step's own admission). The first run hung to the test timeout on the held fake; the test now releases it on failure |
| - S8b: no bound on first-use probes (10) -> TestModelsProbesBounded (four probes, then the step ran) |
diff --git a/internal/runner/thin/models_test.go b/internal/runner/thin/models_test.go| index 0b0493d9..8fc2955d 100644 |
| --- a/internal/runner/thin/models_test.go |
| +++ b/internal/runner/thin/models_test.go |
| @@ -212,8 +212,8 @@ func TestModelsReviewAcrossFamilies(t *testing.T) { |
| }); err != nil { |
| t.Fatal(err) |
| } |
| - // The second key is at its budget, so only this one can review (with |
| - // room equal, another connection would win the tie anyway). |
| + // The second key (Engineering's) is at its budget; this one reviews |
| + // (another connection at the same rule would anyway). |
| now := time.Now().UTC() |
| if _, err := r.state.db.Exec("INSERT INTO budget_charge(turn, step, attempt, connection, model, holder, cost_micros, reported_micros, currency, price_version, day, month, recorded_at) VALUES('', 'earlier', 1, ?, 'z-ai/glm-5.2', 'x', 1, NULL, 'USD', ?, ?, ?, ?)", second, metered.Current[wire.ProviderTensorX], now.Format("2006-01-02"), now.Format("2006-01"), now.Format(time.RFC3339Nano)); err != nil { |
| t.Fatal(err) |
diff --git a/internal/schedule/models_test.go b/internal/schedule/models_test.go| index ccdeabd9..4c4e790d 100644 |
| --- a/internal/schedule/models_test.go |
| +++ b/internal/schedule/models_test.go |
| @@ -128,23 +128,28 @@ func TestDecidePairs(t *testing.T) { |
| t.Fatalf("other family under the cap: %+v", d) |
| } |
| // Same family only: another connection before Engineering's own at |
| - // equal room ... |
| - if d := Decide(in(review, metered("t", 0, glm53), metered("u", 0, glm52))); d.Connection != "u" || d.Model != glm52.ID { |
| - t.Fatalf("same family elsewhere at equal room: %+v", d) |
| - } |
| - // ... but room (and preference) first (security round #5). |
| - if d := Decide(in(review, metered("t", 0, glm53), metered("u", 300_000, glm52))); d.Connection != "t" { |
| - t.Fatalf("room before another connection: %+v", d) |
| - } |
| - pref := in(review, sub("claude-t", "claude", 0.1), sub("claude-u", "claude", 0.1)) |
| - pref.Step.Engineer = &Engineer{ID: "claude-t", Family: "claude", Account: "claude-t"} |
| + // the same rule, whatever the room ... |
| + if d := Decide(in(review, metered("t", 0, glm53), metered("u", 300_000, glm52))); d.Connection != "u" || d.Model != glm52.ID { |
| + t.Fatalf("same family elsewhere at the same rule: %+v", d) |
| + } |
| + // ... but §7's rules first (security round #5): Engineering's own |
| + // subscription before another connection that is metered, and the |
| + // preferred provider before another connection that is not. |
| + sameFamily := metered("u", 0, Model{ID: "claude-like", Family: "claude", Tier: TierStrong, Output: 1}) |
| + subReview := Step{Role: RoleReview, Priority: Urgent, Engineer: &Engineer{ID: "claude-t", Family: "claude", Account: "claude-t"}} |
| + if d := Decide(in(subReview, sub("claude-t", "claude", 0.1), sameFamily)); d.Connection != "claude-t" { |
| + t.Fatalf("subscription before metered: %+v", d) |
| + } |
| + other := sub("bedrock-u", "bedrock", 0.1) |
| + other.Family = "claude" |
| + pref := in(subReview, sub("claude-t", "claude", 0.5), other) |
| pref.Preference = Preference{Provider: "claude"} |
| - if d := Decide(pref); d.Connection != "claude-u" { |
| - t.Fatalf("equal rank, preferred provider: %+v", d) |
| + if d := Decide(pref); d.Connection != "claude-t" || d.Reason != ReasonPreference { |
| + t.Fatalf("the preference before another connection: %+v", d) |
| } |
| - // The tie rule holds in the other-family group too. |
| - if d := Decide(in(review, metered("t", 0, kimiPro), metered("u", 0, kimiPro))); d.Connection != "u" { |
| - t.Fatalf("other family, equal rank: %+v", d) |
| + // The same in the other-family group. |
| + if d := Decide(in(review, metered("t", 0, kimiPro), metered("u", 300_000, kimiPro))); d.Connection != "u" { |
| + t.Fatalf("other family, another connection at the same rule: %+v", d) |
| } |
| // A kept session stays on its own model while it is eligible ... |
| kept := Step{Role: RoleEngineering, Priority: Urgent, Kept: "t", KeptModel: kimiPro.ID} |
diff --git a/internal/schedule/schedule.go b/internal/schedule/schedule.go| index ee97a16c..96062b75 100644 |
| --- a/internal/schedule/schedule.go |
| +++ b/internal/schedule/schedule.go |
| @@ -485,6 +485,22 @@ func groups(in Input) [][]Conn { |
| return [][]Conn{other, same} |
| } |
| +// elsewhere are a rule's candidates for Review with Engineering's own |
| +// connection left out while another remains (§16.3: at equal rank, |
| +// another connection; the rank is the rule that yields them, so room |
| +// orders only what is left). Any other step's are all of them. |
| +func elsewhere(cs []Conn, s Step) []Conn { |
| + e := engineerID(s) |
| + if e == "" { |
| + return cs |
| + } |
| + out := slices.DeleteFunc(slices.Clone(cs), func(c Conn) bool { return c.ID == e }) |
| + if len(out) == 0 { |
| + return cs |
| + } |
| + return out |
| +} |
| + |
| // engineerID is the connection Review's tie rule ranks after another at |
| // equal rank ("" when the step names no Engineer). |
| func engineerID(s Step) string { |
| @@ -523,12 +539,12 @@ func pick(in Input, eff string, pref Preference, cs []Conn) (Conn, Model, string |
| } |
| } |
| if len(mine) > 0 { |
| - return roomiest(mine, now, engineerID(s)), Model{}, ReasonPreference, true |
| + return roomiest(elsewhere(mine, s), now, engineerID(s)), Model{}, ReasonPreference, true |
| } |
| } |
| // 3. The subscription with the most room. |
| if len(subs) > 0 { |
| - return roomiest(subs, now, engineerID(s)), Model{}, ReasonHeadroom, true |
| + return roomiest(elsewhere(subs, s), now, engineerID(s)), Model{}, ReasonHeadroom, true |
| } |
| // 4. The metered connection with the most room; a preferred one first. |
| if len(metered) > 0 { |
| @@ -545,7 +561,7 @@ func pick(in Input, eff string, pref Preference, cs []Conn) (Conn, Model, string |
| if s.Priority == Urgent { |
| reason = ReasonMeteredUrgent |
| } |
| - c := meteredRoomiest(mine, engineerID(s)) |
| + c := meteredRoomiest(elsewhere(mine, s), engineerID(s)) |
| m, _ := PickModel(c.Models, TierCap(c)) |
| return c, m, reason, true |
| } |
diff --git a/internal/schedule/schedule_test.go b/internal/schedule/schedule_test.go| index 45e3929b..4138a401 100644 |
| --- a/internal/schedule/schedule_test.go |
| +++ b/internal/schedule/schedule_test.go |
| @@ -161,20 +161,18 @@ func TestDecideReviewFamily(t *testing.T) { |
| if d := review(Step{}, sub("a", "claude", 0.1), sub("b", "codex", 0.5)); d.Connection != "b" { |
| t.Fatalf("another family first: %+v", d) |
| } |
| - // Within a family, §7's order (room first); another connection than |
| - // Engineering's wins only at equal rank (rev 3.3 §16.3). |
| - if d := review(Step{}, sub("a", "claude", 0.5), sub("a2", "claude", 0.5)); d.Connection != "a2" { |
| - t.Fatalf("another account at equal room: %+v", d) |
| - } |
| - if d := review(Step{}, sub("a", "claude", 0.1), sub("a2", "claude", 0.5)); d.Connection != "a" { |
| - t.Fatalf("room before another account: %+v", d) |
| + // Within a family, §7's rules in order; at equal rank (the same |
| + // rule) another connection than Engineering's, whatever its room |
| + // (rev 3.3 §16.3). |
| + if d := review(Step{}, sub("a", "claude", 0.1), sub("a2", "claude", 0.5)); d.Connection != "a2" { |
| + t.Fatalf("another account next: %+v", d) |
| } |
| if d := review(Step{}, sub("a", "claude", 0.1)); d.Connection != "a" { |
| t.Fatalf("the same account last: %+v", d) |
| } |
| - // Another family over threshold: the same family reviews now rather |
| - // than waiting (another account at equal room). |
| - if d := review(Step{}, sub("a", "claude", 0.3), sub("a2", "claude", 0.3), sub("b", "codex", 0.9)); d.Connection != "a2" { |
| + // Another family over threshold: the same family's other account |
| + // reviews now rather than waiting. |
| + if d := review(Step{}, sub("a", "claude", 0.1), sub("a2", "claude", 0.3), sub("b", "codex", 0.9)); d.Connection != "a2" { |
| t.Fatalf("other family held: %+v", d) |
| } |
| // Metered of another family with a release, before Engineering's own |