oficina / equipo Public

Check for unfinished work again once the runner is stopped

Astra round 6 on the branch (after the protocol move, one P1, one P2):

- P1: the rollback's check for open unfinished work read the replica
  while the runner could still deliver a report, so work accepted after
  the reading could reach the older instance. Only the runner reports
  steps: once it is stopped, the rollback reads again on two readings a
  wait apart, and on any unfinished work starts the runner again and
  refuses before the instance changes.
- P2: with a local gate, hosted CI's diagnostic was cut to the tail of
  its third of the bound, and the fix round kept the last 60 lines, so
  earlier failing shards were lost again. wire.ClipCIOutput keeps the
  end of the text before the units and every unit's share; the runner
  uses it for the combined diagnostic, and the instance for any checks
  output with units in it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by paul@keymail.dev c4c9ebf5d267551672c99053996044fd8927ec5d parent eab203f
7 files changed, +104 −16
  • .rastrillo/budgets.txt +4 −4
  • internal/equipo/chat/review.go +8 −2
  • internal/release/upgrade_test.go +23 −2
  • internal/runner/thin/judge.go +2 −1
  • internal/thintest/fix_round_shards_contract_test.go +30 −0
  • internal/wire/cilogs.go +12 −0
  • scripts/upgrade-thin.sh +25 −7
