oficina / equipo Public

Unfinished work never reaches an older instance as finished

Astra round 2 on the branch (one P1, two P2):

- P1: a report of unfinished work saved while the instance spoke 31,
  or a restart's or republish's push of such a commit, could reach an
  instance that went back to 30. Encode below protocol 31 now sends a
  done step_timeout report as the step failing step_timeout with no
  candidate (wire.WithoutUnfinished), at every send.
- P2: with more than 20 failing units the instance split the output on
  the binding's capped names, so later units hid inside the twentieth.
  Unit headers now have their own prefix ("=== CI unit: "), and the
  instance finds every unit by it; an older runner's output keeps the
  old tail.
- P2: a rebase cleared the unfinished mark; it keeps it now.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by paul@keymail.dev 8f661e2f083a3c7e40e3564aca26be3c5ee16143 parent 5963a0b
9 files changed, +131 −26
  • .rastrillo/budgets.txt +3 −3
  • internal/equipo/chat/review.go +9 −4
  • internal/equipo/chat/unfinished_test.go +3 −0
  • internal/runner/thin/judge_hosted.go +1 −1
  • internal/runner/thin/judge_hosted_test.go +34 −4
  • internal/wire/cilogs.go +14 −14
  • internal/wire/runners.go +5 −0
  • internal/wire/unfinished.go +16 −0
  • internal/wire/unfinished_test.go +46 −0
