Hosted check failures give every shard's failing lines
Stopped-jobs audit, fix 4: the runner kept the tail of every failing
shard's log joined (32 KB), and the instance then gave the fix round
the last 60 lines of that, so only the last failing shard reached the
engineer ("Shard 16 also failed but its output wasn't included"), and
each round fixed one shard.
Now each failing unit gets an equal share of the bound, what a short
one leaves going to the others, and within its share keeps its failure
lines (--- FAIL, FAIL, panic:, Error, with the indented lines after
each) first, then its tail (wire.JoinCIUnits). The runner names each
unit as the binding does, so the instance finds each unit's part again
(wire.SplitCIUnits) and shares the fix round's feedback the same way.
Output from an older runner, with no units found, keeps the old tail.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
5 files changed,
+276
−10
internal/equipo/chat/review.go+13 −2internal/runner/thin/judge_hosted.go+15 −8internal/runner/thin/judge_hosted_test.go+58 −0internal/thintest/fix_round_shards_contract_test.go+48 −0internal/wire/cilogs.go+142 −0
diff --git a/internal/equipo/chat/review.go b/internal/equipo/chat/review.go| index a5b6e7fc..3b35ce39 100644 |
| --- a/internal/equipo/chat/review.go |
| +++ b/internal/equipo/chat/review.go |
| @@ -391,8 +391,15 @@ func feedbackBudget(p progress, limit int) string { |
| writeFeedbackData(&b, limit, "CI failed job", failed) |
| } |
| } |
| - lines := strings.Split(strings.TrimRight(c.Output, "\n"), "\n") |
| - writeFeedbackData(&b, limit, "CI output", strings.Join(lines[max(0, len(lines)-60):], "\n")) |
| + if _, units := wire.SplitCIUnits(c.Output, h.Failed); len(units) > 0 { |
| + // Every failing unit's share, its failing lines first |
| + // (stopped-jobs audit, fix 4: the last lines reached only the |
| + // last unit). |
| + writeFeedbackData(&b, limit, "CI output", wire.JoinCIUnits(units, limit-b.Len()-len("CI output")-220-quotedSlack)) |
| + } else { |
| + lines := strings.Split(strings.TrimRight(c.Output, "\n"), "\n") |
| + writeFeedbackData(&b, limit, "CI output", strings.Join(lines[max(0, len(lines)-60):], "\n")) |
| + } |
| } else if c != nil && c.Checks == wire.ChecksFailed { |
| code := -1 |
| if c.ExitCode != nil { |
| @@ -682,6 +689,10 @@ func (s *Store) NeedsYou(ctx context.Context, person string) (out wire.TaskList, |
| return out, err |
| } |
| +// quotedSlack is what wire.QuotedData adds around a value of several |
| +// lines (its fences, with their nonce), at most. |
| +const quotedSlack = 200 |
| + |
| func writeFeedbackData(b *strings.Builder, limit int, label, value string) { |
| remaining := limit - b.Len() - len(label) - 220 |
| if remaining <= 0 { |
diff --git a/internal/runner/thin/judge_hosted.go b/internal/runner/thin/judge_hosted.go| index 228533be..135c1d6a 100644 |
| --- a/internal/runner/thin/judge_hosted.go |
| +++ b/internal/runner/thin/judge_hosted.go |
| @@ -74,7 +74,7 @@ func (e *Engineer) hostedVerdict(ctx context.Context, r stepRow, rep wire.StepRe |
| return done(wire.ChecksPassed, "") |
| case wire.HostedFailure: |
| code := 1 |
| - logs := "" |
| + var logs []wire.CIUnit |
| cctx, cancel := context.WithTimeout(ctx, hostedRead) |
| full, err := e.CI.CIStatus(cctx, r.Repo, r.Branch, forge.CILogsFailed) |
| cancel() |
| @@ -88,7 +88,9 @@ func (e *Engineer) hostedVerdict(ctx context.Context, r stepRow, rep wire.StepRe |
| if s := strings.TrimSpace(st.Summary); s != "" { |
| head += s + "\n" |
| } |
| - rep.Gate, rep.ExitCode, rep.Output = wire.GateHosted, &code, head+tailBytes(logs, wire.MaxChecksOutput-len(head)) |
| + // Every failing unit's share of the output, its failing lines |
| + // first: the fix round reads them all. |
| + rep.Gate, rep.ExitCode, rep.Output = wire.GateHosted, &code, head+wire.JoinCIUnits(logs, wire.MaxChecksOutput-len(head)) |
| rep.LogTail = lastLines(rep.Output, stepTailLines, wire.MaxLogTail) |
| return done(wire.ChecksFailed, "") |
| case "skipped": |
| @@ -108,7 +110,7 @@ func failedUnits(steps []forge.CIStep) []string { |
| out := []string{} |
| add := func(name string) { |
| if len(out) < wire.MaxHostedFailed { |
| - out = append(out, clipName(strings.Join(strings.Fields(name), " "))) |
| + out = append(out, unitName(name)) |
| } |
| } |
| for _, s := range steps { |
| @@ -129,21 +131,26 @@ func failedUnits(steps []forge.CIStep) []string { |
| return out |
| } |
| -func failedLogs(steps []forge.CIStep) string { |
| - var b strings.Builder |
| +// failedLogs are the logs of the failing units the hub sent, each named |
| +// as failedUnits names it, so the instance can find each unit's part. |
| +func failedLogs(steps []forge.CIStep) []wire.CIUnit { |
| + var out []wire.CIUnit |
| for _, s := range steps { |
| if s.Log != "" { |
| - b.WriteString("=== " + s.Name + "\n" + s.Log + "\n") |
| + out = append(out, wire.CIUnit{Name: unitName(s.Name), Log: s.Log}) |
| } |
| for _, sh := range s.Shards { |
| if sh.Log != "" { |
| - b.WriteString("=== " + s.Name + " " + sh.Name + "\n" + sh.Log + "\n") |
| + out = append(out, wire.CIUnit{Name: unitName(s.Name + " " + sh.Name), Log: sh.Log}) |
| } |
| } |
| } |
| - return b.String() |
| + return out |
| } |
| +// unitName is a unit's name as the binding records it: one line, bounded. |
| +func unitName(name string) string { return clipName(strings.Join(strings.Fields(name), " ")) } |
| + |
| func clipName(s string) string { |
| for len(s) > wire.MaxHostedName { |
| _, n := utf8.DecodeLastRuneInString(s) |
diff --git a/internal/runner/thin/judge_hosted_test.go b/internal/runner/thin/judge_hosted_test.go| index 30abc26f..dca58b28 100644 |
| --- a/internal/runner/thin/judge_hosted_test.go |
| +++ b/internal/runner/thin/judge_hosted_test.go |
| @@ -2,6 +2,7 @@ package thin |
| import ( |
| "context" |
| + "fmt" |
| "strings" |
| "testing" |
| @@ -155,3 +156,60 @@ func TestHostedDiagnosticWaitsWithoutCertifying(t *testing.T) { |
| t.Fatalf("hosted failure lost or certified: %+v", final) |
| } |
| } |
| + |
| +// shardLog is a failing shard's long log: a test failure with its |
| +// message early on, then noise, then its own last lines. |
| +func shardLog(n, size int) string { |
| + var b strings.Builder |
| + fmt.Fprintf(&b, "=== RUN TestShard%d\n--- FAIL: TestShard%d (0.01s)\n shard_test.go:%d: shard %d broke\n", n, n, n, n) |
| + for b.Len() < size { |
| + fmt.Fprintf(&b, "noise line %d of shard %d, nothing to see here\n", b.Len(), n) |
| + } |
| + fmt.Fprintf(&b, "FAIL\tamadan.net/shard%d\t1.0s\n", n) |
| + return b.String() |
| +} |
| + |
| +// TestFailedLogsEveryShard (stopped-jobs audit, fix 4): with three |
| +// failing shards of 40 KB each, every shard is named in the output and |
| +// keeps its failing test and message, within the checks output bound. |
| +// Before, only the tail of all of them joined was kept: the fix round saw |
| +// the last shard only. |
| +func TestFailedLogsEveryShard(t *testing.T) { |
| + ci := &fakeCI{on: true} |
| + e, r, cand := hostedRig(t, ci) |
| + st := ciAt(cand, "failure") |
| + full := st |
| + check := forge.CIStep{Name: "check", State: "failure"} |
| + for n := 1; n <= 3; n++ { |
| + check.Shards = append(check.Shards, forge.CIShard{Name: fmt.Sprintf("shard %d of 23", n*5), State: "failure", Log: shardLog(n, 40<<10)}) |
| + } |
| + st.Steps = []forge.CIStep{{Name: "check", State: "failure", Shards: []forge.CIShard{{Name: "shard 5 of 23", State: "failure"}, {Name: "shard 10 of 23", State: "failure"}, {Name: "shard 15 of 23", State: "failure"}}}} |
| + full.Steps = []forge.CIStep{check} |
| + ci.statuses, ci.failed = []forge.CIStatus{st}, &full |
| + rep, _ := e.hostedVerdict(context.Background(), r, judgeReport(r), st) |
| + if len(rep.Output) > wire.MaxChecksOutput { |
| + t.Fatalf("output %d bytes, over %d", len(rep.Output), wire.MaxChecksOutput) |
| + } |
| + for n := 1; n <= 3; n++ { |
| + for _, want := range []string{fmt.Sprintf("=== check shard %d of 23\n", n*5), fmt.Sprintf("--- FAIL: TestShard%d (0.01s)\n shard_test.go:%d: shard %d broke\n", n, n, n), fmt.Sprintf("FAIL\tamadan.net/shard%d\t1.0s", n)} { |
| + if !strings.Contains(rep.Output, want) { |
| + t.Errorf("output lacks %q", want) |
| + } |
| + } |
| + } |
| +} |
| + |
| +// Each unit gets an equal share; what a short one leaves goes to the |
| +// others, and a unit within its share is kept whole. |
| +func TestCIUnitsShare(t *testing.T) { |
| + short := wire.CIUnit{Name: "lint", Log: "--- FAIL: lint\n"} |
| + long := wire.CIUnit{Name: "test", Log: shardLog(1, 20<<10)} |
| + out := wire.JoinCIUnits([]wire.CIUnit{short, long}, 8<<10) |
| + if len(out) > 8<<10 || len(out) < 7<<10 || !strings.Contains(out, "=== lint\n--- FAIL: lint\n") || !strings.Contains(out, "shard 1 broke") { |
| + t.Fatalf("%d bytes:\n%s", len(out), out) |
| + } |
| + head, units := wire.SplitCIUnits("Hosted CI failed.\n"+out, []string{"lint", "test"}) |
| + if head != "Hosted CI failed.\n" || len(units) != 2 || units[0].Name != "lint" || units[1].Name != "test" || !strings.Contains(units[1].Log, "shard 1 broke") { |
| + t.Fatalf("split %q %+v", head, units) |
| + } |
| +} |
diff --git a/internal/thintest/fix_round_shards_contract_test.go b/internal/thintest/fix_round_shards_contract_test.go| new file mode 100644 |
| index 00000000..3a720484 |
| --- /dev/null |
| +++ b/internal/thintest/fix_round_shards_contract_test.go |
| @@ -0,0 +1,48 @@ |
| +package thintest |
| + |
| +import ( |
| + "fmt" |
| + "strings" |
| + "testing" |
| + |
| + "amadan.net/oficina/equipo/internal/wire" |
| +) |
| + |
| +// TestFixRoundGetsEveryShard (stopped-jobs audit, fix 4): hosted CI |
| +// failed in three shards. The fix round's feedback names every shard and |
| +// keeps each one's failing test and message, within its budget; before, |
| +// it kept the last 60 lines of the output, which only the last shard |
| +// reached ("Shard 16 also failed but its output wasn't included"). |
| +func TestFixRoundGetsEveryShard(t *testing.T) { |
| + r := newToolRigAt(t, wire.ProtocolCurrent) |
| + base, cand := strings.Repeat("1", 40), strings.Repeat("2", 40) |
| + id, _ := r.pushed("s", "Swipe down to dismiss the keyboard", base, cand) |
| + task := r.task(id) |
| + r.expect(wire.FrameWatchMerge) |
| + c := r.dispatched(wire.SpecialistChecks, base, cand, 0) |
| + names := []string{"check shard 5 of 23", "check shard 10 of 23", "check shard 16 of 23"} |
| + var units []wire.CIUnit |
| + for n, name := range names { |
| + var b strings.Builder |
| + fmt.Fprintf(&b, "--- FAIL: TestShard%d (0.01s)\n shard_test.go:%d: shard %d broke\n", n, n, n) |
| + for b.Len() < 12<<10 { |
| + fmt.Fprintf(&b, "ok \tamadan.net/pkg%d\t0.1s\n", b.Len()) |
| + } |
| + units = append(units, wire.CIUnit{Name: name, Log: b.String() + "FAIL\n"}) |
| + } |
| + rep := hostedReport(c, task.Branch, wire.HostedFailure, names...) |
| + head := "Hosted CI on oficina/sample: failed.\nFailed: " + strings.Join(names, "; ") + "\n" |
| + rep.Output = head + wire.JoinCIUnits(units, wire.MaxChecksOutput-len(head)) |
| + r.step("s-c", rep) |
| + fix := r.dispatched(wire.SpecialistEngineering, cand, "", 1) |
| + for n, name := range names { |
| + for _, want := range []string{wire.CIUnitHeader(name) + "\n", fmt.Sprintf("--- FAIL: TestShard%d (0.01s)\n shard_test.go:%d: shard %d broke\n", n, n, n)} { |
| + if !strings.Contains(fix.Feedback, want) { |
| + t.Errorf("feedback lacks %q", want) |
| + } |
| + } |
| + } |
| + if len(fix.Feedback) > wire.MaxTaskBrief+4000 { |
| + t.Fatalf("feedback %d bytes", len(fix.Feedback)) |
| + } |
| +} |
diff --git a/internal/wire/cilogs.go b/internal/wire/cilogs.go| new file mode 100644 |
| index 00000000..41f94d41 |
| --- /dev/null |
| +++ b/internal/wire/cilogs.go |
| @@ -0,0 +1,142 @@ |
| +package wire |
| + |
| +import ( |
| + "sort" |
| + "strings" |
| +) |
| + |
| +// CIUnit is one failing hosted CI unit (a step, or a sharded step's |
| +// shard) and its log, as hosted checks output carries it: a header line |
| +// CIUnitHeader(Name), then the log. |
| +type CIUnit struct{ Name, Log string } |
| + |
| +// CIUnitHeader is the line that starts a unit's part of the output. |
| +func CIUnitHeader(name string) string { return "=== " + name } |
| + |
| +// ciCut marks where a unit's log was cut. |
| +const ciCut = "[...]\n" |
| + |
| +// JoinCIUnits is every unit's part within limit bytes (stopped-jobs |
| +// audit, fix 4: the tail of all the logs joined kept only the last |
| +// failing unit). Each unit gets an equal share; what a shorter one leaves |
| +// goes to the others. Within its share a unit keeps its failure lines |
| +// first (ciFailure, with the indented lines after each), then its tail. |
| +func JoinCIUnits(units []CIUnit, limit int) string { |
| + parts := make([]string, len(units)) |
| + order := make([]int, len(units)) |
| + for i := range order { |
| + order[i] = i |
| + } |
| + sort.SliceStable(order, func(a, b int) bool { return len(units[order[a]].Log) < len(units[order[b]].Log) }) |
| + left := limit |
| + for n, i := range order { |
| + share := left / (len(units) - n) |
| + head := CIUnitHeader(units[i].Name) + "\n" |
| + if share <= len(head) { |
| + continue |
| + } |
| + parts[i] = head + clipCILog(units[i].Log, share-len(head)) |
| + left -= len(parts[i]) |
| + } |
| + return strings.Join(parts, "") |
| +} |
| + |
| +// SplitCIUnits finds the named units' parts in output: head is what |
| +// comes before the first, and each unit runs to the next header. A header |
| +// is a whole line naming one of names; a unit not named is left in the |
| +// part before it. |
| +func SplitCIUnits(output string, names []string) (head string, units []CIUnit) { |
| + known := map[string]bool{} |
| + for _, n := range names { |
| + known[CIUnitHeader(n)] = true |
| + } |
| + lines := strings.SplitAfter(output, "\n") |
| + var b strings.Builder |
| + cur := -1 |
| + flush := func() { |
| + if cur < 0 { |
| + head = b.String() |
| + } else { |
| + units[cur].Log = b.String() |
| + } |
| + b.Reset() |
| + } |
| + for _, line := range lines { |
| + if known[strings.TrimSuffix(line, "\n")] { |
| + flush() |
| + units = append(units, CIUnit{Name: strings.TrimPrefix(strings.TrimSuffix(line, "\n"), "=== ")}) |
| + cur = len(units) - 1 |
| + continue |
| + } |
| + b.WriteString(line) |
| + } |
| + flush() |
| + return head, units |
| +} |
| + |
| +// clipCILog is log within n bytes: whole when it fits; else its failure |
| +// lines first, within half of n, then a cut, then its tail. |
| +func clipCILog(log string, n int) string { |
| + if !strings.HasSuffix(log, "\n") { |
| + log += "\n" |
| + } |
| + if len(log) <= n { |
| + return log |
| + } |
| + lines := strings.SplitAfter(log, "\n") |
| + keep := make([]bool, len(lines)) |
| + for i, l := range lines { |
| + if !ciFailure(l) { |
| + continue |
| + } |
| + keep[i] = true |
| + for j := i + 1; j < len(lines) && j <= i+3 && (strings.HasPrefix(lines[j], " ") || strings.HasPrefix(lines[j], "\t")); j++ { |
| + keep[j] = true |
| + } |
| + } |
| + pick := func(before int) string { |
| + var b strings.Builder |
| + offset := 0 |
| + for i, l := range lines { |
| + if offset+len(l) > before { |
| + break |
| + } |
| + offset += len(l) |
| + if keep[i] && b.Len()+len(l) <= n/2 { |
| + b.WriteString(l) |
| + } |
| + } |
| + return b.String() |
| + } |
| + fails := pick(len(log)) |
| + tail := tailLines(log, n-len(fails)-2*len(ciCut)) |
| + // A failure line the tail keeps is not given twice. |
| + fails = pick(len(log) - len(tail)) |
| + out := fails |
| + if fails != "" || len(tail) < len(log) { |
| + out += ciCut |
| + } |
| + return out + tail |
| +} |
| + |
| +// ciFailure: a line that says what failed (Go's test output and the |
| +// usual error words). |
| +func ciFailure(line string) bool { |
| + t := strings.TrimSpace(line) |
| + return strings.HasPrefix(t, "--- FAIL") || strings.HasPrefix(t, "FAIL") || strings.HasPrefix(t, "panic:") || strings.Contains(t, "Error") |
| +} |
| + |
| +// tailLines is the end of s within limit bytes, starting on a line. |
| +func tailLines(s string, limit int) string { |
| + if limit <= 0 { |
| + return "" |
| + } |
| + if len(s) <= limit { |
| + return s |
| + } |
| + s = s[len(s)-limit:] |
| + if i := strings.IndexByte(s, '\n'); i >= 0 { |
| + s = s[i+1:] |
| + } |
| + return strings.ToValidUTF8(s, "") |
| +} |