diff --git a/.rastrillo/budgets.txt b/.rastrillo/budgets.txt
index 8f46ed1d..0476a5ca 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 23239 - Native preview passes, wrapper grants, Retry/timeline, no-access merge copy; a timed-out step's pushed work on the timeline (2026-11-26); measured 23239 source lines.
-size internal/wire 7408 - Protocol 31 display facts, path validation, task evidence, merge reasons; protocol 32 unfinished work, shell_unavailable, CI units (2026-11-26); measured 7408 source lines.
+size internal/wire 7420 - Protocol 31 display facts, path validation, task evidence, merge reasons; protocol 32 unfinished work, shell_unavailable, CI units (2026-11-26); measured 7420 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 29053 23948 Protocol 31 facts, merge credential, publication guards; step limit, kept timed-out work, shell use, CI unit shares (2026-11-26); measured 29053/23948.
+size internal/runner/thin 29054 23948 Protocol 31 facts, merge credential, publication guards; step limit, kept timed-out work, shell use, CI unit shares (2026-11-26); measured 29054/23948.
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 35055 9910 Detail-only file facts, hosted projection, no-access merges, preview reads; unfinished work, free shell-less rounds, CI feedback (2026-11-26); measured 35055/9910.
+size internal/equipo/chat 35061 9910 Detail-only file facts, hosted projection, no-access merges, preview reads; unfinished work, free shell-less rounds, CI feedback (2026-11-26); measured 35061/9910.
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.
@@ -71,7 +71,7 @@ perf GET /tasks/{id}/files/{file} skip Research kept images: the bytes of one im
perf GET /api/v1/runners skip Mac runners person API: bearer-only JSON for devices; the browser shows runners in the Team section.
time cmd/equipo-runner 60s TestReleaseRunnerHasNoFakeWorker builds the release runner and the thin package under testbuild (about 12s locally).
size internal/headless - 11437 Grant scenarios for a named repository (hub #48); the sign-in's account email at 1280 and 390; measured 11437 test lines.
-size internal/thintest - 35414 Protocol 31 and detail-only contracts, stuck tasks, no-access merges; held retries, unfinished work, shard feedback, free rounds (2026-11-26); measured 35414 test lines.
+size internal/thintest - 35444 Protocol 31 and detail-only contracts, stuck tasks, no-access merges; held retries, unfinished work, shard feedback, free rounds (2026-11-26); measured 35444 test lines.
perf GET /api/v1/projects/{id}/merge-policy skip Merge authority person API: bearer-only JSON for devices; the browser reads the policy on /projects/{id}.
perf GET /api/v1/usage skip Thin v1 person API: bearer-only JSON for devices; the browser reads usage through /usage.
diff --git a/internal/equipo/chat/review.go b/internal/equipo/chat/review.go
index 276781b4..0295c045 100644
--- a/internal/equipo/chat/review.go
+++ b/internal/equipo/chat/review.go
@@ -441,8 +441,14 @@ func feedbackBudget(p progress, limit int) string {
code = *c.ExitCode
}
fmt.Fprintf(&b, "The repository's checks (%s) failed on %s with exit code %d.\n", wire.QuotedData(c.Gate), short(p.candidate), code)
- 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); len(units) > 0 {
+ // The local gate with hosted CI's units beside it: each unit
+ // keeps its share.
+ writeFeedbackData(&b, limit, "CI output", wire.ClipCIOutput(c.Output, 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"))
+ }
}
if r := p.review; r != nil && r.Verdict == wire.VerdictChanges {
fmt.Fprintf(&b, "Review asked for changes on %s.\n", short(p.candidate))
diff --git a/internal/release/upgrade_test.go b/internal/release/upgrade_test.go
index 05db4bf9..46c63a91 100644
--- a/internal/release/upgrade_test.go
+++ b/internal/release/upgrade_test.go
@@ -72,7 +72,7 @@ func newUpgradeRig(t *testing.T) *upgradeRig {
r.write(filepath.Join(bin, "carlos"), "#!/bin/sh\n"+log+`case "$1 $2" in
"db "*) [ -e `+filepath.Join(root, "replicabroken")+` ] && { echo "the copy failed its integrity check" >&2; exit 1; }
case "$2 $*" in pull*) for a; do case $prev in --out) python3 -c "import sqlite3,sys; c=sqlite3.connect(sys.argv[1]); [c.execute('create table '+t+'(x)') for t in ('teams','chat_tasks','chat_steps','chat_turns','runners')]; c.commit()" "$a" ;; esac; prev=$a; done ;;
- *integrity_check*) printf 'integrity_check\nok\n' ;; *step_timeout*) printf 'x\n%s\n' "$(cat `+filepath.Join(root, "unfinished")+` 2>/dev/null || echo 0)" ;; *) printf 'x\n%s\n' "$(cat `+filepath.Join(root, "inflight")+`)" ;; esac ;;
+ *integrity_check*) printf 'integrity_check\nok\n' ;; *step_timeout*) if [ -s `+filepath.Join(root, "unfinished.seq")+` ]; then n=$(head -1 `+filepath.Join(root, "unfinished.seq")+`); sed -i 1d `+filepath.Join(root, "unfinished.seq")+`; else n=$(cat `+filepath.Join(root, "unfinished")+` 2>/dev/null || echo 0); fi; printf 'x\n%s\n' "$n" ;; *) printf 'x\n%s\n' "$(cat `+filepath.Join(root, "inflight")+`)" ;; esac ;;
deploy*) for a; do case $prev in --version) echo "$a" > `+filepath.Join(root, "served")+` ;; esac; prev=$a; done ;;
promote*) shift; for a; do last2=$last; last=$a; done; echo "$last2" > `+filepath.Join(root, "served")+` ;;
esac
@@ -437,7 +437,7 @@ func TestUpgradeRollbackRefusesWithUnfinishedWork(t *testing.T) {
r.write(filepath.Join(r.root, "unfinished"), "2", 0600)
before := r.read(r.log)
out, err := r.run("rollback", "--execute")
- if err == nil || !strings.Contains(out, "refused: 2 open task(s) hold unfinished work") || strings.Contains(r.state(), "rolled_back=1") {
+ if err == nil || !strings.Contains(out, "open tasks with unfinished work: 2") || !strings.Contains(out, "refused: open tasks hold unfinished work") || strings.Contains(r.state(), "rolled_back=1") {
t.Fatalf("rollback with unfinished work: %v\n%s", err, out)
}
if changed := strings.TrimPrefix(r.read(r.log), before); strings.Contains(changed, "systemctl") || strings.Contains(changed, "promote") {
@@ -451,3 +451,24 @@ func TestUpgradeRollbackRefusesWithUnfinishedWork(t *testing.T) {
t.Fatalf("rollback told to go on: %v\n%s", err, out)
}
}
+
+// Unfinished work that comes in after the first reading, before the
+// runner stopped, is found once nothing reports steps: the rollback
+// starts the runner again and refuses, before the instance changes.
+func TestUpgradeRollbackRefusesUnfinishedWorkThatCameIn(t *testing.T) {
+ r := newUpgradeRig(t)
+ if out, err := r.run(upgradeTo, "--execute"); err != nil {
+ t.Fatalf("upgrade: %v\n%s", err, out)
+ }
+ r.write(filepath.Join(r.root, "unfinished.seq"), "0\n0\n1\n", 0600)
+ before := r.read(r.log)
+ out, err := r.run("rollback", "--execute")
+ if err == nil || !strings.Contains(out, "the runner was started again") || strings.Contains(r.state(), "rolled_back=1") {
+ t.Fatalf("rollback with work that came in: %v\n%s", err, out)
+ }
+ changed := strings.TrimPrefix(r.read(r.log), before)
+ if strings.Contains(changed, "promote") || strings.Contains(changed, "daemon-reload") {
+ t.Fatalf("changed the instance or the unit:\n%s", changed)
+ }
+ inOrder(t, changed, "systemctl --user stop", "systemctl --user start")
+}
diff --git a/internal/runner/thin/judge.go b/internal/runner/thin/judge.go
index ed50efbc..9388ff75 100644
--- a/internal/runner/thin/judge.go
+++ b/internal/runner/thin/judge.go
@@ -331,7 +331,8 @@ func (e *Engineer) checks(ctx context.Context, r stepRow, progress func(wire.Ste
res.output = "Uncertified candidate gate diagnostic:\n" + tailBytes(res.output, wire.MaxChecksOutput/3)
}
if hosted != nil {
- res.output += "\nHosted CI diagnostic:\n" + tailBytes(hosted.Output, wire.MaxChecksOutput/3)
+ // Every failing hosted unit keeps its share (wire.ClipCIOutput).
+ res.output += "\nHosted CI diagnostic:\n" + wire.ClipCIOutput(hosted.Output, wire.MaxChecksOutput/3)
if hosted.Checks == wire.ChecksFailed && res.reason == "" && res.terminated {
res.code = 1
}
diff --git a/internal/thintest/fix_round_shards_contract_test.go b/internal/thintest/fix_round_shards_contract_test.go
index 3a720484..c37347b0 100644
--- a/internal/thintest/fix_round_shards_contract_test.go
+++ b/internal/thintest/fix_round_shards_contract_test.go
@@ -46,3 +46,33 @@ func TestFixRoundGetsEveryShard(t *testing.T) {
t.Fatalf("feedback %d bytes", len(fix.Feedback))
}
}
+
+// The local gate failed with hosted CI's failing units beside it (the
+// runner's combined diagnostic): the fix round's feedback still keeps
+// every unit's failing test.
+func TestFixRoundGetsEveryShardBesideTheLocalGate(t *testing.T) {
+ r := newToolRigAt(t, wire.ProtocolCurrent)
+ base, cand := strings.Repeat("1", 40), strings.Repeat("2", 40)
+ id, _ := r.pushed("g", "Swipe down to dismiss the keyboard", base, cand)
+ _ = id
+ r.expect(wire.FrameWatchMerge)
+ c := r.dispatched(wire.SpecialistChecks, base, cand, 0)
+ var units []wire.CIUnit
+ for n := range 3 {
+ 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: fmt.Sprintf("check shard %d of 23", n+1), Log: b.String()})
+ }
+ hosted := "Hosted CI on oficina/sample at 2222222: failed.\n" + wire.JoinCIUnits(units, wire.MaxChecksOutput)
+ output := "Candidate gate diagnostic:\n" + strings.Repeat("local noise\n", 400) + "\nHosted CI diagnostic:\n" + wire.ClipCIOutput(hosted, wire.MaxChecksOutput/3)
+ r.checks("g-c", c, wire.ChecksFailed, exit(1), "", output)
+ fix := r.dispatched(wire.SpecialistEngineering, cand, "", 1)
+ for n := range 3 {
+ if want := fmt.Sprintf("--- FAIL: TestShard%d (0.01s)\n shard_test.go:%d: shard %d broke\n", n, n, n); !strings.Contains(fix.Feedback, want) {
+ t.Errorf("feedback lacks %q", want)
+ }
+ }
+}
diff --git a/internal/wire/cilogs.go b/internal/wire/cilogs.go
index 584fbb62..fc370f53 100644
--- a/internal/wire/cilogs.go
+++ b/internal/wire/cilogs.go
@@ -60,6 +60,18 @@ func JoinCIUnits(units []CIUnit, limit int) string {
return b.String()
}
+// ClipCIOutput is output within limit bytes: with units in it, the end
+// of what comes before the first (at most a third of limit), then every
+// unit's share (JoinCIUnits); without, its tail.
+func ClipCIOutput(output string, limit int) string {
+ head, units := SplitCIUnits(output)
+ if len(units) == 0 {
+ return tailLines(output, limit)
+ }
+ head = tailLines(head, limit/3)
+ return head + JoinCIUnits(units, limit-len(head))
+}
+
// 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.
diff --git a/scripts/upgrade-thin.sh b/scripts/upgrade-thin.sh
index 6d321022..07735a18 100755
--- a/scripts/upgrade-thin.sh
+++ b/scripts/upgrade-thin.sh
@@ -66,6 +66,7 @@ carlos_app=(--app "$APP" --account "$ACCOUNT" --console "$CONSOLE")
# (done, step_timeout; protocol 32): a release before it takes that work
# for finished, so a rollback refuses while any is open.
UNFINISHED="SELECT count(DISTINCT k.id) FROM chat_tasks k JOIN chat_steps s ON s.task_id=k.id WHERE s.specialist='engineering' AND s.state='done' AND s.reason='step_timeout' AND k.stage NOT IN ('done','cancelled')"
+UNFINISHED_REFUSAL="open tasks hold unfinished work a release before protocol 32 takes for finished: finish or cancel them, or set UPGRADE_ALLOW_UNFINISHED=1 to roll back anyway"
IN_FLIGHT="SELECT (SELECT count(*) FROM chat_steps WHERE state IN ('queued','running'))||'/'||(SELECT count(*) FROM chat_steps WHERE specialist='merge' AND state IN ('queued','running'))||'/'||(SELECT count(*) FROM chat_turns WHERE dispatched=1 AND state NOT IN ('replied','failed','cancelled'))"
mode=upgrade
@@ -119,6 +120,16 @@ idle() {
[[ $out =~ ^[0-9]+/[0-9]+/[0-9]+$ ]] || die "could not read the work in flight. $REPLICA"
[[ $out == 0/0/0 ]] || die "in flight (steps/merges/turns): $out; run again when nothing runs"
}
+# No open task holds unfinished work (UNFINISHED), on one reading of the
+# replica, unless the operator said to go on.
+unfinished_none() {
+ local n
+ [[ ${UPGRADE_ALLOW_UNFINISHED:-} == 1 ]] && return 0
+ n=$(carlos db query "${carlos_app[@]}" --sql "$UNFINISHED" | tail -1) || die "could not read the open tasks. $REPLICA"
+ [[ $n =~ ^[0-9]+$ ]] || die "could not read the open tasks. $REPLICA"
+ echo " open tasks with unfinished work: $n"
+ [[ $n == 0 ]]
+}
# The runner scans every preview with the gitleaks beside its own
# executable, held to the hash linked into the runner; without it every
# preview fails (preview_scanner). $1 is a runner release directory: its
@@ -193,16 +204,23 @@ if [[ $mode == rollback ]]; then
prev_sha=$(sha256sum "$prev_exec" | cut -d ' ' -f 1)
step "rollback 0 no open task holds unfinished work"
echo " open tasks whose Engineering ran out of time and kept its work: 0 (a release before"
- echo " protocol 32 takes that work for finished); finish or cancel them first, or set"
+ echo " protocol 32 takes that work for finished), read now and again on two readings once"
+ echo " the runner is stopped (only it reports steps); finish or cancel them first, or set"
echo " UPGRADE_ALLOW_UNFINISHED=1 to roll back anyway"
- if ((execute)) && [[ ${UPGRADE_ALLOW_UNFINISHED:-} != 1 ]]; then
- n=$(carlos db query "${carlos_app[@]}" --sql "$UNFINISHED" | tail -1) || die "could not read the open tasks. $REPLICA"
- [[ $n =~ ^[0-9]+$ ]] || die "could not read the open tasks. $REPLICA"
- [[ $n == 0 ]] || die "$n open task(s) hold unfinished work a release before protocol 32 takes for finished: finish or cancel them, or set UPGRADE_ALLOW_UNFINISHED=1 to roll back anyway"
- fi
+ if ((execute)); then unfinished_none || die "$UNFINISHED_REFUSAL"; fi
step "rollback 1 stop the runner"
# A retry after the previous runner started again does not stop it a second time.
- if ((execute)) && runs "$prev_sha"; then echo " $UNIT already runs $prev_exec"; else run systemctl --user stop "$UNIT"; fi
+ if ((execute)) && runs "$prev_sha"; then echo " $UNIT already runs $prev_exec"; else
+ run systemctl --user stop "$UNIT"
+ # Nothing reports a step now: two readings, a wait apart, so the
+ # replica has caught up with the last report the runner sent.
+ if ((execute)); then
+ for reading in 1 2; do
+ ((reading == 1)) || sleep "${UPGRADE_WAIT:-5}"
+ unfinished_none || { run systemctl --user start "$UNIT"; die "$UNFINISHED_REFUSAL (the runner was started again; nothing else changed)"; }
+ done
+ fi
+ fi
step "rollback 2 the previous runner's service.env and unit"
run cp -p "$snap/service.env" "$RUNNER_ROOT/service.env"
run cp -p "$snap/equipo-runner.service" "$RUNNER_ROOT/equipo-runner.service"