oficina / equipo Public

Merge thin-v1-slice4 round-1 fixes (e7a1b52) into thin-v1-slice4b

Both sides kept: branch head and answer frames, Task.branch_head then
Task.questions, the Link's Synced and Forget hooks. The questions
migration becomes 0046 after slice 4's 0045_thin_branch_head. Budgets
merged (runner/thin 8200, checks 90s, headless 240s). The runner's
reason scan also accepts answer reasons: the launch path serves
questions too.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev cb7a8907be30160e50538f3b2381ec4bbd21f1a6 parent e911755parent e7a1b52
33 files changed, +881 −93
  • .rastrillo/budgets.txt +4 −3
  • docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md +1 −0
  • docs/superpowers/plans/SLICE4-PROGRESS.md +47 −0
  • internal/equipo/chat/review.go +76 −1
  • internal/equipo/chat/runner.go +2 −0
  • internal/equipo/chat/stream.go +1 −1
  • internal/equipo/chat/tasks.go +17 −3
  • internal/equipo/copy.go +1 −0
  • internal/equipo/migrations/0045_thin_branch_head.sql +2 −0
  • internal/equipo/migrations/{0045_thin_questions.sql => 0046_thin_questions.sql} +0 −0
  • internal/equipo/migrations/schema.sql +1 −1
  • internal/equipo/work_pages.go +4 −0
  • internal/headless/review_test.go +21 −0
  • internal/runner/thin/engineer.go +4 −1
  • internal/runner/thin/forge.go +19 −2
  • internal/runner/thin/judge.go +136 −26
  • internal/runner/thin/link.go +6 −0
  • internal/runner/thin/merge.go +114 −47
  • internal/runner/thin/review_fixes_test.go +291 −0
  • internal/runner/thin/run.go +1 −0
  • internal/runner/thin/state.go +5 −0
  • internal/thintest/review_contract_test.go +78 −0
  • internal/wire/frames.go +3 −1
  • internal/wire/tasks.go +25 −0
  • internal/wire/tasks_test.go +1 −1
  • internal/wire/wire_test.go +1 −1
  • internal/wire/wiretest/testdata/api/event-task.json +1 −1
  • internal/wire/wiretest/testdata/api/needs-you.json +1 −1
  • internal/wire/wiretest/testdata/api/task-ready.json +1 −1
  • internal/wire/wiretest/testdata/api/task.json +1 −1
  • internal/wire/wiretest/testdata/api/tasks.json +1 −1
  • internal/wire/wiretest/testdata/frames/branch.json +1 −0
  • scripts/runner-reference-allowlist.json +14 −0

CI cancelled — superseded by a newer push — run details

