Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .agents/skills/hillclimb/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Read `CHARTER.md` first. It holds the invariants and the targets. Do not change
- **Never weaken the eval to pass it.** A broken invariant is fixed in the planner. If the simulator is wrong about the world, say how you know, fix the simulator in its own commit, and record fresh baselines: `go run ./eval -baselines -record "baseline: <what changed>"`. A note that begins with `baseline` is where the best kept row starts again.
- **A new failure becomes a case first.** When a search or a live queue finds a world that breaks an invariant, add it to the eval before fixing it, and watch it fail.
- **Add a mutant with each new invariant,** so the eval is shown to see what it claims to see.
- **The checker explores what the simulator only samples.** `go run ./eval` also runs `eval/check.go`: every order in which the tick, CI, GitHub and people can move, in worlds of one to four pull requests, with each invariant checked in every state. It is a bounded search: its line says how many worlds it explored whole and how many stopped at the cap. `go run ./eval -check` goes deeper, and `go run ./eval -check "<world name>"` prints a world's counterexample with every world the planner read and every action it returned. A fault it finds is fixed in the planner, with a test in `internal/queue` that fails without the fix.
- **The checker explores what the simulator only samples.** `go run ./eval` also runs `eval/check.go`: every order in which the tick, CI, GitHub and people can move, in worlds of one to four pull requests, with each invariant checked in every state. A world's pull request may break the build by itself, fail only beside another, or need another, so that a tree holding it without that one fails. It is a bounded search: its line says how many worlds it explored whole and how many stopped at the cap. `go run ./eval -check` goes deeper, and `go run ./eval -check "<world name>"` prints a world's counterexample with every world the planner read and every action it returned. A fault it finds is fixed in the planner, with a test in `internal/queue` that fails without the fix.
- **Mind the size.** The engine's line count is an indicator. A mechanism that buys less than a twentieth on its indicator doesn't stay.
- **The shapes are estimates.** `go run ./eval -live <ticks> [-clone <repo>] -like <shape>` scores a real queue from the ticks it recorded (reading `<repo>` to check whether pull requests ejected at an earlier head later landed the same change), then plays the same arrivals on the shape's CI with builds as long and as flaky as the real ones, and prints the two rows together. Where they are more than a fifth apart, find out why before trusting either. With `-from` and `-to` it replays that window from the records: each pull request's label, head, checks, waits and conflicts enter at the record that shows them, builds take as long as the window's did, and a red candidate nobody was blamed for counts as CI's failure. The row then holds `simulated` and `over_live`. The replay stops at the window's end, so a slower planner lands fewer and its waits read shorter for it: read landings beside the median, the p90 and builds per landing, and what each side left waiting. `-perturb builds-double` (or `builds-half`, `one-slot`, `no-batch`) plays a wrong queue: a comparison worth trusting puts it outside a fifth. When a rate in a shape is wrong, change it in its own commit and record fresh baselines.
- **A recorded window sets the planner beside another queue's record.** `go run ./eval -history <trace.json> "<slots> <batch> [<gather> [<minutes a probe takes>]]" ...` plays a window of a real repository to the planner, on that window's build times: its pull requests, their heads, own checks and conflicts, and the pull requests that broke the build, as `trace` in `eval/history.go` holds them. It prints each setting under the row the record's own queue made, and records nothing. Give it the CI the repository has: `-rerun 13m` where CI runs a red build's failed jobs once more, `-runs-out` where a build runs to its end though its branch is deleted, `-unrepaired` where nothing mends a conflict but the author. A row is one window, not an indicator: say how many cases a column rests on before reading it.
Expand Down
65 changes: 54 additions & 11 deletions eval/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ type checkedPR struct {
head queue.SHA
breaks bool
clash int
needs int
queued bool
landed bool
first bool
order uint8
checks queue.Verdict
wait string
}
Expand All @@ -43,17 +46,36 @@ func culpritPR(number int, prs []checkedPR) bool {
if idx < 0 {
return false
}
if prs[idx].breaks {
pr := prs[idx]
if pr.breaks {
return true
}
if pr.needs > 0 {
needed := slices.IndexFunc(prs, func(p checkedPR) bool { return p.number == pr.needs })
if needed < 0 || !(prs[needed].landed || readyAhead(prs[needed], pr)) {
return true
}
}
for _, o := range prs {
if (o.number == prs[idx].clash || o.clash == number) && (o.landed || o.queued) {
if (o.number == pr.clash || o.clash == number) && (o.landed || o.queued) {
return true
}
}
return false
}

func readyAhead(a, b checkedPR) bool {
switch {
case !a.queued || a.checks != queue.Success || a.wait != "":
return false
case a.first != b.first:
return a.first
case a.order != b.order:
return a.order < b.order
}
return a.number < b.number
}

// fairTest says an ejection's evidence is a fair test of its pull request, by when CI really began
// each build: the first is a build that passed without it, and among the rest are two builds
// of that tree with it that failed, one begun no later than the pass and one no earlier.
Expand Down Expand Up @@ -204,7 +226,7 @@ func checkDrain(prs []checkedPR, after string) string {

type pullSpec struct {
Breaks, Conflict, Unready, First, Hold bool
Clash, Ahead int
Clash, Needs, Ahead int
}

type bounds struct {
Expand Down Expand Up @@ -436,7 +458,7 @@ func (c *checker) build(sha, trunk queue.SHA) queue.Build {
func (c *checker) guilty(sha queue.SHA) bool {
mask := c.commits[sha].holds
for i, p := range c.world.Pulls {
if mask&pullBit(i+1) != 0 && (p.Breaks || (p.Clash > 0 && mask&pullBit(p.Clash) != 0)) {
if mask&pullBit(i+1) != 0 && (p.Breaks || (p.Clash > 0 && mask&pullBit(p.Clash) != 0) || (p.Needs > 0 && mask&pullBit(p.Needs) == 0)) {
return true
}
}
Expand Down Expand Up @@ -877,8 +899,8 @@ func (c *checker) checkedPull(s *worldState, number int) checkedPR {
landed := c.holds(s.trunk, p.head(number, p.gitHead))
return checkedPR{
number: number, head: p.head(number, p.githubHead),
breaks: c.world.Pulls[number-1].Breaks, clash: c.world.Pulls[number-1].Clash,
queued: p.queued && !landed && !p.merged, landed: landed,
breaks: c.world.Pulls[number-1].Breaks, clash: c.world.Pulls[number-1].Clash, needs: c.world.Pulls[number-1].Needs,
queued: p.queued && !landed && !p.merged, landed: landed, first: p.first, order: p.order,
checks: p.checks, wait: p.waitReason(),
Comment thread
jeremy marked this conversation as resolved.
Resolved
}
}
Expand Down Expand Up @@ -1118,8 +1140,7 @@ func (t *checkTick) delete(a queue.Action) bool {
}

func (t *checkTick) eject(pulls map[int]pullRequest, a queue.Action) (string, bool) {
prs := t.c.checkedPulls(t.state)
culprit := a.Cause == "culprit" && culpritPR(a.PR, prs)
culprit := a.Cause == "culprit" && culpritPR(a.PR, t.c.drainPulls(t.state))
flaked := t.state.flaked || t.state.episodes > 1
if broken := checkEject(a, culprit, flaked, t.c.checkedBuild(t.state)); len(broken) > 0 {
return strings.Join(broken, "; "), false
Expand Down Expand Up @@ -1725,6 +1746,7 @@ var (
)

func clash(n int) pullSpec { return pullSpec{Clash: n} }
func needs(n int) pullSpec { return pullSpec{Needs: n} }
func ahead(n int) pullSpec { return pullSpec{Ahead: n} }
func pulls(ps ...pullSpec) []pullSpec { return ps }

Expand Down Expand Up @@ -1802,15 +1824,36 @@ func defaultWorlds() []checkWorld {
}
}

return append(worlds,
return append(append(worlds,
checkWorld{"3 PRs crashes+lost (good+breaks+good)", dials(2, 3, false), pulls(good, breaks, good), false, false, bCrash},
checkWorld{"3 PRs moves+stale (good+breaks+ahead)", dials(2, 3, false), pulls(good, breaks, ahead(2)), false, false, bMove},
checkWorld{"4 PRs batch (good*4)", dials(2, 4, false), pulls(good, good, good, good), false, false, b4},
checkWorld{"4 PRs batch (good*3+breaks)", dials(2, 4, false), pulls(good, good, good, breaks), false, false, b4},
checkWorld{"4 PRs batch (clash+ahead+breaks)", dials(2, 4, false), pulls(good, clash(1), ahead(2), breaks), false, false, b4},
checkWorld{"4 PRs 3x2 (breaks+good*2+clash)", cfg32, pulls(breaks, good, good, clash(2)), false, false, b4},
checkWorld{"4 PRs probes (good+clash+good+breaks)", dials(2, 4, true), pulls(good, clash(1), good, breaks), false, false, b4},
)
), needsWorlds()...)
}

func needsWorlds() []checkWorld {
cfg := dials(2, 2, true)
return []checkWorld{
{Name: "3 PRs #2 and #3 need each other (2 of 2, probes)", Config: cfg, Pulls: pulls(good, needs(3), needs(2)), Instant: true, Bounds: bounds{MaxStates: 5000}},
{Name: "3 PRs #3 needs #2 (2 of 2, probes)", Config: cfg, Pulls: pulls(good, good, needs(2)), Instant: true, Bounds: bounds{MaxStates: 5000}},
{Name: "3 PRs #3 needs #2 and is ready later (2 of 2, probes)", Config: cfg, Pulls: pulls(good, good, late(needs(2))), Bounds: bounds{Moves: 1, MaxStates: 5000}},
}
}

func needsASuspectWorld() checkWorld {
return checkWorld{
Name: "3 PRs #1 breaks and #3 needs #2 (2 of 2, probes)",
Config: dials(2, 2, true), Pulls: pulls(breaks, good, needs(2)), Bounds: bounds{MaxStates: 5000},
}
}

func late(p pullSpec) pullSpec {
p.Unready = true
return p
}

func smallKeepWorlds() []checkWorld {
Expand Down Expand Up @@ -2050,7 +2093,7 @@ func runCheck(name string) bool {
}

func findWorld(name string) (checkWorld, bool) {
for _, list := range [][]checkWorld{deepWorlds(), mutantWorlds(), keepMutantWorlds()} {
for _, list := range [][]checkWorld{deepWorlds(), mutantWorlds(), keepMutantWorlds(), {needsASuspectWorld()}} {
for _, w := range list {
if w.Name == name {
return w, true
Expand Down
32 changes: 32 additions & 0 deletions eval/check_mutants.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ func checkerMutants() []checkMutant {
},
},
},
checkMutant{
name: "goes on beside a candidate stacked on a red one",
mutant: mutant{verify: queue.Verify, plan: besideStacked},
},
checkMutant{
name: "spans a round that had not begun",
mutant: mutant{
Expand All @@ -70,6 +74,33 @@ func checkerMutants() []checkMutant {
)
}

func besideStacked(w queue.World, c queue.Config) []queue.Action {
acts := queue.Plan(w, c)
if !c.Probes || slices.ContainsFunc(acts, func(a queue.Action) bool { return a.Do == "push" }) {
return acts
}
onRed := func(b queue.Build) bool {
return slices.ContainsFunc(w.Builds, func(r queue.Build) bool {
n := len(r.Chain)
return r.Kind == queue.Candidate && r.Verdict == queue.Failure && r.Landed.IsZero() && n > 0 &&
len(b.Chain) > n && b.Base == r.Base && b.Chain[n-1].Merge == r.SHA
})
}
stacked := func(b queue.Build) bool {
return b.Kind == queue.Candidate && b.Verdict == queue.Pending && b.Landed.IsZero() && onRed(b)
}
beside := w
beside.Builds = slices.DeleteFunc(slices.Clone(w.Builds), stacked)
hidden := len(w.Builds) - len(beside.Builds)
if hidden == 0 || c.Slots <= hidden {
return acts
}
c.Slots -= hidden
return slices.DeleteFunc(queue.Plan(beside, c), func(a queue.Action) bool {
return a.Do == "push" && slices.ContainsFunc(w.Builds, func(b queue.Build) bool { return b.SHA == a.Build.SHA })
})
}

func mutantWorlds() []checkWorld {
cfg := dials(2, 1, false)
return []checkWorld{
Expand All @@ -79,6 +110,7 @@ func mutantWorlds() []checkWorld {
{"1 PR crashes+stale+moves", cfg, pulls(good), false, false, bounds{Crashes: 1, Stale: 1, Moves: 1, MaxStates: 6000}},
{"2 PRs (good+good) flakes+crashes", cfg, pulls(good, good), false, false, bounds{Flakes: 1, Crashes: 1, MaxStates: 8000}},
{"2 PRs (good+breaks) timeouts", dials(2, 2, false), pulls(good, breaks), false, false, bounds{Timeouts: 1, MaxStates: 2000}},
needsWorlds()[0],
}
}

Expand Down
99 changes: 99 additions & 0 deletions eval/check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1105,3 +1105,102 @@ func TestKeepCheckerLowerTimesOutWhileTheTipIsKept(t *testing.T) {
t.Fatal("no timed-out lower reading")
}
}

func TestCheckerGuiltyWithNeeds(t *testing.T) {
for _, tc := range []struct {
name string
pulls []pullSpec
tree []int
want bool
}{
{"neither of the pair", pulls(good, needs(3), needs(2)), []int{1}, false},
{"#2 without #3", pulls(good, needs(3), needs(2)), []int{1, 2}, true},
{"#3 without #2", pulls(good, needs(3), needs(2)), []int{1, 3}, true},
{"the pair", pulls(good, needs(3), needs(2)), []int{1, 2, 3}, false},
{"#3 without the #2 it needs", pulls(good, good, needs(2)), []int{1, 3}, true},
{"#3 with the #2 it needs", pulls(good, good, needs(2)), []int{1, 2, 3}, false},
{"#2, which needs nothing", pulls(good, good, needs(2)), []int{1, 2}, false},
} {
c := newChecker(checkWorld{Config: dials(2, 2, true), Pulls: tc.pulls}, mutant{plan: queue.Plan, verify: queue.Verify})
sha := queue.SHA("trunk0")
for _, n := range tc.tree {
sha = c.addCommit(sha, queue.SHA(fmt.Sprintf("head%d", n)), n, "")
}
if got := c.guilty(sha); got != tc.want {
t.Errorf("%s: guilty %v, want %v", tc.name, got, tc.want)
}
}
}

func TestCheckerCulpritPRWithNeeds(t *testing.T) {
needing := checkedPR{number: 3, needs: 2, queued: true, order: 3, checks: queue.Success}
for _, tc := range []struct {
name string
needed checkedPR
want bool
}{
{"the one it needs landed", checkedPR{number: 2, landed: true}, false},
{"the one it needs is queued ahead", checkedPR{number: 2, queued: true, order: 2, checks: queue.Success}, false},
{"the one it needs is queued behind", checkedPR{number: 2, queued: true, order: 4, checks: queue.Success}, true},
{"the one it needs goes first", checkedPR{number: 2, queued: true, first: true, order: 4, checks: queue.Success}, false},
{"the one it needs is ahead and held", checkedPR{number: 2, queued: true, order: 2, checks: queue.Success, wait: "it is labelled hold"}, true},
{"the one it needs is ahead and its checks run", checkedPR{number: 2, queued: true, order: 2, checks: queue.Pending}, true},
{"the one it needs is gone", checkedPR{number: 2}, true},
} {
if got := culpritPR(3, []checkedPR{{number: 1, queued: true, order: 1, checks: queue.Success}, tc.needed, needing}); got != tc.want {
t.Errorf("%s: culprit %v, want %v", tc.name, got, tc.want)
}
}
}

func TestCheckerCallsAPullRequestACulpritWhenTheOneItNeedsConflictsWithTheTrunk(t *testing.T) {
for _, spare := range []bool{false, true} {
cfg := dials(2, 2, true)
cfg.Spare = spare
w := checkWorld{Name: "3 PRs #3 needs #2, which conflicts", Config: cfg, Pulls: pulls(good, conflict, needs(2)), Instant: true, Bounds: bounds{MaxStates: 5000}}
res := explore(w, mutant{plan: queue.Plan, verify: queue.Verify})
if res.Broken != "" || res.Capped {
t.Errorf("spare %v: broken %q, capped %v, %d states", spare, res.Broken, res.Capped, res.States)
}
}
}

func TestCheckerKillsGoingOnBesideAStackedCandidateOnlyWhereAPullRequestNeedsAnother(t *testing.T) {
m := mutant{plan: besideStacked, verify: queue.Verify}
var plain []checkWorld
for _, spare := range []bool{false, true} {
for _, w := range needsWorlds()[:1] {
w.Config.Spare = spare
if res := explore(w, m); res.Broken != "invariant 3: #3 is innocent and was ejected with no flake in play" {
t.Errorf("%s, spare %v: broken %q, want #3 innocent on invariant 3", w.Name, spare, res.Broken)
}
}
for _, w := range append(defaultWorlds(), checkWorld{"3 PRs good+breaks+good (2 of 2, probes)", dials(2, 2, true), pulls(good, breaks, good), false, true, bounds{MaxStates: 5000}}) {
if w.Config.Probes && w.Config.Keep == 0 && !slices.ContainsFunc(w.Pulls, func(p pullSpec) bool { return p.Needs > 0 }) {
w.Config.Spare = spare
plain = append(plain, w)
}
}
}
sum := checkSuite(plain, m)
t.Logf("%d worlds with probes and no pull request that needs another: %d whole, %d capped, %d states", sum.worlds, sum.whole, sum.capped, sum.states)
for _, inv := range sum.brokenInvs {
t.Errorf("%s is broken in %s:\n%s", inv, sum.bestByInv[inv].world.Name, formatTrace(sum.bestByInv[inv].result))
}
}

// #1 breaks and #3 needs #2. The candidates of #1 and #2 and of all three fail, and the chain goes
// on with #3 alone while #1 and #2 are suspects. #2 is cleared and lands, and #3 leaves on the
// fair test of its own build, though the trunk with #3 now passes.
func TestCheckerCurrentPlannerEjectsAPullRequestThatNeedsASuspectSetAside(t *testing.T) {
for _, spare := range []bool{false, true} {
w := needsASuspectWorld()
w.Config.Spare = spare
m := mutant{plan: queue.Plan, verify: queue.Verify}
res := explore(w, m)
t.Logf("spare %v: capped %v, %d states:\n%s", spare, res.Capped, res.States, formatCounterexample(w, m, res))
if res.Broken != "invariant 3: #3 is innocent and was ejected with no flake in play" {
t.Errorf("spare %v: broken %q, want #3 innocent on invariant 3", spare, res.Broken)
}
}
}