diff --git a/.rastrillo/budgets.txt b/.rastrillo/budgets.txt
index dae31c67..1c6a1c89 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 22616 - Stuck tasks, merge_credential copy, no-access merges (2026-11-26); a timed-out step's pushed work on the timeline (2026-11-26); measured 22616 source lines.
-size internal/wire 7268 - Native task evidence, merge reasons (2026-11-26); protocol 31 unfinished work, shell_unavailable, CI unit logs (2026-11-26); measured 7268 source lines.
+size internal/wire 7289 - Native task evidence, merge reasons (2026-11-26); protocol 31 unfinished work, shell_unavailable, CI unit logs (2026-11-26); measured 7289 source lines.
size internal/equipotest - 12017 Task 21 repairs historical migration and conversation fixtures after Plan 3, and the Rastrillo upgrade contract comparing served assets with what Assets serves; measured 0/12017 source/test lines.
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 28906 23621 Protocol 30 tools, merge credential (2026-11-26); step limit, kept timed-out work, shell use, CI unit shares (2026-11-26); measured 28906/23621.
+size internal/runner/thin 28906 23651 Protocol 30 tools, merge credential (2026-11-26); step limit, kept timed-out work, shell use, CI unit shares (2026-11-26); measured 28906/23651.
time internal/thintest 240s Thin contract and page tests, the Assistant's and the models' included, share one harness. Measured 202s on a shared 16 CPU box (2026-11-13); CI runs two lanes.
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).
@@ -56,7 +56,7 @@ perf GET /api/v1/tasks/{id} skip Thin v1 person API: bearer-only JSON for device
perf GET /api/v1/assistant/snapshot skip Assistant person API: bearer-only JSON for Base's chat, not a browser screen.
perf GET /api/v1/assistant/messages skip Assistant person API: bearer-only JSON for Base's chat, not a browser screen.
perf GET /api/v1/assistant/events skip Assistant event stream (Server-Sent Events), bearer-only and long-lived; not a screen.
-size internal/equipo/chat 34975 9740 Native task projection, no-access merges; unfinished candidates, free shell-less rounds, CI unit feedback (2026-11-26); measured 34975/9740.
+size internal/equipo/chat 34980 9743 Native task projection, no-access merges; unfinished candidates, free shell-less rounds, CI unit feedback (2026-11-26); measured 34980/9743.
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/internal/equipo/chat/review.go b/internal/equipo/chat/review.go
index d68234c4..b30f23e5 100644
--- a/internal/equipo/chat/review.go
+++ b/internal/equipo/chat/review.go
@@ -44,7 +44,7 @@ type progress struct {
// automatic rounds (freeRound).
free int
// unfinishedWork: the candidate holds the work of an Engineering step
- // that ran out of time, with any Copy commit on top.
+ // that ran out of time, with any Copy commit or rebase on top.
unfinishedWork bool
}
@@ -103,7 +103,11 @@ func progressOfKind(steps []stepRecord, kind string) progress {
p.eng = s
if s.Pushed && s.CandidateSHA != "" {
p.candidate, p.checks, p.review, p.merge = s.CandidateSHA, nil, nil, nil
- p.unfinishedWork = s.State == wire.StepDone && s.Reason == reasonUnfinished
+ // A rebase only puts the work on the new tip (and never
+ // keeps timed-out work): the mark stays as it was.
+ if !s.Rebase {
+ p.unfinishedWork = s.State == wire.StepDone && s.Reason == reasonUnfinished
+ }
}
case wire.SpecialistCopy:
if s.State == wire.StepDone && s.Pushed && s.CandidateSHA != "" {
@@ -403,7 +407,7 @@ func feedbackBudget(p progress, limit int) string {
var h wire.HostedResult
_ = json.Unmarshal([]byte(c.HostedCI), &h)
fmt.Fprintf(&b, "The repository's hosted CI failed on %s.\n", short(p.candidate))
- _, units := wire.SplitCIUnits(c.Output, h.Failed)
+ _, units := wire.SplitCIUnits(c.Output)
logged := map[string]bool{}
for _, u := range units {
logged[u.Name] = true
@@ -508,7 +512,8 @@ func (t *txn) stepBrief(k taskRecord, s stepRecord) (string, error) {
const reasonUnfinished = "step_timeout"
// unfinished: the candidate is the work of an Engineering step that ran
-// out of time before it finished (a Copy commit on top keeps it so).
+// out of time before it finished (a Copy commit or a rebase on top keeps
+// it so).
func unfinished(p progress) bool { return p.candidate != "" && p.unfinishedWork }
// unfinishedReview is Review's part of the brief for such a candidate
diff --git a/internal/equipo/chat/unfinished_test.go b/internal/equipo/chat/unfinished_test.go
index ab019ca2..4b0e090a 100644
--- a/internal/equipo/chat/unfinished_test.go
+++ b/internal/equipo/chat/unfinished_test.go
@@ -13,6 +13,7 @@ func TestUnfinishedSurvivesCopy(t *testing.T) {
timedOut := stepRecord{Specialist: wire.SpecialistEngineering, State: wire.StepDone, Pushed: true, CandidateSHA: "eng", Reason: "step_timeout"}
copied := stepRecord{Specialist: wire.SpecialistCopy, State: wire.StepDone, Pushed: true, CandidateSHA: "copy"}
finished := stepRecord{Specialist: wire.SpecialistEngineering, State: wire.StepDone, Pushed: true, CandidateSHA: "fix", Round: 1}
+ rebased := stepRecord{Specialist: wire.SpecialistEngineering, State: wire.StepDone, Pushed: true, CandidateSHA: "rebased", Rebase: true}
for name, c := range map[string]struct {
steps []stepRecord
want bool
@@ -22,6 +23,8 @@ func TestUnfinishedSurvivesCopy(t *testing.T) {
"finished after": {[]stepRecord{timedOut, copied, finished}, false},
"finished": {[]stepRecord{finished}, false},
"copy on a finished": {[]stepRecord{finished, copied}, false},
+ "rebased": {[]stepRecord{timedOut, copied, rebased}, true},
+ "rebased, finished": {[]stepRecord{finished, rebased}, false},
} {
if got := unfinished(progressOf(c.steps)); got != c.want {
t.Errorf("%s: unfinished %v, want %v", name, got, c.want)
diff --git a/internal/runner/thin/judge_hosted.go b/internal/runner/thin/judge_hosted.go
index 135c1d6a..2171a77a 100644
--- a/internal/runner/thin/judge_hosted.go
+++ b/internal/runner/thin/judge_hosted.go
@@ -132,7 +132,7 @@ func failedUnits(steps []forge.CIStep) []string {
}
// 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.
+// as failedUnits names a unit.
func failedLogs(steps []forge.CIStep) []wire.CIUnit {
var out []wire.CIUnit
for _, s := range steps {
diff --git a/internal/runner/thin/judge_hosted_test.go b/internal/runner/thin/judge_hosted_test.go
index 7c1757c8..f6f11fb7 100644
--- a/internal/runner/thin/judge_hosted_test.go
+++ b/internal/runner/thin/judge_hosted_test.go
@@ -116,7 +116,7 @@ func TestHostedChecksFailure(t *testing.T) {
if !strings.HasPrefix(rep.Output, head) {
t.Fatalf("output %q", rep.Output)
}
- hasLogs := strings.Contains(rep.Output, "budget size: 1 problem") && strings.Contains(rep.Output, "=== check shard 5 of 23\n--- FAIL: TestHeadless/2_project")
+ hasLogs := strings.Contains(rep.Output, "budget size: 1 problem") && strings.Contains(rep.Output, wire.CIUnitHeader("check shard 5 of 23")+"\n--- FAIL: TestHeadless/2_project")
if hasLogs != sameRun {
t.Fatalf("same run %v, logs %v: %q", sameRun, hasLogs, rep.Output)
}
@@ -191,7 +191,7 @@ func TestFailedLogsEveryShard(t *testing.T) {
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)} {
+ for _, want := range []string{wire.CIUnitHeader(fmt.Sprintf("check shard %d of 23", n*5)) + "\n", 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)
}
@@ -205,10 +205,10 @@ 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") {
+ if len(out) > 8<<10 || len(out) < 7<<10 || !strings.Contains(out, wire.CIUnitHeader("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"})
+ head, units := wire.SplitCIUnits("Hosted CI failed.\n" + out)
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)
}
@@ -237,3 +237,33 @@ func TestCIUnitsEveryNameFirst(t *testing.T) {
}
}
}
+
+// With more failing units than the binding names (wire.MaxHostedFailed),
+// every unit's log is still its own part: the instance finds each by its
+// header, not by the binding's capped list.
+func TestFailedLogsBeyondTheNamedUnits(t *testing.T) {
+ ci := &fakeCI{on: true}
+ e, r, cand := hostedRig(t, ci)
+ st := ciAt(cand, "failure")
+ snap, logs := forge.CIStep{Name: "check", State: "failure"}, forge.CIStep{Name: "check", State: "failure"}
+ total := wire.MaxHostedFailed + 3
+ for n := 1; n <= total; n++ {
+ name := fmt.Sprintf("shard %d of 23", n)
+ snap.Shards = append(snap.Shards, forge.CIShard{Name: name, State: "failure"})
+ logs.Shards = append(logs.Shards, forge.CIShard{Name: name, State: "failure", Log: shardLog(n, 4<<10)})
+ }
+ st.Steps = []forge.CIStep{snap}
+ full := st
+ full.Steps = []forge.CIStep{logs}
+ ci.statuses, ci.failed = []forge.CIStatus{st}, &full
+ rep, _ := e.hostedVerdict(context.Background(), r, judgeReport(r), st)
+ _, units := wire.SplitCIUnits(rep.Output)
+ if len(rep.Hosted.Failed) != wire.MaxHostedFailed || len(units) != total || len(rep.Output) > wire.MaxChecksOutput {
+ t.Fatalf("%d named, %d units found, %d bytes", len(rep.Hosted.Failed), len(units), len(rep.Output))
+ }
+ for n, u := range units {
+ if u.Name != fmt.Sprintf("check shard %d of 23", n+1) || !strings.Contains(u.Log, fmt.Sprintf("--- FAIL: TestShard%d ", n+1)) || strings.Contains(u.Log, "=== CI unit") {
+ t.Fatalf("unit %d %q: %q", n, u.Name, u.Log)
+ }
+ }
+}
diff --git a/internal/wire/cilogs.go b/internal/wire/cilogs.go
index 3fb4b1eb..b59b68da 100644
--- a/internal/wire/cilogs.go
+++ b/internal/wire/cilogs.go
@@ -10,8 +10,14 @@ import (
// CIUnitHeader(Name), then the log.
type CIUnit struct{ Name, Log string }
+// ciUnitPrefix starts a unit's header: distinct from Go's own "=== RUN"
+// lines, so the instance finds every unit without the binding's capped
+// list of names. A log could forge one; that only moves budget between
+// parts of the same quoted data.
+const ciUnitPrefix = "=== CI unit: "
+
// CIUnitHeader is the line that starts a unit's part of the output.
-func CIUnitHeader(name string) string { return "=== " + name }
+func CIUnitHeader(name string) string { return ciUnitPrefix + strings.ReplaceAll(name, "\n", " ") }
// ciCut marks where a unit's log was cut.
const ciCut = "[...]\n"
@@ -53,16 +59,10 @@ func JoinCIUnits(units []CIUnit, limit int) string {
return b.String()
}
-// 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")
+// SplitCIUnits finds the units' parts in output: head is what comes
+// before the first header, and each unit runs to the next. Output with no
+// headers (an older runner's) is all head.
+func SplitCIUnits(output string) (head string, units []CIUnit) {
var b strings.Builder
cur := -1
flush := func() {
@@ -73,10 +73,10 @@ func SplitCIUnits(output string, names []string) (head string, units []CIUnit) {
}
b.Reset()
}
- for _, line := range lines {
- if known[strings.TrimSuffix(line, "\n")] {
+ for _, line := range strings.SplitAfter(output, "\n") {
+ if name, ok := strings.CutPrefix(strings.TrimSuffix(line, "\n"), ciUnitPrefix); ok {
flush()
- units = append(units, CIUnit{Name: strings.TrimPrefix(strings.TrimSuffix(line, "\n"), "=== ")})
+ units = append(units, CIUnit{Name: name})
cur = len(units) - 1
continue
}
diff --git a/internal/wire/runners.go b/internal/wire/runners.go
index 0714f4e6..14458ca7 100644
--- a/internal/wire/runners.go
+++ b/internal/wire/runners.go
@@ -645,6 +645,11 @@ func Encode(f Frame, protocol int) (Frame, error) {
}
changed = dropped
}
+ if protocol < ProtocolUnfinishedWork {
+ if v, ok := body.(*StepReport); ok && WithoutUnfinished(v) {
+ changed = true
+ }
+ }
if protocol < ProtocolPinnedRelease {
if v, ok := body.(*ReleaseCommand); ok && v.Connection != "" {
return Frame{}, fmt.Errorf("%w: a pinned release at protocol %d", ErrProtocol, protocol)
diff --git a/internal/wire/unfinished.go b/internal/wire/unfinished.go
new file mode 100644
index 00000000..e0f2fe7d
--- /dev/null
+++ b/internal/wire/unfinished.go
@@ -0,0 +1,16 @@
+package wire
+
+// WithoutUnfinished is a step report as an instance below
+// ProtocolUnfinishedWork must read it. Such an instance drops the reason
+// of a done Engineering step, so a timed-out step's pushed work (done,
+// step_timeout) would read as finished: it goes as the step failing
+// step_timeout, its candidate unpublished, as before protocol 31. This
+// holds for a report saved while the instance spoke 31 and sent after it
+// went back (Encode at each send). Reports whether it changed rep.
+func WithoutUnfinished(rep *StepReport) bool {
+ if rep.State != StepDone || rep.Reason != "step_timeout" {
+ return false
+ }
+ rep.State, rep.Pushed, rep.CandidateSHA, rep.Askable = StepFailed, false, "", false
+ return true
+}
diff --git a/internal/wire/unfinished_test.go b/internal/wire/unfinished_test.go
new file mode 100644
index 00000000..5894990a
--- /dev/null
+++ b/internal/wire/unfinished_test.go
@@ -0,0 +1,46 @@
+package wire_test
+
+import (
+ "bytes"
+ "testing"
+
+ "amadan.net/oficina/equipo/internal/wire"
+)
+
+// A timed-out step's pushed work (done, step_timeout) reaches an instance
+// at protocol 31 as it is, and one below it as the step failing
+// step_timeout with no candidate: an instance that went back to 30 after
+// the report was saved never reads unfinished work as finished. Other
+// reports are unchanged.
+func TestUnfinishedReportDowngrade(t *testing.T) {
+ cand := "2222222222222222222222222222222222222222"
+ unfinished := wire.StepReport{TaskID: "tk1", StepID: "s1", Attempt: 1, State: wire.StepDone, Reason: "step_timeout", CandidateSHA: cand, Pushed: true, Askable: true, Termination: true, Findings: []wire.Finding{}}
+ f, err := wire.NewFrame("r", wire.FrameStep, unfinished)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if same, err := wire.Encode(f, wire.ProtocolUnfinishedWork); err != nil || !bytes.Equal(same.Data, f.Data) {
+ t.Fatalf("at 31: %v %s", err, same.Data)
+ }
+ old, err := wire.Encode(f, wire.ProtocolStuckTasks)
+ if err != nil {
+ t.Fatal(err)
+ }
+ body, err := old.Decode()
+ if err != nil {
+ t.Fatal(err)
+ }
+ if v := body.(*wire.StepReport); v.State != wire.StepFailed || v.Reason != "step_timeout" || v.Pushed || v.CandidateSHA != "" || v.Askable || !v.Termination {
+ t.Fatalf("at 30: %+v", v)
+ }
+ for _, rep := range []wire.StepReport{
+ {TaskID: "tk1", StepID: "s1", Attempt: 1, State: wire.StepDone, CandidateSHA: cand, Pushed: true, Termination: true, Findings: []wire.Finding{}},
+ {TaskID: "tk1", StepID: "s1", Attempt: 1, State: wire.StepDone, Reason: wire.ReasonShellUnavailable, CandidateSHA: cand, Pushed: true, Termination: true, Findings: []wire.Finding{}},
+ {TaskID: "tk1", StepID: "s1", Attempt: 1, State: wire.StepFailed, Reason: "step_timeout", Termination: true, Findings: []wire.Finding{}},
+ } {
+ f, _ := wire.NewFrame("r", wire.FrameStep, rep)
+ if same, err := wire.Encode(f, wire.ProtocolStuckTasks); err != nil || !bytes.Equal(same.Data, f.Data) {
+ t.Fatalf("%+v at 30 changed: %v %s", rep, err, same.Data)
+ }
+ }
+}