diff --git a/.rastrillo/budgets.txt b/.rastrillo/budgets.txt
index 9d667334..a28820fc 100644
--- a/.rastrillo/budgets.txt
+++ b/.rastrillo/budgets.txt
@@ -16,7 +16,7 @@ time internal/equipotest 300s Final fix package rerun measured 187.035s (review
size internal/equipo 12000 - Thin v1 slice 4 adds the thin sidebar (rail.go), review and checks lines on the task card and pages, and their copy (about 190 lines). Thin v1 slice 3 adds the task card, the thin Tasks and Projects pages and their actions over the chat store, and their copy (about 280 lines). Thin v1 slice 2 adds activity labels, card copy and card rendering on the chat page (about 250 lines); slice 1 added the chat wiring and page (about 180 lines) beside code its slice 7 sweep deletes (the live hub, the old coordinator); lower then. Task 7 keeps the existing ceiling by moving transaction-bound event lookup into conversation. Measured 10796 source and 437 test lines; roster, database, pending copy and execution wiring remain here.
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 75s CI worker measured 44.553s (44.6s rounded), and 61.1s on the loaded slice 4b CI run (package unchanged); 75s gives 23 percent headroom over that. Shared baseline capture reduces repeated Go runs; retain the CI allowance for sandbox sentinels, timeout and child cleanup.
+time internal/runner/checks 90s CI worker measured 44.553s (44.6s rounded); 60s gives 34 percent headroom. Shared baseline capture reduces repeated Go runs; retain the CI allowance for sandbox sentinels, timeout and child cleanup. 2026-11-07: loaded CI (host load about 24) measured 66.5s with the package unchanged by thin v1 slice 4 beyond optional check mounts; 90s keeps 35 percent headroom.
time internal/runner 330s Plan 3 CI repair measured 292.120s for the full package (controller CI 472.184s). Parallel plan graphs and removal of repeated progress floods reduced their local targeted run from 146.920s to 30.784s; the original bug graph retains volume coverage. Keep 330s for journal, proxy, recovery and namespace integration, with 13 percent headroom.
perf GET /api/runner/v2/artifacts/{assignment}/{artifact} skip Authenticated runner artifact download, not a browser GET screen. Runner long-poll and blob downloads use POST and are outside the screen inventory.
@@ -35,9 +35,10 @@ 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.
time internal/runner/containment 15s Plan 3 loaded CI measured 10.817s; niced serial reruns measured 5.773s and 5.750s. The added coordinator mount check has no repeated launches to remove; 15s leaves 38 percent headroom for namespace, process-exit and recovery assertions.
time internal/tryequipo 30s Release starter-set controller K3 records CI runs of 10.8s and 13.1s; 30s retains the guide integration checks with headroom on the shared runner.
-size internal/runner/thin 8000 - Thin v1 slice 3 adds Engineering steps beside the coordinator: the durable step state and engine (step.go) and the executor that checks out the task tree, runs the CLI in the implement containment, commits and pushes (engineer.go), about 800 lines sharing the coordinator's launch, tool socket and account selection. Measured 5686 source lines. Splitting would export the launch internals; revisit at the slice 7 sweep. Slice 4 adds checks and review on a candidate (judge.go) and the merge watch (merge.go), about 800 lines, sharing the Engineer launch path; measured 6808. Slice 4b keeps Engineering and Review sessions and answers the creator's questions from them (ask.go: kept-session and ask state, read-only git tools, the answer stream), about 700 lines on the same launch path; measured 7685.
+size internal/runner/thin 8200 - Thin v1 slice 3 adds Engineering steps beside the coordinator: the durable step state and engine (step.go) and the executor that checks out the task tree, runs the CLI in the implement containment, commits and pushes (engineer.go), about 800 lines sharing the coordinator's launch, tool socket and account selection. Measured 5686 source lines. Splitting would export the launch internals; revisit at the slice 7 sweep. Slice 4 adds checks and review on a candidate (judge.go) and the merge watch (merge.go), about 800 lines, sharing the Engineer launch path; measured 6808, 7035 after review round 1 (branch head watch, deadlines, streamed outputs). Slice 4b keeps Engineering and Review sessions and answers the creator's questions from them (ask.go: kept-session and ask state, read-only git tools, the answer stream), about 700 lines on the same launch path.
time internal/thintest 30s Thin v1 contract tests: a real instance and a scripted runner per test, fixtures replayed against every request, frame and event. Slice 3 adds the task, step-sync and grant contracts; CI measured 14.805s. 30s keeps room for the slice 4 review contracts.
-time internal/headless 240s Thin v1 headless suite: real instance, runner and bubblewrap per scenario (spec 7, under two minutes). Slice 4b adds 4b_ask (a task to ready to merge, then four questions; about 12s); loaded CI measured 182.9s for the package, 135s for TestHeadless itself. 240s keeps 30 percent headroom.
+time internal/runner/thin 30s 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). Measured 17.8s locally under load.
+time internal/headless 240s Thin v1 headless suite: real instance, runner and bubblewrap per scenario (spec 7, under two minutes). Slice 4 adds the review and checks scenarios (4_review with its fix rounds, branch move and merge; 4_checks_honest); loaded CI measured 170s on 2026-11-07. Slice 4b adds 4b_ask (about 12s); loaded CI measured 182.9s. 240s keeps 30 percent headroom.
perf GET /api/v1/turns/{id} skip Thin v1 person API: bearer-only JSON for devices, not a browser screen.
perf GET /api/v1/events skip Thin v1 person event stream (Server-Sent Events), long-lived by design; not a screen.
perf GET /api/runner/stream skip Thin v1 runner WebSocket, bearer-only and long-lived; not a browser screen.
diff --git a/docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md b/docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md
index 8e0d5f4e..688e84b6 100644
--- a/docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md
+++ b/docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md
@@ -4833,6 +4833,7 @@ records remain unchanged.
| `work.review.same_account` | same family, same account | Thin v1 slice 4 review and checks (task card, task and Tasks pages, sidebar) | Runtime; COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| `work.merge` | Open on Amadan to merge | Thin v1 slice 4 review and checks (task card, task and Tasks pages, sidebar) | Runtime; COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| `work.needs.fix_rounds` | Needs you: still not approved after two fix rounds | Thin v1 slice 4 review and checks (task card, task and Tasks pages, sidebar) | Runtime; COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
+| `work.needs.branch_moved` | Needs you: the branch moved on Amadan after it was checked | Thin v1 slice 4 review round 1 (task card and pages) | Runtime; COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| `work.needs.review_blocked` | Needs you: the review ended without a verdict | Thin v1 slice 4 review and checks (task card, task and Tasks pages, sidebar) | Runtime; COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| `work.reason.no_verdict` | the review gave no verdict | Thin v1 slice 4 review and checks (task card, task and Tasks pages, sidebar) | Runtime; COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| `work.reason.candidate_unavailable` | the commit was not on Amadan | Thin v1 slice 4 review and checks (task card, task and Tasks pages, sidebar) | Runtime; COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
diff --git a/docs/superpowers/plans/SLICE4-PROGRESS.md b/docs/superpowers/plans/SLICE4-PROGRESS.md
index f728ad0f..b8e81e52 100644
--- a/docs/superpowers/plans/SLICE4-PROGRESS.md
+++ b/docs/superpowers/plans/SLICE4-PROGRESS.md
@@ -200,6 +200,51 @@ CI: green at fe298b5 (the code; this log's commit changes docs only),
after two red runs fixed on the way: the old engine suites asserted the
old sidebar, then a variable left unused.
+10. Review round 1 (Astra, REQUEST CHANGES, six Important). Each fix has
+ a test that failed first:
+ 1. Readiness holds only while the task branch is at the judged SHA.
+ The runner's watch reads the task branch's head with the default
+ branch's tip (one `ls-remote`), on the minute check and after every
+ sync, and reports any change (`branch` frame, durable). Away from
+ the newest candidate (or gone), the task leaves Ready to merge, its
+ checks, verdict and label are empty, `branch_head` names the new
+ head and Needs you is `branch_moved` ("Needs you: the branch moved
+ on Amadan after it was checked"); the card shows none of the old
+ judgements beside the branch's link. Back at the SHA, it is ready
+ again. A report about an older candidate is ignored.
+ `TestContractBranchMovedInvalidatesReadiness`; headless `4_review`
+ pushes over the approved SHA in the forge and back.
+ 2, 3. The squash check reads paths NUL-delimited and compares whole
+ tree entries (`diff-tree` of the candidate against the tip: mode,
+ type, object, or absence); any git failure is unknown, never
+ merged. `TestMergedSquashCheckIsConservative` (Astra's `café.txt`
+ and executable-bit reproductions, squashed and unmerged deletes,
+ an unreadable base).
+ 4. `needs_network` is a known step reason. `TestRunnerReasonsAreKnown`
+ reads every reason literal the step code emits (fail, done,
+ reason fields, `reasonFor`) from the source and checks it against
+ `wire.StepReasons` (observed failing without `needs_network`).
+ Fallback (decided): a reason the instance does not know is recorded
+ as `unknown`, never refused, so a newer runner's durable report is
+ acked once instead of closing the connection on every replay.
+ `TestContractCannotRunReasonsAreDelivered` (delivery, ack, review
+ follows, for `needs_network` and an unknown reason).
+ 5. Fetches have deadlines: two minutes per attempt (four attempts with
+ backoff), ten minutes for a judge's preparation as a whole and for
+ Engineering's fetch; git and its remote helper run in their own
+ process group, killed together, with a bounded wait.
+ `TestJudgeFetchHasDeadlines` (a remote that accepts and never
+ answers: `clone_failed` in under a second instead of hanging).
+ 6. The review diff is read through a bound (the command is stopped
+ past 48 KiB), and the checks tree's objects stream `rev-list |
+ pack-objects | index-pack` with a 2 GiB bound; `ls-remote` and the
+ merge check's git output are bounded too.
+ `TestOversizedCandidateStaysOutOfMemory` (a 16 MiB candidate: under
+ 8 MiB allocated for each; before, the diff alone allocated 642 MiB
+ for 96 MiB), and the pack bound refuses an oversized candidate.
+ Size exemptions: `internal/runner/thin` 7200, `internal/equipo/chat`
+ 5300; time record for `internal/runner/thin` 30s.
+
## Live runs (budget: 10 coordinator turns, 4 Engineering steps, 6 Review steps)
Used: 1 coordinator turn (the suite scenario), 2 Engineering steps (the
@@ -290,6 +335,8 @@ the plan 3 inventory:
- `work.reason.no_verdict` "the review gave no verdict",
`.candidate_unavailable` "the commit was not on Amadan",
`.account_unavailable` "no model account was ready"
+- `work.needs.branch_moved` "Needs you: the branch moved on Amadan
+ after it was checked" (review round 1)
- `work.review_findings` "Review found", `work.needs_empty` "Nothing
needs you right now."
diff --git a/internal/equipo/chat/review.go b/internal/equipo/chat/review.go
index c9ce07f5..03dea83e 100644
--- a/internal/equipo/chat/review.go
+++ b/internal/equipo/chat/review.go
@@ -26,6 +26,16 @@ type progress struct {
// review the newest steps judging it (nil until dispatched).
candidate string
checks, review *stepRecord
+ // moved: the task branch is no longer at candidate, so nothing judged
+ // of it applies and the task is not ready.
+ moved bool
+}
+
+// progressFor is progressOf with the branch's state on Amadan.
+func progressFor(k taskRecord, steps []stepRecord) progress {
+ p := progressOf(steps)
+ p.moved = p.candidate != "" && k.MovedFrom == p.candidate
+ return p
}
func progressOf(steps []stepRecord) progress {
@@ -55,6 +65,9 @@ func progressOf(steps []stepRecord) progress {
// judged reports the checks outcome and the verdict on the candidate,
// "" while a judgement is missing or has not finished.
func (p progress) judged() (checks, reason, verdict, label string) {
+ if p.moved {
+ return
+ }
if c := p.checks; c != nil && c.State == wire.StepDone {
checks, reason = c.Checks, c.Reason
}
@@ -67,6 +80,9 @@ func (p progress) judged() (checks, reason, verdict, label string) {
// needsYou is what the person must decide now, from the task's stage and
// its steps alone (so every client computes the same).
func (p progress) needsYou(k taskRecord) string {
+ if p.moved && !wire.FinalStage(k.Stage) && !k.CancelRequested {
+ return wire.NeedsBranchMoved
+ }
if k.Stage == wire.StageReadyToMerge {
return wire.NeedsMerge
}
@@ -109,12 +125,21 @@ func (t *txn) advance(k *taskRecord) error {
if err != nil {
return err
}
- p := progressOf(steps)
+ p := progressFor(*k, steps)
if p.candidate != "" && k.Watching != p.candidate && p.eng != nil {
if err := t.watch(k, p.eng.Person, p.candidate); err != nil {
return err
}
}
+ if p.moved {
+ // The branch is not at the judged SHA: never ready; the person
+ // decides (the head goes back, or a new task).
+ if k.Stage == wire.StageReadyToMerge {
+ k.Stage = wire.StageInReview
+ return t.saveTask(k)
+ }
+ return nil
+ }
if p.last == nil || p.last.State != wire.StepDone || p.candidate == "" {
return nil
}
@@ -307,6 +332,56 @@ func (t *txn) merged(l Lease, v *wire.MergedReport) error {
return t.saveTask(&k)
}
+// branchMoved applies the runner's view of the task branch's head on
+// Amadan: away from the newest candidate, readiness is gone; back at it,
+// the task is judged as before. Only the person's primary runner, only
+// the newest candidate.
+func (t *txn) branchMoved(l Lease, v *wire.BranchReport) error {
+ if v.Head != "" && !validSHA(v.Head) || !validSHA(v.CandidateSHA) {
+ return ErrInvalid
+ }
+ k, err := t.loadTask(v.TaskID)
+ if err != nil {
+ return err
+ }
+ steps, err := t.steps(k.ID)
+ if err != nil {
+ return err
+ }
+ p := progressOf(steps)
+ if p.eng == nil || p.eng.Person != l.Runner.Person {
+ return ErrNotFound
+ }
+ primary, err := t.s.authority.PrimaryRunner(t.db, p.eng.Person)
+ if err != nil {
+ return err
+ }
+ if primary != l.Runner.RunnerID {
+ return ErrForbidden
+ }
+ if wire.FinalStage(k.Stage) || v.CandidateSHA != p.candidate {
+ return nil
+ }
+ if v.Head == v.CandidateSHA {
+ if k.MovedFrom == "" {
+ return nil
+ }
+ k.MovedFrom, k.BranchHead = "", ""
+ } else {
+ if k.MovedFrom == v.CandidateSHA && k.BranchHead == v.Head {
+ return nil
+ }
+ k.MovedFrom, k.BranchHead = v.CandidateSHA, v.Head
+ if k.Stage == wire.StageReadyToMerge {
+ k.Stage = wire.StageInReview
+ }
+ }
+ if err := t.saveTask(&k); err != nil {
+ return err
+ }
+ return t.advance(&k)
+}
+
// advanceAll moves every open task of a person forward (after a sync:
// tasks pushed before this instance judged candidates, or a report
// whose follow-up was lost).
diff --git a/internal/equipo/chat/runner.go b/internal/equipo/chat/runner.go
index 2469ed52..1fc4e479 100644
--- a/internal/equipo/chat/runner.go
+++ b/internal/equipo/chat/runner.go
@@ -218,6 +218,8 @@ func (s *Store) Apply(ctx context.Context, l Lease, f wire.Frame, body any) erro
return t.merged(l, v)
case *wire.AnswerReport:
return t.answer(l, v)
+ case *wire.BranchReport:
+ return t.branchMoved(l, v)
}
return ErrInvalid
})
diff --git a/internal/equipo/chat/stream.go b/internal/equipo/chat/stream.go
index 2894fb8e..75532b0c 100644
--- a/internal/equipo/chat/stream.go
+++ b/internal/equipo/chat/stream.go
@@ -153,7 +153,7 @@ func (rc *runnerConn) read(ctx context.Context) websocket.StatusCode {
switch v := body.(type) {
case *wire.Hello:
err = store.Heartbeat(ctx, rc.lease, *v)
- case *wire.Sync, *wire.Ack, *wire.DeltaReport, *wire.Reply, *wire.TurnReport, *wire.ToolCall, *wire.ActivityReport, *wire.MoveIn, *wire.NotebookReport, *wire.StepReport, *wire.MergedReport, *wire.AnswerReport:
+ case *wire.Sync, *wire.Ack, *wire.DeltaReport, *wire.Reply, *wire.TurnReport, *wire.ToolCall, *wire.ActivityReport, *wire.MoveIn, *wire.NotebookReport, *wire.StepReport, *wire.MergedReport, *wire.AnswerReport, *wire.BranchReport:
err = store.Apply(ctx, rc.lease, f, body)
case *wire.LeaseCheck:
// Answered only while this connection holds the lease.
diff --git a/internal/equipo/chat/tasks.go b/internal/equipo/chat/tasks.go
index 4e0dafef..cde7f0e3 100644
--- a/internal/equipo/chat/tasks.go
+++ b/internal/equipo/chat/tasks.go
@@ -41,6 +41,11 @@ type taskRecord struct {
UpdatedAt time.Time
// Watching is the candidate the runner was asked to watch for a merge.
Watching string
+ // MovedFrom is the candidate the task branch moved away from (to
+ // BranchHead, "" when the branch is gone); while it is the newest
+ // candidate, nothing judged of it applies.
+ MovedFrom string
+ BranchHead string
}
func (taskRecord) TableName() string { return "chat_tasks" }
@@ -273,8 +278,11 @@ func (t *txn) taskView(k taskRecord) (wire.Task, error) {
v.URL = BranchURL(p.Repo, k.Branch)
}
}
- pr := progressOf(steps)
+ pr := progressFor(k, steps)
v.CandidateSHA = pr.candidate
+ if pr.moved {
+ v.BranchHead = k.BranchHead
+ }
v.Checks, v.ChecksReason, v.Verdict, v.ReviewLabel = pr.judged()
v.NeedsYou = pr.needsYou(k)
if pr.eng != nil {
@@ -303,7 +311,7 @@ func (t *txn) saveTask(k *taskRecord) error {
}
k.Revision++
k.UpdatedAt = t.now()
- if err := t.db.Model(&taskRecord{}).Where("id = ?", k.ID).Select("stage", "base_sha", "cancel_requested", "revision", "updated_at").Updates(k).Error; err != nil {
+ if err := t.db.Model(&taskRecord{}).Where("id = ?", k.ID).Select("stage", "base_sha", "cancel_requested", "revision", "updated_at", "moved_from", "branch_head").Updates(k).Error; err != nil {
return err
}
if wire.FinalStage(k.Stage) && !wire.FinalStage(before) {
@@ -619,9 +627,15 @@ func (t *txn) cancelTask(person, id string) (int64, error) {
// stepReport applies a runner's step report: only the current attempt,
// only forward, the base and candidate set once per attempt.
func (t *txn) stepReport(l Lease, v *wire.StepReport) error {
- if !wire.StepReasons[v.Reason] || v.BaseSHA != "" && !validSHA(v.BaseSHA) || v.CandidateSHA != "" && !validSHA(v.CandidateSHA) {
+ if v.BaseSHA != "" && !validSHA(v.BaseSHA) || v.CandidateSHA != "" && !validSHA(v.CandidateSHA) {
return ErrInvalid
}
+ if !wire.StepReasons[v.Reason] {
+ // A reason this instance does not know (a newer runner) is recorded
+ // as unknown: refusing it would close the connection and the
+ // durable report would be refused again on every replay.
+ v.Reason = wire.ReasonUnknown
+ }
switch v.State {
case wire.StepRunning, wire.StepDone, wire.StepFailed, wire.StepCancelled:
default:
diff --git a/internal/equipo/copy.go b/internal/equipo/copy.go
index 1c731e7a..4dbb7be5 100644
--- a/internal/equipo/copy.go
+++ b/internal/equipo/copy.go
@@ -551,6 +551,7 @@ var pageCopy = map[string]string{
"work.review.same_account": "same family, same account", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context)
"work.merge": "Open on Amadan to merge", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context)
"work.needs.fix_rounds": "Needs you: still not approved after two fix rounds", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context)
+ "work.needs.branch_moved": "Needs you: the branch moved on Amadan after it was checked", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context)
"work.needs.review_blocked": "Needs you: the review ended without a verdict", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context)
"work.reason.no_verdict": "the review gave no verdict", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context)
"work.reason.candidate_unavailable": "the commit was not on Amadan", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context)
diff --git a/internal/equipo/migrations/0045_thin_branch_head.sql b/internal/equipo/migrations/0045_thin_branch_head.sql
new file mode 100644
index 00000000..d1d8a8f9
--- /dev/null
+++ b/internal/equipo/migrations/0045_thin_branch_head.sql
@@ -0,0 +1,2 @@
+ALTER TABLE chat_tasks ADD COLUMN moved_from text;
+ALTER TABLE chat_tasks ADD COLUMN branch_head text;
diff --git a/internal/equipo/migrations/0045_thin_questions.sql b/internal/equipo/migrations/0046_thin_questions.sql
similarity index 100%
rename from internal/equipo/migrations/0045_thin_questions.sql
rename to internal/equipo/migrations/0046_thin_questions.sql
diff --git a/internal/equipo/migrations/schema.sql b/internal/equipo/migrations/schema.sql
index 2470074b..f658a977 100644
--- a/internal/equipo/migrations/schema.sql
+++ b/internal/equipo/migrations/schema.sql
@@ -592,7 +592,7 @@ CREATE TABLE chat_coordinators (person text PRIMARY KEY, state text, turn_id tex
CREATE TABLE chat_notebooks (person text PRIMARY KEY, entries text, revision integer, updated_at datetime);
CREATE INDEX chat_card_task ON chat_cards(task_id);
CREATE TABLE chat_project_attachments (project_id text, kind text, ref text, name text, created_at datetime, PRIMARY KEY (project_id, kind, ref));
-CREATE TABLE chat_tasks (id text PRIMARY KEY, project_id text, title text, brief text, stage text, branch text, base_sha text, creator text, turn_id text, cancel_requested numeric, revision integer, created_at datetime, updated_at datetime, watching text);
+CREATE TABLE chat_tasks (id text PRIMARY KEY, project_id text, title text, brief text, stage text, branch text, base_sha text, creator text, turn_id text, cancel_requested numeric, revision integer, created_at datetime, updated_at datetime, watching text, moved_from text, branch_head text);
CREATE INDEX chat_task_project ON chat_tasks(project_id);
CREATE TABLE chat_steps (id text PRIMARY KEY, task_id text, idx integer, specialist text, person text, state text, reason text, attempt integer, base_sha text, candidate_sha text, pushed numeric, terminated numeric, summary text, log_tail text, started_at datetime, finished_at datetime, revision integer, created_at datetime, updated_at datetime, round integer, family text, account text, verdict text, review_label text, findings text, checks text, gate text, exit_code integer, output text, republish numeric, from_attempt integer, askable numeric);
CREATE INDEX chat_step_task ON chat_steps(task_id);
diff --git a/internal/equipo/work_pages.go b/internal/equipo/work_pages.go
index b003b343..60443407 100644
--- a/internal/equipo/work_pages.go
+++ b/internal/equipo/work_pages.go
@@ -133,6 +133,10 @@ func taskLineOf(t wire.Task, viewer string) taskLine {
switch t.NeedsYou {
case wire.NeedsFixRounds, wire.NeedsReviewBlocked:
v.StageLine = copyText("work.needs." + t.NeedsYou)
+ case wire.NeedsBranchMoved:
+ // What was checked and reviewed is not what the branch holds now:
+ // none of it is shown beside the branch's link.
+ v.StageLine, v.ChecksLine, v.ReviewLine = copyText("work.needs.branch_moved"), "", ""
}
v.Merge = t.Stage == wire.StageReadyToMerge && t.URL != ""
v.Cancel = !wire.FinalStage(t.Stage)
diff --git a/internal/headless/review_test.go b/internal/headless/review_test.go
index 9c38cdca..7b7ac8f0 100644
--- a/internal/headless/review_test.go
+++ b/internal/headless/review_test.go
@@ -137,6 +137,27 @@ func scenarioReview(t *testing.T, env *Env) {
if needs, err := env.Client.NeedsYou(s.ctx); err != nil || len(needs.Items) != 1 || needs.Items[0].ID != id {
t.Fatalf("needs you %+v %v", needs, err)
}
+ // Astra round 1: the task branch moves on the forge (someone pushes
+ // over the approved SHA): the task is no longer ready and shows none
+ // of what was judged; back at the judged SHA it is ready again.
+ other, err := exec.Command("git", "--git-dir="+bare, "commit-tree", k.CandidateSHA+"^{tree}", "-p", k.CandidateSHA, "-m", "someone else").Output()
+ if err != nil {
+ t.Fatal(err)
+ }
+ if out, err := exec.Command("git", "--git-dir="+bare, "update-ref", "refs/heads/"+k.Branch, strings.TrimSpace(string(other))).CombinedOutput(); err != nil {
+ t.Fatalf("push over: %v %s", err, out)
+ }
+ s.wait(t, "branch moved", time.Minute, func(c *thintest.Conversation) bool {
+ m := c.Tasks[id]
+ return m.NeedsYou == wire.NeedsBranchMoved && m.Stage == wire.StageInReview && m.Verdict == "" && m.Checks == "" && m.BranchHead == strings.TrimSpace(string(other))
+ })
+ if out, err := exec.Command("git", "--git-dir="+bare, "update-ref", "refs/heads/"+k.Branch, k.CandidateSHA).CombinedOutput(); err != nil {
+ t.Fatalf("push back: %v %s", err, out)
+ }
+ s.wait(t, "ready again", time.Minute, func(c *thintest.Conversation) bool {
+ m := c.Tasks[id]
+ return m.Stage == wire.StageReadyToMerge && m.NeedsYou == wire.NeedsMerge && m.Verdict == wire.VerdictApprove
+ })
// The person merges on the forge; the minute check sees it.
if out, err := exec.Command("git", "--git-dir="+bare, "update-ref", "refs/heads/main", k.CandidateSHA).CombinedOutput(); err != nil {
t.Fatalf("merge: %v %s", err, out)
diff --git a/internal/runner/thin/engineer.go b/internal/runner/thin/engineer.go
index bb672c94..3476290a 100644
--- a/internal/runner/thin/engineer.go
+++ b/internal/runner/thin/engineer.go
@@ -119,7 +119,10 @@ func (e *Engineer) Exec(ctx context.Context, r stepRow, progress func(wire.StepR
}
e.log("step republish", errors.New("the recorded commit is gone; running the step again"))
}
- if err := e.Clones.Ensure(ctx, r.Repo); err != nil {
+ fctx, cancel := context.WithTimeout(ctx, prepTimeout)
+ err := e.fetch(fctx, r.Repo)
+ cancel()
+ if err != nil {
e.log("step clone", err)
return fail("clone_failed", true)
}
diff --git a/internal/runner/thin/forge.go b/internal/runner/thin/forge.go
index 3efbab59..66ef091f 100644
--- a/internal/runner/thin/forge.go
+++ b/internal/runner/thin/forge.go
@@ -17,6 +17,7 @@ import (
"slices"
"strings"
"sync"
+ "syscall"
"time"
"amadan.net/oficina/equipo/internal/runner/forge"
@@ -345,7 +346,7 @@ func (c *Clones) fetch(ctx context.Context, repo string, shallow bool, branch st
return err
}
git := func(args ...string) error {
- cmd := exec.CommandContext(ctx, c.Git, args...)
+ cmd := groupCommand(ctx, c.Git, args...)
cmd.Dir = filepath.Dir(dir)
for k, v := range env {
cmd.Env = append(cmd.Env, k+"="+v)
@@ -387,6 +388,22 @@ var branchName = regexp.MustCompile(`^[A-Za-z0-9][A-Za-z0-9._/-]{0,100}$`)
func validBranch(b string) bool { return branchName.MatchString(b) && !strings.Contains(b, "..") }
+// groupCommand is a git command whose whole process group (git and its
+// remote helper) dies when ctx ends, and whose Wait does not hang on a
+// helper still holding its output.
+func groupCommand(ctx context.Context, name string, args ...string) *exec.Cmd {
+ cmd := exec.CommandContext(ctx, name, args...)
+ cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
+ cmd.Cancel = func() error {
+ if cmd.Process == nil {
+ return nil
+ }
+ return syscall.Kill(-cmd.Process.Pid, syscall.SIGKILL)
+ }
+ cmd.WaitDelay = 5 * time.Second
+ return cmd
+}
+
// DefaultBranch asks the remote which branch HEAD names.
func (c *Clones) DefaultBranch(ctx context.Context, repo string) (string, error) {
remote, err := c.Forge.Remote(ctx, repo)
@@ -403,7 +420,7 @@ func (c *Clones) DefaultBranch(ctx context.Context, repo string) (string, error)
env["GIT_CONFIG_KEY_9"] = "http.extraHeader"
env["GIT_CONFIG_VALUE_9"] = "Authorization: Basic " + base64.StdEncoding.EncodeToString([]byte("x:"+remote.GitPassword))
}
- cmd := exec.CommandContext(ctx, c.Git, "-c", "protocol."+protocol+".allow=always", "-c", "http.followRedirects=false", "ls-remote", "--symref", "--", remote.URL, "HEAD")
+ cmd := groupCommand(ctx, c.Git, "-c", "protocol."+protocol+".allow=always", "-c", "http.followRedirects=false", "ls-remote", "--symref", "--", remote.URL, "HEAD")
cmd.Dir = c.Root
for k, v := range env {
cmd.Env = append(cmd.Env, k+"="+v)
diff --git a/internal/runner/thin/judge.go b/internal/runner/thin/judge.go
index ee9f0a16..83498938 100644
--- a/internal/runner/thin/judge.go
+++ b/internal/runner/thin/judge.go
@@ -42,20 +42,11 @@ func (e *Engineer) judgeTree(ctx context.Context, r stepRow) (workspace.TaskTree
if err := e.lease(ctx); err != nil {
return workspace.TaskTree{}, "cancelled", err
}
- // The hub may refuse a burst of fetches (a runner that just started
- // indexes every repository): try again before giving up.
- var err error
- for i := 0; i < fetchAttempts; i++ {
- if err = e.Clones.Ensure(ctx, r.Repo); err == nil || ctx.Err() != nil {
- break
- }
- e.log("judge clone", err)
- select {
- case <-ctx.Done():
- case <-time.After(time.Duration(i+1) * fetchBackoff):
- }
- }
- if err != nil {
+ // Preparation as a whole has a deadline, so the serial step worker is
+ // never held by it.
+ ctx, cancel := context.WithTimeout(ctx, prepTimeout)
+ defer cancel()
+ if err := e.fetch(ctx, r.Repo); err != nil {
return workspace.TaskTree{}, "clone_failed", err
}
t := e.tree(r, r.CandidateSHA)
@@ -73,8 +64,34 @@ func (e *Engineer) judgeTree(ctx context.Context, r stepRow) (workspace.TaskTree
var (
fetchAttempts = 4
fetchBackoff = 10 * time.Second
+ fetchTimeout = 2 * time.Minute
+ prepTimeout = 10 * time.Minute
)
+// fetch brings the project clone up to date. Each attempt has its own
+// deadline; the hub may refuse a burst of fetches (a runner that just
+// started indexes every repository), so it tries again with backoff.
+func (e *Engineer) fetch(ctx context.Context, repo string) error {
+ var err error
+ for i := 0; i < fetchAttempts; i++ {
+ actx, cancel := context.WithTimeout(ctx, fetchTimeout)
+ err = e.Clones.Ensure(actx, repo)
+ cancel()
+ if err == nil || ctx.Err() != nil {
+ break
+ }
+ e.log("fetch", err)
+ select {
+ case <-ctx.Done():
+ case <-time.After(time.Duration(i+1) * fetchBackoff):
+ }
+ }
+ if err == nil {
+ err = ctx.Err()
+ }
+ return err
+}
+
var shaPattern = regexp.MustCompile(`^(?:[0-9a-f]{40}|[0-9a-f]{64})$`)
// lease waits for the execution lease: nothing runs without it.
@@ -271,32 +288,103 @@ func (e *Engineer) checkRepository(ctx context.Context, tree workspace.TaskTree,
cmd.Stdin, cmd.Stdout, cmd.Stderr = stdin, stdout, io.Discard
return cmd.Run()
}
- var objects, pack bytes.Buffer
- if err := git(nil, &objects, nil, "--git-dir="+tree.GitDir, "rev-list", "--objects", "--no-walk", sha); err != nil {
+ dot := filepath.Join(tree.Dir, ".git")
+ if err := git(nil, nil, nil, "init", "-q", "--template=", "--object-format="+map[bool]string{true: "sha256", false: "sha1"}[len(sha) == 64], tree.Dir); err != nil {
return err
}
- if err := git(&objects, &pack, nil, "--git-dir="+tree.GitDir, "pack-objects", "--stdout", "-q"); err != nil {
+ // The candidate's objects stream from the private repository into
+ // the tree's own, one pipe each, never whole in memory; the pack is
+ // bounded so an oversized candidate cannot fill the disk either.
+ return e.streamObjects(ctx, env, tree, dot, sha)
+}
+
+// maxCheckPack bounds the objects a checks tree's .git receives.
+var maxCheckPack int64 = 2 << 30
+
+func (e *Engineer) streamObjects(ctx context.Context, env map[string]string, tree workspace.TaskTree, dot, sha string) error {
+ ctx, cancel := context.WithCancel(ctx)
+ defer cancel()
+ command := func(dir string, extra map[string]string, args ...string) *exec.Cmd {
+ cmd := groupCommand(ctx, e.O.Runner.GitPath, args...)
+ cmd.Dir = dir
+ for k, v := range env {
+ cmd.Env = append(cmd.Env, k+"="+v)
+ }
+ for k, v := range extra {
+ cmd.Env = append(cmd.Env, k+"="+v)
+ }
+ cmd.Stderr = io.Discard
+ return cmd
+ }
+ list := command(tree.Dir, nil, "--git-dir="+tree.GitDir, "rev-list", "--objects", "--no-walk", sha)
+ pack := command(tree.Dir, nil, "--git-dir="+tree.GitDir, "pack-objects", "--stdout", "-q")
+ index := command(tree.Dir, map[string]string{"GIT_DIR": dot, "GIT_WORK_TREE": tree.Dir}, "index-pack", "--stdin")
+ index.Stdout = io.Discard
+ objects, err := list.StdoutPipe()
+ if err != nil {
return err
}
- dot := filepath.Join(tree.Dir, ".git")
- if err := git(nil, nil, nil, "init", "-q", "--template=", "--object-format="+map[bool]string{true: "sha256", false: "sha1"}[len(sha) == 64], tree.Dir); err != nil {
+ pack.Stdin = objects
+ packed, err := pack.StdoutPipe()
+ if err != nil {
return err
}
- in := map[string]string{"GIT_DIR": dot, "GIT_WORK_TREE": tree.Dir}
- if err := git(&pack, nil, in, "index-pack", "--stdin"); err != nil {
+ limited := &limitReader{r: packed, n: maxCheckPack}
+ index.Stdin = limited
+ for _, c := range []*exec.Cmd{list, pack, index} {
+ if err := c.Start(); err != nil {
+ cancel()
+ return err
+ }
+ }
+ errIndex := index.Wait()
+ if limited.over {
+ cancel()
+ }
+ errPack, errList := pack.Wait(), list.Wait()
+ if limited.over {
+ return errors.New("checks repository too large")
+ }
+ if err := errors.Join(errList, errPack, errIndex); err != nil {
return err
}
+ in := map[string]string{"GIT_DIR": dot, "GIT_WORK_TREE": tree.Dir}
+ git := func(args ...string) error {
+ c := command(tree.Dir, in, args...)
+ c.Stdout = io.Discard
+ return c.Run()
+ }
if err := os.WriteFile(filepath.Join(dot, "shallow"), []byte(sha+"\n"), 0600); err != nil {
return err
}
for _, args := range [][]string{{"update-ref", "refs/heads/" + tree.Branch, sha}, {"symbolic-ref", "HEAD", "refs/heads/" + tree.Branch}, {"read-tree", sha}, {"update-index", "-q", "--refresh"}} {
- if err := git(nil, nil, in, args...); err != nil && args[0] != "update-index" {
+ if err := git(args...); err != nil && args[0] != "update-index" {
return err
}
}
return nil
}
+// limitReader passes at most n bytes, then reports EOF and marks over.
+type limitReader struct {
+ r io.Reader
+ n int64
+ over bool
+}
+
+func (l *limitReader) Read(p []byte) (int, error) {
+ if l.n <= 0 {
+ l.over = true
+ return 0, io.EOF
+ }
+ if int64(len(p)) > l.n {
+ p = p[:l.n]
+ }
+ k, err := l.r.Read(p)
+ l.n -= int64(k)
+ return k, err
+}
+
// gateResult is how a gate's run ended.
type gateResult struct {
output, reason string
@@ -619,14 +707,36 @@ func treeDiff(ctx context.Context, git, gitDir, from, to string, limit int) (str
for k, v := range env {
cmd.Env = append(cmd.Env, k+"="+v)
}
- cmd.Stderr = io.Discard
- out, err := cmd.Output()
+ out, clipped, err := boundedOutput(cmd, limit)
if err != nil {
return "", err
}
s := strings.ToValidUTF8(string(out), "?")
- if len(s) > limit {
- s = s[:limit] + "\n[the rest of the diff is cut; read the files in /workspace]"
+ if clipped {
+ s += "\n[the rest of the diff is cut; read the files in /workspace]"
}
return s, nil
}
+
+// boundedOutput runs cmd and returns at most limit bytes of its stdout;
+// past that it stops the command and reports clipped. Nothing beyond
+// limit is held in memory.
+func boundedOutput(cmd *exec.Cmd, limit int) ([]byte, bool, error) {
+ cmd.Stderr = io.Discard
+ pipe, err := cmd.StdoutPipe()
+ if err != nil {
+ return nil, false, err
+ }
+ if err := cmd.Start(); err != nil {
+ return nil, false, err
+ }
+ out, readErr := io.ReadAll(io.LimitReader(pipe, int64(limit)+1))
+ if len(out) > limit {
+ _ = cmd.Process.Kill()
+ _, _ = io.Copy(io.Discard, pipe)
+ _ = cmd.Wait()
+ return out[:limit], true, nil
+ }
+ err = cmd.Wait()
+ return out, false, errors.Join(readErr, err)
+}
diff --git a/internal/runner/thin/link.go b/internal/runner/thin/link.go
index 67f0f950..f8d8b399 100644
--- a/internal/runner/thin/link.go
+++ b/internal/runner/thin/link.go
@@ -36,6 +36,9 @@ type Link struct {
Recheck func()
// Forget removes the session directories a forget_task released.
Forget func(dirs []string)
+ // Synced runs after every sync sent (the merge and branch watch looks
+ // at once).
+ Synced func()
Hello func() wire.Hello
Logger *slog.Logger
// Connected is called with true once a generation is granted and false
@@ -316,6 +319,9 @@ func (l *Link) session(ctx context.Context) (time.Duration, error) {
// On every sync, re-probe attempts still waiting for their proof.
go l.Steps.Probe(ctx)
}
+ if l.Synced != nil {
+ go l.Synced()
+ }
type outcome struct {
retry time.Duration
diff --git a/internal/runner/thin/merge.go b/internal/runner/thin/merge.go
index 6eab6834..a5d91cda 100644
--- a/internal/runner/thin/merge.go
+++ b/internal/runner/thin/merge.go
@@ -1,14 +1,16 @@
package thin
import (
+ "bytes"
"context"
"database/sql"
"encoding/base64"
- "io"
+ "errors"
"log/slog"
"os/exec"
"path/filepath"
"strings"
+ "sync"
"time"
"amadan.net/oficina/equipo/internal/runner/workspace"
@@ -23,7 +25,9 @@ import (
// of the tip (a merge or fast-forward), or every path the task changed
// now as the candidate has it (a squash).
-const watchSchema = `CREATE TABLE IF NOT EXISTS watches (task_id TEXT PRIMARY KEY, person TEXT NOT NULL, repo TEXT NOT NULL, branch TEXT NOT NULL, candidate_sha TEXT NOT NULL, base_sha TEXT NOT NULL DEFAULT '', seen_tip TEXT NOT NULL DEFAULT '');`
+// seen_head is the task branch's head last reported (the candidate when
+// the watch starts); any change is reported (FrameBranch).
+const watchSchema = `CREATE TABLE IF NOT EXISTS watches (task_id TEXT PRIMARY KEY, person TEXT NOT NULL, repo TEXT NOT NULL, branch TEXT NOT NULL, candidate_sha TEXT NOT NULL, base_sha TEXT NOT NULL DEFAULT '', seen_tip TEXT NOT NULL DEFAULT '', seen_head TEXT NOT NULL DEFAULT '');`
// AcceptWatch records a watch_merge exactly once: a candidate replaces
// the task's watch, an empty one ends it.
@@ -39,17 +43,17 @@ func (s *State) AcceptWatch(ctx context.Context, frameID string, w wire.WatchMer
}
var base string
_ = t.QueryRow("SELECT base_sha FROM steps WHERE task_id=? AND base_sha<>'' ORDER BY created_at LIMIT 1", w.TaskID).Scan(&base)
- _, err = t.Exec("INSERT INTO watches(task_id, person, repo, branch, candidate_sha, base_sha) VALUES(?,?,?,?,?,?) ON CONFLICT(task_id) DO UPDATE SET candidate_sha=excluded.candidate_sha, branch=excluded.branch, repo=excluded.repo, seen_tip=''", w.TaskID, w.Person, w.Repo, w.Branch, w.CandidateSHA, base)
+ _, err = t.Exec("INSERT INTO watches(task_id, person, repo, branch, candidate_sha, base_sha, seen_head) VALUES(?,?,?,?,?,?,?) ON CONFLICT(task_id) DO UPDATE SET candidate_sha=excluded.candidate_sha, branch=excluded.branch, repo=excluded.repo, seen_tip='', seen_head=excluded.candidate_sha", w.TaskID, w.Person, w.Repo, w.Branch, w.CandidateSHA, base, w.CandidateSHA)
return err
})
}
type watch struct {
- task, person, repo, branch, candidate, base, seen string
+ task, person, repo, branch, candidate, base, seen, head string
}
func (s *State) watches(ctx context.Context) ([]watch, error) {
- rows, err := s.db.QueryContext(ctx, "SELECT task_id, person, repo, branch, candidate_sha, base_sha, seen_tip FROM watches ORDER BY repo, task_id")
+ rows, err := s.db.QueryContext(ctx, "SELECT task_id, person, repo, branch, candidate_sha, base_sha, seen_tip, seen_head FROM watches ORDER BY repo, task_id")
if err != nil {
return nil, err
}
@@ -57,7 +61,7 @@ func (s *State) watches(ctx context.Context) ([]watch, error) {
var out []watch
for rows.Next() {
var w watch
- if err := rows.Scan(&w.task, &w.person, &w.repo, &w.branch, &w.candidate, &w.base, &w.seen); err != nil {
+ if err := rows.Scan(&w.task, &w.person, &w.repo, &w.branch, &w.candidate, &w.base, &w.seen, &w.head); err != nil {
return nil, err
}
out = append(out, w)
@@ -80,6 +84,21 @@ func (s *State) landed(ctx context.Context, w watch) error {
})
}
+// branchSeen reports the task branch's new head and records it, in one
+// transaction with the durable report.
+func (s *State) branchSeen(ctx context.Context, w watch, head string) error {
+ return s.tx(ctx, func(t *sql.Tx) error {
+ res, err := t.Exec("UPDATE watches SET seen_head=? WHERE task_id=? AND candidate_sha=? AND seen_head=?", head, w.task, w.candidate, w.head)
+ if err != nil {
+ return err
+ }
+ if n, _ := res.RowsAffected(); n != 1 {
+ return nil
+ }
+ return s.enqueue(t, wire.FrameBranch, "", wire.BranchReport{TaskID: w.task, CandidateSHA: w.candidate, Head: head})
+ })
+}
+
func (s *State) sawTip(ctx context.Context, w watch, tip string) error {
_, err := s.db.ExecContext(ctx, "UPDATE watches SET seen_tip=? WHERE task_id=? AND candidate_sha=?", tip, w.task, w.candidate)
return err
@@ -94,15 +113,32 @@ type MergeWatch struct {
Notify func()
Logger *slog.Logger
Every time.Duration
+
+ kick chan struct{}
+ once sync.Once
+}
+
+func (m *MergeWatch) kicks() chan struct{} {
+ m.once.Do(func() { m.kick = make(chan struct{}, 1) })
+ return m.kick
+}
+
+// Kick checks at once (after every sync with the instance).
+func (m *MergeWatch) Kick() {
+ select {
+ case m.kicks() <- struct{}{}:
+ default:
+ }
}
-// Loop checks every Every until ctx ends.
+// Loop checks every Every, and when kicked, until ctx ends.
func (m *MergeWatch) Loop(ctx context.Context) {
for {
select {
case <-ctx.Done():
return
case <-time.After(m.Every):
+ case <-m.kicks():
}
m.Check(ctx)
}
@@ -121,7 +157,11 @@ func (m *MergeWatch) Check(ctx context.Context) {
sent := false
for repo, list := range byRepo {
cctx, cancel := context.WithTimeout(ctx, 2*time.Minute)
- branch, tip, err := m.Clones.DefaultTip(cctx, repo)
+ names := make([]string, 0, len(list))
+ for _, w := range list {
+ names = append(names, w.branch)
+ }
+ branch, tip, heads, err := m.Clones.Heads(cctx, repo, names)
if err != nil {
cancel()
m.log("merge tip", err)
@@ -131,22 +171,28 @@ func (m *MergeWatch) Check(ctx context.Context) {
for _, w := range list {
moved = moved || w.seen != tip
}
- if !moved {
- cancel()
- continue
- }
- if err := m.Clones.Ensure(cctx, repo); err != nil {
- cancel()
- m.log("merge fetch", err)
- continue
+ landed := map[string]bool{}
+ if moved {
+ if err := m.Clones.Ensure(cctx, repo); err != nil {
+ m.log("merge fetch", err)
+ } else {
+ for _, w := range list {
+ if m.merged(cctx, repo, branch, w) {
+ m.log("merge report", m.State.landed(ctx, w))
+ landed[w.task], sent = true, true
+ continue
+ }
+ m.log("merge seen", m.State.sawTip(ctx, w, tip))
+ }
+ }
}
+ // The task branch itself: any head but the candidate takes the
+ // task out of Ready to merge on the instance.
for _, w := range list {
- if m.merged(cctx, repo, branch, w) {
- m.log("merge report", m.State.landed(ctx, w))
+ if head := heads[w.branch]; !landed[w.task] && head != w.head {
+ m.log("branch report", m.State.branchSeen(ctx, w, head))
sent = true
- continue
}
- m.log("merge seen", m.State.sawTip(ctx, w, tip))
}
cancel()
}
@@ -156,19 +202,23 @@ func (m *MergeWatch) Check(ctx context.Context) {
}
// merged reports whether w's candidate is on the default branch: an
-// ancestor of its tip, or (a squash) every path the task changed reads
-// at the tip as at the candidate.
+// ancestor of its tip, or (a squash) every path the task changed has the
+// same tree entry (mode, type and object, or absence) at the tip as at
+// the candidate. Paths are read NUL-delimited. Anything git cannot
+// answer is unknown, and unknown is never merged.
func (m *MergeWatch) merged(ctx context.Context, repo, branch string, w watch) bool {
- git := func(args ...string) (string, error) {
- cmd := exec.CommandContext(ctx, m.Git, append([]string{"--git-dir=" + m.Clones.Path(repo)}, args...)...)
+ git := func(args ...string) ([]byte, error) {
+ cmd := exec.CommandContext(ctx, m.Git, append([]string{"--git-dir=" + m.Clones.Path(repo), "--literal-pathspecs"}, args...)...)
env := workspace.GitEnvironment()
env["HOME"] = "/nonexistent"
for k, v := range env {
cmd.Env = append(cmd.Env, k+"="+v)
}
- cmd.Stderr = io.Discard
- out, err := cmd.Output()
- return strings.TrimSpace(string(out)), err
+ out, clipped, err := boundedOutput(cmd, 4<<20)
+ if clipped {
+ return nil, errors.New("output too large")
+ }
+ return out, err
}
tip := "refs/heads/" + branch
if _, err := git("cat-file", "-e", w.candidate+"^{commit}"); err != nil {
@@ -180,14 +230,22 @@ func (m *MergeWatch) merged(ctx context.Context, repo, branch string, w watch) b
if w.base == "" {
return false
}
- files, err := git("diff-tree", "--no-commit-id", "--name-only", "-r", "--no-renames", "--no-ext-diff", "--no-textconv", w.base, w.candidate)
- if err != nil || files == "" {
+ changed, err := git("diff-tree", "-r", "-z", "--name-only", "--no-renames", "--no-ext-diff", "--no-textconv", w.base, w.candidate, "--")
+ if err != nil || len(changed) == 0 {
return false
}
- for _, f := range strings.Split(files, "\n") {
- a, errA := git("rev-parse", "--verify", "-q", w.candidate+":"+f)
- b, errB := git("rev-parse", "--verify", "-q", tip+":"+f)
- if (errA == nil) != (errB == nil) || a != b {
+ // diff-tree compares whole entries: a path differs if its mode, type
+ // or object differs, or it exists on one side only.
+ differ, err := git("diff-tree", "-r", "-z", "--name-only", "--no-renames", "--no-ext-diff", "--no-textconv", w.candidate, tip, "--")
+ if err != nil {
+ return false
+ }
+ other := map[string]bool{}
+ for _, p := range bytes.Split(differ, []byte{0}) {
+ other[string(p)] = true
+ }
+ for _, p := range bytes.Split(changed, []byte{0}) {
+ if len(p) > 0 && other[string(p)] {
return false
}
}
@@ -200,12 +258,12 @@ func (m *MergeWatch) log(msg string, err error) {
}
}
-// DefaultTip asks the remote for its default branch and that branch's
-// tip, in one ls-remote.
-func (c *Clones) DefaultTip(ctx context.Context, repo string) (string, string, error) {
+// Heads asks the remote, in one ls-remote, for its default branch, that
+// branch's tip and the heads of the named branches (absent: gone).
+func (c *Clones) Heads(ctx context.Context, repo string, branches []string) (string, string, map[string]string, error) {
remote, err := c.Forge.Remote(ctx, repo)
if err != nil {
- return "", "", err
+ return "", "", nil, err
}
env := workspace.GitEnvironment()
env["HOME"] = "/nonexistent"
@@ -217,29 +275,38 @@ func (c *Clones) DefaultTip(ctx context.Context, repo string) (string, string, e
env["GIT_CONFIG_KEY_9"] = "http.extraHeader"
env["GIT_CONFIG_VALUE_9"] = "Authorization: Basic " + base64.StdEncoding.EncodeToString([]byte("x:"+remote.GitPassword))
}
- cmd := exec.CommandContext(ctx, c.Git, "-c", "protocol."+protocol+".allow=always", "-c", "http.followRedirects=false", "ls-remote", "--symref", "--", remote.URL, "HEAD")
+ args := []string{"-c", "protocol." + protocol + ".allow=always", "-c", "http.followRedirects=false", "ls-remote", "--symref", "--", remote.URL, "HEAD"}
+ for _, b := range branches {
+ if validBranch(b) {
+ args = append(args, "refs/heads/"+b)
+ }
+ }
+ cmd := groupCommand(ctx, c.Git, args...)
cmd.Dir = c.Root
for k, v := range env {
cmd.Env = append(cmd.Env, k+"="+v)
}
- cmd.Stderr = io.Discard
- out, err := cmd.Output()
- if err != nil {
- return "", "", err
+ out, clipped, err := boundedOutput(cmd, 1<<20)
+ if err != nil || clipped {
+ return "", "", nil, errors.Join(err, errors.New("ls-remote"))
}
- branch, tip := "", ""
+ branch, tip, heads := "", "", map[string]string{}
for _, line := range strings.Split(string(out), "\n") {
if rest, ok := strings.CutPrefix(line, "ref: refs/heads/"); ok {
b, _, _ := strings.Cut(rest, "\t")
if validBranch(b) {
branch = b
}
- } else if sha, ref, ok := strings.Cut(line, "\t"); ok && ref == "HEAD" && shaPattern.MatchString(sha) {
- tip = sha
+ } else if sha, ref, ok := strings.Cut(line, "\t"); ok && shaPattern.MatchString(sha) {
+ if ref == "HEAD" {
+ tip = sha
+ } else if b, ok := strings.CutPrefix(ref, "refs/heads/"); ok {
+ heads[b] = sha
+ }
}
}
if branch == "" || tip == "" {
- return "", "", ErrNoCreate
+ return "", "", nil, ErrNoCreate
}
- return branch, tip, nil
+ return branch, tip, heads, nil
}
diff --git a/internal/runner/thin/review_fixes_test.go b/internal/runner/thin/review_fixes_test.go
new file mode 100644
index 00000000..7576f393
--- /dev/null
+++ b/internal/runner/thin/review_fixes_test.go
@@ -0,0 +1,291 @@
+package thin
+
+import (
+ "bytes"
+ "context"
+ "crypto/rand"
+ "go/ast"
+ "go/parser"
+ "go/token"
+ "net"
+ "os"
+ "os/exec"
+ "path/filepath"
+ "runtime"
+ "strconv"
+ "strings"
+ "testing"
+ "time"
+
+ "amadan.net/oficina/equipo/internal/runner/workspace"
+ "amadan.net/oficina/equipo/internal/wire"
+)
+
+func gitT(t *testing.T, dir string, args ...string) string {
+ t.Helper()
+ cmd := exec.Command("git", args...)
+ cmd.Dir = dir
+ cmd.Env = append(os.Environ(), "GIT_AUTHOR_NAME=t", "GIT_AUTHOR_EMAIL=t@t", "GIT_COMMITTER_NAME=t", "GIT_COMMITTER_EMAIL=t@t", "GIT_CONFIG_GLOBAL=/dev/null")
+ out, err := cmd.CombinedOutput()
+ if err != nil {
+ t.Fatalf("git %v: %v %s", args, err, out)
+ }
+ return strings.TrimSpace(string(out))
+}
+
+// mergeRig is a clone (as the runner keeps it) with a base commit, a
+// task candidate made by change, and main moved on by mainChange.
+func mergeRig(t *testing.T, change, mainChange func(dir string)) (*MergeWatch, watch) {
+ t.Helper()
+ root := t.TempDir()
+ work := filepath.Join(root, "work")
+ gitT(t, root, "init", "-q", "-b", "main", work)
+ os.WriteFile(filepath.Join(work, "café.txt"), []byte("old\n"), 0644)
+ os.WriteFile(filepath.Join(work, "run.sh"), []byte("echo hi\n"), 0644)
+ gitT(t, work, "add", "-A")
+ gitT(t, work, "commit", "-qm", "base")
+ base := gitT(t, work, "rev-parse", "HEAD")
+ gitT(t, work, "checkout", "-qb", "task")
+ change(work)
+ gitT(t, work, "add", "-A")
+ gitT(t, work, "commit", "-qm", "candidate")
+ cand := gitT(t, work, "rev-parse", "HEAD")
+ gitT(t, work, "checkout", "-q", "main")
+ mainChange(work)
+ gitT(t, work, "add", "-A")
+ gitT(t, work, "commit", "-qm", "main moves", "--allow-empty")
+ c := &Clones{Root: filepath.Join(root, "clones"), Git: "/usr/bin/git"}
+ repo := "amadan.net/oficina/sample"
+ os.MkdirAll(filepath.Dir(c.Path(repo)), 0700)
+ gitT(t, root, "clone", "-q", "--bare", "--no-local", work, c.Path(repo))
+ gitT(t, root, "--git-dir="+c.Path(repo), "fetch", "-q", work, "task:task")
+ return &MergeWatch{Clones: c, Git: "/usr/bin/git"}, watch{task: "tk1", repo: repo, branch: "equipo/tk1", candidate: cand, base: base}
+}
+
+// Astra round 1, findings 2 and 3: the squash check reads paths
+// NUL-delimited, tells a missing entry from a failed lookup, and compares
+// whole tree entries (mode, type and object). When in doubt, not merged.
+func TestMergedSquashCheckIsConservative(t *testing.T) {
+ for _, tc := range []struct {
+ name string
+ change, mainChange func(string)
+ want bool
+ }{
+ {"unmerged edit to café.txt", func(d string) { os.WriteFile(filepath.Join(d, "café.txt"), []byte("new\n"), 0644) }, func(d string) {}, false},
+ {"unmerged executable bit", func(d string) { os.Chmod(filepath.Join(d, "run.sh"), 0755) }, func(d string) {}, false},
+ {"squashed edit to café.txt", func(d string) { os.WriteFile(filepath.Join(d, "café.txt"), []byte("new\n"), 0644) }, func(d string) { os.WriteFile(filepath.Join(d, "café.txt"), []byte("new\n"), 0644) }, true},
+ {"squashed executable bit", func(d string) { os.Chmod(filepath.Join(d, "run.sh"), 0755) }, func(d string) { os.Chmod(filepath.Join(d, "run.sh"), 0755) }, true},
+ {"squashed delete", func(d string) { os.Remove(filepath.Join(d, "café.txt")) }, func(d string) { os.Remove(filepath.Join(d, "café.txt")) }, true},
+ {"unmerged delete", func(d string) { os.Remove(filepath.Join(d, "café.txt")) }, func(d string) {}, false},
+ } {
+ m, w := mergeRig(t, tc.change, tc.mainChange)
+ if got := m.merged(context.Background(), w.repo, "main", w); got != tc.want {
+ t.Fatalf("%s: merged %v, want %v", tc.name, got, tc.want)
+ }
+ }
+ // A failed lookup is unknown, never merged.
+ m, w := mergeRig(t, func(d string) { os.WriteFile(filepath.Join(d, "café.txt"), []byte("new\n"), 0644) }, func(d string) { os.WriteFile(filepath.Join(d, "café.txt"), []byte("new\n"), 0644) })
+ w.base = strings.Repeat("e", 40)
+ if m.merged(context.Background(), w.repo, "main", w) {
+ t.Fatal("merged with an unreadable base")
+ }
+}
+
+// stalledRemote accepts connections and never answers.
+func stalledRemote(t *testing.T) string {
+ l, err := net.Listen("tcp", "127.0.0.1:0")
+ if err != nil {
+ t.Fatal(err)
+ }
+ t.Cleanup(func() { l.Close() })
+ go func() {
+ for {
+ c, err := l.Accept()
+ if err != nil {
+ return
+ }
+ t.Cleanup(func() { c.Close() })
+ }
+ }()
+ return "https://" + l.Addr().String() + "/oficina/sample"
+}
+
+type stalledForge struct {
+ Forge
+ url string
+}
+
+func (f stalledForge) Remote(context.Context, string) (workspace.Remote, error) {
+ return workspace.Remote{URL: f.url, GitPassword: "p"}, nil
+}
+
+// Astra round 1, finding 5: a fetch that stalls reaches its deadline,
+// the retries and the backoff, and the step ends clone_failed; the serial
+// step worker is never held.
+func TestJudgeFetchHasDeadlines(t *testing.T) {
+ old := []any{fetchAttempts, fetchBackoff, fetchTimeout}
+ fetchAttempts, fetchBackoff, fetchTimeout = 2, 10*time.Millisecond, 300*time.Millisecond
+ t.Cleanup(func() {
+ fetchAttempts, fetchBackoff, fetchTimeout = old[0].(int), old[1].(time.Duration), old[2].(time.Duration)
+ })
+ root := t.TempDir()
+ e := &Engineer{Clones: &Clones{Root: root, Git: "/usr/bin/git", Forge: stalledForge{url: stalledRemote(t)}}, Owners: []string{"p@x"}}
+ e.O.Runner.GitPath, e.O.Runner.WorkspaceRoot, e.O.Runner.StateDir = "/usr/bin/git", root, root
+ r := stepRow{DispatchCommand: wire.DispatchCommand{Person: "p@x", TaskID: "tk1", StepID: "s1", Attempt: 1, Specialist: wire.SpecialistChecks, Repo: "amadan.net/oficina/sample", Branch: "equipo/tk1-x", CandidateSHA: strings.Repeat("a", 40)}}
+ done := make(chan string, 1)
+ go func() {
+ _, reason, _ := e.judgeTree(context.Background(), r)
+ done <- reason
+ }()
+ select {
+ case reason := <-done:
+ if reason != "clone_failed" {
+ t.Fatalf("reason %q", reason)
+ }
+ case <-time.After(15 * time.Second):
+ t.Fatal("a stalled fetch held the step")
+ }
+}
+
+// Astra round 1, finding 6: the review diff and the checks repository
+// are streamed with limits: an oversized candidate never lands in the
+// runner's memory.
+func TestOversizedCandidateStaysOutOfMemory(t *testing.T) {
+ if testing.Short() {
+ t.Skip("writes 16 MiB")
+ }
+ root := t.TempDir()
+ work := filepath.Join(root, "work")
+ gitT(t, root, "init", "-q", "-b", "main", work)
+ os.WriteFile(filepath.Join(work, "a.txt"), []byte("a\n"), 0644)
+ gitT(t, work, "add", "-A")
+ gitT(t, work, "commit", "-qm", "base")
+ base := gitT(t, work, "rev-parse", "HEAD")
+ // 16 MiB of text lines that do not compress or delta well.
+ var big bytes.Buffer
+ raw := make([]byte, 48<<17)
+ rand.Read(raw)
+ for i := 0; i < len(raw); i += 48 {
+ big.WriteString(strconv.Quote(string(raw[i:i+48])) + "\n")
+ }
+ os.WriteFile(filepath.Join(work, "big.txt"), big.Bytes(), 0644)
+ gitT(t, work, "add", "-A")
+ gitT(t, work, "commit", "-qm", "big")
+ cand := gitT(t, work, "rev-parse", "HEAD")
+ big.Reset()
+ raw = nil
+ measure := func(name string, fn func()) {
+ t.Helper()
+ runtime.GC()
+ var a, b runtime.MemStats
+ runtime.ReadMemStats(&a)
+ fn()
+ runtime.ReadMemStats(&b)
+ if grew := b.TotalAlloc - a.TotalAlloc; grew > 8<<20 {
+ t.Fatalf("%s allocated %d MiB", name, grew>>20)
+ }
+ }
+ gitDir := filepath.Join(work, ".git")
+ measure("diff", func() {
+ d, err := treeDiff(context.Background(), "/usr/bin/git", gitDir, base, cand, wire.MaxDiffBytes)
+ if err != nil || len(d) > wire.MaxDiffBytes+200 || !strings.Contains(d, "the rest of the diff is cut") {
+ t.Fatalf("diff %d bytes %v", len(d), err)
+ }
+ })
+ tree := workspace.TaskTree{Dir: filepath.Join(root, "tree"), GitDir: gitDir, Git: "/usr/bin/git", Branch: "equipo/tk1-x", Base: cand}
+ os.MkdirAll(tree.Dir, 0700)
+ e := &Engineer{}
+ e.O.Runner.GitPath = "/usr/bin/git"
+ measure("checks repository", func() {
+ if err := e.checkRepository(context.Background(), tree, cand); err != nil {
+ t.Fatal(err)
+ }
+ })
+ if got := gitT(t, tree.Dir, "rev-parse", "HEAD"); got != cand {
+ t.Fatalf("checks repository at %s", got)
+ }
+ // Past the pack bound the checks repository is refused, not filled.
+ old := maxCheckPack
+ maxCheckPack = 1 << 20
+ t.Cleanup(func() { maxCheckPack = old })
+ small := tree
+ small.Dir = filepath.Join(root, "tree2")
+ os.MkdirAll(small.Dir, 0700)
+ if err := e.checkRepository(context.Background(), small, cand); err == nil || !strings.Contains(err.Error(), "too large") {
+ t.Fatalf("an oversized pack was taken: %v", err)
+ }
+}
+
+// Astra round 1, finding 4: every step reason this runner emits is one
+// the instance knows. The literals are read from the source: reasons in
+// fail(...), done(...), stepResult/gateResult{reason: ...}, assignments
+// to a Reason or reason field, and reasonFor's returns.
+func TestRunnerReasonsAreKnown(t *testing.T) {
+ fset := token.NewFileSet()
+ files, _ := filepath.Glob("*.go")
+ steps := map[string]bool{"engineer.go": true, "judge.go": true, "step.go": true, "merge.go": true}
+ found := map[string]bool{}
+ lit := func(e ast.Expr) {
+ if b, ok := e.(*ast.BasicLit); ok && b.Kind == token.STRING {
+ s, _ := strconv.Unquote(b.Value)
+ found[s] = true
+ }
+ }
+ for _, f := range files {
+ if strings.HasSuffix(f, "_test.go") {
+ continue
+ }
+ file, err := parser.ParseFile(fset, f, nil, 0)
+ if err != nil {
+ t.Fatal(err)
+ }
+ ast.Inspect(file, func(n ast.Node) bool {
+ if !steps[f] {
+ // Elsewhere only reasonFor, which steps share.
+ if d, ok := n.(*ast.FuncDecl); !ok || d.Name.Name != "reasonFor" {
+ return true
+ }
+ }
+ switch v := n.(type) {
+ case *ast.CallExpr:
+ if id, ok := v.Fun.(*ast.Ident); ok && (id.Name == "fail" || id.Name == "done") {
+ for _, a := range v.Args {
+ lit(a)
+ }
+ }
+ case *ast.KeyValueExpr:
+ if id, ok := v.Key.(*ast.Ident); ok && (id.Name == "reason" || id.Name == "Reason") {
+ lit(v.Value)
+ }
+ case *ast.AssignStmt:
+ for i, l := range v.Lhs {
+ if sel, ok := l.(*ast.SelectorExpr); ok && (sel.Sel.Name == "Reason" || sel.Sel.Name == "reason") && i < len(v.Rhs) {
+ lit(v.Rhs[i])
+ }
+ }
+ case *ast.FuncDecl:
+ if v.Name.Name == "reasonFor" {
+ ast.Inspect(v, func(n ast.Node) bool {
+ if r, ok := n.(*ast.ReturnStmt); ok {
+ for _, e := range r.Results {
+ lit(e)
+ }
+ }
+ return true
+ })
+ }
+ }
+ return true
+ })
+ }
+ if !found["needs_macos"] || !found["no_verdict"] || !found["push_failed"] {
+ t.Fatalf("the scan found too little: %v", found)
+ }
+ for s := range found {
+ // The launch path also serves questions (ask.go), whose reasons
+ // the instance knows as answer reasons (session_gone on resume).
+ if s != "" && !wire.StepReasons[s] && !wire.AnswerReasons[s] {
+ t.Errorf("the runner emits reason %q the instance does not know", s)
+ }
+ }
+}
diff --git a/internal/runner/thin/run.go b/internal/runner/thin/run.go
index 70d5bdba..49b75165 100644
--- a/internal/runner/thin/run.go
+++ b/internal/runner/thin/run.go
@@ -185,6 +185,7 @@ func Run(ctx context.Context, c runner.Config, o Options) error {
if merges.Every <= 0 {
merges.Every = reachEvery + 5*time.Second
}
+ link.Synced = merges.Kick
go merges.Loop(ctx)
if engineer.MaxStep == 0 {
engineer.MaxStep = DefaultMaxStep
diff --git a/internal/runner/thin/state.go b/internal/runner/thin/state.go
index cd37ab48..3559731c 100644
--- a/internal/runner/thin/state.go
+++ b/internal/runner/thin/state.go
@@ -66,6 +66,11 @@ func OpenState(ctx context.Context, dir string) (*State, error) {
}
// Added in slice 3 review: a step's namespace and the ending it
// reported while its termination is still to be proven.
+ // Added in slice 4 review: the task branch head last reported.
+ if _, err = d.ExecContext(ctx, "ALTER TABLE watches ADD COLUMN seen_head TEXT NOT NULL DEFAULT ''"); err != nil && !strings.Contains(err.Error(), "duplicate column") {
+ d.Close()
+ return nil, err
+ }
for _, col := range []string{"ns_id", "final_state", "final_reason"} {
if _, err = d.ExecContext(ctx, "ALTER TABLE steps ADD COLUMN "+col+" TEXT NOT NULL DEFAULT ''"); err != nil && !strings.Contains(err.Error(), "duplicate column") {
d.Close()
diff --git a/internal/thintest/review_contract_test.go b/internal/thintest/review_contract_test.go
index 263b4d1e..e80ff0ce 100644
--- a/internal/thintest/review_contract_test.go
+++ b/internal/thintest/review_contract_test.go
@@ -286,3 +286,81 @@ func TestContractSyncJudgesOldCandidates(t *testing.T) {
}
r.dispatched(wire.SpecialistChecks, base, cand, 0)
}
+
+// Astra round 1, finding 1: readiness holds only while the task branch is
+// at the judged SHA. A push of B over approved A takes the task out of
+// Ready to merge and drops A's checks and verdict from the task (the link
+// opens B); the branch back at A restores it. A report about an older
+// candidate changes nothing.
+func TestContractBranchMovedInvalidatesReadiness(t *testing.T) {
+ r := newToolRig(t)
+ ctx := r.ctx
+ base, cand, other := strings.Repeat("1", 40), strings.Repeat("2", 40), strings.Repeat("5", 40)
+ id, _ := r.pushed("g", "Fix the README typo", base, cand)
+ c := r.dispatched(wire.SpecialistChecks, base, cand, 0)
+ r.checks("g-c", c, wire.ChecksPassed, exit(0), "", "ok\n")
+ rv := r.dispatched(wire.SpecialistReview, base, cand, 0)
+ r.verdict("g-r", rv, wire.VerdictApprove)
+ r.wait("ready", func(c *Conversation) bool { return c.Tasks[id].Stage == wire.StageReadyToMerge })
+ branch := func(frame, head string) {
+ if err := r.runner.Send(ctx, frame, wire.FrameBranch, wire.BranchReport{TaskID: id, CandidateSHA: cand, Head: head}); err != nil {
+ t.Fatal(err)
+ }
+ }
+ branch("b-moved", other)
+ shape(t, "frames/branch.json", r.runner.Sent[len(r.runner.Sent)-1])
+ r.wait("moved", func(c *Conversation) bool { return c.Tasks[id].NeedsYou == wire.NeedsBranchMoved })
+ k, _ := r.client.Task(ctx, id)
+ if k.Stage != wire.StageInReview || k.Checks != "" || k.Verdict != "" || k.ReviewLabel != "" || k.BranchHead != other || k.CandidateSHA != cand {
+ t.Fatalf("readiness kept after the branch moved: %+v", k)
+ }
+ if page := r.get(r.inst.Cookie(), "/conversation", 200); strings.Contains(page, "data-merge") || strings.Contains(page, "Approved (") || !strings.Contains(page, "Needs you: the branch moved on Amadan after it was checked") || strings.Contains(page, "Checks passed") {
+ t.Fatalf("card after the branch moved: %s", page)
+ }
+ if needs, _ := r.client.NeedsYou(ctx); len(needs.Items) != 1 || needs.Items[0].NeedsYou != wire.NeedsBranchMoved {
+ t.Fatalf("needs you %+v", needs)
+ }
+ // Deleted: still not ready.
+ branch("b-gone", "")
+ r.wait("gone", func(c *Conversation) bool {
+ return c.Tasks[id].NeedsYou == wire.NeedsBranchMoved && c.Tasks[id].BranchHead == ""
+ })
+ // Back at the judged SHA: ready again.
+ branch("b-back", cand)
+ r.wait("ready again", func(c *Conversation) bool {
+ k := c.Tasks[id]
+ return k.Stage == wire.StageReadyToMerge && k.Verdict == wire.VerdictApprove && k.NeedsYou == wire.NeedsMerge
+ })
+ // A report about a candidate that is not the newest is ignored.
+ if err := r.runner.Send(ctx, "b-old", wire.FrameBranch, wire.BranchReport{TaskID: id, CandidateSHA: other, Head: base}); err != nil {
+ t.Fatal(err)
+ }
+ r.client.Task(ctx, id)
+ if k, _ := r.client.Task(ctx, id); k.Stage != wire.StageReadyToMerge {
+ t.Fatalf("an old candidate's branch report moved the task: %+v", k)
+ }
+}
+
+// Astra round 1, finding 4: a checks result the runner can emit
+// (needs_network) is acked and recorded, and review follows; a reason
+// the instance does not know is recorded as unknown rather than refused
+// (which closed the connection and replayed the report forever).
+func TestContractCannotRunReasonsAreDelivered(t *testing.T) {
+ r := newToolRig(t)
+ base := strings.Repeat("1", 40)
+ for i, reason := range []string{"needs_network", "needs_quantum_computer"} {
+ cand := strings.Repeat(string(rune('6'+i)), 40)
+ key := "h" + itoa(i)
+ id, _ := r.pushed(key, "Task "+key, base, cand)
+ c := r.dispatched(wire.SpecialistChecks, base, cand, 0)
+ r.checks(key+"-c", c, wire.ChecksCannotRun, nil, reason, "")
+ r.dispatched(wire.SpecialistReview, base, cand, 0)
+ want := reason
+ if !wire.StepReasons[reason] {
+ want = wire.ReasonUnknown
+ }
+ if k, _ := r.client.Task(r.ctx, id); k.Checks != wire.ChecksCannotRun || k.ChecksReason != want {
+ t.Fatalf("%s recorded as %+v", reason, k)
+ }
+ }
+}
diff --git a/internal/wire/frames.go b/internal/wire/frames.go
index 1fb13739..e11a34d6 100644
--- a/internal/wire/frames.go
+++ b/internal/wire/frames.go
@@ -59,7 +59,7 @@ type Frame struct {
// Durable reports whether a frame must be acked and resent until acked.
func (f Frame) Durable() bool {
switch f.Type {
- case FrameMessage, FrameCancel, FrameReply, FrameTurn, FrameToolCall, FrameToolResult, FrameMoveIn, FrameNotebook, FrameReset, FrameDispatch, FrameCancelStep, FrameStep, FrameRecheck, FrameWatchMerge, FrameMerged, FrameAsk, FrameCancelAsk, FrameAnswer, FrameForgetTask:
+ case FrameMessage, FrameCancel, FrameReply, FrameTurn, FrameToolCall, FrameToolResult, FrameMoveIn, FrameNotebook, FrameReset, FrameDispatch, FrameCancelStep, FrameStep, FrameRecheck, FrameWatchMerge, FrameMerged, FrameAsk, FrameCancelAsk, FrameAnswer, FrameForgetTask, FrameBranch:
return true
}
return false
@@ -132,6 +132,8 @@ func (f Frame) Decode() (any, error) {
v = &AnswerReport{}
case FrameForgetTask:
v = &ForgetTaskCommand{}
+ case FrameBranch:
+ v = &BranchReport{}
default:
return nil, fmt.Errorf("%w: frame type %q", ErrStrict, f.Type)
}
diff --git a/internal/wire/tasks.go b/internal/wire/tasks.go
index fbfa4b1d..02ffc60b 100644
--- a/internal/wire/tasks.go
+++ b/internal/wire/tasks.go
@@ -87,6 +87,9 @@ const (
NeedsFixRounds = "fix_rounds"
NeedsReviewBlocked = "review_blocked"
NeedsRetry = "retry"
+ // NeedsBranchMoved: the task branch's head on Amadan is no longer the
+ // SHA that was checked and reviewed, so nothing judged applies.
+ NeedsBranchMoved = "branch_moved"
)
// MaxFixRounds is how many Engineering fix rounds the coordinator sends
@@ -236,6 +239,10 @@ type Task struct {
ReviewLabel string `json:"review_label"`
NeedsYou string `json:"needs_you"`
FixRounds int `json:"fix_rounds"`
+ // BranchHead is the task branch's head on Amadan when it moved away
+ // from CandidateSHA ("" while it is there, or once the branch is gone
+ // with NeedsYou branch_moved).
+ BranchHead string `json:"branch_head"`
// Questions are the creator's questions to the specialists and their
// answers, oldest first (the task thread beside Thread's notes).
Questions []Question `json:"questions"`
@@ -316,6 +323,9 @@ const (
// watching); FrameMerged reports that it landed.
FrameWatchMerge = "watch_merge"
FrameMerged = "merged"
+ // FrameBranch reports the task branch's head when it differs from the
+ // watched candidate (or is back at it).
+ FrameBranch = "branch"
)
// DispatchCommand starts one attempt of a step on the person's runner.
@@ -363,6 +373,14 @@ type MergedReport struct {
CandidateSHA string `json:"candidate_sha"`
}
+// BranchReport is the task branch's head on Amadan as the runner saw it,
+// sent when it changes: Head "" means the branch is gone.
+type BranchReport struct {
+ TaskID string `json:"task_id"`
+ CandidateSHA string `json:"candidate_sha"`
+ Head string `json:"head"`
+}
+
// CancelStepCommand interrupts one attempt of a step.
type CancelStepCommand struct {
Person string `json:"person"`
@@ -439,8 +457,15 @@ var StepReasons = map[string]bool{
"needs_macos": true,
"checks_timeout": true,
"checks_unavailable": true,
+ "needs_network": true,
+ // ReasonUnknown is what the instance records for a reason it does not
+ // know (a newer runner), rather than refusing the report.
+ ReasonUnknown: true,
}
+// ReasonUnknown stands in for a step reason the instance does not know.
+const ReasonUnknown = "unknown"
+
// Coordinator tools for tasks.
const (
ToolRecordTask = "record_task"
diff --git a/internal/wire/tasks_test.go b/internal/wire/tasks_test.go
index aa0462d9..74ee1f23 100644
--- a/internal/wire/tasks_test.go
+++ b/internal/wire/tasks_test.go
@@ -31,7 +31,7 @@ func TestTaskBranch(t *testing.T) {
}
func TestStepFramesAreDurable(t *testing.T) {
- for _, kind := range []string{wire.FrameDispatch, wire.FrameCancelStep, wire.FrameStep, wire.FrameRecheck, wire.FrameWatchMerge, wire.FrameMerged} {
+ for _, kind := range []string{wire.FrameDispatch, wire.FrameCancelStep, wire.FrameStep, wire.FrameRecheck, wire.FrameWatchMerge, wire.FrameMerged, wire.FrameBranch} {
if !(wire.Frame{Type: kind}).Durable() {
t.Fatalf("%s is not durable", kind)
}
diff --git a/internal/wire/wire_test.go b/internal/wire/wire_test.go
index d75e9ffd..87f6c8a4 100644
--- a/internal/wire/wire_test.go
+++ b/internal/wire/wire_test.go
@@ -33,7 +33,7 @@ func TestFrameFixturesRoundTrip(t *testing.T) {
t.Fatalf("%s: round trip\n got %s\nwant %s", name, out, raw)
}
}
- for _, kind := range []string{wire.FrameWelcome, wire.FrameMessage, wire.FrameCancel, wire.FrameDrain, wire.FrameAck, wire.FrameHello, wire.FrameSync, wire.FrameDelta, wire.FrameReply, wire.FrameTurn, wire.FrameLease, wire.FrameToolCall, wire.FrameToolResult, wire.FrameActivity, wire.FrameMoveIn, wire.FrameNotebook, wire.FrameReset, wire.FrameDispatch, wire.FrameCancelStep, wire.FrameStep, wire.FrameRecheck, wire.FrameWatchMerge, wire.FrameMerged, wire.FrameAsk, wire.FrameCancelAsk, wire.FrameAnswer, wire.FrameForgetTask} {
+ for _, kind := range []string{wire.FrameWelcome, wire.FrameMessage, wire.FrameCancel, wire.FrameDrain, wire.FrameAck, wire.FrameHello, wire.FrameSync, wire.FrameDelta, wire.FrameReply, wire.FrameTurn, wire.FrameLease, wire.FrameToolCall, wire.FrameToolResult, wire.FrameActivity, wire.FrameMoveIn, wire.FrameNotebook, wire.FrameReset, wire.FrameDispatch, wire.FrameCancelStep, wire.FrameStep, wire.FrameRecheck, wire.FrameWatchMerge, wire.FrameMerged, wire.FrameAsk, wire.FrameCancelAsk, wire.FrameAnswer, wire.FrameForgetTask, wire.FrameBranch} {
if !seen[kind] {
t.Fatalf("no fixture for frame %s", kind)
}
diff --git a/internal/wire/wiretest/testdata/api/event-task.json b/internal/wire/wiretest/testdata/api/event-task.json
index 8d3e6050..0b559c5a 100644
--- a/internal/wire/wiretest/testdata/api/event-task.json
+++ b/internal/wire/wiretest/testdata/api/event-task.json
@@ -1 +1 @@
-{"cursor":42,"type":"task","resource":"task","id":"tk0001","revision":5,"data":{"id":"tk0001","revision":5,"project_id":"p_0001","project":"Sample","repo":"amadan.net/oficina/sample","title":"Swipe back from the edge does nothing","brief":"Swiping from the left edge should go back a pane.","stage":"in_progress","branch":"equipo/tk0001-swipe-back-from-the-edge-does-nothing","base_sha":"1111111111111111111111111111111111111111","url":"https://amadan.net/oficina/sample?branch=equipo/tk0001-swipe-back-from-the-edge-does-nothing","creator":"owner@example.com","turn_id":"t_0001","findings":[{"id":"f_0001","text":"The edge-swipe handler returns false, so back never fires.","repo":"amadan.net/oficina/sample","path":"panes/swipe.go","line":4,"at":"2026-11-07T10:00:02Z"}],"steps":[{"id":"s_0001","revision":3,"task_id":"tk0001","index":1,"specialist":"engineering","state":"done","reason":"","attempt":1,"base_sha":"1111111111111111111111111111111111111111","candidate_sha":"2222222222222222222222222222222222222222","pushed":true,"terminated":true,"summary":"EdgeSwipe now goes back on a swipe from the edge.","log_tail":"Edit panes/swipe.go\nDone.","started_at":"2026-11-07T10:00:03Z","finished_at":"2026-11-07T10:01:40Z","round":0,"family":"claude","account":"claude-a","verdict":"","review_label":"","findings":[],"checks":"","gate":"","exit_code":null,"askable":true}],"thread":[{"id":"e_0001","author":"owner@example.com","text":"It happens on the iPhone only.","at":"2026-11-07T10:00:30Z"}],"created_at":"2026-11-07T10:00:01Z","updated_at":"2026-11-07T10:01:40Z","candidate_sha":"2222222222222222222222222222222222222222","checks":"","checks_reason":"","verdict":"","review_label":"","needs_you":"","fix_rounds":0,"questions":[{"id":"q_0001","revision":3,"task_id":"tk0001","step_id":"s_0001","specialist":"engineering","asker":"owner@example.com","text":"What did you change and why?","state":"answered","reason":"","attempt":1,"answer":"I made the edge swipe return true, so a swipe from the left edge goes back a pane. Before, the handler always said no.","created_at":"2026-11-07T10:05:00Z","updated_at":"2026-11-07T10:05:09Z","timing":null}]}}
+{"cursor":42,"type":"task","resource":"task","id":"tk0001","revision":5,"data":{"id":"tk0001","revision":5,"project_id":"p_0001","project":"Sample","repo":"amadan.net/oficina/sample","title":"Swipe back from the edge does nothing","brief":"Swiping from the left edge should go back a pane.","stage":"in_progress","branch":"equipo/tk0001-swipe-back-from-the-edge-does-nothing","base_sha":"1111111111111111111111111111111111111111","url":"https://amadan.net/oficina/sample?branch=equipo/tk0001-swipe-back-from-the-edge-does-nothing","creator":"owner@example.com","turn_id":"t_0001","findings":[{"id":"f_0001","text":"The edge-swipe handler returns false, so back never fires.","repo":"amadan.net/oficina/sample","path":"panes/swipe.go","line":4,"at":"2026-11-07T10:00:02Z"}],"steps":[{"id":"s_0001","revision":3,"task_id":"tk0001","index":1,"specialist":"engineering","state":"done","reason":"","attempt":1,"base_sha":"1111111111111111111111111111111111111111","candidate_sha":"2222222222222222222222222222222222222222","pushed":true,"terminated":true,"summary":"EdgeSwipe now goes back on a swipe from the edge.","log_tail":"Edit panes/swipe.go\nDone.","started_at":"2026-11-07T10:00:03Z","finished_at":"2026-11-07T10:01:40Z","round":0,"family":"claude","account":"claude-a","verdict":"","review_label":"","findings":[],"checks":"","gate":"","exit_code":null,"askable":true}],"thread":[{"id":"e_0001","author":"owner@example.com","text":"It happens on the iPhone only.","at":"2026-11-07T10:00:30Z"}],"created_at":"2026-11-07T10:00:01Z","updated_at":"2026-11-07T10:01:40Z","candidate_sha":"2222222222222222222222222222222222222222","checks":"","checks_reason":"","verdict":"","review_label":"","needs_you":"","fix_rounds":0,"branch_head":"","questions":[{"id":"q_0001","revision":3,"task_id":"tk0001","step_id":"s_0001","specialist":"engineering","asker":"owner@example.com","text":"What did you change and why?","state":"answered","reason":"","attempt":1,"answer":"I made the edge swipe return true, so a swipe from the left edge goes back a pane. Before, the handler always said no.","created_at":"2026-11-07T10:05:00Z","updated_at":"2026-11-07T10:05:09Z","timing":null}]}}
diff --git a/internal/wire/wiretest/testdata/api/needs-you.json b/internal/wire/wiretest/testdata/api/needs-you.json
index d2b20994..6a335486 100644
--- a/internal/wire/wiretest/testdata/api/needs-you.json
+++ b/internal/wire/wiretest/testdata/api/needs-you.json
@@ -1 +1 @@
-{"items":[{"id":"tk0001","revision":9,"project_id":"p_0001","project":"Sample","repo":"amadan.net/oficina/sample","title":"Swipe back from the edge does nothing","brief":"Swiping from the left edge should go back a pane.","stage":"ready_to_merge","branch":"equipo/tk0001-swipe-back-from-the-edge-does-nothing","base_sha":"1111111111111111111111111111111111111111","url":"https://amadan.net/oficina/sample?branch=equipo/tk0001-swipe-back-from-the-edge-does-nothing","creator":"owner@example.com","turn_id":"t_0001","findings":[{"id":"f_0001","text":"The edge-swipe handler returns false, so back never fires.","repo":"amadan.net/oficina/sample","path":"panes/swipe.go","line":4,"at":"2026-11-07T10:00:02Z"}],"steps":[{"id":"s_0001","revision":3,"task_id":"tk0001","index":1,"specialist":"engineering","state":"done","reason":"","attempt":1,"base_sha":"1111111111111111111111111111111111111111","candidate_sha":"2222222222222222222222222222222222222222","pushed":true,"terminated":true,"summary":"EdgeSwipe now goes back on a swipe from the edge.","log_tail":"Edit panes/swipe.go\nDone.","started_at":"2026-11-07T10:00:03Z","finished_at":"2026-11-07T10:01:40Z","round":0,"family":"claude","account":"claude-a","verdict":"","review_label":"","findings":[],"checks":"","gate":"","exit_code":null,"askable":true},{"id":"s_0002","revision":2,"task_id":"tk0001","index":2,"specialist":"checks","state":"done","reason":"","attempt":1,"base_sha":"1111111111111111111111111111111111111111","candidate_sha":"2222222222222222222222222222222222222222","pushed":false,"terminated":true,"summary":"","log_tail":"ok \tamadan.net/oficina/sample/panes\t0.012s","started_at":"2026-11-07T10:01:45Z","finished_at":"2026-11-07T10:02:30Z","round":0,"family":"","account":"","verdict":"","review_label":"","findings":[],"checks":"passed","gate":"make ci","exit_code":0,"askable":false},{"id":"s_0003","revision":2,"task_id":"tk0001","index":3,"specialist":"review","state":"done","reason":"","attempt":1,"base_sha":"1111111111111111111111111111111111111111","candidate_sha":"2222222222222222222222222222222222222222","pushed":false,"terminated":true,"summary":"The change makes EdgeSwipe go back and keeps the pane order. Approved.","log_tail":"Read panes/swipe.go","started_at":"2026-11-07T10:02:31Z","finished_at":"2026-11-07T10:04:10Z","round":0,"family":"claude","account":"claude-a","verdict":"approve","review_label":"same_family","findings":[{"id":"rf_0001","text":"Consider a test for a swipe that starts mid-screen.","repo":"amadan.net/oficina/sample","path":"panes/swipe.go","line":4,"at":"2026-11-07T10:04:10Z"}],"checks":"","gate":"","exit_code":null,"askable":true}],"thread":[{"id":"e_0001","author":"owner@example.com","text":"It happens on the iPhone only.","at":"2026-11-07T10:00:30Z"}],"created_at":"2026-11-07T10:00:01Z","updated_at":"2026-11-07T10:04:10Z","candidate_sha":"2222222222222222222222222222222222222222","checks":"passed","checks_reason":"","verdict":"approve","review_label":"same_family","needs_you":"merge","fix_rounds":0,"questions":[{"id":"q_0001","revision":3,"task_id":"tk0001","step_id":"s_0001","specialist":"engineering","asker":"owner@example.com","text":"What did you change and why?","state":"answered","reason":"","attempt":1,"answer":"I made the edge swipe return true, so a swipe from the left edge goes back a pane. Before, the handler always said no.","created_at":"2026-11-07T10:05:00Z","updated_at":"2026-11-07T10:05:09Z","timing":null}]}]}
+{"items":[{"id":"tk0001","revision":9,"project_id":"p_0001","project":"Sample","repo":"amadan.net/oficina/sample","title":"Swipe back from the edge does nothing","brief":"Swiping from the left edge should go back a pane.","stage":"ready_to_merge","branch":"equipo/tk0001-swipe-back-from-the-edge-does-nothing","base_sha":"1111111111111111111111111111111111111111","url":"https://amadan.net/oficina/sample?branch=equipo/tk0001-swipe-back-from-the-edge-does-nothing","creator":"owner@example.com","turn_id":"t_0001","findings":[{"id":"f_0001","text":"The edge-swipe handler returns false, so back never fires.","repo":"amadan.net/oficina/sample","path":"panes/swipe.go","line":4,"at":"2026-11-07T10:00:02Z"}],"steps":[{"id":"s_0001","revision":3,"task_id":"tk0001","index":1,"specialist":"engineering","state":"done","reason":"","attempt":1,"base_sha":"1111111111111111111111111111111111111111","candidate_sha":"2222222222222222222222222222222222222222","pushed":true,"terminated":true,"summary":"EdgeSwipe now goes back on a swipe from the edge.","log_tail":"Edit panes/swipe.go\nDone.","started_at":"2026-11-07T10:00:03Z","finished_at":"2026-11-07T10:01:40Z","round":0,"family":"claude","account":"claude-a","verdict":"","review_label":"","findings":[],"checks":"","gate":"","exit_code":null,"askable":true},{"id":"s_0002","revision":2,"task_id":"tk0001","index":2,"specialist":"checks","state":"done","reason":"","attempt":1,"base_sha":"1111111111111111111111111111111111111111","candidate_sha":"2222222222222222222222222222222222222222","pushed":false,"terminated":true,"summary":"","log_tail":"ok \tamadan.net/oficina/sample/panes\t0.012s","started_at":"2026-11-07T10:01:45Z","finished_at":"2026-11-07T10:02:30Z","round":0,"family":"","account":"","verdict":"","review_label":"","findings":[],"checks":"passed","gate":"make ci","exit_code":0,"askable":false},{"id":"s_0003","revision":2,"task_id":"tk0001","index":3,"specialist":"review","state":"done","reason":"","attempt":1,"base_sha":"1111111111111111111111111111111111111111","candidate_sha":"2222222222222222222222222222222222222222","pushed":false,"terminated":true,"summary":"The change makes EdgeSwipe go back and keeps the pane order. Approved.","log_tail":"Read panes/swipe.go","started_at":"2026-11-07T10:02:31Z","finished_at":"2026-11-07T10:04:10Z","round":0,"family":"claude","account":"claude-a","verdict":"approve","review_label":"same_family","findings":[{"id":"rf_0001","text":"Consider a test for a swipe that starts mid-screen.","repo":"amadan.net/oficina/sample","path":"panes/swipe.go","line":4,"at":"2026-11-07T10:04:10Z"}],"checks":"","gate":"","exit_code":null,"askable":true}],"thread":[{"id":"e_0001","author":"owner@example.com","text":"It happens on the iPhone only.","at":"2026-11-07T10:00:30Z"}],"created_at":"2026-11-07T10:00:01Z","updated_at":"2026-11-07T10:04:10Z","candidate_sha":"2222222222222222222222222222222222222222","checks":"passed","checks_reason":"","verdict":"approve","review_label":"same_family","needs_you":"merge","fix_rounds":0,"branch_head":"","questions":[{"id":"q_0001","revision":3,"task_id":"tk0001","step_id":"s_0001","specialist":"engineering","asker":"owner@example.com","text":"What did you change and why?","state":"answered","reason":"","attempt":1,"answer":"I made the edge swipe return true, so a swipe from the left edge goes back a pane. Before, the handler always said no.","created_at":"2026-11-07T10:05:00Z","updated_at":"2026-11-07T10:05:09Z","timing":null}]}]}
diff --git a/internal/wire/wiretest/testdata/api/task-ready.json b/internal/wire/wiretest/testdata/api/task-ready.json
index a6dfcd29..b1ec5259 100644
--- a/internal/wire/wiretest/testdata/api/task-ready.json
+++ b/internal/wire/wiretest/testdata/api/task-ready.json
@@ -1 +1 @@
-{"id":"tk0001","revision":9,"project_id":"p_0001","project":"Sample","repo":"amadan.net/oficina/sample","title":"Swipe back from the edge does nothing","brief":"Swiping from the left edge should go back a pane.","stage":"ready_to_merge","branch":"equipo/tk0001-swipe-back-from-the-edge-does-nothing","base_sha":"1111111111111111111111111111111111111111","url":"https://amadan.net/oficina/sample?branch=equipo/tk0001-swipe-back-from-the-edge-does-nothing","creator":"owner@example.com","turn_id":"t_0001","findings":[{"id":"f_0001","text":"The edge-swipe handler returns false, so back never fires.","repo":"amadan.net/oficina/sample","path":"panes/swipe.go","line":4,"at":"2026-11-07T10:00:02Z"}],"steps":[{"id":"s_0001","revision":3,"task_id":"tk0001","index":1,"specialist":"engineering","state":"done","reason":"","attempt":1,"base_sha":"1111111111111111111111111111111111111111","candidate_sha":"2222222222222222222222222222222222222222","pushed":true,"terminated":true,"summary":"EdgeSwipe now goes back on a swipe from the edge.","log_tail":"Edit panes/swipe.go\nDone.","started_at":"2026-11-07T10:00:03Z","finished_at":"2026-11-07T10:01:40Z","round":0,"family":"claude","account":"claude-a","verdict":"","review_label":"","findings":[],"checks":"","gate":"","exit_code":null,"askable":true},{"id":"s_0002","revision":2,"task_id":"tk0001","index":2,"specialist":"checks","state":"done","reason":"","attempt":1,"base_sha":"1111111111111111111111111111111111111111","candidate_sha":"2222222222222222222222222222222222222222","pushed":false,"terminated":true,"summary":"","log_tail":"ok \tamadan.net/oficina/sample/panes\t0.012s","started_at":"2026-11-07T10:01:45Z","finished_at":"2026-11-07T10:02:30Z","round":0,"family":"","account":"","verdict":"","review_label":"","findings":[],"checks":"passed","gate":"make ci","exit_code":0,"askable":false},{"id":"s_0003","revision":2,"task_id":"tk0001","index":3,"specialist":"review","state":"done","reason":"","attempt":1,"base_sha":"1111111111111111111111111111111111111111","candidate_sha":"2222222222222222222222222222222222222222","pushed":false,"terminated":true,"summary":"The change makes EdgeSwipe go back and keeps the pane order. Approved.","log_tail":"Read panes/swipe.go","started_at":"2026-11-07T10:02:31Z","finished_at":"2026-11-07T10:04:10Z","round":0,"family":"claude","account":"claude-a","verdict":"approve","review_label":"same_family","findings":[{"id":"rf_0001","text":"Consider a test for a swipe that starts mid-screen.","repo":"amadan.net/oficina/sample","path":"panes/swipe.go","line":4,"at":"2026-11-07T10:04:10Z"}],"checks":"","gate":"","exit_code":null,"askable":true}],"thread":[{"id":"e_0001","author":"owner@example.com","text":"It happens on the iPhone only.","at":"2026-11-07T10:00:30Z"}],"created_at":"2026-11-07T10:00:01Z","updated_at":"2026-11-07T10:04:10Z","candidate_sha":"2222222222222222222222222222222222222222","checks":"passed","checks_reason":"","verdict":"approve","review_label":"same_family","needs_you":"merge","fix_rounds":0,"questions":[{"id":"q_0001","revision":3,"task_id":"tk0001","step_id":"s_0001","specialist":"engineering","asker":"owner@example.com","text":"What did you change and why?","state":"answered","reason":"","attempt":1,"answer":"I made the edge swipe return true, so a swipe from the left edge goes back a pane. Before, the handler always said no.","created_at":"2026-11-07T10:05:00Z","updated_at":"2026-11-07T10:05:09Z","timing":null}]}
+{"id":"tk0001","revision":9,"project_id":"p_0001","project":"Sample","repo":"amadan.net/oficina/sample","title":"Swipe back from the edge does nothing","brief":"Swiping from the left edge should go back a pane.","stage":"ready_to_merge","branch":"equipo/tk0001-swipe-back-from-the-edge-does-nothing","base_sha":"1111111111111111111111111111111111111111","url":"https://amadan.net/oficina/sample?branch=equipo/tk0001-swipe-back-from-the-edge-does-nothing","creator":"owner@example.com","turn_id":"t_0001","findings":[{"id":"f_0001","text":"The edge-swipe handler returns false, so back never fires.","repo":"amadan.net/oficina/sample","path":"panes/swipe.go","line":4,"at":"2026-11-07T10:00:02Z"}],"steps":[{"id":"s_0001","revision":3,"task_id":"tk0001","index":1,"specialist":"engineering","state":"done","reason":"","attempt":1,"base_sha":"1111111111111111111111111111111111111111","candidate_sha":"2222222222222222222222222222222222222222","pushed":true,"terminated":true,"summary":"EdgeSwipe now goes back on a swipe from the edge.","log_tail":"Edit panes/swipe.go\nDone.","started_at":"2026-11-07T10:00:03Z","finished_at":"2026-11-07T10:01:40Z","round":0,"family":"claude","account":"claude-a","verdict":"","review_label":"","findings":[],"checks":"","gate":"","exit_code":null,"askable":true},{"id":"s_0002","revision":2,"task_id":"tk0001","index":2,"specialist":"checks","state":"done","reason":"","attempt":1,"base_sha":"1111111111111111111111111111111111111111","candidate_sha":"2222222222222222222222222222222222222222","pushed":false,"terminated":true,"summary":"","log_tail":"ok \tamadan.net/oficina/sample/panes\t0.012s","started_at":"2026-11-07T10:01:45Z","finished_at":"2026-11-07T10:02:30Z","round":0,"family":"","account":"","verdict":"","review_label":"","findings":[],"checks":"passed","gate":"make ci","exit_code":0,"askable":false},{"id":"s_0003","revision":2,"task_id":"tk0001","index":3,"specialist":"review","state":"done","reason":"","attempt":1,"base_sha":"1111111111111111111111111111111111111111","candidate_sha":"2222222222222222222222222222222222222222","pushed":false,"terminated":true,"summary":"The change makes EdgeSwipe go back and keeps the pane order. Approved.","log_tail":"Read panes/swipe.go","started_at":"2026-11-07T10:02:31Z","finished_at":"2026-11-07T10:04:10Z","round":0,"family":"claude","account":"claude-a","verdict":"approve","review_label":"same_family","findings":[{"id":"rf_0001","text":"Consider a test for a swipe that starts mid-screen.","repo":"amadan.net/oficina/sample","path":"panes/swipe.go","line":4,"at":"2026-11-07T10:04:10Z"}],"checks":"","gate":"","exit_code":null,"askable":true}],"thread":[{"id":"e_0001","author":"owner@example.com","text":"It happens on the iPhone only.","at":"2026-11-07T10:00:30Z"}],"created_at":"2026-11-07T10:00:01Z","updated_at":"2026-11-07T10:04:10Z","candidate_sha":"2222222222222222222222222222222222222222","checks":"passed","checks_reason":"","verdict":"approve","review_label":"same_family","needs_you":"merge","fix_rounds":0,"branch_head":"","questions":[{"id":"q_0001","revision":3,"task_id":"tk0001","step_id":"s_0001","specialist":"engineering","asker":"owner@example.com","text":"What did you change and why?","state":"answered","reason":"","attempt":1,"answer":"I made the edge swipe return true, so a swipe from the left edge goes back a pane. Before, the handler always said no.","created_at":"2026-11-07T10:05:00Z","updated_at":"2026-11-07T10:05:09Z","timing":null}]}
diff --git a/internal/wire/wiretest/testdata/api/task.json b/internal/wire/wiretest/testdata/api/task.json
index c4f86d80..96576266 100644
--- a/internal/wire/wiretest/testdata/api/task.json
+++ b/internal/wire/wiretest/testdata/api/task.json
@@ -1 +1 @@
-{"id":"tk0001","revision":5,"project_id":"p_0001","project":"Sample","repo":"amadan.net/oficina/sample","title":"Swipe back from the edge does nothing","brief":"Swiping from the left edge should go back a pane.","stage":"in_progress","branch":"equipo/tk0001-swipe-back-from-the-edge-does-nothing","base_sha":"1111111111111111111111111111111111111111","url":"https://amadan.net/oficina/sample?branch=equipo/tk0001-swipe-back-from-the-edge-does-nothing","creator":"owner@example.com","turn_id":"t_0001","findings":[{"id":"f_0001","text":"The edge-swipe handler returns false, so back never fires.","repo":"amadan.net/oficina/sample","path":"panes/swipe.go","line":4,"at":"2026-11-07T10:00:02Z"}],"steps":[{"id":"s_0001","revision":3,"task_id":"tk0001","index":1,"specialist":"engineering","state":"done","reason":"","attempt":1,"base_sha":"1111111111111111111111111111111111111111","candidate_sha":"2222222222222222222222222222222222222222","pushed":true,"terminated":true,"summary":"EdgeSwipe now goes back on a swipe from the edge.","log_tail":"Edit panes/swipe.go\nDone.","started_at":"2026-11-07T10:00:03Z","finished_at":"2026-11-07T10:01:40Z","round":0,"family":"claude","account":"claude-a","verdict":"","review_label":"","findings":[],"checks":"","gate":"","exit_code":null,"askable":true}],"thread":[{"id":"e_0001","author":"owner@example.com","text":"It happens on the iPhone only.","at":"2026-11-07T10:00:30Z"}],"created_at":"2026-11-07T10:00:01Z","updated_at":"2026-11-07T10:01:40Z","candidate_sha":"2222222222222222222222222222222222222222","checks":"","checks_reason":"","verdict":"","review_label":"","needs_you":"","fix_rounds":0,"questions":[{"id":"q_0001","revision":3,"task_id":"tk0001","step_id":"s_0001","specialist":"engineering","asker":"owner@example.com","text":"What did you change and why?","state":"answered","reason":"","attempt":1,"answer":"I made the edge swipe return true, so a swipe from the left edge goes back a pane. Before, the handler always said no.","created_at":"2026-11-07T10:05:00Z","updated_at":"2026-11-07T10:05:09Z","timing":null}]}
+{"id":"tk0001","revision":5,"project_id":"p_0001","project":"Sample","repo":"amadan.net/oficina/sample","title":"Swipe back from the edge does nothing","brief":"Swiping from the left edge should go back a pane.","stage":"in_progress","branch":"equipo/tk0001-swipe-back-from-the-edge-does-nothing","base_sha":"1111111111111111111111111111111111111111","url":"https://amadan.net/oficina/sample?branch=equipo/tk0001-swipe-back-from-the-edge-does-nothing","creator":"owner@example.com","turn_id":"t_0001","findings":[{"id":"f_0001","text":"The edge-swipe handler returns false, so back never fires.","repo":"amadan.net/oficina/sample","path":"panes/swipe.go","line":4,"at":"2026-11-07T10:00:02Z"}],"steps":[{"id":"s_0001","revision":3,"task_id":"tk0001","index":1,"specialist":"engineering","state":"done","reason":"","attempt":1,"base_sha":"1111111111111111111111111111111111111111","candidate_sha":"2222222222222222222222222222222222222222","pushed":true,"terminated":true,"summary":"EdgeSwipe now goes back on a swipe from the edge.","log_tail":"Edit panes/swipe.go\nDone.","started_at":"2026-11-07T10:00:03Z","finished_at":"2026-11-07T10:01:40Z","round":0,"family":"claude","account":"claude-a","verdict":"","review_label":"","findings":[],"checks":"","gate":"","exit_code":null,"askable":true}],"thread":[{"id":"e_0001","author":"owner@example.com","text":"It happens on the iPhone only.","at":"2026-11-07T10:00:30Z"}],"created_at":"2026-11-07T10:00:01Z","updated_at":"2026-11-07T10:01:40Z","candidate_sha":"2222222222222222222222222222222222222222","checks":"","checks_reason":"","verdict":"","review_label":"","needs_you":"","fix_rounds":0,"branch_head":"","questions":[{"id":"q_0001","revision":3,"task_id":"tk0001","step_id":"s_0001","specialist":"engineering","asker":"owner@example.com","text":"What did you change and why?","state":"answered","reason":"","attempt":1,"answer":"I made the edge swipe return true, so a swipe from the left edge goes back a pane. Before, the handler always said no.","created_at":"2026-11-07T10:05:00Z","updated_at":"2026-11-07T10:05:09Z","timing":null}]}
diff --git a/internal/wire/wiretest/testdata/api/tasks.json b/internal/wire/wiretest/testdata/api/tasks.json
index 199b379b..0c43bba0 100644
--- a/internal/wire/wiretest/testdata/api/tasks.json
+++ b/internal/wire/wiretest/testdata/api/tasks.json
@@ -1 +1 @@
-{"items":[{"id":"tk0001","revision":5,"project_id":"p_0001","project":"Sample","repo":"amadan.net/oficina/sample","title":"Swipe back from the edge does nothing","brief":"Swiping from the left edge should go back a pane.","stage":"in_progress","branch":"equipo/tk0001-swipe-back-from-the-edge-does-nothing","base_sha":"1111111111111111111111111111111111111111","url":"https://amadan.net/oficina/sample?branch=equipo/tk0001-swipe-back-from-the-edge-does-nothing","creator":"owner@example.com","turn_id":"t_0001","findings":[{"id":"f_0001","text":"The edge-swipe handler returns false, so back never fires.","repo":"amadan.net/oficina/sample","path":"panes/swipe.go","line":4,"at":"2026-11-07T10:00:02Z"}],"steps":[{"id":"s_0001","revision":3,"task_id":"tk0001","index":1,"specialist":"engineering","state":"done","reason":"","attempt":1,"base_sha":"1111111111111111111111111111111111111111","candidate_sha":"2222222222222222222222222222222222222222","pushed":true,"terminated":true,"summary":"EdgeSwipe now goes back on a swipe from the edge.","log_tail":"Edit panes/swipe.go\nDone.","started_at":"2026-11-07T10:00:03Z","finished_at":"2026-11-07T10:01:40Z","round":0,"family":"claude","account":"claude-a","verdict":"","review_label":"","findings":[],"checks":"","gate":"","exit_code":null,"askable":true}],"thread":[{"id":"e_0001","author":"owner@example.com","text":"It happens on the iPhone only.","at":"2026-11-07T10:00:30Z"}],"created_at":"2026-11-07T10:00:01Z","updated_at":"2026-11-07T10:01:40Z","candidate_sha":"2222222222222222222222222222222222222222","checks":"","checks_reason":"","verdict":"","review_label":"","needs_you":"","fix_rounds":0,"questions":[{"id":"q_0001","revision":3,"task_id":"tk0001","step_id":"s_0001","specialist":"engineering","asker":"owner@example.com","text":"What did you change and why?","state":"answered","reason":"","attempt":1,"answer":"I made the edge swipe return true, so a swipe from the left edge goes back a pane. Before, the handler always said no.","created_at":"2026-11-07T10:05:00Z","updated_at":"2026-11-07T10:05:09Z","timing":null}]}]}
+{"items":[{"id":"tk0001","revision":5,"project_id":"p_0001","project":"Sample","repo":"amadan.net/oficina/sample","title":"Swipe back from the edge does nothing","brief":"Swiping from the left edge should go back a pane.","stage":"in_progress","branch":"equipo/tk0001-swipe-back-from-the-edge-does-nothing","base_sha":"1111111111111111111111111111111111111111","url":"https://amadan.net/oficina/sample?branch=equipo/tk0001-swipe-back-from-the-edge-does-nothing","creator":"owner@example.com","turn_id":"t_0001","findings":[{"id":"f_0001","text":"The edge-swipe handler returns false, so back never fires.","repo":"amadan.net/oficina/sample","path":"panes/swipe.go","line":4,"at":"2026-11-07T10:00:02Z"}],"steps":[{"id":"s_0001","revision":3,"task_id":"tk0001","index":1,"specialist":"engineering","state":"done","reason":"","attempt":1,"base_sha":"1111111111111111111111111111111111111111","candidate_sha":"2222222222222222222222222222222222222222","pushed":true,"terminated":true,"summary":"EdgeSwipe now goes back on a swipe from the edge.","log_tail":"Edit panes/swipe.go\nDone.","started_at":"2026-11-07T10:00:03Z","finished_at":"2026-11-07T10:01:40Z","round":0,"family":"claude","account":"claude-a","verdict":"","review_label":"","findings":[],"checks":"","gate":"","exit_code":null,"askable":true}],"thread":[{"id":"e_0001","author":"owner@example.com","text":"It happens on the iPhone only.","at":"2026-11-07T10:00:30Z"}],"created_at":"2026-11-07T10:00:01Z","updated_at":"2026-11-07T10:01:40Z","candidate_sha":"2222222222222222222222222222222222222222","checks":"","checks_reason":"","verdict":"","review_label":"","needs_you":"","fix_rounds":0,"branch_head":"","questions":[{"id":"q_0001","revision":3,"task_id":"tk0001","step_id":"s_0001","specialist":"engineering","asker":"owner@example.com","text":"What did you change and why?","state":"answered","reason":"","attempt":1,"answer":"I made the edge swipe return true, so a swipe from the left edge goes back a pane. Before, the handler always said no.","created_at":"2026-11-07T10:05:00Z","updated_at":"2026-11-07T10:05:09Z","timing":null}]}]}
diff --git a/internal/wire/wiretest/testdata/frames/branch.json b/internal/wire/wiretest/testdata/frames/branch.json
new file mode 100644
index 00000000..d3833def
--- /dev/null
+++ b/internal/wire/wiretest/testdata/frames/branch.json
@@ -0,0 +1 @@
+{"id":"r13","type":"branch","data":{"task_id":"tk0001","candidate_sha":"2222222222222222222222222222222222222222","head":"3333333333333333333333333333333333333333"}}
diff --git a/scripts/runner-reference-allowlist.json b/scripts/runner-reference-allowlist.json
index faf28b18..c3fefad5 100644
--- a/scripts/runner-reference-allowlist.json
+++ b/scripts/runner-reference-allowlist.json
@@ -10428,5 +10428,19 @@
"match": "node",
"count": 1,
"reason": "DOM Node API in the thinking-line design mockup's script; not the old runner or a Node.js runtime."
+ },
+ {
+ "path": "internal/runner/thin/review_fixes_test.go",
+ "line_sha256": "469749cabd0dfcbaf26ba724860992bb46b9b52b94efd42022a3064fffa2ae1d",
+ "match": "Node",
+ "count": 1,
+ "reason": "Go's go/ast node type in the test that reads the step reasons the runner emits; not a runtime reference."
+ },
+ {
+ "path": "internal/runner/thin/review_fixes_test.go",
+ "line_sha256": "e25121c0619a5e2e5ec6c9fc77006c60bd90e403eac575a05283685c2be88deb",
+ "match": "Node",
+ "count": 1,
+ "reason": "Go's go/ast node type in the test that reads the step reasons the runner emits; not a runtime reference."
}
]