Placement, withdrawal, transfers and publication on the instance
Checks whose change needs a Mac are placed on a worker whose tags cover their needs (the primary otherwise, honest needs_macos as before); a fitting offline worker leaves them waiting, and after 30 minutes they resolve cannot_run/runner_offline. A protocol 2 lease naming an attempt is its start authorization, serialised with withdrawal: not started, the next attempt is placed at once; started, it is cancelled and replaced only after its termination. placement_refused re-places. Transfers authorise every chunk; packs travel as blob commands; only the primary's published report sets Pushed for a worker's commit, with Retry republishing it. Engineering is pinned per task; questions go to the runner holding the session. GET /api/v1/runners, snapshot runners, per-runner events.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
32 files changed,
+1,799
−62
.rastrillo/budgets.txt+4 −4internal/equipo/app.go+7 −0internal/equipo/chat/http.go+10 −0internal/equipo/chat/questions.go+7 −9internal/equipo/chat/review.go+3 −0internal/equipo/chat/runner.go+32 −10internal/equipo/chat/runners.go+492 −0internal/equipo/chat/store.go+29 −7internal/equipo/chat/stream.go+19 −3internal/equipo/chat/tasks.go+85 −14internal/equipo/chat/transfers.go+305 −0internal/equipo/migrations/0047_thin_runners.sql+1 −0internal/equipo/migrations/schema.sql+1 −1internal/equipo/static/chat-stream.js+3 −1internal/thintest/client.go+21 −3internal/thintest/migration_contract_test.go+1 −1internal/thintest/placement_contract_test.go+479 −0internal/thintest/review_contract_test.go+13 −0internal/thintest/transfer_contract_test.go+230 −0internal/wire/api.go+16 −0internal/wire/frames.go+8 −0internal/wire/runners.go+5 −2internal/wire/tasks.go+18 −0internal/wire/wiretest/fixtures.go+2 −0internal/wire/wiretest/testdata/api/event-runner.json+1 −1internal/wire/wiretest/testdata/api/needs-you.json+1 −1internal/wire/wiretest/testdata/api/runners.json+1 −0internal/wire/wiretest/testdata/api/snapshot.json+1 −1internal/wire/wiretest/testdata/api/task-merged.json+1 −1internal/wire/wiretest/testdata/api/task-ready.json+1 −1internal/wire/wiretest/testdata/api/task.json+1 −1internal/wire/wiretest/testdata/api/tasks.json+1 −1
CI failed — run details
Intent
diff --git a/.rastrillo/budgets.txt b/.rastrillo/budgets.txt| index 0aea824a..66578e7a 100644 |
| --- a/.rastrillo/budgets.txt |
| +++ b/.rastrillo/budgets.txt |
| @@ -20,7 +20,7 @@ time internal/runner/checks 90s CI worker measured 44.553s (44.6s rounded); 60s |
| 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. |
| -size internal/runner 9550 8800 Thin v1 slice 1 exports helpers for internal/runner/thin beside the old runtime its slice 7 sweep deletes; lower then. Task 17 fix round 1 adds authenticated terminal-login composition and saved-report recovery beside the existing runner journal and state lock. Measured 9421 source and 8719 test lines. Login lifecycle, subprocess handling and environment parsing stay in setup/provider; the 100-line source raise retains only production HTTP/config wiring here. Existing test and 330s time ceilings are unchanged. |
| +size internal/runner 9650 8950 Mac runners (slices A and B) add the worker enrolment check (enrol.go) and its test. Thin v1 slice 1 exports helpers for internal/runner/thin beside the old runtime its slice 7 sweep deletes; lower then. Task 17 fix round 1 adds authenticated terminal-login composition and saved-report recovery beside the existing runner journal and state lock. Measured 9421 source and 8719 test lines. Login lifecycle, subprocess handling and environment parsing stay in setup/provider; the 100-line source raise retains only production HTTP/config wiring here. Existing test and 330s time ceilings are unchanged. |
| time internal/runner/provider/claude 45s Task 5 measured 32.430s for fake CLI sessions and fsynced account, policy, capture and refresh checks; 45s gives 38 percent headroom on the shared runner. |
| time internal/runner/provider/codex 35s Plan 3 CI repair measured 24.464s for the full package (controller CI 27.908s). Independent policy subtests now run in parallel; 35s leaves 25 percent above the loaded CI measurement for schema, native approval and fsynced capture fixtures. |
| @@ -35,8 +35,8 @@ 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 8500 - Thin v1 slice 4c adds the merge step (mergestep.go, about 190 lines) and the rebase round beside the slice 4b ask fixes. 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. |
| +size internal/runner/thin 11000 - Mac runners slices A and B add protocol negotiation (link.go), the capability report, the start authorization, the pack relay, the primary's publication and the test-build fake worker, about 2000 lines on the same step engine. Thin v1 slice 4c adds the merge step (mergestep.go, about 190 lines) and the rebase round beside the slice 4b ask fixes. 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 60s Mac runners slices A and B add role, scoping, migration, placement, withdrawal, transfer and publication contracts; measured 35.7s locally under load. 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/runner/thin 45s Thin v1 slice 4 review: real git repositories for the merge and squash checks, a stalled fetch, and a 16 MiB candidate streamed through the review diff and the checks pack (about 5s). Measured 17.8s locally under load. Slice 4b review adds a 16 MiB git output bound, an injected index-pack failure and stall (3s deadline) and held-answer tests; measured 30.3s locally under load. 45s keeps 33 percent headroom. |
| 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. |
| @@ -48,6 +48,6 @@ perf GET /api/v1/projects skip Thin v1 person API: bearer-only JSON for devices; |
| perf GET /api/v1/notebook skip Thin v1 person API: bearer-only JSON for devices; the browser reads the notebook through /conversation/notebook. |
| perf GET /api/v1/tasks skip Thin v1 person API: bearer-only JSON for devices; the browser reads tasks through /tasks. |
| perf GET /api/v1/tasks/{id} skip Thin v1 person API: bearer-only JSON for devices; the browser reads a task through /tasks/{id}. |
| -size internal/equipo/chat 6500 - Thin v1 slice 4c adds the merge policy, the merge card, the rebase round and duplicate reports (merge.go, about 380 lines). Thin v1 instance core: conversation, projects, tasks, review and, from slice 4b, questions to the specialists (questions.go, about 470 lines) share one store, transaction and event log; splitting would export the transaction internals. Measured 5514 source lines; revisit at the slice 7 sweep. |
| +size internal/equipo/chat 8600 - Mac runners slices A and B add per-runner mailboxes, placement, withdrawal, the offline rule, the runners view, transfers and publication (runners.go, transfers.go, about 1000 lines). Thin v1 slice 4c adds the merge policy, the merge card, the rebase round and duplicate reports (merge.go, about 380 lines). Thin v1 instance core: conversation, projects, tasks, review and, from slice 4b, questions to the specialists (questions.go, about 470 lines) share one store, transaction and event log; splitting would export the transaction internals. Measured 5514 source lines; revisit at the slice 7 sweep. |
| perf GET /api/v1/questions/{id} skip Thin v1 person API: bearer-only JSON for devices; the browser reads questions on /tasks/{id}. |
| perf GET /api/v1/steps/{id}/log skip Thin v1 person API: bearer-only JSON for devices; the browser shows the log tail on /tasks/{id}. |
diff --git a/internal/equipo/app.go b/internal/equipo/app.go| index 36b13290..feab5bb6 100644 |
| --- a/internal/equipo/app.go |
| +++ b/internal/equipo/app.go |
| @@ -60,6 +60,13 @@ func (a *application) startBackground() *background.Group { |
| if err := a.store.personDevices().Sweep(ctx); err != nil { |
| a.logger.Error(copyAuthSweep, "err", err) |
| } |
| + if !a.executionEnabled { |
| + return |
| + } |
| + // Steps waiting for a runner, and the offline rule. |
| + if err := a.store.Chat().Place(ctx); err != nil { |
| + a.logger.Error(copyChatSweep, "err", err) |
| + } |
| }) |
| a.background.Loop(context.Background(), time.Hour, func() { |
| ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) |
diff --git a/internal/equipo/chat/http.go b/internal/equipo/chat/http.go| index 108d06f2..a1a4b025 100644 |
| --- a/internal/equipo/chat/http.go |
| +++ b/internal/equipo/chat/http.go |
| @@ -81,6 +81,7 @@ func (h *HTTP) Mount(r chi.Router) { |
| r.Get("/questions/{id}", h.thinOr("GET /questions/{id}", thinQuestion, h.bearer(h.question))) |
| r.Post("/questions/{id}/cancel", h.bearer(h.cancelQuestion)) |
| r.Get("/needs-you", h.thinOr("GET /needs-you", deviceClient, h.bearer(h.needsYou))) |
| + r.Get("/runners", h.thinOr("GET /runners", deviceClient, h.bearer(h.runners))) |
| r.Get("/events", h.events) |
| } |
| @@ -404,6 +405,15 @@ func (h *HTTP) resetNotebook(w http.ResponseWriter, r *http.Request, p personapi |
| writeJSON(w, http.StatusAccepted, out) |
| } |
| +func (h *HTTP) runners(w http.ResponseWriter, r *http.Request, p personapi.PersonPrincipal) { |
| + out, err := h.Store.RunnerList(r.Context(), p.Address) |
| + if err != nil { |
| + h.fail(w, r, err) |
| + return |
| + } |
| + writeJSON(w, 200, out) |
| +} |
| + |
| func (h *HTTP) needsYou(w http.ResponseWriter, r *http.Request, p personapi.PersonPrincipal) { |
| out, err := h.Store.NeedsYou(r.Context(), p.Address) |
| if err != nil { |
diff --git a/internal/equipo/chat/questions.go b/internal/equipo/chat/questions.go| index a34f7198..265676e2 100644 |
| --- a/internal/equipo/chat/questions.go |
| +++ b/internal/equipo/chat/questions.go |
| @@ -229,7 +229,8 @@ func (t *txn) nextQuestion(k taskRecord) error { |
| base = s.BaseSHA |
| } |
| cmd := wire.AskCommand{Person: s.Person, TaskID: k.ID, StepID: s.ID, QuestionID: q.ID, Attempt: q.Attempt, Specialist: s.Specialist, Repo: p.Repo, Branch: k.Branch, BaseSHA: base, CandidateSHA: s.CandidateSHA, Title: k.Title, Text: q.Text} |
| - if err := t.command(s.Person, wire.FrameAsk, cmd); err != nil { |
| + // Asked of the runner that holds the step's session, never another. |
| + if err := t.commandTo(s.RunnerID, s.Person, wire.FrameAsk, cmd); err != nil { |
| return err |
| } |
| q.Dispatched = true |
| @@ -291,7 +292,7 @@ func (t *txn) stopQuestion(q *questionRecord, reason string) error { |
| if err := t.db.Where("id = ?", q.StepID).First(&s).Error; err != nil { |
| return err |
| } |
| - return t.command(s.Person, wire.FrameCancelAsk, wire.CancelAskCommand{Person: s.Person, TaskID: q.TaskID, QuestionID: q.ID, Attempt: q.Attempt}) |
| + return t.commandTo(s.RunnerID, s.Person, wire.FrameCancelAsk, wire.CancelAskCommand{Person: s.Person, TaskID: q.TaskID, QuestionID: q.ID, Attempt: q.Attempt}) |
| } |
| // ownQuestion loads a question for a runner frame: only the step's |
| @@ -310,12 +311,9 @@ func (t *txn) ownQuestion(l Lease, id string) (questionRecord, error) { |
| if s.Person != l.Runner.Person { |
| return q, ErrNotFound |
| } |
| - primary, err := t.s.authority.PrimaryRunner(t.db, s.Person) |
| - if err != nil { |
| - return q, err |
| - } |
| - if primary != l.Runner.RunnerID { |
| - return q, ErrForbidden |
| + // Only the runner that holds the step's session answers for it. |
| + if s.RunnerID != l.Runner.RunnerID { |
| + return q, ErrRefused |
| } |
| return q, nil |
| } |
| @@ -462,7 +460,7 @@ func (t *txn) syncQuestions(l Lease, held []wire.AskRun) error { |
| if err := t.db.Where("id = ?", q.StepID).First(&s).Error; err != nil { |
| return err |
| } |
| - if s.Person != l.Runner.Person { |
| + if s.Person != l.Runner.Person || s.RunnerID != l.Runner.RunnerID { |
| continue |
| } |
| var unacked int64 |
diff --git a/internal/equipo/chat/review.go b/internal/equipo/chat/review.go| index 9e7f59c1..b86edcf7 100644 |
| --- a/internal/equipo/chat/review.go |
| +++ b/internal/equipo/chat/review.go |
| @@ -98,6 +98,9 @@ func (p progress) needsYou(k taskRecord) string { |
| if wire.FinalStage(k.Stage) || k.CancelRequested || p.last == nil { |
| return "" |
| } |
| + if p.last.Specialist == wire.SpecialistEngineering && p.last.State == wire.StepDone && p.last.Publication == wire.PublicationFailed { |
| + return wire.NeedsRetry |
| + } |
| if p.last.State == wire.StepFailed && p.last.Terminated { |
| if p.last.Specialist == wire.SpecialistReview { |
| return wire.NeedsReviewBlocked |
diff --git a/internal/equipo/chat/runner.go b/internal/equipo/chat/runner.go| index 436ca837..9fed3451 100644 |
| --- a/internal/equipo/chat/runner.go |
| +++ b/internal/equipo/chat/runner.go |
| @@ -71,18 +71,30 @@ func (s *Store) Connect(ctx context.Context, p RunnerPrincipal, process string, |
| return err |
| } |
| } |
| - return t.runnerEvent(p.Person, r) |
| + if err := t.runnerEvent(p.Person, r); err != nil { |
| + return err |
| + } |
| + // A runner that fits may have come online. |
| + return t.placeWaiting(p.Person) |
| }) |
| return lease, err |
| } |
| +// runnerEvent tells the person about one of their runners, each runner |
| +// by its own id. |
| func (t *txn) runnerEvent(person string, r runnerSessionRecord) error { |
| - primary, err := t.s.authority.PrimaryRunner(t.db, person) |
| - if err != nil || primary != r.RunnerID { |
| + rs, err := t.runners(person) |
| + if err != nil { |
| return err |
| } |
| - v := wire.Runner{ID: r.RunnerID, Revision: r.Revision, Online: r.Connected} |
| - return t.event(person, wire.EventRunner, "runner", r.RunnerID, r.Revision, "", "", 0, v) |
| + for _, info := range rs { |
| + if info.ID == r.RunnerID { |
| + v := runnerView(info) |
| + v.Online = r.Connected |
| + return t.event(person, wire.EventRunner, "runner", r.RunnerID, r.Revision, "", "", 0, v) |
| + } |
| + } |
| + return nil |
| } |
| // current checks, inside a write, that this lease still holds the |
| @@ -131,7 +143,10 @@ func (s *Store) Heartbeat(ctx context.Context, l Lease, hello wire.Hello) error |
| } |
| } |
| if !online { |
| - return t.runnerEvent(l.Runner.Person, r) |
| + if err := t.runnerEvent(l.Runner.Person, r); err != nil { |
| + return err |
| + } |
| + return t.placeWaiting(l.Runner.Person) |
| } |
| return nil |
| }) |
| @@ -235,6 +250,10 @@ func (s *Store) Apply(ctx context.Context, l Lease, f wire.Frame, body any) erro |
| return t.answer(l, v) |
| case *wire.BranchReport: |
| return t.branchMoved(l, v) |
| + case *wire.Blob: |
| + return t.blob(l, v) |
| + case *wire.PublishedReport: |
| + return t.published(l, v) |
| } |
| return ErrInvalid |
| }) |
| @@ -274,6 +293,9 @@ func (t *txn) ack(l Lease, id string) error { |
| if err := t.db.Model(&commandRecord{}).Where("seq = ?", c.Seq).Update("acked_at", now).Error; err != nil { |
| return err |
| } |
| + if c.Kind == wire.FrameBlob { |
| + return t.blobAcked(c.Body) |
| + } |
| if c.Kind != wire.FrameMessage { |
| return nil |
| } |
| @@ -395,19 +417,19 @@ func (t *txn) report(l Lease, v *wire.TurnReport) error { |
| // sync reconciles after a reconnect: a turn the instance thinks is running |
| // that the runner no longer holds has failed visibly. |
| func (t *txn) sync(l Lease, v *wire.Sync) error { |
| - // Each runner settles only its own steps. |
| + // Each runner settles only its own steps and questions. |
| if err := t.syncSteps(l, v.Steps); err != nil { |
| return err |
| } |
| + if err := t.syncQuestions(l, v.Asks); err != nil { |
| + return err |
| + } |
| // Only the person's primary runner holds their turns and questions; |
| // another of their runners must not fail the primary's work. |
| primary, err := t.s.authority.PrimaryRunner(t.db, l.Runner.Person) |
| if err != nil || primary != l.Runner.RunnerID { |
| return err |
| } |
| - if err := t.syncQuestions(l, v.Asks); err != nil { |
| - return err |
| - } |
| if err := t.advanceAll(l.Runner.Person); err != nil { |
| return err |
| } |
diff --git a/internal/equipo/chat/runners.go b/internal/equipo/chat/runners.go| index 0eb5991b..cc2d4de2 100644 |
| --- a/internal/equipo/chat/runners.go |
| +++ b/internal/equipo/chat/runners.go |
| @@ -1,7 +1,12 @@ |
| package chat |
| import ( |
| + "context" |
| + "encoding/json" |
| + "errors" |
| + "slices" |
| "strings" |
| + "time" |
| "amadan.net/oficina/equipo/internal/wire" |
| "gorm.io/gorm" |
| @@ -62,3 +67,490 @@ func cleanHello(h wire.Hello) wire.Hello { |
| } |
| return h |
| } |
| + |
| +// runnerInfo is one of a person's runners as placement and the runners |
| +// view see it. |
| +type runnerInfo struct { |
| + ID, Role, Label string |
| + Seq int64 |
| + Online bool |
| + Protocol int |
| + Revision int64 |
| + SeenAt time.Time |
| + Hello wire.Hello |
| + Running int64 |
| +} |
| + |
| +func (r runnerInfo) tags() []string { |
| + if r.Hello.Capabilities == nil || r.Protocol < wire.Protocol2 { |
| + // A protocol 1 runner is the Linux default. |
| + return []string{wire.TagLinux} |
| + } |
| + return r.Hello.Capabilities.Tags |
| +} |
| + |
| +// runners are the person's unrevoked runners in enrolment order, with |
| +// what each last said and how many steps it runs. |
| +func (t *txn) runners(person string) ([]runnerInfo, error) { |
| + var rows []struct { |
| + ID, Role, Label string |
| + Seq int64 |
| + } |
| + if err := t.db.Raw(`SELECT id, coalesce(role, '') AS role, coalesce(label, '') AS label, rowid AS seq FROM runners |
| + WHERE person = ? AND revoked_at IS NULL ORDER BY rowid`, person).Scan(&rows).Error; err != nil { |
| + return nil, err |
| + } |
| + out := make([]runnerInfo, 0, len(rows)) |
| + for _, r := range rows { |
| + info := runnerInfo{ID: r.ID, Role: wire.RolePrimary, Label: r.Label, Seq: r.Seq} |
| + if r.Role == wire.RoleWorker { |
| + info.Role = wire.RoleWorker |
| + } |
| + var sess runnerSessionRecord |
| + err := t.db.Where("runner_id = ?", r.ID).First(&sess).Error |
| + if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) { |
| + return nil, err |
| + } |
| + if err == nil { |
| + info.Online = sess.Connected && t.now().Sub(sess.SeenAt) < runnerOnline |
| + info.Protocol, info.Revision, info.SeenAt = max(sess.Protocol, wire.Protocol1), sess.Revision, sess.SeenAt |
| + if sess.Hello != "" { |
| + if err := json.Unmarshal([]byte(sess.Hello), &info.Hello); err != nil { |
| + return nil, err |
| + } |
| + if info.Hello.Label != "" { |
| + info.Label = info.Hello.Label |
| + } |
| + } |
| + } |
| + if err := t.db.Model(&stepRecord{}).Where("runner_id = ? AND state IN ?", r.ID, []string{wire.StepQueued, wire.StepRunning}).Count(&info.Running).Error; err != nil { |
| + return nil, err |
| + } |
| + out = append(out, info) |
| + } |
| + return out, nil |
| +} |
| + |
| +// runnerView is the Runner resource. |
| +func runnerView(r runnerInfo) wire.Runner { |
| + v := wire.Runner{ID: r.ID, Revision: r.Revision, Online: r.Online, Label: r.Label, Role: r.Role, Platform: r.Hello.Platform, Capabilities: r.Hello.Capabilities} |
| + if !r.SeenAt.IsZero() { |
| + at := r.SeenAt |
| + v.Since = &at |
| + } |
| + return v |
| +} |
| + |
| +// runnerLabel names a runner for people ("" when unknown). |
| +func (t *txn) runnerLabel(id string) string { |
| + if id == "" { |
| + return "" |
| + } |
| + var labels []string |
| + _ = t.db.Raw(`SELECT coalesce(label, '') FROM runners WHERE id = ?`, id).Scan(&labels).Error |
| + var sess runnerSessionRecord |
| + if t.db.Where("runner_id = ?", id).First(&sess).Error == nil && sess.Hello != "" { |
| + var h wire.Hello |
| + if json.Unmarshal([]byte(sess.Hello), &h) == nil && h.Label != "" { |
| + return h.Label |
| + } |
| + } |
| + if len(labels) == 1 { |
| + return labels[0] |
| + } |
| + return "" |
| +} |
| + |
| +// phaseCommitted is a worker's Engineering report that its candidate is |
| +// committed (not pushed): the outbound transfer opens for it. |
| +const phaseCommitted = "committed" |
| + |
| +// WithdrawAfter is how long a worker holding a step must be offline |
| +// before the step is withdrawn for another runner that fits: a brief |
| +// disconnect cancels nothing. |
| +const WithdrawAfter = 2 * time.Minute |
| + |
| +// OfflineLimit is how long a step waits for the only runner that fits |
| +// before checks resolve as not run (runner_offline). |
| +const OfflineLimit = 30 * time.Minute |
| + |
| +// checksNeeds are the tags checks of the task's newest candidate need: |
| +// macOS and Xcode when the change touched Apple files or the |
| +// repository's gate needs Xcode (the primary's index says so), and the |
| +// iOS simulator when the repository has a shared scheme. |
| +func (t *txn) checksNeeds(k taskRecord, s stepRecord) ([]string, error) { |
| + var eng stepRecord |
| + err := t.db.Where("task_id = ? AND specialist = ? AND candidate_sha = ?", k.ID, wire.SpecialistEngineering, s.CandidateSHA).Order("idx DESC").First(&eng).Error |
| + if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) { |
| + return nil, err |
| + } |
| + var p projectRecord |
| + if err := t.db.Where("id = ?", k.ProjectID).First(&p).Error; err != nil { |
| + return nil, err |
| + } |
| + h, err := t.hello(s.Person) |
| + if err != nil { |
| + return nil, err |
| + } |
| + var info wire.RepoInfo |
| + for _, r := range h.Catalog { |
| + if r.Repo == p.Repo { |
| + info = r |
| + } |
| + } |
| + if !eng.Apple && !info.NeedsMacOS { |
| + return []string{}, nil |
| + } |
| + needs := []string{wire.TagMacOS, wire.TagXcode} |
| + if info.Simulator { |
| + needs = append(needs, wire.TagIOSSimulator) |
| + } |
| + return needs, nil |
| +} |
| + |
| +func decodeList(raw string) []string { |
| + out := []string{} |
| + if raw != "" { |
| + _ = json.Unmarshal([]byte(raw), &out) |
| + } |
| + return out |
| +} |
| + |
| +func encodeList(v []string) string { |
| + if len(v) == 0 { |
| + return "" |
| + } |
| + raw, _ := json.Marshal(v) |
| + return string(raw) |
| +} |
| + |
| +// place chooses the runner for a step's current attempt (Mac runners spec |
| +// §1.4). Only checks are placed by their needs in this release: |
| +// Engineering, Review and merges run on the primary (Engineering pinned |
| +// there for the task), as before. Among the person's runners whose tags |
| +// cover the needs: the primary if it does, else the online worker running |
| +// fewest steps, ties by enrolment order. A fitting runner that is offline |
| +// leaves the step waiting (placed false). When no runner has ever had the |
| +// tags, or the primary cannot relay a pack (protocol 1), the step goes to |
| +// the primary without needs and ends honestly there (needs_macos). |
| +func (t *txn) place(k taskRecord, s *stepRecord) (placed bool, err error) { |
| + primary, err := t.s.authority.PrimaryRunner(t.db, s.Person) |
| + if err != nil { |
| + return false, err |
| + } |
| + s.Placement, s.WaitingSince = "", nil |
| + switch s.Specialist { |
| + case wire.SpecialistEngineering: |
| + s.Needs = "" |
| + s.RunnerID = primary |
| + if k.EngineeringRunner != "" && k.EngineeringRunner != primary { |
| + // Pinned elsewhere (a worker, from slice F): fix rounds, |
| + // retries and republishes go there while it is enrolled. |
| + rs, err := t.runners(s.Person) |
| + if err != nil { |
| + return false, err |
| + } |
| + for _, r := range rs { |
| + if r.ID == k.EngineeringRunner { |
| + s.RunnerID = r.ID |
| + } |
| + } |
| + } |
| + if k.EngineeringRunner == "" && s.RunnerID != "" { |
| + if err := t.db.Model(&taskRecord{}).Where("id = ?", k.ID).Update("engineering_runner", s.RunnerID).Error; err != nil { |
| + return false, err |
| + } |
| + } |
| + return true, nil |
| + case wire.SpecialistChecks: |
| + default: |
| + s.Needs, s.RunnerID = "", primary |
| + return true, nil |
| + } |
| + needs, err := t.checksNeeds(k, *s) |
| + if err != nil { |
| + return false, err |
| + } |
| + s.Needs = encodeList(needs) |
| + s.RunnerID = primary |
| + if len(needs) == 0 { |
| + return true, nil |
| + } |
| + rs, err := t.runners(s.Person) |
| + if err != nil { |
| + return false, err |
| + } |
| + refused := decodeList(s.RefusedBy) |
| + var fit []runnerInfo |
| + relay := false |
| + for _, r := range rs { |
| + if r.ID == primary && r.Protocol >= wire.Protocol2 { |
| + relay = true |
| + } |
| + if wire.Covers(r.tags(), needs) && !slices.Contains(refused, r.ID) && r.Protocol >= wire.Protocol2 { |
| + fit = append(fit, r) |
| + } |
| + } |
| + if len(fit) == 0 || !relay { |
| + // Nobody can: the primary judges it and says why (needs_macos). |
| + return true, nil |
| + } |
| + var chosen *runnerInfo |
| + for i := range fit { |
| + r := &fit[i] |
| + switch { |
| + case r.ID == primary: |
| + chosen = r |
| + case !r.Online: |
| + case chosen == nil || chosen.ID != primary && r.Running < chosen.Running: |
| + chosen = r |
| + } |
| + if chosen != nil && chosen.ID == primary { |
| + break |
| + } |
| + } |
| + if chosen == nil { |
| + now := t.now() |
| + s.RunnerID, s.Placement, s.WaitingSince = "", wire.PlacementWaiting, &now |
| + return false, nil |
| + } |
| + s.RunnerID = chosen.ID |
| + return true, nil |
| +} |
| + |
| +// replace ends the current attempt's placement and places the next one: |
| +// after a refusal, a withdrawal before it started, or a withdrawn |
| +// attempt's termination. The caller saves s. |
| +func (t *txn) replace(k taskRecord, s *stepRecord) error { |
| + if err := t.voidAttempt(*s); err != nil { |
| + return err |
| + } |
| + s.Attempt++ |
| + s.State, s.Reason, s.Terminated, s.StartedAt, s.FinishedAt, s.Withdrawn, s.TerminationKind = wire.StepQueued, "", false, nil, nil, false, "" |
| + s.Summary, s.LogTail, s.Checks, s.Gate, s.ExitCode, s.Output = "", "", "", "", nil, "" |
| + return t.dispatchStep(k, s) |
| +} |
| + |
| +// voidAttempt makes sure nothing of an attempt is served again: its |
| +// unacked dispatch and the chunks of its transfers. |
| +func (t *txn) voidAttempt(s stepRecord) error { |
| + if err := t.db.Model(&commandRecord{}).Where("runner_id = ? AND kind = ? AND acked_at IS NULL AND body LIKE ?", s.RunnerID, wire.FrameDispatch, `%"step_id":"`+s.ID+`","attempt":`+itoa64(s.Attempt)+`,%`).Update("acked_at", t.now()).Error; err != nil { |
| + return err |
| + } |
| + return t.closeTransfers(s.ID, s.Attempt) |
| +} |
| + |
| +// withdraw takes an attempt back from its runner, serialised with its |
| +// start authorization by the write transaction: not started, it can never |
| +// start (the attempt moves on) and the next one is placed at once; |
| +// started, the runner is asked to cancel it and the next attempt is placed |
| +// only once its termination is reported, as Retry requires. |
| +func (t *txn) withdraw(k *taskRecord, s *stepRecord) error { |
| + if s.Withdrawn || wire.StepTerminal(s.State) { |
| + return nil |
| + } |
| + if s.StartedAt == nil { |
| + if err := t.replace(*k, s); err != nil { |
| + return err |
| + } |
| + return t.saveStep(s, k) |
| + } |
| + s.Withdrawn = true |
| + if err := t.saveStep(s, k); err != nil { |
| + return err |
| + } |
| + return t.commandTo(s.RunnerID, s.Person, wire.FrameCancelStep, wire.CancelStepCommand{Person: s.Person, TaskID: k.ID, StepID: s.ID, Attempt: s.Attempt}) |
| +} |
| + |
| +// Authorize is the start authorization of one step attempt (a protocol 2 |
| +// lease naming it): granted only to the runner the attempt is placed on, |
| +// while it is current and not withdrawn, and the first grant records that |
| +// it started. Refused is the reason a lease is refused, "" when granted. |
| +func (s *Store) Authorize(ctx context.Context, l Lease, stepID string, attempt int64) (refused string, err error) { |
| + err = s.tx(ctx, func(t *txn) error { |
| + if _, err := t.current(l); err != nil { |
| + return err |
| + } |
| + var st stepRecord |
| + if err := t.db.Where("id = ? AND person = ?", stepID, l.Runner.Person).First(&st).Error; errors.Is(err, gorm.ErrRecordNotFound) { |
| + refused = "withdrawn" |
| + return nil |
| + } else if err != nil { |
| + return err |
| + } |
| + if st.Attempt != attempt || st.RunnerID != l.Runner.RunnerID || st.Withdrawn || wire.StepTerminal(st.State) { |
| + refused = "withdrawn" |
| + return nil |
| + } |
| + if st.StartedAt != nil { |
| + return nil |
| + } |
| + now := t.now() |
| + return t.db.Model(&stepRecord{}).Where("id = ? AND attempt = ?", st.ID, st.Attempt).Update("started_at", now).Error |
| + }) |
| + return refused, err |
| +} |
| + |
| +// placeWaiting places the person's steps waiting for a runner, when one |
| +// that fits may have come online. |
| +func (t *txn) placeWaiting(person string) error { |
| + var rows []stepRecord |
| + if err := t.db.Where("person = ? AND placement = ? AND state = ?", person, wire.PlacementWaiting, wire.StepQueued).Order("created_at").Find(&rows).Error; err != nil { |
| + return err |
| + } |
| + for i := range rows { |
| + s := rows[i] |
| + k, err := t.loadTask(s.TaskID) |
| + if err != nil { |
| + return err |
| + } |
| + if wire.FinalStage(k.Stage) || k.CancelRequested { |
| + continue |
| + } |
| + since := s.WaitingSince |
| + if err := t.dispatchStep(k, &s); err != nil { |
| + return err |
| + } |
| + if s.Placement == wire.PlacementWaiting { |
| + // Still waiting: the clock does not restart. |
| + s.WaitingSince = since |
| + if err := t.db.Model(&stepRecord{}).Where("id = ?", s.ID).Update("waiting_since", since).Error; err != nil { |
| + return err |
| + } |
| + continue |
| + } |
| + if err := t.saveStep(&s, &k); err != nil { |
| + return err |
| + } |
| + } |
| + return nil |
| +} |
| + |
| +// Place runs placement for every person: steps waiting for a runner are |
| +// placed when one that fits is online; checks that waited OfflineLimit |
| +// resolve as not run (runner_offline, never a pass) and review goes on; |
| +// a step placed on a worker that went offline is withdrawn when another |
| +// runner that fits is online. The instance runs it every minute. |
| +func (s *Store) Place(ctx context.Context) error { |
| + return s.tx(ctx, func(t *txn) error { |
| + var persons []string |
| + if err := t.db.Model(&stepRecord{}).Where("state IN ? AND (placement = ? OR runner_id IN (SELECT id FROM runners WHERE role = ?))", []string{wire.StepQueued, wire.StepRunning}, wire.PlacementWaiting, wire.RoleWorker).Distinct().Pluck("person", &persons).Error; err != nil { |
| + return err |
| + } |
| + for _, p := range persons { |
| + if err := t.placeWaiting(p); err != nil { |
| + return err |
| + } |
| + if err := t.offline(p); err != nil { |
| + return err |
| + } |
| + } |
| + return nil |
| + }) |
| +} |
| + |
| +// offline applies the offline rule to the person's checks. |
| +func (t *txn) offline(person string) error { |
| + rs, err := t.runners(person) |
| + if err != nil { |
| + return err |
| + } |
| + byID := map[string]runnerInfo{} |
| + for _, r := range rs { |
| + byID[r.ID] = r |
| + } |
| + var rows []stepRecord |
| + if err := t.db.Where("person = ? AND specialist = ? AND state IN ?", person, wire.SpecialistChecks, []string{wire.StepQueued, wire.StepRunning}).Find(&rows).Error; err != nil { |
| + return err |
| + } |
| + for i := range rows { |
| + s := rows[i] |
| + k, err := t.loadTask(s.TaskID) |
| + if err != nil { |
| + return err |
| + } |
| + if wire.FinalStage(k.Stage) || k.CancelRequested || s.Withdrawn { |
| + continue |
| + } |
| + if s.Placement == wire.PlacementWaiting { |
| + if s.WaitingSince != nil && t.now().Sub(*s.WaitingSince) >= OfflineLimit { |
| + if err := t.resolveOffline(&k, &s); err != nil { |
| + return err |
| + } |
| + } |
| + continue |
| + } |
| + r, ok := byID[s.RunnerID] |
| + if !ok || r.Role != wire.RoleWorker || r.Online { |
| + continue |
| + } |
| + // Placed on a worker that is offline: withdraw it if another |
| + // runner that fits is online now, or once it has been offline for |
| + // the limit (the next attempt then waits, or resolves). |
| + alt := false |
| + for _, o := range rs { |
| + if o.ID != r.ID && o.Online && o.Protocol >= wire.Protocol2 && wire.Covers(o.tags(), decodeList(s.Needs)) && !slices.Contains(decodeList(s.RefusedBy), o.ID) { |
| + alt = true |
| + } |
| + } |
| + away := t.now().Sub(r.SeenAt) |
| + if alt && away >= WithdrawAfter || away >= OfflineLimit { |
| + if err := t.withdraw(&k, &s); err != nil { |
| + return err |
| + } |
| + if s.Placement == wire.PlacementWaiting && !alt { |
| + // It waited for that runner already. |
| + seen := r.SeenAt |
| + if err := t.db.Model(&stepRecord{}).Where("id = ?", s.ID).Update("waiting_since", seen).Error; err != nil { |
| + return err |
| + } |
| + } |
| + } |
| + } |
| + return nil |
| +} |
| + |
| +// resolveOffline ends waiting checks honestly: not run, the runner was |
| +// offline. Review proceeds on the candidate. |
| +func (t *txn) resolveOffline(k *taskRecord, s *stepRecord) error { |
| + now := t.now() |
| + s.State, s.Checks, s.Reason, s.Gate, s.ExitCode, s.Terminated, s.FinishedAt, s.Placement = wire.StepDone, wire.ChecksCannotRun, "runner_offline", "", nil, true, &now, "" |
| + s.LogTail = "Not run: the runner that can check this change was offline." |
| + if err := t.saveStep(s, k); err != nil { |
| + return err |
| + } |
| + return t.advance(k) |
| +} |
| + |
| +// RunnerList is GET /api/v1/runners: the person's runners. |
| +func (s *Store) RunnerList(ctx context.Context, person string) (out wire.RunnerList, err error) { |
| + err = s.read(ctx, func(tx *gorm.DB) error { |
| + if err := s.authority.CurrentPerson(ctx, tx); err != nil { |
| + return err |
| + } |
| + out.Items, err = (&txn{s: s, db: tx}).runnerViews(person) |
| + return err |
| + }) |
| + return out, err |
| +} |
| + |
| +func (t *txn) runnerViews(person string) ([]wire.Runner, error) { |
| + rs, err := t.runners(person) |
| + if err != nil { |
| + return nil, err |
| + } |
| + out := make([]wire.Runner, 0, len(rs)) |
| + for _, r := range rs { |
| + out = append(out, runnerView(r)) |
| + } |
| + slices.SortStableFunc(out, func(a, b wire.Runner) int { |
| + if a.Role == b.Role { |
| + return 0 |
| + } |
| + if a.Role == wire.RolePrimary { |
| + return -1 |
| + } |
| + return 1 |
| + }) |
| + return out, nil |
| +} |
diff --git a/internal/equipo/chat/store.go b/internal/equipo/chat/store.go| index fe19e710..8b865f41 100644 |
| --- a/internal/equipo/chat/store.go |
| +++ b/internal/equipo/chat/store.go |
| @@ -78,6 +78,10 @@ func NewStore(d *db.DB, a Authority, hub *Hub) *Store { |
| return &Store{db: d, authority: a, hub: hub, now: func() time.Time { return time.Now().UTC() }, process: newID("p")} |
| } |
| +// SetClock replaces the store's clock (tests: the 30-minute offline rule |
| +// with a fake clock). |
| +func (s *Store) SetClock(now func() time.Time) { s.now = now } |
| + |
| // Process identifies this instance process in runner leases. |
| func (s *Store) Process() string { return s.process } |
| @@ -503,6 +507,9 @@ func (s *Store) Snapshot(ctx context.Context, person string) (out wire.Snapshot, |
| if out.Cards, e = full.snapshotCards(person); e != nil { |
| return e |
| } |
| + if out.Runners, e = full.runnerViews(person); e != nil { |
| + return e |
| + } |
| out.Tasks, e = full.recentTasks(wire.MaxProjectCards) |
| return e |
| }) |
| @@ -528,15 +535,16 @@ func (s *Store) runnerView(tx *gorm.DB, person string) (wire.Runner, error) { |
| if err != nil || id == "" { |
| return wire.Runner{}, err |
| } |
| - var r runnerSessionRecord |
| - err = tx.Where("runner_id = ?", id).First(&r).Error |
| - if errors.Is(err, gorm.ErrRecordNotFound) { |
| - return wire.Runner{ID: id}, nil |
| - } |
| + rs, err := (&txn{s: s, db: tx}).runners(person) |
| if err != nil { |
| return wire.Runner{}, err |
| } |
| - return wire.Runner{ID: id, Revision: r.Revision, Online: r.Connected && s.now().Sub(r.SeenAt) < runnerOnline}, nil |
| + for _, r := range rs { |
| + if r.ID == id { |
| + return runnerView(r), nil |
| + } |
| + } |
| + return wire.Runner{ID: id}, nil |
| } |
| // Events reads the person's events after cursor. A cursor older than the |
| @@ -592,6 +600,20 @@ func (s *Store) Sweep(ctx context.Context) error { |
| if err := tx.Exec("DELETE FROM runner_commands WHERE acked_at IS NOT NULL AND acked_at < ? AND seq < (SELECT max(seq) FROM runner_commands)", cut).Error; err != nil { |
| return err |
| } |
| - return tx.Exec("DELETE FROM runner_inbox WHERE seen_at < ?", s.now().Add(-7*24*time.Hour)).Error |
| + if err := tx.Exec("DELETE FROM runner_inbox WHERE seen_at < ?", s.now().Add(-7*24*time.Hour)).Error; err != nil { |
| + return err |
| + } |
| + // Transfers past their TTL, and their chunks. |
| + var old []transferRecord |
| + if err := tx.Where("expires_at < ? AND state <> ?", s.now(), transferClosed).Find(&old).Error; err != nil { |
| + return err |
| + } |
| + t := &txn{s: s, db: tx, touched: map[string]bool{}} |
| + for _, tr := range old { |
| + if err := t.dropChunks(tr); err != nil { |
| + return err |
| + } |
| + } |
| + return tx.Exec("DELETE FROM runner_transfers WHERE expires_at < ?", s.now()).Error |
| }) |
| } |
diff --git a/internal/equipo/chat/stream.go b/internal/equipo/chat/stream.go| index 3895d3ef..e0f0110d 100644 |
| --- a/internal/equipo/chat/stream.go |
| +++ b/internal/equipo/chat/stream.go |
| @@ -169,11 +169,27 @@ 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, *wire.BranchReport: |
| + 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, *wire.Blob, *wire.PublishedReport: |
| err = store.Apply(ctx, rc.lease, f, body) |
| case *wire.LeaseCheck: |
| - // Answered only while this connection holds the lease. |
| - if err = store.Confirm(ctx, rc.lease); err == nil { |
| + // Answered only while this connection holds the lease; at |
| + // protocol 2 a lease naming a step attempt is its start |
| + // authorization (or a publication's, before the push). |
| + refused := "" |
| + switch { |
| + case v.StepID != "" && v.Publication != "": |
| + refused, err = store.AuthorizePublication(ctx, rc.lease, v.StepID, v.Attempt, v.Publication) |
| + case v.StepID != "": |
| + refused, err = store.Authorize(ctx, rc.lease, v.StepID, v.Attempt) |
| + default: |
| + err = store.Confirm(ctx, rc.lease) |
| + } |
| + if err == nil && refused != "" { |
| + no, _ := wire.NewFrame("n"+f.ID, wire.FrameRefused, wire.Refused{ID: f.ID, Reason: refused}) |
| + if rc.send(ctx, no) != nil { |
| + return 0 |
| + } |
| + } else if err == nil { |
| ack, _ := wire.NewFrame("a"+f.ID, wire.FrameAck, wire.Ack{ID: f.ID}) |
| if rc.send(ctx, ack) != nil { |
| return 0 |
diff --git a/internal/equipo/chat/tasks.go b/internal/equipo/chat/tasks.go| index 70f114a2..c03896e6 100644 |
| --- a/internal/equipo/chat/tasks.go |
| +++ b/internal/equipo/chat/tasks.go |
| @@ -5,6 +5,7 @@ import ( |
| "crypto/rand" |
| "encoding/json" |
| "errors" |
| + "fmt" |
| "path" |
| "regexp" |
| "strings" |
| @@ -130,6 +131,9 @@ type stepRecord struct { |
| // Publication of a worker's Engineering candidate by the primary. |
| Publication string |
| PublicationID string |
| + // Apple: Engineering's change touched Apple files (its checks need |
| + // macOS). |
| + Apple bool |
| } |
| func (stepRecord) TableName() string { return "chat_steps" } |
| @@ -286,8 +290,9 @@ func (t *txn) latestStep(taskID string) (stepRecord, bool, error) { |
| return s, err == nil, err |
| } |
| -func stepView(s stepRecord) wire.Step { |
| - return wire.Step{ID: s.ID, Revision: s.Revision, TaskID: s.TaskID, Index: s.Idx, Specialist: s.Specialist, State: s.State, Reason: s.Reason, Attempt: s.Attempt, BaseSHA: s.BaseSHA, CandidateSHA: s.CandidateSHA, Pushed: s.Pushed, Terminated: s.Terminated, Summary: s.Summary, LogTail: s.LogTail, StartedAt: s.StartedAt, FinishedAt: s.FinishedAt, |
| +func stepView(s stepRecord, label string) wire.Step { |
| + needs := decodeList(s.Needs) |
| + return wire.Step{RunnerID: s.RunnerID, RunnerLabel: label, Needs: needs, Placement: s.Placement, Publication: s.Publication, TerminationKind: s.TerminationKind, ID: s.ID, Revision: s.Revision, TaskID: s.TaskID, Index: s.Idx, Specialist: s.Specialist, State: s.State, Reason: s.Reason, Attempt: s.Attempt, BaseSHA: s.BaseSHA, CandidateSHA: s.CandidateSHA, Pushed: s.Pushed, Terminated: s.Terminated, Summary: s.Summary, LogTail: s.LogTail, StartedAt: s.StartedAt, FinishedAt: s.FinishedAt, |
| Round: s.Round, Family: s.Family, Account: s.Account, Verdict: s.Verdict, ReviewLabel: s.ReviewLabel, Findings: decodeFindings(s.Findings), Checks: s.Checks, Gate: s.Gate, ExitCode: s.ExitCode, Askable: s.Askable, |
| Rebase: s.Rebase, MergeSHA: s.MergeSHA, Into: s.MergeInto, Strategy: s.MergeStrategy, WithoutChecks: s.WithoutChecks} |
| } |
| @@ -319,7 +324,7 @@ func (t *txn) taskView(k taskRecord) (wire.Task, error) { |
| return v, err |
| } |
| for _, s := range steps { |
| - v.Steps = append(v.Steps, stepView(s)) |
| + v.Steps = append(v.Steps, stepView(s, t.runnerLabel(s.RunnerID))) |
| if s.Pushed { |
| v.URL = BranchURL(p.Repo, k.Branch) |
| } |
| @@ -340,6 +345,7 @@ func (t *txn) taskView(k taskRecord) (wire.Task, error) { |
| } |
| v.Questions = qs |
| v.Merged = mergedView(k) |
| + v.EngineeringRunner = k.EngineeringRunner |
| if v.Reports, err = reportCount(t.db, k.ID); err != nil { |
| return v, err |
| } |
| @@ -397,7 +403,7 @@ func (t *txn) taskEvent(k taskRecord) error { |
| func (t *txn) saveStep(s *stepRecord, k *taskRecord) error { |
| s.Revision++ |
| s.UpdatedAt = t.now() |
| - if err := t.db.Model(&stepRecord{}).Where("id = ?", s.ID).Select("state", "reason", "attempt", "base_sha", "candidate_sha", "pushed", "terminated", "summary", "log_tail", "started_at", "finished_at", "revision", "updated_at", "family", "account", "verdict", "review_label", "findings", "checks", "gate", "exit_code", "output", "republish", "from_attempt", "askable", "rebase", "from_base", "from_candidate", "merge_sha", "merge_into", "merge_strategy", "without_checks", "runner_id", "needs", "placement", "waiting_since", "refused_by", "withdrawn", "termination_kind", "publication", "publication_id").Updates(s).Error; err != nil { |
| + if err := t.db.Model(&stepRecord{}).Where("id = ?", s.ID).Select("state", "reason", "attempt", "base_sha", "candidate_sha", "pushed", "terminated", "summary", "log_tail", "started_at", "finished_at", "revision", "updated_at", "family", "account", "verdict", "review_label", "findings", "checks", "gate", "exit_code", "output", "republish", "from_attempt", "askable", "rebase", "from_base", "from_candidate", "merge_sha", "merge_into", "merge_strategy", "without_checks", "runner_id", "needs", "placement", "waiting_since", "refused_by", "withdrawn", "termination_kind", "publication", "publication_id", "apple").Updates(s).Error; err != nil { |
| return err |
| } |
| members, err := t.members() |
| @@ -405,7 +411,7 @@ func (t *txn) saveStep(s *stepRecord, k *taskRecord) error { |
| return err |
| } |
| for _, m := range members { |
| - if err := t.event(m, wire.EventStep, "step", s.ID, s.Revision, "", "", s.Attempt, stepView(*s)); err != nil { |
| + if err := t.event(m, wire.EventStep, "step", s.ID, s.Revision, "", "", s.Attempt, stepView(*s, t.runnerLabel(s.RunnerID))); err != nil { |
| return err |
| } |
| } |
| @@ -606,12 +612,9 @@ func (t *txn) startTask(r turnRecord, id, brief string) (wire.ToolResult, error) |
| // dispatchStep queues the dispatch command for the step's attempt on the |
| // runner it is placed on, with the task's findings. The caller saves s. |
| func (t *txn) dispatchStep(k taskRecord, s *stepRecord) error { |
| - if s.RunnerID == "" { |
| - primary, err := t.s.authority.PrimaryRunner(t.db, s.Person) |
| - if err != nil { |
| - return err |
| - } |
| - s.RunnerID = primary |
| + placed, err := t.place(k, s) |
| + if err != nil || !placed { |
| + return err |
| } |
| var p projectRecord |
| if err := t.db.Where("id = ?", k.ProjectID).First(&p).Error; err != nil { |
| @@ -641,6 +644,21 @@ func (t *txn) dispatchStep(k taskRecord, s *stepRecord) error { |
| // (FromBase..FromCandidate) on it. |
| cmd.Rebase, cmd.FromBase, cmd.CandidateSHA = true, s.FromBase, s.FromCandidate |
| } |
| + primary, err := t.s.authority.PrimaryRunner(t.db, s.Person) |
| + if err != nil { |
| + return err |
| + } |
| + cmd.RunnerID = s.RunnerID |
| + if s.RunnerID != primary { |
| + // Placed on a worker: what it needs, and the candidate relayed |
| + // from the primary as a pack in an inbound transfer. |
| + cmd.Needs = decodeList(s.Needs) |
| + if s.Specialist == wire.SpecialistChecks { |
| + if _, err := t.openTransfer(k, *s, primary, s.RunnerID, wire.TransferInbound, cmd.BaseSHA, s.CandidateSHA); err != nil { |
| + return err |
| + } |
| + } |
| + } |
| return t.commandTo(s.RunnerID, s.Person, wire.FrameDispatch, cmd) |
| } |
| @@ -744,6 +762,38 @@ func (t *txn) stepReport(l Lease, v *wire.StepReport) error { |
| if err != nil { |
| return err |
| } |
| + role, err := t.s.authority.RunnerRole(t.db, l.Runner.RunnerID) |
| + if err != nil { |
| + return err |
| + } |
| + if v.Pushed && role != wire.RolePrimary { |
| + // Only the primary publishes: a worker's pushed is refused. |
| + return fmt.Errorf("%w: a worker reported pushed", ErrRefused) |
| + } |
| + if v.TerminationKind != "" && s.TerminationKind == "" && (v.TerminationKind == wire.TerminationNamespace || v.TerminationKind == wire.TerminationProcessGroup) { |
| + s.TerminationKind = v.TerminationKind |
| + } |
| + if !wire.StepTerminal(s.State) && wire.StepTerminal(v.State) && v.State != wire.StepDone && v.Termination { |
| + switch { |
| + case s.Withdrawn && s.Reason != "": |
| + // Withdrawn to end as not run (a pack too large to relay). |
| + s.Terminated, s.TerminationKind = true, firstSet(v.TerminationKind, s.TerminationKind) |
| + return t.resolveNotRun(&k, &s, s.Reason) |
| + case s.Withdrawn: |
| + // Its termination is proven: the next attempt goes elsewhere. |
| + if err := t.replace(k, &s); err != nil { |
| + return err |
| + } |
| + return t.saveStep(&s, &k) |
| + case v.State == wire.StepFailed && v.Reason == "placement_refused": |
| + // It lacks a need: place it again without that runner. |
| + s.RefusedBy = encodeList(append(decodeList(s.RefusedBy), l.Runner.RunnerID)) |
| + if err := t.replace(k, &s); err != nil { |
| + return err |
| + } |
| + return t.saveStep(&s, &k) |
| + } |
| + } |
| now := t.now() |
| changed := false |
| if wire.StepTerminal(s.State) { |
| @@ -772,11 +822,12 @@ func (t *txn) stepReport(l Lease, v *wire.StepReport) error { |
| case wire.StepDone: |
| switch s.Specialist { |
| case wire.SpecialistEngineering: |
| - // Done is only for the attempt's own candidate, pushed. |
| - if s.CandidateSHA == "" || v.CandidateSHA != s.CandidateSHA || !v.Pushed { |
| + // Done is only for the attempt's own candidate: pushed by the |
| + // primary, or committed by a worker (the primary publishes it). |
| + if s.CandidateSHA == "" || v.CandidateSHA != s.CandidateSHA || !v.Pushed && role == wire.RolePrimary { |
| return nil |
| } |
| - s.Pushed = true |
| + s.Pushed, s.Apple = v.Pushed, v.Apple |
| s.Askable = v.Askable |
| if s.Rebase && s.BaseSHA != "" { |
| // The change sits on the new tip now: review reads it from |
| @@ -825,6 +876,11 @@ func (t *txn) stepReport(l Lease, v *wire.StepReport) error { |
| if !changed { |
| return nil |
| } |
| + if role != wire.RolePrimary && s.Specialist == wire.SpecialistEngineering && s.CandidateSHA != "" && v.Phase == phaseCommitted { |
| + if err := t.candidateCommitted(k, s); err != nil { |
| + return err |
| + } |
| + } |
| if wire.StepTerminal(s.State) && k.CancelRequested && !wire.FinalStage(k.Stage) && (s.State == wire.StepCancelled || s.Terminated) { |
| k.Stage = wire.StageCancelled |
| } |
| @@ -1021,6 +1077,21 @@ func (s *Store) RetryTask(ctx context.Context, person, id string) (attempt int64 |
| if err != nil { |
| return err |
| } |
| + if found && st.Specialist == wire.SpecialistEngineering && st.State == wire.StepDone && st.Publication == wire.PublicationFailed { |
| + // A worker's commit the primary could not push: publish the |
| + // recorded commit again, without running Engineering. |
| + var tr transferRecord |
| + if err := t.db.Where("step_id = ? AND attempt = ? AND direction = ?", st.ID, st.Attempt, wire.TransferOutbound).Order("created_at DESC").First(&tr).Error; err != nil { |
| + return ErrNotRetryable |
| + } |
| + st.Reason = "" |
| + if err := t.publish(&k, &st, tr); err != nil { |
| + return err |
| + } |
| + k.Stage = wire.StageInProgress |
| + attempt = st.Attempt |
| + return t.saveTask(&k) |
| + } |
| if !found || st.State != wire.StepFailed || !st.Terminated { |
| return ErrNotRetryable |
| } |
diff --git a/internal/equipo/chat/transfers.go b/internal/equipo/chat/transfers.go| new file mode 100644 |
| index 00000000..af391996 |
| --- /dev/null |
| +++ b/internal/equipo/chat/transfers.go |
| @@ -0,0 +1,305 @@ |
| +package chat |
| + |
| +import ( |
| + "context" |
| + "encoding/base64" |
| + "encoding/json" |
| + "errors" |
| + "fmt" |
| + "regexp" |
| + |
| + "amadan.net/oficina/equipo/internal/wire" |
| + "gorm.io/gorm" |
| +) |
| + |
| +// Candidates travel as packs, not credentials (Mac runners spec §2). A |
| +// worker has no clone and no forge access: the primary uploads the exact |
| +// candidate a worker judges (inbound), and a worker's own commit comes |
| +// back to the primary (outbound), which alone publishes it. A transfer |
| +// row authorises every chunk; chunks travel to the receiver as blob |
| +// commands in its mailbox. |
| + |
| +// Transfer states. |
| +const ( |
| + transferOpen = "open" |
| + transferComplete = "complete" |
| + transferClosed = "closed" |
| +) |
| + |
| +var hexDigest = regexp.MustCompile(`^[0-9a-f]{64}$`) |
| + |
| +// openTransfer opens a transfer for one attempt, in the transaction that |
| +// placed it (inbound) or accepted its candidate (outbound), and asks the |
| +// sender for the pack (send_pack names the transfer it uploads under). |
| +func (t *txn) openTransfer(k taskRecord, s stepRecord, from, to, direction, base, candidate string) (transferRecord, error) { |
| + var p projectRecord |
| + if err := t.db.Where("id = ?", k.ProjectID).First(&p).Error; err != nil { |
| + return transferRecord{}, err |
| + } |
| + now := t.now() |
| + tr := transferRecord{ID: newID("tr_"), Person: s.Person, FromRunner: from, ToRunner: to, Repo: p.Repo, TaskID: k.ID, StepID: s.ID, Attempt: s.Attempt, BaseSHA: base, CandidateSHA: candidate, Direction: direction, State: transferOpen, ExpiresAt: now.Add(wire.TransferTTL), CreatedAt: now} |
| + if err := t.db.Create(&tr).Error; err != nil { |
| + return tr, err |
| + } |
| + return tr, t.commandTo(from, s.Person, wire.FrameSendPack, wire.SendPackCommand{Transfer: transferHeader(tr), Have: []string{}}) |
| +} |
| + |
| +func transferHeader(tr transferRecord) wire.TransferHeader { |
| + return wire.TransferHeader{ID: tr.ID, Direction: tr.Direction, Repo: tr.Repo, TaskID: tr.TaskID, StepID: tr.StepID, Attempt: tr.Attempt, BaseSHA: tr.BaseSHA, CandidateSHA: tr.CandidateSHA} |
| +} |
| + |
| +// closeTransfers ends every transfer of a step attempt: nothing of it is |
| +// served again and its chunks are gone. |
| +func (t *txn) closeTransfers(stepID string, attempt int64) error { |
| + var trs []transferRecord |
| + if err := t.db.Where("step_id = ? AND attempt = ? AND state <> ?", stepID, attempt, transferClosed).Find(&trs).Error; err != nil { |
| + return err |
| + } |
| + for _, tr := range trs { |
| + if err := t.dropChunks(tr); err != nil { |
| + return err |
| + } |
| + if err := t.db.Model(&transferRecord{}).Where("id = ?", tr.ID).Update("state", transferClosed).Error; err != nil { |
| + return err |
| + } |
| + } |
| + return nil |
| +} |
| + |
| +// dropChunks voids a transfer's unacked chunks and send_pack, and empties |
| +// every chunk it relayed. |
| +func (t *txn) dropChunks(tr transferRecord) error { |
| + like := `%"transfer":{"id":"` + tr.ID + `"%` |
| + if err := t.db.Model(&commandRecord{}).Where("kind IN ? AND acked_at IS NULL AND body LIKE ?", []string{wire.FrameBlob, wire.FrameSendPack}, like).Update("acked_at", t.now()).Error; err != nil { |
| + return err |
| + } |
| + return t.db.Model(&commandRecord{}).Where("kind = ? AND body LIKE ?", wire.FrameBlob, like).Update("body", "{}").Error |
| +} |
| + |
| +// errTransferRefused refuses a chunk: logged, acked, no effect. |
| +func errTransferRefused(why string) error { |
| + return fmt.Errorf("%w: transfer_refused: %s", ErrRefused, why) |
| +} |
| + |
| +// blob accepts one chunk only from the connection of the transfer's |
| +// sender, for an open transfer whose attempt is the step's current one |
| +// and neither withdrawn nor ended, with the header exactly as opened, and |
| +// within bounds. Anything else is refused before a byte is kept. |
| +func (t *txn) blob(l Lease, v *wire.Blob) error { |
| + var tr transferRecord |
| + if err := t.db.Where("id = ?", v.Transfer.ID).First(&tr).Error; errors.Is(err, gorm.ErrRecordNotFound) { |
| + return errTransferRefused("no such transfer") |
| + } else if err != nil { |
| + return err |
| + } |
| + if tr.FromRunner != l.Runner.RunnerID || tr.Person != l.Runner.Person { |
| + return errTransferRefused("not this runner's transfer") |
| + } |
| + if tr.State != transferOpen { |
| + return errTransferRefused("transfer not open") |
| + } |
| + if transferHeader(tr) != v.Transfer { |
| + return errTransferRefused("header does not match the transfer") |
| + } |
| + var s stepRecord |
| + if err := t.db.Where("id = ?", tr.StepID).First(&s).Error; err != nil { |
| + return err |
| + } |
| + k, err := t.loadTask(s.TaskID) |
| + if err != nil { |
| + return err |
| + } |
| + if s.Attempt != tr.Attempt || s.Withdrawn || wire.FinalStage(k.Stage) || k.CancelRequested || tr.Direction == wire.TransferInbound && wire.StepTerminal(s.State) { |
| + return errTransferRefused("attempt not current") |
| + } |
| + data, err := base64.StdEncoding.DecodeString(v.Data) |
| + if err != nil || len(v.Data) > wire.MaxBlobData || !hexDigest.MatchString(v.SHA256) || v.Total < 1 || v.Index < 0 || v.Index >= v.Total { |
| + return errTransferRefused("bad chunk") |
| + } |
| + if tr.Received > 0 && (v.Total != tr.Total || v.SHA256 != tr.SHA256) || v.Index != tr.Received { |
| + return errTransferRefused("chunk out of order") |
| + } |
| + if tr.Bytes+int64(len(data)) > wire.MaxTransferBytes { |
| + tr.State = transferClosed |
| + if err := t.dropChunks(tr); err != nil { |
| + return err |
| + } |
| + if err := t.db.Model(&transferRecord{}).Where("id = ?", tr.ID).Update("state", transferClosed).Error; err != nil { |
| + return err |
| + } |
| + // Too large to relay: the checks cannot run on that runner. |
| + if tr.Direction == wire.TransferInbound && !wire.StepTerminal(s.State) { |
| + return t.withdrawResolving(&k, &s, "checks_unavailable") |
| + } |
| + return nil |
| + } |
| + tr.Total, tr.SHA256, tr.Received, tr.Bytes = v.Total, v.SHA256, tr.Received+1, tr.Bytes+int64(len(data)) |
| + if tr.Received == tr.Total { |
| + tr.State = transferComplete |
| + } |
| + if err := t.db.Model(&transferRecord{}).Where("id = ?", tr.ID).Select("total", "sha256", "received", "bytes", "state").Updates(&tr).Error; err != nil { |
| + return err |
| + } |
| + if err := t.commandTo(tr.ToRunner, tr.Person, wire.FrameBlob, v); err != nil { |
| + return err |
| + } |
| + if tr.State == transferComplete && tr.Direction == wire.TransferOutbound { |
| + return t.publish(&k, &s, tr) |
| + } |
| + return nil |
| +} |
| + |
| +// blobAcked closes a transfer once its receiver acked the last chunk. |
| +func (t *txn) blobAcked(body string) error { |
| + var v wire.Blob |
| + if err := json.Unmarshal([]byte(body), &v); err != nil || v.Index != v.Total-1 { |
| + return nil |
| + } |
| + var tr transferRecord |
| + if err := t.db.Where("id = ? AND state = ?", v.Transfer.ID, transferComplete).First(&tr).Error; errors.Is(err, gorm.ErrRecordNotFound) { |
| + return nil |
| + } else if err != nil { |
| + return err |
| + } |
| + if err := t.dropChunks(tr); err != nil { |
| + return err |
| + } |
| + return t.db.Model(&transferRecord{}).Where("id = ?", tr.ID).Update("state", transferClosed).Error |
| +} |
| + |
| +// withdrawResolving withdraws an attempt that will end as not run for |
| +// reason (checks): resolved at once when it never started, else once its |
| +// termination is reported. |
| +func (t *txn) withdrawResolving(k *taskRecord, s *stepRecord, reason string) error { |
| + if s.StartedAt == nil { |
| + if err := t.voidAttempt(*s); err != nil { |
| + return err |
| + } |
| + if err := t.resolveNotRun(k, s, reason); err != nil { |
| + return err |
| + } |
| + return nil |
| + } |
| + s.Withdrawn, s.Reason = true, reason |
| + if err := t.saveStep(s, k); err != nil { |
| + return err |
| + } |
| + return t.commandTo(s.RunnerID, s.Person, wire.FrameCancelStep, wire.CancelStepCommand{Person: s.Person, TaskID: k.ID, StepID: s.ID, Attempt: s.Attempt}) |
| +} |
| + |
| +// resolveNotRun ends checks as not run, with reason; review goes on. |
| +func (t *txn) resolveNotRun(k *taskRecord, s *stepRecord, reason string) error { |
| + now := t.now() |
| + s.State, s.Checks, s.Reason, s.Gate, s.ExitCode, s.Terminated, s.FinishedAt, s.Placement, s.Withdrawn = wire.StepDone, wire.ChecksCannotRun, reason, "", nil, true, &now, "", false |
| + if err := t.saveStep(s, k); err != nil { |
| + return err |
| + } |
| + return t.advance(k) |
| +} |
| + |
| +// publish asks the primary to publish a worker's commit once its pack |
| +// has arrived: the step's publication is pending with a new id, and the |
| +// command is written in the same transaction. |
| +func (t *txn) publish(k *taskRecord, s *stepRecord, tr transferRecord) error { |
| + primary, err := t.s.authority.PrimaryRunner(t.db, s.Person) |
| + if err != nil || primary == "" { |
| + return err |
| + } |
| + s.Publication, s.PublicationID = wire.PublicationPending, newID("pb_") |
| + if err := t.saveStep(s, k); err != nil { |
| + return err |
| + } |
| + return t.commandTo(primary, s.Person, wire.FramePublish, wire.PublishCommand{Publication: s.PublicationID, TaskID: k.ID, StepID: s.ID, Attempt: s.Attempt, Repo: tr.Repo, Branch: k.Branch, Person: s.Person, BaseSHA: tr.BaseSHA, CandidateSHA: tr.CandidateSHA, Transfer: tr.ID}) |
| +} |
| + |
| +// published applies the primary's answer: only the primary, only for the |
| +// pending publication of the current attempt and its candidate. Pushed |
| +// is set only here for a worker's commit; then checks and review follow. |
| +func (t *txn) published(l Lease, v *wire.PublishedReport) error { |
| + primary, err := t.s.authority.PrimaryRunner(t.db, l.Runner.Person) |
| + if err != nil { |
| + return err |
| + } |
| + if primary != l.Runner.RunnerID { |
| + return fmt.Errorf("%w: published from a runner that is not the primary", ErrRefused) |
| + } |
| + var s stepRecord |
| + if err := t.db.Where("id = ? AND task_id = ? AND person = ?", v.StepID, v.TaskID, l.Runner.Person).First(&s).Error; errors.Is(err, gorm.ErrRecordNotFound) { |
| + return fmt.Errorf("%w: published for no such step", ErrRefused) |
| + } else if err != nil { |
| + return err |
| + } |
| + if s.Attempt != v.Attempt || s.PublicationID != v.Publication || s.Publication != wire.PublicationPending || s.CandidateSHA != v.CandidateSHA { |
| + return nil |
| + } |
| + k, err := t.loadTask(s.TaskID) |
| + if err != nil { |
| + return err |
| + } |
| + if v.Pushed { |
| + s.Pushed, s.Publication = true, wire.PublicationPublished |
| + } else { |
| + s.Publication = wire.PublicationFailed |
| + switch v.Reason { |
| + case "push_conflict", "cancelled", "candidate_unavailable": |
| + s.Reason = v.Reason |
| + default: |
| + s.Reason = "push_failed" |
| + } |
| + } |
| + if err := t.saveStep(&s, &k); err != nil { |
| + return err |
| + } |
| + return t.advance(&k) |
| +} |
| + |
| +// AuthorizePublication is the primary's confirmation immediately before |
| +// it pushes a worker's commit: the publication is still the step's |
| +// pending one and the task is neither cancelled nor ended. |
| +func (s *Store) AuthorizePublication(ctx context.Context, l Lease, stepID string, attempt int64, publication string) (refused string, err error) { |
| + err = s.tx(ctx, func(t *txn) error { |
| + if _, err := t.current(l); err != nil { |
| + return err |
| + } |
| + refused, err = t.authorizePublication(l, stepID, attempt, publication) |
| + return err |
| + }) |
| + return refused, err |
| +} |
| + |
| +func (t *txn) authorizePublication(l Lease, stepID string, attempt int64, publication string) (string, error) { |
| + primary, err := t.s.authority.PrimaryRunner(t.db, l.Runner.Person) |
| + if err != nil { |
| + return "", err |
| + } |
| + var s stepRecord |
| + if err := t.db.Where("id = ? AND person = ?", stepID, l.Runner.Person).First(&s).Error; errors.Is(err, gorm.ErrRecordNotFound) { |
| + return "withdrawn", nil |
| + } else if err != nil { |
| + return "", err |
| + } |
| + k, err := t.loadTask(s.TaskID) |
| + if err != nil { |
| + return "", err |
| + } |
| + if primary != l.Runner.RunnerID || s.Attempt != attempt || s.PublicationID != publication || s.Publication != wire.PublicationPending || k.CancelRequested || wire.FinalStage(k.Stage) { |
| + return "cancelled", nil |
| + } |
| + return "", nil |
| +} |
| + |
| +// candidateCommitted opens the outbound transfer for a worker's commit |
| +// when the instance accepts its committed report, for exactly that |
| +// candidate. |
| +func (t *txn) candidateCommitted(k taskRecord, s stepRecord) error { |
| + primary, err := t.s.authority.PrimaryRunner(t.db, s.Person) |
| + if err != nil || primary == "" || primary == s.RunnerID { |
| + return err |
| + } |
| + var open int64 |
| + if err := t.db.Model(&transferRecord{}).Where("step_id = ? AND attempt = ? AND direction = ?", s.ID, s.Attempt, wire.TransferOutbound).Count(&open).Error; err != nil || open > 0 { |
| + return err |
| + } |
| + _, err = t.openTransfer(k, s, s.RunnerID, primary, wire.TransferOutbound, s.BaseSHA, s.CandidateSHA) |
| + return err |
| +} |
diff --git a/internal/equipo/migrations/0047_thin_runners.sql b/internal/equipo/migrations/0047_thin_runners.sql| index 6092e4c3..a152e531 100644 |
| --- a/internal/equipo/migrations/0047_thin_runners.sql |
| +++ b/internal/equipo/migrations/0047_thin_runners.sql |
| @@ -9,6 +9,7 @@ ALTER TABLE chat_steps ADD COLUMN withdrawn numeric; |
| ALTER TABLE chat_steps ADD COLUMN termination_kind text; |
| ALTER TABLE chat_steps ADD COLUMN publication text; |
| ALTER TABLE chat_steps ADD COLUMN publication_id text; |
| +ALTER TABLE chat_steps ADD COLUMN apple numeric; |
| ALTER TABLE chat_tasks ADD COLUMN engineering_runner text; |
| ALTER TABLE runner_sessions ADD COLUMN protocol integer; |
| CREATE INDEX runner_command_runner ON runner_commands(runner_id); |
diff --git a/internal/equipo/migrations/schema.sql b/internal/equipo/migrations/schema.sql| index 19c60aac..9eca4b47 100644 |
| --- a/internal/equipo/migrations/schema.sql |
| +++ b/internal/equipo/migrations/schema.sql |
| @@ -595,7 +595,7 @@ 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, moved_from text, branch_head text, merge_asked text, merged_sha text, merged_into text, merge_strategy text, merged_without_checks numeric, merged_at datetime, engineering_runner 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, rebase numeric, from_base text, from_candidate text, merge_sha text, merge_into text, merge_strategy text, without_checks numeric, runner_id text, needs text, placement text, waiting_since datetime, refused_by text, withdrawn numeric, termination_kind text, publication text, publication_id text); |
| +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, rebase numeric, from_base text, from_candidate text, merge_sha text, merge_into text, merge_strategy text, without_checks numeric, runner_id text, needs text, placement text, waiting_since datetime, refused_by text, withdrawn numeric, termination_kind text, publication text, publication_id text, apple numeric); |
| CREATE INDEX chat_step_task ON chat_steps(task_id); |
| CREATE TABLE chat_task_entries (id text PRIMARY KEY, task_id text, idempotency_key text, kind text, author text, text text, repo text, path text, line integer, created_at datetime); |
| CREATE INDEX chat_entry_task ON chat_task_entries(task_id); |
diff --git a/internal/equipo/static/chat-stream.js b/internal/equipo/static/chat-stream.js| index 037a26d1..48688090 100644 |
| --- a/internal/equipo/static/chat-stream.js |
| +++ b/internal/equipo/static/chat-stream.js |
| @@ -458,7 +458,9 @@ |
| // Cards (and the tasks on them) are rendered by the server, like |
| // committed replies. |
| refresh().catch(function () { location.reload(); }); |
| - } else if (type === "runner" && offline) { |
| + } else if (type === "runner" && offline && v.role !== "worker") { |
| + // The offline line is the primary's: a worker going offline is not |
| + // the coordinator going away. |
| offline.hidden = !!v.online; |
| } |
| } |
diff --git a/internal/thintest/client.go b/internal/thintest/client.go| index 3d44843f..04b9c738 100644 |
| --- a/internal/thintest/client.go |
| +++ b/internal/thintest/client.go |
| @@ -119,6 +119,11 @@ func (c *Client) Tasks(ctx context.Context) (out wire.TaskList, err error) { |
| } |
| // NeedsYou lists the person's tasks waiting for their decision. |
| +func (c *Client) Runners(ctx context.Context) (out wire.RunnerList, err error) { |
| + err = c.do(ctx, "GET", "/api/v1/runners", nil, &out) |
| + return |
| +} |
| + |
| func (c *Client) NeedsYou(ctx context.Context) (out wire.TaskList, err error) { |
| return out, c.do(ctx, "GET", "/api/v1/needs-you", nil, &out) |
| } |
| @@ -244,6 +249,9 @@ type Conversation struct { |
| // Tasks are the team's tasks; Steps every step seen, by id. |
| Tasks map[string]wire.Task |
| Steps map[string]wire.Step |
| + // Runners are the person's runners by id, from the snapshot and the |
| + // runner events. |
| + Runners map[string]wire.Runner |
| // Stages records each task's stages in the order seen. |
| Stages map[string][]string |
| // Activity is each turn's activity in arrival order, until its reply. |
| @@ -277,6 +285,10 @@ func (c *Conversation) Reset(s wire.Snapshot) { |
| c.Messages, c.Order, c.Turns, c.Drafts = map[string]wire.Message{}, nil, map[string]wire.Turn{}, map[string]string{} |
| c.Cards, c.Projects = map[string]wire.Card{}, map[string]wire.Project{} |
| c.Tasks, c.Steps, c.Stages = map[string]wire.Task{}, map[string]wire.Step{}, map[string][]string{} |
| + c.Runners = map[string]wire.Runner{} |
| + for _, r := range s.Runners { |
| + c.Runners[r.ID] = r |
| + } |
| c.Questions, c.DeltaResources = map[string]wire.Question{}, map[string]int{} |
| for _, k := range s.Tasks { |
| c.applyTask(k) |
| @@ -429,9 +441,15 @@ func (c *Conversation) Apply(e wire.Event) bool { |
| } |
| case wire.EventRunner: |
| var r wire.Runner |
| - if json.Unmarshal(e.Data, &r) == nil && r.Revision > c.Runner.Revision { |
| - c.Runner = r |
| - applied = true |
| + if json.Unmarshal(e.Data, &r) == nil { |
| + // Every runner has its own events; Runner stays the primary. |
| + if old, ok := c.Runners[r.ID]; !ok || r.Revision > old.Revision { |
| + c.Runners[r.ID] = r |
| + applied = true |
| + } |
| + if r.Role != wire.RoleWorker && r.Revision > c.Runner.Revision { |
| + c.Runner = r |
| + } |
| } |
| } |
| if applied { |
diff --git a/internal/thintest/migration_contract_test.go b/internal/thintest/migration_contract_test.go| index c0cb46fd..044672bb 100644 |
| --- a/internal/thintest/migration_contract_test.go |
| +++ b/internal/thintest/migration_contract_test.go |
| @@ -26,7 +26,7 @@ func slice4(t *testing.T, path string) { |
| "ALTER TABLE chat_tasks DROP COLUMN engineering_runner", |
| "ALTER TABLE chat_steps DROP COLUMN runner_id", "ALTER TABLE chat_steps DROP COLUMN needs", "ALTER TABLE chat_steps DROP COLUMN placement", |
| "ALTER TABLE chat_steps DROP COLUMN waiting_since", "ALTER TABLE chat_steps DROP COLUMN refused_by", "ALTER TABLE chat_steps DROP COLUMN withdrawn", |
| - "ALTER TABLE chat_steps DROP COLUMN termination_kind", "ALTER TABLE chat_steps DROP COLUMN publication", "ALTER TABLE chat_steps DROP COLUMN publication_id", |
| + "ALTER TABLE chat_steps DROP COLUMN termination_kind", "ALTER TABLE chat_steps DROP COLUMN publication", "ALTER TABLE chat_steps DROP COLUMN publication_id", "ALTER TABLE chat_steps DROP COLUMN apple", |
| "DELETE FROM rastrillo_migrations WHERE id LIKE 'equipo/0047_%'", |
| } { |
| if _, err := d.Writer().Exec(q); err != nil { |
diff --git a/internal/thintest/placement_contract_test.go b/internal/thintest/placement_contract_test.go| new file mode 100644 |
| index 00000000..cc3061a7 |
| --- /dev/null |
| +++ b/internal/thintest/placement_contract_test.go |
| @@ -0,0 +1,479 @@ |
| +package thintest |
| + |
| +import ( |
| + "crypto/sha256" |
| + "encoding/base64" |
| + "encoding/hex" |
| + "strings" |
| + "testing" |
| + "time" |
| + |
| + "amadan.net/oficina/equipo/internal/equipo/chat" |
| + "amadan.net/oficina/equipo/internal/wire" |
| +) |
| + |
| +// peer is a scripted runner with the frames it received but has not |
| +// looked at yet. |
| +type peer struct { |
| + t *testing.T |
| + r *toolRig |
| + fr *FakeRunner |
| + held []heldFrame |
| + seq int |
| +} |
| + |
| +func (p *peer) id(prefix string) string { |
| + p.seq++ |
| + return prefix + "-" + itoa(p.seq) |
| +} |
| + |
| +// send sends a frame and, for a durable one, waits for its ack. |
| +func (p *peer) send(kind string, body any) string { |
| + p.t.Helper() |
| + id := p.id("p-" + kind) |
| + if err := p.fr.Send(p.r.ctx, id, kind, body); err != nil { |
| + p.t.Fatal(err) |
| + } |
| + if !(wire.Frame{Type: kind}).Durable() && kind != wire.FrameLease { |
| + return id |
| + } |
| + for { |
| + f, body, err := p.fr.Next(p.r.ctx) |
| + if err != nil { |
| + p.t.Fatalf("waiting for the ack of %s: %v", id, err) |
| + } |
| + if a, ok := body.(*wire.Ack); ok && a.ID == id { |
| + return id |
| + } |
| + if rf, ok := body.(*wire.Refused); ok && rf.ID == id { |
| + p.held = append(p.held, heldFrame{f, body, nil}) |
| + return id |
| + } |
| + if f.Type != wire.FrameAck { |
| + p.held = append(p.held, heldFrame{f, body, p.fr.Received[len(p.fr.Received)-1]}) |
| + } |
| + } |
| +} |
| + |
| +// lease asks for the start authorization of an attempt: true when acked, |
| +// false when refused. |
| +func (p *peer) lease(step string, attempt int64) bool { |
| + p.t.Helper() |
| + id := p.send(wire.FrameLease, wire.LeaseCheck{Generation: p.fr.Welcome.Generation, StepID: step, Attempt: attempt}) |
| + for i, h := range p.held { |
| + if rf, ok := h.body.(*wire.Refused); ok && rf.ID == id { |
| + p.held = append(p.held[:i:i], p.held[i+1:]...) |
| + return false |
| + } |
| + } |
| + return true |
| +} |
| + |
| +// leasePublication is the primary's confirmation before it pushes. |
| +func (p *peer) leasePublication(step string, attempt int64, publication string) bool { |
| + p.t.Helper() |
| + id := p.send(wire.FrameLease, wire.LeaseCheck{Generation: p.fr.Welcome.Generation, StepID: step, Attempt: attempt, Publication: publication}) |
| + for i, h := range p.held { |
| + if rf, ok := h.body.(*wire.Refused); ok && rf.ID == id { |
| + p.held = append(p.held[:i:i], p.held[i+1:]...) |
| + return false |
| + } |
| + } |
| + return true |
| +} |
| + |
| +// expect returns the next frame of kind (held first), acking it. |
| +func (p *peer) expect(kind string) (wire.Frame, any) { |
| + p.t.Helper() |
| + for i, h := range p.held { |
| + if h.f.Type == kind { |
| + p.held = append(p.held[:i:i], p.held[i+1:]...) |
| + p.ack(h.f) |
| + return h.f, h.body |
| + } |
| + } |
| + for { |
| + f, body, err := p.fr.Next(p.r.ctx) |
| + if err != nil { |
| + p.t.Fatalf("waiting for %s: %v", kind, err) |
| + } |
| + if f.Type == kind { |
| + p.ack(f) |
| + return f, body |
| + } |
| + if f.Type != wire.FrameAck { |
| + p.held = append(p.held, heldFrame{f, body, p.fr.Received[len(p.fr.Received)-1]}) |
| + } |
| + } |
| +} |
| + |
| +// none checks, after d, that nothing of kind was sent to this runner and |
| +// none waits in its mailbox. (A read deadline would close the socket.) |
| +func (p *peer) none(kind string, d time.Duration) { |
| + p.t.Helper() |
| + time.Sleep(d) |
| + for _, h := range p.held { |
| + if h.f.Type == kind { |
| + p.t.Fatalf("unexpected %s: %s", kind, h.raw) |
| + } |
| + } |
| + var n int |
| + if err := p.r.inst.DB.Writer().QueryRow("SELECT count(*) FROM runner_commands WHERE runner_id = ? AND kind = ? AND acked_at IS NULL", p.fr.Welcome.RunnerID, kind).Scan(&n); err != nil { |
| + p.t.Fatal(err) |
| + } |
| + if n != 0 { |
| + p.t.Fatalf("%d %s waiting for this runner", n, kind) |
| + } |
| +} |
| + |
| +// heartbeat says hello again (under the store's clock), then waits for a |
| +// lease round trip so it has been applied. |
| +func (p *peer) heartbeat(h wire.Hello) { |
| + p.t.Helper() |
| + h.Generation = p.fr.Welcome.Generation |
| + if err := p.fr.Send(p.r.ctx, p.id("hb"), wire.FrameHello, h); err != nil { |
| + p.t.Fatal(err) |
| + } |
| + p.lease("", 0) |
| +} |
| + |
| +func (p *peer) ack(f wire.Frame) { |
| + if f.Durable() { |
| + if err := p.fr.Send(p.r.ctx, "a-"+f.ID, wire.FrameAck, wire.Ack{ID: f.ID}); err != nil { |
| + p.t.Fatal(err) |
| + } |
| + } |
| +} |
| + |
| +// primaryHello is the tool rig's hello at protocol 2 from a Linux primary. |
| +func primaryHello(generation int64) wire.Hello { |
| + return wire.Hello{Generation: generation, Repos: []string{"amadan.net/oficina/sample", "amadan.net/oficina/equipo"}, CreateIn: []string{"oficina"}, Agent: "equipo-test", Catalog: []wire.RepoInfo{{Repo: "amadan.net/oficina/sample", DefaultBranch: "main", Summary: "Woodstar is a reading app.", Names: []string{"sample", "Woodstar"}, Hints: []string{"go"}}}, Accounts: []wire.Account{{ID: "claude-a", Provider: "claude", Email: Owner, Healthy: true}}, Versions: map[string]string{"runner": "test", "claude": "2.1.312"}, |
| + Protocol: wire.Protocol2, Platform: &wire.Platform{OS: "linux", Arch: "amd64"}, Label: "docs-t1", Sandbox: wire.SandboxBubblewrap, Capabilities: &wire.Capabilities{Simulators: []wire.Simulator{}, Tags: []string{wire.TagLinux, wire.TagClaude, wire.TagGo}}} |
| +} |
| + |
| +// runnersRig is the tool rig with its primary at protocol 2. |
| +type runnersRig struct { |
| + *toolRig |
| + primary *peer |
| + // creds are each worker connection's credential and label. |
| + creds map[*FakeRunner][2]string |
| +} |
| + |
| +func newRunnersRig(t *testing.T) *runnersRig { |
| + r := newToolRig(t) |
| + gen := r.runner.Welcome.Generation |
| + r.runner.Close() |
| + p, err := DialRunnerHello(r.ctx, r.inst.URL, r.rig.runner, primaryHello(gen)) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + t.Cleanup(p.Close) |
| + if p.Welcome.Role != wire.RolePrimary || p.Welcome.Protocol != wire.Protocol2 { |
| + t.Fatalf("primary welcome %+v", p.Welcome) |
| + } |
| + r.runner = p |
| + rr := &runnersRig{toolRig: r, primary: &peer{t: t, r: r, fr: p}, creds: map[*FakeRunner][2]string{}} |
| + return rr |
| +} |
| + |
| +// worker enrols and connects a Mac worker. |
| +func (r *runnersRig) newWorker(label string) (*peer, string) { |
| + r.t.Helper() |
| + token := r.inst.EnrolRunner(r.t).Token |
| + return r.dialWorker(token, label, 0), token |
| +} |
| + |
| +func (r *runnersRig) dialWorker(token, label string, gen int64) *peer { |
| + r.t.Helper() |
| + h := WorkerHello(gen) |
| + h.Label = label |
| + w, err := DialRunnerHello(r.ctx, r.inst.URL, token, h) |
| + if err != nil { |
| + r.t.Fatal(err) |
| + } |
| + r.t.Cleanup(w.Close) |
| + r.creds[w] = [2]string{token, label} |
| + return &peer{t: r.t, r: r.toolRig, fr: w} |
| +} |
| + |
| +// candidate records a task and runs its Engineering step on the primary to |
| +// a pushed candidate that touched Apple files, so its checks need a Mac. |
| +// It returns the task and the checks step's id once it exists. |
| +func (r *runnersRig) candidate(title string, apple bool) (task, sha string) { |
| + r.t.Helper() |
| + task = taskID(r.t, r.call("c-"+title, wire.ToolRecordTask, map[string]string{"repo": "oficina/sample", "title": title, "brief": "b"})) |
| + r.call("s-"+title, wire.ToolStartTask, map[string]string{"task": task, "brief": "go"}) |
| + _, body := r.expect(wire.FrameDispatch) |
| + d := body.(*wire.DispatchCommand) |
| + if d.RunnerID == "" || len(d.Needs) != 0 { |
| + r.t.Fatalf("engineering dispatch %+v", d) |
| + } |
| + sha = strings.Repeat(string(rune('a'+len(title)%6)), 40) |
| + r.step("e1-"+task, wire.StepReport{TaskID: task, StepID: d.StepID, Attempt: 1, State: wire.StepRunning, BaseSHA: strings.Repeat("1", 40), Findings: []wire.Finding{}}) |
| + r.step("e2-"+task, wire.StepReport{TaskID: task, StepID: d.StepID, Attempt: 1, State: wire.StepRunning, CandidateSHA: sha, Findings: []wire.Finding{}}) |
| + r.step("e3-"+task, wire.StepReport{TaskID: task, StepID: d.StepID, Attempt: 1, State: wire.StepDone, CandidateSHA: sha, Pushed: true, Termination: true, TerminationKind: wire.TerminationNamespace, Apple: apple, Findings: []wire.Finding{}}) |
| + return task, sha |
| +} |
| + |
| +func (r *runnersRig) checksStep(task string) wire.Step { |
| + r.t.Helper() |
| + k, err := r.client.Task(r.ctx, task) |
| + if err != nil { |
| + r.t.Fatal(err) |
| + } |
| + for _, s := range k.Steps { |
| + if s.Specialist == wire.SpecialistChecks { |
| + return s |
| + } |
| + } |
| + r.t.Fatalf("no checks step: %+v", k.Steps) |
| + return wire.Step{} |
| +} |
| + |
| +// relay uploads a one-chunk pack from the primary for the inbound |
| +// transfer it was asked for, and returns the chunk the worker receives. |
| +func (r *runnersRig) relay(w *peer, data []byte) *wire.Blob { |
| + r.t.Helper() |
| + _, body := r.primary.expect(wire.FrameSendPack) |
| + sp := body.(*wire.SendPackCommand) |
| + sum := sha256.Sum256(data) |
| + r.primary.send(wire.FrameBlob, wire.Blob{Transfer: sp.Transfer, Index: 0, Total: 1, SHA256: hex.EncodeToString(sum[:]), Data: base64.StdEncoding.EncodeToString(data)}) |
| + _, got := w.expect(wire.FrameBlob) |
| + return got.(*wire.Blob) |
| +} |
| + |
| +func passed(task, step string, attempt int64, sha string) wire.StepReport { |
| + zero := 0 |
| + return wire.StepReport{TaskID: task, StepID: step, Attempt: attempt, State: wire.StepDone, CandidateSHA: sha, Checks: wire.ChecksPassed, Gate: "xcodebuild test", ExitCode: &zero, Output: "** TEST SUCCEEDED **", Termination: true, TerminationKind: wire.TerminationProcessGroup, Findings: []wire.Finding{}} |
| +} |
| + |
| +// M1 at the contract: an iOS change's checks are placed on the Mac |
| +// worker, the candidate is relayed as a pack from the primary, the worker |
| +// starts the attempt with its start authorization and passes it, and |
| +// review is placed back on the primary. Linux checks stay on the primary. |
| +func TestContractChecksPlacedOnTheWorker(t *testing.T) { |
| + r := newRunnersRig(t) |
| + w, _ := r.newWorker("Tito Studio") |
| + task, sha := r.candidate("iOS swipe", true) |
| + _, body := w.expect(wire.FrameDispatch) |
| + d := body.(*wire.DispatchCommand) |
| + shape(t, "frames/dispatch-needs.json", w.fr.Received[len(w.fr.Received)-1]) |
| + if d.Specialist != wire.SpecialistChecks || d.CandidateSHA != sha || d.RunnerID == "" || strings.Join(d.Needs, ",") != "macos,xcode" { |
| + t.Fatalf("worker dispatch %+v", d) |
| + } |
| + blob := r.relay(w, []byte("PACK one commit")) |
| + shape(t, "frames/blob.json", w.fr.Received[len(w.fr.Received)-1]) |
| + if blob.Transfer.Direction != wire.TransferInbound || blob.Transfer.StepID != d.StepID || blob.Transfer.Attempt != 1 || blob.Transfer.CandidateSHA != sha { |
| + t.Fatalf("relayed header %+v", blob.Transfer) |
| + } |
| + s := r.checksStep(task) |
| + if s.RunnerLabel != "Tito Studio" || s.Placement != "" || strings.Join(s.Needs, ",") != "macos,xcode" { |
| + t.Fatalf("checks step %+v", s) |
| + } |
| + if !w.lease(d.StepID, 1) { |
| + t.Fatal("start refused") |
| + } |
| + if !w.lease(d.StepID, 1) { |
| + t.Fatal("a repeated start authorization (a resent lease) was refused") |
| + } |
| + w.send(wire.FrameStep, wire.StepReport{TaskID: task, StepID: d.StepID, Attempt: 1, State: wire.StepRunning, CandidateSHA: sha, Findings: []wire.Finding{}}) |
| + w.send(wire.FrameStep, passed(task, d.StepID, 1, sha)) |
| + _, body = r.expect(wire.FrameDispatch) |
| + if rv := body.(*wire.DispatchCommand); rv.Specialist != wire.SpecialistReview || len(rv.Needs) != 0 { |
| + t.Fatalf("review dispatch %+v", rv) |
| + } |
| + k, _ := r.client.Task(r.ctx, task) |
| + if k.Checks != wire.ChecksPassed || k.Steps[1].TerminationKind != wire.TerminationProcessGroup || k.Steps[1].StartedAt == nil { |
| + t.Fatalf("task %+v", k) |
| + } |
| + runners, err := r.client.Runners(r.ctx) |
| + if err != nil || len(runners.Items) != 2 || runners.Items[0].Role != wire.RolePrimary || runners.Items[1].Label != "Tito Studio" || !runners.Items[1].Online { |
| + t.Fatalf("runners %+v %v", runners, err) |
| + } |
| + |
| + // A change that needs no Mac stays on the primary, worker or not. |
| + plain, _ := r.candidate("Go fix", false) |
| + _, body = r.expect(wire.FrameDispatch) |
| + if c := body.(*wire.DispatchCommand); c.Specialist != wire.SpecialistChecks || c.TaskID != plain || len(c.Needs) != 0 { |
| + t.Fatalf("plain checks %+v", c) |
| + } |
| +} |
| + |
| +// M3 at the contract: with no worker that fits, checks go to the primary |
| +// with no needs and end there honestly (needs_macos), as before. |
| +func TestContractChecksWithoutAWorker(t *testing.T) { |
| + r := newRunnersRig(t) |
| + task, sha := r.candidate("iOS swipe", true) |
| + _, body := r.expect(wire.FrameDispatch) |
| + d := body.(*wire.DispatchCommand) |
| + if d.Specialist != wire.SpecialistChecks || len(d.Needs) != 0 || d.CandidateSHA != sha { |
| + t.Fatalf("checks %+v", d) |
| + } |
| + if s := r.checksStep(task); s.Placement != "" || s.RunnerLabel != "docs-t1" { |
| + t.Fatalf("checks step %+v", s) |
| + } |
| +} |
| + |
| +// M2 at the contract: the fitting worker is offline, so checks wait |
| +// (placement waiting_runner, no dispatch anywhere); it reconnects and the |
| +// step is placed on it. A second task waits 30 minutes (a fake clock) and |
| +// resolves as not run, runner_offline, never a pass; review proceeds. |
| +func TestContractChecksWaitForTheWorker(t *testing.T) { |
| + r := newRunnersRig(t) |
| + w, token := r.newWorker("Tito Studio") |
| + gen := w.fr.Welcome.Generation |
| + w.fr.Close() |
| + time.Sleep(100 * time.Millisecond) |
| + task, _ := r.candidate("iOS swipe", true) |
| + if s := r.checksStep(task); s.Placement != wire.PlacementWaiting || s.RunnerID != "" { |
| + t.Fatalf("checks did not wait: %+v", s) |
| + } |
| + r.primary.none(wire.FrameSendPack, 200*time.Millisecond) |
| + w = r.dialWorker(token, "Tito Studio", gen) |
| + _, body := w.expect(wire.FrameDispatch) |
| + if d := body.(*wire.DispatchCommand); d.TaskID != task || d.Attempt != 1 { |
| + t.Fatalf("dispatch after reconnect %+v", d) |
| + } |
| + if s := r.checksStep(task); s.Placement != "" || s.RunnerLabel != "Tito Studio" { |
| + t.Fatalf("not placed after reconnect: %+v", s) |
| + } |
| + |
| + w.fr.Close() |
| + time.Sleep(100 * time.Millisecond) |
| + other, _ := r.candidate("iOS other", true) |
| + if s := r.checksStep(other); s.Placement != wire.PlacementWaiting { |
| + t.Fatalf("second checks did not wait: %+v", s) |
| + } |
| + clock := time.Now().UTC() |
| + r.inst.Store.Chat().SetClock(func() time.Time { return clock }) |
| + if err := r.inst.Store.Chat().Place(r.ctx); err != nil { |
| + t.Fatal(err) |
| + } |
| + if s := r.checksStep(other); s.State != wire.StepQueued { |
| + t.Fatalf("resolved before 30 minutes: %+v", s) |
| + } |
| + clock = clock.Add(chat.OfflineLimit) |
| + if err := r.inst.Store.Chat().Place(r.ctx); err != nil { |
| + t.Fatal(err) |
| + } |
| + k, _ := r.client.Task(r.ctx, other) |
| + s := r.checksStep(other) |
| + if s.State != wire.StepDone || s.Checks != wire.ChecksCannotRun || s.Reason != "runner_offline" || k.Checks == wire.ChecksPassed || k.ChecksReason != "runner_offline" { |
| + t.Fatalf("offline checks %+v task %+v", s, k) |
| + } |
| + _, body = r.expect(wire.FrameDispatch) |
| + if rv := body.(*wire.DispatchCommand); rv.TaskID != other || rv.Specialist != wire.SpecialistReview { |
| + t.Fatalf("review did not proceed: %+v", rv) |
| + } |
| +} |
| + |
| +// M6 placement at the contract: a worker that lacks a need refuses the |
| +// dispatch (placement_refused) and the step is placed on another worker. |
| +// The first worker's later reports for that attempt are refused. |
| +func TestContractPlacementRefused(t *testing.T) { |
| + r := newRunnersRig(t) |
| + a, _ := r.newWorker("Mac A") |
| + task, sha := r.candidate("iOS swipe", true) |
| + _, body := a.expect(wire.FrameDispatch) |
| + d := body.(*wire.DispatchCommand) |
| + b, _ := r.newWorker("Mac B") |
| + a.send(wire.FrameStep, wire.StepReport{TaskID: task, StepID: d.StepID, Attempt: 1, State: wire.StepFailed, Reason: "placement_refused", Termination: true, Findings: []wire.Finding{}}) |
| + _, body = b.expect(wire.FrameDispatch) |
| + d2 := body.(*wire.DispatchCommand) |
| + if d2.StepID != d.StepID || d2.Attempt != 2 { |
| + t.Fatalf("re-placed dispatch %+v", d2) |
| + } |
| + if a.lease(d.StepID, 1) || a.lease(d.StepID, 2) { |
| + t.Fatal("the refusing worker may still start the step") |
| + } |
| + // A delayed result from the first attempt is refused. |
| + a.send(wire.FrameStep, passed(task, d.StepID, 1, sha)) |
| + if s := r.checksStep(task); s.Attempt != 2 || s.State != wire.StepQueued || s.RunnerLabel != "Mac B" { |
| + t.Fatalf("after a stale report %+v", s) |
| + } |
| +} |
| + |
| +// Withdrawal (M6): an unacked dispatch on a worker that went offline is |
| +// withdrawn when another fitting worker is online; it never started, so |
| +// the next attempt is placed at once and the first can never start. An |
| +// attempt that did start is cancelled instead, and the next attempt |
| +// exists only once its termination is reported. |
| +func TestContractWithdrawal(t *testing.T) { |
| + r := newRunnersRig(t) |
| + a, tokenA := r.newWorker("Mac A") |
| + genA := a.fr.Welcome.Generation |
| + task, _ := r.candidate("iOS swipe", true) |
| + if _, _, err := a.fr.Expect(r.ctx, wire.FrameDispatch); err != nil { // received, never acked |
| + t.Fatal(err) |
| + } |
| + step := r.checksStep(task).ID |
| + a.fr.Close() |
| + b, _ := r.newWorker("Mac B") |
| + // A short absence withdraws nothing. |
| + if err := r.inst.Store.Chat().Place(r.ctx); err != nil { |
| + t.Fatal(err) |
| + } |
| + b.none(wire.FrameDispatch, 100*time.Millisecond) |
| + clock := time.Now().UTC().Add(chat.WithdrawAfter) |
| + r.inst.Store.Chat().SetClock(func() time.Time { return clock }) |
| + b.heartbeat(withLabel(WorkerHello(0), "Mac B")) |
| + if err := r.inst.Store.Chat().Place(r.ctx); err != nil { |
| + t.Fatal(err) |
| + } |
| + _, body := b.expect(wire.FrameDispatch) |
| + if d := body.(*wire.DispatchCommand); d.StepID != step || d.Attempt != 2 { |
| + t.Fatalf("withdrawn and re-placed %+v", d) |
| + } |
| + r.inst.Store.Chat().SetClock(func() time.Time { return time.Now().UTC() }) |
| + a = r.dialWorker(tokenA, "Mac A", genA) |
| + if a.lease(step, 1) { |
| + t.Fatal("a withdrawn attempt was authorised to start") |
| + } |
| + a.none(wire.FrameDispatch, 200*time.Millisecond) |
| + |
| + // Attempt 2 starts on B, then B goes away; A is online and fits. |
| + if !b.lease(step, 2) { |
| + t.Fatal("attempt 2 refused") |
| + } |
| + b.fr.Close() |
| + // (B's last heartbeat was stamped by the first fake clock.) |
| + clock = time.Now().UTC().Add(2*chat.WithdrawAfter + time.Second) |
| + r.inst.Store.Chat().SetClock(func() time.Time { return clock }) |
| + a.heartbeat(withLabel(WorkerHello(0), "Mac A")) |
| + if err := r.inst.Store.Chat().Place(r.ctx); err != nil { |
| + t.Fatal(err) |
| + } |
| + r.inst.Store.Chat().SetClock(func() time.Time { return time.Now().UTC() }) |
| + a.none(wire.FrameDispatch, 300*time.Millisecond) |
| + if s := r.checksStep(task); s.Attempt != 2 || s.State == wire.StepDone { |
| + t.Fatalf("a started attempt was replaced before its termination: %+v", s) |
| + } |
| + // B comes back, is told to cancel, and proves termination: only then |
| + // is attempt 3 placed (on A). |
| + bb := r.reconnectPeer(b) |
| + _, body = bb.expect(wire.FrameCancelStep) |
| + if c := body.(*wire.CancelStepCommand); c.StepID != step || c.Attempt != 2 { |
| + t.Fatalf("cancel %+v", c) |
| + } |
| + bb.send(wire.FrameStep, wire.StepReport{TaskID: task, StepID: step, Attempt: 2, State: wire.StepCancelled, Reason: "cancelled", Termination: true, TerminationKind: wire.TerminationProcessGroup, Findings: []wire.Finding{}}) |
| + _, body = a.expect(wire.FrameDispatch) |
| + if d := body.(*wire.DispatchCommand); d.StepID != step || d.Attempt != 3 { |
| + t.Fatalf("attempt 3 %+v", d) |
| + } |
| +} |
| + |
| +// reconnectPeer dials a runner again with the same credential and |
| +// generation. |
| +func (r *runnersRig) reconnectPeer(p *peer) *peer { |
| + r.t.Helper() |
| + c, ok := r.creds[p.fr] |
| + if !ok { |
| + r.t.Fatal("unknown peer") |
| + } |
| + return r.dialWorker(c[0], c[1], p.fr.Welcome.Generation) |
| +} |
| + |
| +func withLabel(h wire.Hello, label string) wire.Hello { |
| + h.Label = label |
| + return h |
| +} |
diff --git a/internal/thintest/review_contract_test.go b/internal/thintest/review_contract_test.go| index 3c54741c..9a60e2d4 100644 |
| --- a/internal/thintest/review_contract_test.go |
| +++ b/internal/thintest/review_contract_test.go |
| @@ -112,8 +112,21 @@ func TestContractReviewAndChecks(t *testing.T) { |
| if k.CandidateSHA != cand2 || k.Checks != "" || k.Verdict != "" || k.ReviewLabel != "" || k.Stage != wire.StageInReview { |
| t.Fatalf("judgements of the old candidate kept: %+v", k) |
| } |
| + // A delayed checks result for the older SHA, arriving on the new |
| + // candidate's checks step (a runner that judged the old one), is |
| + // dropped by the judged-SHA rule. |
| + r.step("a-c2-old", wire.StepReport{TaskID: id, StepID: c2.StepID, Attempt: 1, State: wire.StepDone, CandidateSHA: cand, Termination: true, Checks: wire.ChecksPassed, Gate: "make ci", ExitCode: exit(0), Findings: []wire.Finding{}}) |
| + if k, _ = r.client.Task(ctx, id); k.Checks != "" || k.Steps[len(k.Steps)-1].State == wire.StepDone { |
| + t.Fatalf("an older SHA's checks counted: %+v", k) |
| + } |
| r.checks("a-c2", c2, wire.ChecksPassed, exit(0), "", "ok\n") |
| rv2 := r.dispatched(wire.SpecialistReview, base, cand2, 1) |
| + // Likewise a delayed review verdict of the older SHA on the new review |
| + // step: it cannot make the newer candidate ready. |
| + r.step("a-r2-old", wire.StepReport{TaskID: id, StepID: rv2.StepID, Attempt: 1, State: wire.StepDone, CandidateSHA: cand, Termination: true, Verdict: wire.VerdictApprove, ReviewLabel: wire.ReviewSameFamily, Findings: []wire.Finding{}}) |
| + if k, _ = r.client.Task(ctx, id); k.Verdict != "" || k.Stage == wire.StageReadyToMerge { |
| + t.Fatalf("an older SHA's verdict counted: %+v", k) |
| + } |
| // A review of the old candidate arriving late changes nothing. |
| r.verdict("a-r-late", rv1, wire.VerdictApprove) |
| r.verdict("a-r2", rv2, wire.VerdictApprove) |
diff --git a/internal/thintest/transfer_contract_test.go b/internal/thintest/transfer_contract_test.go| new file mode 100644 |
| index 00000000..4314b22d |
| --- /dev/null |
| +++ b/internal/thintest/transfer_contract_test.go |
| @@ -0,0 +1,230 @@ |
| +package thintest |
| + |
| +import ( |
| + "crypto/sha256" |
| + "encoding/base64" |
| + "encoding/hex" |
| + "strings" |
| + "testing" |
| + "time" |
| + |
| + "amadan.net/oficina/equipo/internal/wire" |
| +) |
| + |
| +func chunk(h wire.TransferHeader, data []byte) wire.Blob { |
| + sum := sha256.Sum256(data) |
| + return wire.Blob{Transfer: h, Index: 0, Total: 1, SHA256: hex.EncodeToString(sum[:]), Data: base64.StdEncoding.EncodeToString(data)} |
| +} |
| + |
| +// relayed counts the blob commands that reached a runner's mailbox. |
| +func (r *runnersRig) relayed(p *peer) int { |
| + r.t.Helper() |
| + var n int |
| + if err := r.inst.DB.Writer().QueryRow("SELECT count(*) FROM runner_commands WHERE runner_id = ? AND kind = ?", p.fr.Welcome.RunnerID, wire.FrameBlob).Scan(&n); err != nil { |
| + r.t.Fatal(err) |
| + } |
| + return n |
| +} |
| + |
| +// Every chunk is authorised against its transfer before a byte is kept: |
| +// a chunk from another runner, under another task's transfer, for |
| +// another candidate, in the wrong direction, or for an attempt Retry has |
| +// replaced, is refused and nothing reaches the receiver. |
| +func TestContractTransferAuthorization(t *testing.T) { |
| + r := newRunnersRig(t) |
| + w, _ := r.newWorker("Mac A") |
| + other, _ := r.newWorker("Mac B") |
| + taskA, _ := r.candidate("iOS one", true) |
| + _, body := r.primary.expect(wire.FrameSendPack) |
| + ha := body.(*wire.SendPackCommand).Transfer |
| + _, body = w.expect(wire.FrameDispatch) |
| + da := body.(*wire.DispatchCommand) |
| + taskB, _ := r.candidate("iOS two", true) |
| + _, body = r.primary.expect(wire.FrameSendPack) |
| + hb := body.(*wire.SendPackCommand).Transfer |
| + if ha.TaskID != taskA || hb.TaskID != taskB || ha.Direction != wire.TransferInbound { |
| + t.Fatalf("headers %+v %+v", ha, hb) |
| + } |
| + before := r.relayed(w) + r.relayed(other) |
| + data := []byte("PACK") |
| + // A second worker uploading for a transfer not its own. |
| + other.send(wire.FrameBlob, chunk(ha, data)) |
| + // Chunks for task A sent under task B's transfer. |
| + mixed := hb |
| + mixed.TaskID, mixed.StepID = ha.TaskID, ha.StepID |
| + r.primary.send(wire.FrameBlob, chunk(mixed, data)) |
| + // A candidate that does not match the opened transfer. |
| + wrong := ha |
| + wrong.CandidateSHA = strings.Repeat("9", 40) |
| + r.primary.send(wire.FrameBlob, chunk(wrong, data)) |
| + // An inbound transfer answered in the outbound direction. |
| + back := ha |
| + back.Direction = wire.TransferOutbound |
| + w.send(wire.FrameBlob, chunk(back, data)) |
| + // Out of bounds: a chunk index past the total. |
| + bad := chunk(ha, data) |
| + bad.Index = 3 |
| + r.primary.send(wire.FrameBlob, bad) |
| + if n := r.relayed(w) + r.relayed(other); n != before { |
| + t.Fatalf("%d refused chunks were relayed", n-before) |
| + } |
| + // A stale attempt's chunks after Retry: the worker refuses, the |
| + // attempt is replaced, and the old transfer's chunk is refused. |
| + w.send(wire.FrameStep, wire.StepReport{TaskID: taskA, StepID: da.StepID, Attempt: 1, State: wire.StepFailed, Reason: "placement_refused", Termination: true, Findings: []wire.Finding{}}) |
| + r.primary.send(wire.FrameBlob, chunk(ha, data)) |
| + if n := r.relayed(w) + r.relayed(other); n != before { |
| + t.Fatalf("a stale attempt's chunk was relayed") |
| + } |
| + // The new attempt's transfer is open, and its chunk goes through. |
| + _, body = r.primary.expect(wire.FrameSendPack) |
| + h2 := body.(*wire.SendPackCommand).Transfer |
| + if h2.Attempt != 2 || h2.StepID != ha.StepID || h2.ID == ha.ID { |
| + t.Fatalf("second transfer %+v", h2) |
| + } |
| + r.primary.send(wire.FrameBlob, chunk(h2, data)) |
| + _, got := other.expect(wire.FrameBlob) |
| + if got.(*wire.Blob).Transfer != h2 { |
| + t.Fatalf("relayed %+v", got) |
| + } |
| +} |
| + |
| +// Oversize (M7): a transfer past 64 MB is refused, and checks that never |
| +// started end as not run (checks_unavailable), never a pass. |
| +func TestContractTransferTooLarge(t *testing.T) { |
| + r := newRunnersRig(t) |
| + w, _ := r.newWorker("Mac A") |
| + task, _ := r.candidate("iOS big", true) |
| + _, body := r.primary.expect(wire.FrameSendPack) |
| + h := body.(*wire.SendPackCommand).Transfer |
| + w.expect(wire.FrameDispatch) |
| + if _, err := r.inst.DB.Writer().Exec("UPDATE runner_transfers SET bytes = ? WHERE id = ?", wire.MaxTransferBytes-2, h.ID); err != nil { |
| + t.Fatal(err) |
| + } |
| + r.primary.send(wire.FrameBlob, chunk(h, []byte("PACK"))) |
| + s := r.checksStep(task) |
| + if s.State != wire.StepDone || s.Checks != wire.ChecksCannotRun || s.Reason != "checks_unavailable" { |
| + t.Fatalf("oversized candidate: %+v", s) |
| + } |
| + if n := r.relayed(w); n != 0 { |
| + t.Fatalf("oversized chunk relayed") |
| + } |
| +} |
| + |
| +// pinWorker makes the next Engineering step of a task run on a worker (the |
| +// slice F placement; here a test seam on the pin). |
| +func (r *runnersRig) pinWorker(task string, w *peer) { |
| + r.t.Helper() |
| + if _, err := r.inst.DB.Writer().Exec("UPDATE chat_tasks SET engineering_runner = ? WHERE id = ?", w.fr.Welcome.RunnerID, task); err != nil { |
| + r.t.Fatal(err) |
| + } |
| +} |
| + |
| +// workerCommit runs a task's Engineering step on the worker to a commit |
| +// and its pack, which reaches the primary with a publish command. |
| +func (r *runnersRig) workerCommit(w *peer, title string) (task string, d *wire.DispatchCommand, sha string, pub *wire.PublishCommand) { |
| + r.t.Helper() |
| + task = taskID(r.t, r.call("c-"+title, wire.ToolRecordTask, map[string]string{"repo": "oficina/sample", "title": title, "brief": "b"})) |
| + r.pinWorker(task, w) |
| + r.call("s-"+title, wire.ToolStartTask, map[string]string{"task": task, "brief": "go"}) |
| + _, body := w.expect(wire.FrameDispatch) |
| + d = body.(*wire.DispatchCommand) |
| + if d.Specialist != wire.SpecialistEngineering { |
| + r.t.Fatalf("dispatch %+v", d) |
| + } |
| + if !w.lease(d.StepID, d.Attempt) { |
| + r.t.Fatal("start refused") |
| + } |
| + sha = strings.Repeat("c", 40) |
| + w.send(wire.FrameStep, wire.StepReport{TaskID: task, StepID: d.StepID, Attempt: d.Attempt, State: wire.StepRunning, BaseSHA: strings.Repeat("1", 40), Findings: []wire.Finding{}}) |
| + w.send(wire.FrameStep, wire.StepReport{TaskID: task, StepID: d.StepID, Attempt: d.Attempt, State: wire.StepRunning, CandidateSHA: sha, Phase: "committed", Findings: []wire.Finding{}}) |
| + _, body = w.expect(wire.FrameSendPack) |
| + h := body.(*wire.SendPackCommand).Transfer |
| + if h.Direction != wire.TransferOutbound || h.CandidateSHA != sha { |
| + r.t.Fatalf("outbound header %+v", h) |
| + } |
| + // A worker claiming it pushed is refused: the step does not end. |
| + w.send(wire.FrameStep, wire.StepReport{TaskID: task, StepID: d.StepID, Attempt: d.Attempt, State: wire.StepDone, CandidateSHA: sha, Pushed: true, Termination: true, Findings: []wire.Finding{}}) |
| + if k, _ := r.client.Task(r.ctx, task); k.Steps[0].State != wire.StepRunning || k.Steps[0].Pushed { |
| + r.t.Fatalf("a worker's pushed was accepted: %+v", k.Steps[0]) |
| + } |
| + w.send(wire.FrameStep, wire.StepReport{TaskID: task, StepID: d.StepID, Attempt: d.Attempt, State: wire.StepDone, CandidateSHA: sha, Termination: true, TerminationKind: wire.TerminationProcessGroup, Findings: []wire.Finding{}}) |
| + w.send(wire.FrameBlob, chunk(h, []byte("PACK commit"))) |
| + r.primary.expect(wire.FrameBlob) |
| + _, body = r.primary.expect(wire.FramePublish) |
| + pub = body.(*wire.PublishCommand) |
| + if pub.CandidateSHA != sha || pub.Transfer != h.ID || pub.StepID != d.StepID { |
| + r.t.Fatalf("publish %+v", pub) |
| + } |
| + return task, d, sha, pub |
| +} |
| + |
| +// Publication stays the primary's word: a worker's pushed is refused; the |
| +// candidate counts as pushed only on the primary's published report for |
| +// the current attempt and candidate, and only then are checks and review |
| +// created. A failed push is Needs you retry, and Retry publishes the same |
| +// commit again without running Engineering. |
| +func TestContractPublication(t *testing.T) { |
| + r := newRunnersRig(t) |
| + w, _ := r.newWorker("Mac A") |
| + task, d, sha, pub := r.workerCommit(w, "iOS fix") |
| + // The worker claiming it pushed is refused. |
| + w.send(wire.FrameStep, wire.StepReport{TaskID: task, StepID: d.StepID, Attempt: d.Attempt, State: wire.StepDone, CandidateSHA: sha, Pushed: true, Termination: true, Findings: []wire.Finding{}}) |
| + k, _ := r.client.Task(r.ctx, task) |
| + if k.Steps[0].Pushed || k.Steps[0].Publication != wire.PublicationPending || k.CandidateSHA != "" || len(k.Steps) != 1 { |
| + t.Fatalf("before publication %+v", k.Steps[0]) |
| + } |
| + // A published report from the worker is refused. |
| + w.send(wire.FramePublished, wire.PublishedReport{Publication: pub.Publication, TaskID: task, StepID: d.StepID, Attempt: d.Attempt, CandidateSHA: sha, Pushed: true}) |
| + if k, _ = r.client.Task(r.ctx, task); k.Steps[0].Pushed { |
| + t.Fatal("a worker published") |
| + } |
| + // The primary's push fails: Needs you retry. |
| + if !r.primary.leasePublication(d.StepID, d.Attempt, pub.Publication) { |
| + t.Fatal("publication refused") |
| + } |
| + r.primary.send(wire.FramePublished, wire.PublishedReport{Publication: pub.Publication, TaskID: task, StepID: d.StepID, Attempt: d.Attempt, CandidateSHA: sha, Pushed: false, Reason: "push_failed"}) |
| + k, _ = r.client.Task(r.ctx, task) |
| + if k.NeedsYou != wire.NeedsRetry || k.Steps[0].Publication != wire.PublicationFailed { |
| + t.Fatalf("after a failed push %+v", k) |
| + } |
| + acc, err := r.client.RetryTask(r.ctx, task) |
| + if err != nil || acc.Attempt != d.Attempt { |
| + t.Fatalf("retry %+v %v", acc, err) |
| + } |
| + _, body := r.primary.expect(wire.FramePublish) |
| + again := body.(*wire.PublishCommand) |
| + if again.CandidateSHA != sha || again.Transfer != pub.Transfer || again.Publication == pub.Publication || again.Attempt != d.Attempt { |
| + t.Fatalf("republish %+v", again) |
| + } |
| + w.none(wire.FrameDispatch, 50*time.Millisecond) |
| + // The old publication is no longer the pending one. |
| + if r.primary.leasePublication(d.StepID, d.Attempt, pub.Publication) { |
| + t.Fatal("a superseded publication was confirmed") |
| + } |
| + r.primary.send(wire.FramePublished, wire.PublishedReport{Publication: again.Publication, TaskID: task, StepID: d.StepID, Attempt: d.Attempt, CandidateSHA: sha, Pushed: true}) |
| + _, body = r.expect(wire.FrameDispatch) |
| + if c := body.(*wire.DispatchCommand); c.Specialist != wire.SpecialistChecks || c.CandidateSHA != sha { |
| + t.Fatalf("checks after publication %+v", c) |
| + } |
| + if k, _ = r.client.Task(r.ctx, task); !k.Steps[0].Pushed || k.Steps[0].Publication != wire.PublicationPublished || k.CandidateSHA != sha || k.EngineeringRunner != w.fr.Welcome.RunnerID { |
| + t.Fatalf("published %+v", k) |
| + } |
| +} |
| + |
| +// Cancel after the pack arrived and before the push: the primary's |
| +// confirmation right before it pushes is refused, so nothing is pushed. |
| +func TestContractCancelBeforePublication(t *testing.T) { |
| + r := newRunnersRig(t) |
| + w, _ := r.newWorker("Mac A") |
| + task, d, sha, pub := r.workerCommit(w, "iOS cancel") |
| + if _, err := r.client.CancelTask(r.ctx, task); err != nil { |
| + t.Fatal(err) |
| + } |
| + if r.primary.leasePublication(d.StepID, d.Attempt, pub.Publication) { |
| + t.Fatal("a cancelled task's publication was confirmed") |
| + } |
| + r.primary.send(wire.FramePublished, wire.PublishedReport{Publication: pub.Publication, TaskID: task, StepID: d.StepID, Attempt: d.Attempt, CandidateSHA: sha, Pushed: false, Reason: "cancelled"}) |
| + if k, _ := r.client.Task(r.ctx, task); k.Stage != wire.StageCancelled || k.Steps[0].Pushed { |
| + t.Fatalf("cancelled %+v", k) |
| + } |
| +} |
diff --git a/internal/wire/api.go b/internal/wire/api.go| index ba4504a0..e3e69b3f 100644 |
| --- a/internal/wire/api.go |
| +++ b/internal/wire/api.go |
| @@ -197,6 +197,19 @@ type Runner struct { |
| ID string `json:"id"` |
| Revision int64 `json:"revision"` |
| Online bool `json:"online"` |
| + // Label is the machine's name ("Tito Studio"); Role primary or worker; |
| + // Since when it last came online or went offline; Platform and |
| + // Capabilities what it reported (null until it has). |
| + Label string `json:"label"` |
| + Role string `json:"role"` |
| + Since *time.Time `json:"since"` |
| + Platform *Platform `json:"platform"` |
| + Capabilities *Capabilities `json:"capabilities"` |
| +} |
| + |
| +// RunnerList is GET /api/v1/runners: the person's runners, primary first. |
| +type RunnerList struct { |
| + Items []Runner `json:"items"` |
| } |
| // Delta appends streamed text to the draft of a running turn. |
| @@ -323,6 +336,9 @@ type Snapshot struct { |
| // Coordinator says whether the coordinator has moved in. |
| Coordinator Coordinator `json:"coordinator"` |
| Cursor int64 `json:"cursor"` |
| + // Runners are all the person's runners (Runner stays, the primary, |
| + // for one release). |
| + Runners []Runner `json:"runners"` |
| } |
| // SendMessage is the body of POST /api/v1/messages. |
diff --git a/internal/wire/frames.go b/internal/wire/frames.go| index ee79f449..b8c947c3 100644 |
| --- a/internal/wire/frames.go |
| +++ b/internal/wire/frames.go |
| @@ -272,6 +272,11 @@ type RepoInfo struct { |
| Names []string `json:"names"` |
| Hints []string `json:"hints"` |
| UpdatedAt time.Time `json:"updated_at"` |
| + // Protocol 2: the repository's gate calls Xcode's tools or it is an |
| + // Xcode project (NeedsMacOS), and it has a shared scheme for the iOS |
| + // simulator (Simulator). The instance derives checks' needs from these. |
| + NeedsMacOS bool `json:"needs_macos,omitempty"` |
| + Simulator bool `json:"ios_simulator,omitempty"` |
| } |
| // SessionState is the runner's durable coordinator session for a person. |
| @@ -299,6 +304,9 @@ type LeaseCheck struct { |
| // and not withdrawn, and records that it started. |
| StepID string `json:"step_id,omitempty"` |
| Attempt int64 `json:"attempt,omitempty"` |
| + // Publication: the primary confirms, right before it pushes a worker's |
| + // commit, that this publication is still pending. |
| + Publication string `json:"publication,omitempty"` |
| } |
| // Sync is sent on every connect, after hello. |
diff --git a/internal/wire/runners.go b/internal/wire/runners.go| index 2738f83e..cfc4ede3 100644 |
| --- a/internal/wire/runners.go |
| +++ b/internal/wire/runners.go |
| @@ -329,14 +329,17 @@ func downgrade(body any) bool { |
| switch v := body.(type) { |
| case *Hello: |
| v.Protocol, v.Platform, v.Label, v.Sandbox, v.Capabilities = 0, nil, "", "", nil |
| + for i := range v.Catalog { |
| + v.Catalog[i].NeedsMacOS, v.Catalog[i].Simulator = false, false |
| + } |
| case *Welcome: |
| v.Protocol, v.Role, v.Release = 0, "", "" |
| case *DispatchCommand: |
| v.Needs, v.RunnerID = nil, "" |
| case *LeaseCheck: |
| - v.StepID, v.Attempt = "", 0 |
| + v.StepID, v.Attempt, v.Publication = "", 0, "" |
| case *StepReport: |
| - v.TerminationKind, v.Have, v.Phase = "", nil, "" |
| + v.TerminationKind, v.Have, v.Phase, v.Apple = "", nil, "", false |
| default: |
| return false |
| } |
diff --git a/internal/wire/tasks.go b/internal/wire/tasks.go| index cbb1937f..405fdd56 100644 |
| --- a/internal/wire/tasks.go |
| +++ b/internal/wire/tasks.go |
| @@ -107,6 +107,9 @@ const ( |
| // NeedsMergeConflict: the branch still conflicts with the default |
| // branch after Engineering's one rebase round. |
| NeedsMergeConflict = "merge_conflict" |
| + // NeedsRunnerOffline: the only runner that can do the next step has |
| + // been offline for 30 minutes. |
| + NeedsRunnerOffline = "runner_offline" |
| ) |
| // MaxRebaseRounds is how many times Engineering is sent to put the change |
| @@ -243,6 +246,16 @@ type Step struct { |
| Into string `json:"into"` |
| Strategy string `json:"strategy"` |
| WithoutChecks bool `json:"without_checks"` |
| + // Runners: where the attempt runs (RunnerLabel for people; the house |
| + // rule mentions it only when it is not the primary), what it needs, |
| + // whether it waits for a runner, how its end was proven, and the |
| + // publication of a worker's Engineering candidate. |
| + RunnerID string `json:"runner_id"` |
| + RunnerLabel string `json:"runner_label"` |
| + Needs []string `json:"needs"` |
| + Placement string `json:"placement"` |
| + Publication string `json:"publication"` |
| + TerminationKind string `json:"termination_kind"` |
| } |
| // Task is one piece of work under a project. Branch is the task's own |
| @@ -290,6 +303,8 @@ type Task struct { |
| // Reports counts the person's reports attached to this task after it |
| // was recorded (the same problem reported again). |
| Reports int `json:"reports"` |
| + // EngineeringRunner is the runner Engineering is pinned to. |
| + EngineeringRunner string `json:"engineering_runner"` |
| } |
| // Merged is how Equipo merged a task: SHA on Into, with Strategy; |
| @@ -499,6 +514,9 @@ type StepReport struct { |
| TerminationKind string `json:"termination_kind,omitempty"` |
| Have []string `json:"have,omitempty"` |
| Phase string `json:"phase,omitempty"` |
| + // Apple: Engineering's change touched Swift, Objective-C or Xcode |
| + // files, so its checks need macOS. |
| + Apple bool `json:"apple,omitempty"` |
| } |
| // RecheckCommand asks the runner to check now what its agent reaches. |
diff --git a/internal/wire/wiretest/fixtures.go b/internal/wire/wiretest/fixtures.go| index 1b648082..7e2a9598 100644 |
| --- a/internal/wire/wiretest/fixtures.go |
| +++ b/internal/wire/wiretest/fixtures.go |
| @@ -81,6 +81,8 @@ func APIType(name string) any { |
| return &wire.TaskList{} |
| case "task-accepted.json": |
| return &wire.TaskAccepted{} |
| + case "runners.json": |
| + return &wire.RunnerList{} |
| case "step-log.json": |
| return &wire.StepLog{} |
| case "thread-request.json": |
diff --git a/internal/wire/wiretest/testdata/api/event-runner.json b/internal/wire/wiretest/testdata/api/event-runner.json| index d3bcb73b..c11a309e 100644 |
| --- a/internal/wire/wiretest/testdata/api/event-runner.json |
| +++ b/internal/wire/wiretest/testdata/api/event-runner.json |
| @@ -1 +1 @@ |
| -{"cursor":43,"type":"runner","resource":"runner","id":"RUNNER1","revision":4,"data":{"id":"RUNNER1","revision":4,"online":false}} |
| +{"cursor":43,"type":"runner","resource":"runner","id":"RUNNER1","revision":4,"data":{"id":"RUNNER1","revision":4,"online":false,"label":"docs-t1","role":"primary","since":"2026-11-07T10:12:00Z","platform":null,"capabilities":null}} |
| \ No newline at end of file |
diff --git a/internal/wire/wiretest/testdata/api/needs-you.json b/internal/wire/wiretest/testdata/api/needs-you.json| index 8f299580..a90582e3 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,"rebase":false,"merge_sha":"","into":"","strategy":"","without_checks":false},{"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,"rebase":false,"merge_sha":"","into":"","strategy":"","without_checks":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,"rebase":false,"merge_sha":"","into":"","strategy":"","without_checks":false}],"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}],"merged":null,"reports":0}]} |
| +{"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,"rebase":false,"merge_sha":"","into":"","strategy":"","without_checks":false,"runner_id":"RUNNER1","runner_label":"","needs":[],"placement":"","publication":"","termination_kind":"namespace"},{"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,"rebase":false,"merge_sha":"","into":"","strategy":"","without_checks":false,"runner_id":"RUNNER1","runner_label":"","needs":[],"placement":"","publication":"","termination_kind":"namespace"},{"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,"rebase":false,"merge_sha":"","into":"","strategy":"","without_checks":false,"runner_id":"RUNNER1","runner_label":"","needs":[],"placement":"","publication":"","termination_kind":"namespace"}],"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}],"merged":null,"reports":0,"engineering_runner":"RUNNER1"}]} |
| \ No newline at end of file |
diff --git a/internal/wire/wiretest/testdata/api/runners.json b/internal/wire/wiretest/testdata/api/runners.json| new file mode 100644 |
| index 00000000..943e8388 |
| --- /dev/null |
| +++ b/internal/wire/wiretest/testdata/api/runners.json |
| @@ -0,0 +1 @@ |
| +{"items":[{"id":"RUNNER1","revision":4,"online":true,"label":"docs-t1","role":"primary","since":"2026-11-07T10:12:00Z","platform":{"os":"linux","arch":"amd64"},"capabilities":{"xcode":{"version":"","build":""},"simulators":[],"toolchains":{"go":"go1.26.10","swift":"","node":""},"harness":{"claude":"2.1.312","codex":"","srt":""},"tags":["linux","claude","go"]}},{"id":"RUNNER2","revision":2,"online":false,"label":"Tito Studio","role":"worker","since":"2026-11-07T10:12:00Z","platform":{"os":"darwin","arch":"arm64"},"capabilities":{"xcode":{"version":"16.2","build":"16C5032a"},"simulators":[{"name":"iPhone 16 Pro","runtime":"iOS 18.2","udid":"5C0A1E2B-3D4F-4A5B-9C6D-7E8F90A1B2C3","state":"Shutdown"}],"toolchains":{"go":"","swift":"6.0.3","node":"v22.12.0"},"harness":{"claude":"2.1.312","codex":"","srt":"0.0.81"},"tags":["macos","xcode","ios_simulator","claude"]}}]} |
| \ No newline at end of file |
diff --git a/internal/wire/wiretest/testdata/api/snapshot.json b/internal/wire/wiretest/testdata/api/snapshot.json| index 1b69337d..c0ab65a7 100644 |
| --- a/internal/wire/wiretest/testdata/api/snapshot.json |
| +++ b/internal/wire/wiretest/testdata/api/snapshot.json |
| @@ -1 +1 @@ |
| -{"me":{"id":"owner@example.com","address":"owner@example.com","role":"owner","person":{"address":"owner@example.com","display_identity":"owner@example.com","active":true,"role":"owner"},"team_id":"TEAM1","team_name":"Example","revision":1},"messages":[{"id":"m_0001","revision":1,"role":"person","text":"hello","turn_id":"t_0001","created_at":"2026-11-06T10:00:00Z"}],"turns":[{"id":"t_0001","revision":2,"kind":"","state":"running","reason":"","attempt":1,"message_ids":["m_0001"],"reply_id":"","created_at":"2026-11-06T10:00:00Z","updated_at":"2026-11-06T10:00:01Z","timing":null}],"runner":{"id":"RUNNER1","revision":3,"online":true},"projects":[{"id":"p_0001","revision":1,"repo":"amadan.net/oficina/sample","name":"oficina/sample","title":"Sample","attachments":[{"kind":"repo","ref":"amadan.net/oficina/sample","name":"oficina/sample"}],"state":"active","added_by":"owner@example.com","created_at":"2026-11-06T10:00:00Z","updated_at":"2026-11-06T10:00:00Z"}],"cards":[{"id":"c_0001","revision":1,"kind":"project","state":"added","turn_id":"t_0001","project_id":"p_0001","name":"oficina/sample","question":"","options":[],"choice":"","task_id":"","created_at":"2026-11-06T10:00:00Z","updated_at":"2026-11-06T10:00:00Z"}],"tasks":[],"coordinator":{"id":"owner@example.com","revision":2,"state":"ready","turn_id":"","moved_in_at":"2026-11-06T09:59:00Z"},"cursor":40} |
| +{"me":{"id":"owner@example.com","address":"owner@example.com","role":"owner","person":{"address":"owner@example.com","display_identity":"owner@example.com","active":true,"role":"owner"},"team_id":"TEAM1","team_name":"Example","revision":1},"messages":[{"id":"m_0001","revision":1,"role":"person","text":"hello","turn_id":"t_0001","created_at":"2026-11-06T10:00:00Z"}],"turns":[{"id":"t_0001","revision":2,"kind":"","state":"running","reason":"","attempt":1,"message_ids":["m_0001"],"reply_id":"","created_at":"2026-11-06T10:00:00Z","updated_at":"2026-11-06T10:00:01Z","timing":null}],"runner":{"id":"RUNNER1","revision":3,"online":true,"label":"docs-t1","role":"primary","since":"2026-11-07T10:12:00Z","platform":null,"capabilities":null},"projects":[{"id":"p_0001","revision":1,"repo":"amadan.net/oficina/sample","name":"oficina/sample","title":"Sample","attachments":[{"kind":"repo","ref":"amadan.net/oficina/sample","name":"oficina/sample"}],"state":"active","added_by":"owner@example.com","created_at":"2026-11-06T10:00:00Z","updated_at":"2026-11-06T10:00:00Z"}],"cards":[{"id":"c_0001","revision":1,"kind":"project","state":"added","turn_id":"t_0001","project_id":"p_0001","name":"oficina/sample","question":"","options":[],"choice":"","task_id":"","created_at":"2026-11-06T10:00:00Z","updated_at":"2026-11-06T10:00:00Z"}],"tasks":[],"coordinator":{"id":"owner@example.com","revision":2,"state":"ready","turn_id":"","moved_in_at":"2026-11-06T09:59:00Z"},"cursor":40,"runners":[{"id":"RUNNER1","revision":3,"online":true,"label":"docs-t1","role":"primary","since":"2026-11-07T10:12:00Z","platform":null,"capabilities":null}]} |
| \ No newline at end of file |
diff --git a/internal/wire/wiretest/testdata/api/task-merged.json b/internal/wire/wiretest/testdata/api/task-merged.json| index 6d25f4f1..ba252b5a 100644 |
| --- a/internal/wire/wiretest/testdata/api/task-merged.json |
| +++ b/internal/wire/wiretest/testdata/api/task-merged.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":"done","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,"rebase":false,"merge_sha":"","into":"","strategy":"","without_checks":false},{"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,"rebase":false,"merge_sha":"","into":"","strategy":"","without_checks":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,"rebase":false,"merge_sha":"","into":"","strategy":"","without_checks":false},{"id":"s_0009","revision":2,"task_id":"tk0001","index":4,"specialist":"merge","state":"done","reason":"","attempt":1,"base_sha":"1111111111111111111111111111111111111111","candidate_sha":"2222222222222222222222222222222222222222","pushed":false,"terminated":true,"summary":"","log_tail":"Read panes/swipe.go","started_at":"2026-11-07T10:02:31Z","finished_at":"2026-11-07T10:04:10Z","round":0,"family":"","account":"","verdict":"","review_label":"","findings":[],"checks":"","gate":"","exit_code":null,"askable":true,"rebase":false,"merge_sha":"eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee","into":"main","strategy":"merge","without_checks":false}],"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":"","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}],"merged":{"sha":"eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee","into":"main","strategy":"merge","without_checks":false,"at":"2026-11-07T12:00:00Z"},"reports":0} |
| +{"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":"done","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,"rebase":false,"merge_sha":"","into":"","strategy":"","without_checks":false,"runner_id":"RUNNER1","runner_label":"","needs":[],"placement":"","publication":"","termination_kind":"namespace"},{"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,"rebase":false,"merge_sha":"","into":"","strategy":"","without_checks":false,"runner_id":"RUNNER1","runner_label":"","needs":[],"placement":"","publication":"","termination_kind":"namespace"},{"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,"rebase":false,"merge_sha":"","into":"","strategy":"","without_checks":false,"runner_id":"RUNNER1","runner_label":"","needs":[],"placement":"","publication":"","termination_kind":"namespace"},{"id":"s_0009","revision":2,"task_id":"tk0001","index":4,"specialist":"merge","state":"done","reason":"","attempt":1,"base_sha":"1111111111111111111111111111111111111111","candidate_sha":"2222222222222222222222222222222222222222","pushed":false,"terminated":true,"summary":"","log_tail":"Read panes/swipe.go","started_at":"2026-11-07T10:02:31Z","finished_at":"2026-11-07T10:04:10Z","round":0,"family":"","account":"","verdict":"","review_label":"","findings":[],"checks":"","gate":"","exit_code":null,"askable":true,"rebase":false,"merge_sha":"eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee","into":"main","strategy":"merge","without_checks":false,"runner_id":"RUNNER1","runner_label":"","needs":[],"placement":"","publication":"","termination_kind":"namespace"}],"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":"","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}],"merged":{"sha":"eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee","into":"main","strategy":"merge","without_checks":false,"at":"2026-11-07T12:00:00Z"},"reports":0,"engineering_runner":"RUNNER1"} |
| \ No newline at end of file |
diff --git a/internal/wire/wiretest/testdata/api/task-ready.json b/internal/wire/wiretest/testdata/api/task-ready.json| index 32fd7fa3..62f6057f 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,"rebase":false,"merge_sha":"","into":"","strategy":"","without_checks":false},{"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,"rebase":false,"merge_sha":"","into":"","strategy":"","without_checks":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,"rebase":false,"merge_sha":"","into":"","strategy":"","without_checks":false}],"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}],"merged":null,"reports":0} |
| +{"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,"rebase":false,"merge_sha":"","into":"","strategy":"","without_checks":false,"runner_id":"RUNNER1","runner_label":"","needs":[],"placement":"","publication":"","termination_kind":"namespace"},{"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,"rebase":false,"merge_sha":"","into":"","strategy":"","without_checks":false,"runner_id":"RUNNER1","runner_label":"","needs":[],"placement":"","publication":"","termination_kind":"namespace"},{"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,"rebase":false,"merge_sha":"","into":"","strategy":"","without_checks":false,"runner_id":"RUNNER1","runner_label":"","needs":[],"placement":"","publication":"","termination_kind":"namespace"}],"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}],"merged":null,"reports":0,"engineering_runner":"RUNNER1"} |
| \ No newline at end of file |
diff --git a/internal/wire/wiretest/testdata/api/task.json b/internal/wire/wiretest/testdata/api/task.json| index e421ff6e..3210b8b8 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,"rebase":false,"merge_sha":"","into":"","strategy":"","without_checks":false}],"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}],"merged":null,"reports":0} |
| +{"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,"rebase":false,"merge_sha":"","into":"","strategy":"","without_checks":false,"runner_id":"RUNNER1","runner_label":"","needs":[],"placement":"","publication":"","termination_kind":"namespace"}],"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}],"merged":null,"reports":0,"engineering_runner":"RUNNER1"} |
| \ No newline at end of file |
diff --git a/internal/wire/wiretest/testdata/api/tasks.json b/internal/wire/wiretest/testdata/api/tasks.json| index 0a0a2a37..38b21bff 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,"rebase":false,"merge_sha":"","into":"","strategy":"","without_checks":false}],"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}],"merged":null,"reports":0}]} |
| +{"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,"rebase":false,"merge_sha":"","into":"","strategy":"","without_checks":false,"runner_id":"RUNNER1","runner_label":"","needs":[],"placement":"","publication":"","termination_kind":"namespace"}],"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}],"merged":null,"reports":0,"engineering_runner":"RUNNER1"}]} |
| \ No newline at end of file |