oficina / equipo Public

Stop jobs whose merge or publish failed with nothing to answer

Paul's live check (2026-11-16): a legacy job spun "Almost ready" after
its go-ahead was given and going live failed, with nothing open for him
to answer.

- A task back at Ready to merge because the merge it was given failed
  now counts as settled: autoMerge never tries the SHA again, so only
  the person's Merge moves it. jobStop reads it as blocked, going live,
  so the job card is stopped (not working, finishing) and the Assistant
  is told once.
- A merged task's site that did not go live is read from its newest
  publish step, failed or cancelled, whatever step came after; a
  cancelled publish no longer reads as done.
- Contract tests replay Paul's sequence (question answered, no work,
  nudged through, built, go-ahead) for a legacy hand-off and a job
  thread: publish failed and not asked again, failed and declined when
  asked again, cancelled, merge failed -> stopped; Publish declined ->
  done.

Budgets: internal/equipo/chat 30035, internal/thintest 30294.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by paul@keymail.dev 6bbcfa9678a8a38c7a3aedf1e157b3a4bdaef8f9 parent c6feb47
3 files changed, +262 −11
  • .rastrillo/budgets.txt +2 −2
  • internal/equipo/chat/handoff.go +36 −9
  • internal/thintest/assistant_job_state_contract_test.go +224 −0

CI passed — run details

diff --git a/.rastrillo/budgets.txt b/.rastrillo/budgets.txt
index 6842c003..01c3c075 100644
--- a/.rastrillo/budgets.txt
+++ b/.rastrillo/budgets.txt
@@ -56,7 +56,7 @@ perf GET /api/v1/tasks/{id} skip Thin v1 person API: bearer-only JSON for device
perf GET /api/v1/assistant/snapshot skip Assistant person API: bearer-only JSON for Base's chat, not a browser screen.
perf GET /api/v1/assistant/messages skip Assistant person API: bearer-only JSON for Base's chat, not a browser screen.
perf GET /api/v1/assistant/events skip Assistant event stream (Server-Sent Events), bearer-only and long-lived; not a screen.
-size internal/equipo/chat 30008 - Transactional authority and dispatch stay together; project confirmation, fenced moves and notebook learning. Measured 30008 source lines.
+size internal/equipo/chat 30035 - Transactional authority and dispatch stay together; job stop after a failed merge or publish. Measured 30035 source lines.
perf GET /api/v1/questions/{id} skip Thin v1 person API: bearer-only JSON for devices; the browser reads questions on /tasks/{id}.
perf GET /api/v1/steps/{id}/log skip Thin v1 person API: bearer-only JSON for devices; the browser shows the log tail on /tasks/{id}.
perf GET /api/v1/connections/preference skip Connections slice 1 person API: bearer-only JSON for devices; the browser shows the preference on /conversation/connections.
@@ -71,7 +71,7 @@ perf GET /tasks/{id}/files/{file} skip Research kept images: the bytes of one im
perf GET /api/v1/runners skip Mac runners person API: bearer-only JSON for devices; the browser shows runners in the Team section.
time cmd/equipo-runner 60s TestReleaseRunnerHasNoFakeWorker builds the release runner and the thin package under testbuild (about 12s locally).
size internal/headless - 11062 End-to-end scenarios through a real runner and instance: Copy setting, the Assistant's job threads, streamed replies, warm start, glance. Measured 11062 test lines.
-size internal/thintest - 30070 Shared instance harness: placement consent, restart proof, preserved context and responsive browser contracts. Measured 30070 test lines.
+size internal/thintest - 30294 Shared instance harness: placement consent, restart proof, settled job states and responsive browser contracts. Measured 30294 test lines.
perf GET /api/v1/projects/{id}/merge-policy skip Merge authority person API: bearer-only JSON for devices; the browser reads the policy on /projects/{id}.
perf GET /api/v1/usage skip Thin v1 person API: bearer-only JSON for devices; the browser reads usage through /usage.
perf GET /api/v1/advice skip Thin v1 person API: bearer-only JSON for devices; the browser reads advice through /usage and /conversation.
diff --git a/internal/equipo/chat/handoff.go b/internal/equipo/chat/handoff.go
index ec379930..80a0165b 100644
--- a/internal/equipo/chat/handoff.go
+++ b/internal/equipo/chat/handoff.go
@@ -699,8 +699,9 @@ func (t *txn) handoffTasks(h handoffRecord) ([]taskRecord, error) {
}
// handoffSettled: none of the hand-off's work moves on its own: each
-// task ended (and is not being published), or stopped and needs someone;
-// or, with no task, it stopped (handoffStopped).
+// task ended (and is not being published), or stopped and needs someone
+// (a merge that failed back at Ready to merge among them); or, with no
+// task, it stopped (handoffStopped).
func (t *txn) handoffSettled(h handoffRecord) (bool, error) {
tasks, err := t.handoffTasks(h)
if err != nil {
@@ -722,14 +723,35 @@ func (t *txn) handoffSettled(h handoffRecord) (bool, error) {
continue
}
// Ready to merge is not settled: Equipo may merge it on its own,
- // and a merge that waits for the person raises its card.
- if needs := progressFor(k, steps).needsYou(k); needs == "" || needs == wire.NeedsMerge {
+ // and a merge that waits for the person raises its card. Once the
+ // merge the person or Equipo started failed, nothing merges it on
+ // its own (autoMerge never tries a SHA again): it waits on them.
+ pr := progressFor(k, steps)
+ if needs := pr.needsYou(k); needs == "" || needs == wire.NeedsMerge && !mergeFailed(k, pr) {
return false, nil
}
}
return true, nil
}
+// mergeFailed: the task is back at Ready to merge because its candidate's
+// merge failed and ended (merge.go's mergeFailed): only the person's
+// Merge tries it again.
+func mergeFailed(k taskRecord, p progress) bool {
+ return k.Stage == wire.StageReadyToMerge && p.merge != nil && p.merge.State == wire.StepFailed && p.merge.Terminated
+}
+
+// publishFailed: the task's newest publish step ended without publishing
+// (failed, or cancelled before it was sent): its site did not go live.
+func publishFailed(steps []stepRecord) bool {
+ for i := len(steps) - 1; i >= 0; i-- {
+ if s := steps[i]; s.Specialist == wire.SpecialistPublish {
+ return s.State == wire.StepFailed || s.State == wire.StepCancelled
+ }
+ }
+ return false
+}
+
// handoffStopped: the hand-off's Coordinator turns all ended, having
// recorded or joined no work, and none left a question open for the
// person (its card asks them). A turn that failed, or that the runner
@@ -849,9 +871,9 @@ const (
// holds it is a failed step the instance marks retryable (needsYou
// retry, its newest step neither a merge nor a publish); stopNoWork when
// it has no task and its turns ended with none; stopBlocked for anything
-// else (a task's need only the person meets, a failed merge or publish
-// among them, or, while the work has not ended, an open card that stops
-// it).
+// else (a task's need only the person meets, a failed merge or a site
+// that did not go live among them, or, while the work has not ended, an
+// open card that stops it).
func (t *txn) stopReason(h handoffRecord) (string, error) {
settled, err := t.handoffSettled(h)
if err != nil || !settled {
@@ -892,14 +914,19 @@ func (t *txn) jobStop(h handoffRecord, settled bool) (reason, cause string, ende
}
live := newest != nil && (newest.Specialist == wire.SpecialistMerge || newest.Specialist == wire.SpecialistPublish)
if wire.FinalStage(k.Stage) {
- if live && newest.Specialist == wire.SpecialistPublish && newest.State == wire.StepFailed {
+ // Merged, and its site did not go live, whatever step came
+ // after its publish.
+ if k.Stage == wire.StageDone && publishFailed(steps) {
return stopBlocked, causeGoingLive, false, nil
}
done = done || k.Stage == wire.StageDone
continue
}
ended = false
- switch needs := progressFor(k, steps).needsYou(k); {
+ pr := progressFor(k, steps)
+ switch needs := pr.needsYou(k); {
+ case needs == wire.NeedsMerge && mergeFailed(k, pr):
+ return stopBlocked, causeGoingLive, false, nil
case needs == wire.NeedsRetry && live:
return stopBlocked, causeGoingLive, false, nil
case needs == wire.NeedsRetry:
diff --git a/internal/thintest/assistant_job_state_contract_test.go b/internal/thintest/assistant_job_state_contract_test.go
new file mode 100644
index 00000000..35208814
--- /dev/null
+++ b/internal/thintest/assistant_job_state_contract_test.go
@@ -0,0 +1,224 @@
+package thintest
+
+import (
+ "database/sql"
+ "strings"
+ "testing"
+ "time"
+
+ "amadan.net/oficina/equipo/internal/wire"
+)
+
+// Settled but not done (Paul's live check, 2026-11-16): a job whose work
+// went as far as it will go on its own, with nothing open in front of
+// the person, is never left working. A failed go-live the person is not
+// asked about again (or declined when asked again) is stopped, for a
+// legacy hand-off and a job thread alike; a merged website whose Publish
+// was declined is done.
+
+// paulsWebsite is Paul's live sequence: "Can you make me a website?"
+// handed over (a legacy hand-off, or a new one with a thread); the team
+// asks "Which website?" and the person answers; that turn ends with no
+// work, so the Assistant nudges it through from its team_update turn;
+// the nudge's turn builds the site, its preview comes up and the person
+// gives the go-ahead. It returns the request, the task and the merge
+// step's dispatch, every team_update turn so far ended.
+func (o *teamRig) paulsWebsite(legacy bool) (request, id string, merge *wire.DispatchCommand) {
+ o.t.Helper()
+ t := o.t
+ o.sitesOn(wire.ProtocolAssistant, true)
+ o.shipsNo(o.project())
+ words := "Can you make me a website?"
+ o.ask(words)
+ var turn, lane string
+ if legacy {
+ request, turn = o.legacyHandoff("pw", words)
+ lane = wire.LaneCoordinator
+ } else {
+ var cmd *wire.MessageCommand
+ request, cmd = o.handoff("pw1", words, "")
+ turn, lane = cmd.TurnID, wire.JobLane(request)
+ }
+ o.in(turn, func() {
+ if res := o.call("pw-ask", wire.ToolAskPerson, map[string]any{"question": "Which website?", "options": []string{"A new one", "One I have"}}); res.Code != "asked" {
+ t.Fatalf("ask %+v", res)
+ }
+ })
+ o.reply(turn)
+ var card string
+ var revision int64
+ o.until("the question", func() bool {
+ return o.inst.DB.Writer().QueryRow("SELECT id, revision FROM chat_cards WHERE turn_id = ? AND kind = ? AND state = ?", turn, wire.CardQuestion, wire.CardOpen).Scan(&card, &revision) == nil
+ })
+ ans, err := o.client.Answer(o.ctx, card, "A new one", revision)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if next := o.message(lane); next.TurnID != ans.Turn.ID {
+ t.Fatalf("the answer's frame %+v", next)
+ }
+ o.reply(ans.Turn.ID)
+ o.noteFor("the no-work note", noWork(request, 2))
+ o.reply(o.turn)
+ u := o.message(wire.LaneAssistant)
+ if u.Kind != wire.TurnTeamUpdate {
+ t.Fatalf("update frame %+v", u)
+ }
+ o.in(u.TurnID, func() { nudged(t, o.teamNudge("pw-nudge", request, "make me a website"), request, 1) })
+ next := o.message(lane)
+ o.reply(u.TurnID)
+ base, cand := strings.Repeat("1", 40), strings.Repeat("2", 40)
+ o.in(next.TurnID, func() { id, _ = o.websiteReady("pw", "Disability benefits website", base, cand, true) })
+ o.reply(next.TurnID)
+ pv := o.previewDispatch(cand)
+ o.built("pw-pv-built", pv, digestA)
+ o.previewDone("pw-pv-done", pv, wire.PreviewResult{Phase: wire.PreviewDone, App: "eq-" + id, URL: "https://eq-" + id + ".docs-t1.example.ts.net/", Digest: digestA, Outcome: wire.PreviewDeployed})
+ ahead := o.assistantCard("the go-ahead", func(c wire.AssistantCard) bool {
+ return isMergeOutcome(c) && c.State == wire.CardOpen && len(c.Links) == 1
+ })
+ if _, err := o.a.Answer(o.ctx, ahead.ID, wire.ChoiceMerge, ahead.Revision); err != nil {
+ t.Fatal(err)
+ }
+ merge = o.dispatched(wire.SpecialistMerge, base, cand, 0)
+ o.endUpdates()
+ return request, id, merge
+}
+
+// paulsPublish takes paulsWebsite's merge through and gives the Publish:
+// the publish step's dispatch.
+func (o *teamRig) paulsPublish(id string, merge *wire.DispatchCommand) *wire.DispatchCommand {
+ o.t.Helper()
+ o.mergedStep("pw-m", merge, strings.Repeat("e", 40))
+ o.wait("done", func(c *Conversation) bool { return c.Tasks[id].Stage == wire.StageDone })
+ publish := o.assistantCard("the Publish card", func(c wire.AssistantCard) bool { return isPublishOutcome(c) && c.State == wire.CardOpen })
+ if _, err := o.a.Answer(o.ctx, publish.ID, wire.ChoicePublish, publish.Revision); err != nil {
+ o.t.Fatal(err)
+ }
+ return o.publishDispatch()
+}
+
+// endUpdates ends the rig's Assistant turn and then every team_update
+// turn once it is dispatched, by its id (its frame may have gone by),
+// until none is queued or running.
+func (o *teamRig) endUpdates() {
+ o.t.Helper()
+ inFlight := "SELECT count(*) FROM chat_turns WHERE id = ? AND state IN (?, ?, ?)"
+ if o.rows(inFlight, o.turn, wire.TurnQueued, wire.TurnRunning, wire.TurnWaiting) == 1 {
+ o.reply(o.turn)
+ }
+ for range 50 {
+ time.Sleep(20 * time.Millisecond)
+ var turn string
+ var dispatched bool
+ err := o.inst.DB.Writer().QueryRow("SELECT id, dispatched FROM chat_turns WHERE kind = ? AND lane = ? AND state IN (?, ?, ?) ORDER BY created_at, id LIMIT 1", wire.TurnTeamUpdate, wire.LaneAssistant, wire.TurnQueued, wire.TurnRunning, wire.TurnWaiting).Scan(&turn, &dispatched)
+ switch {
+ case err == sql.ErrNoRows:
+ return
+ case err != nil:
+ o.t.Fatal(err)
+ case dispatched:
+ o.reply(turn)
+ }
+ }
+ o.t.Fatal("team_update turns keep coming")
+}
+
+// openOutcomes are the go-ahead and Publish cards open in the Assistant
+// lane.
+func (o *teamRig) openOutcomes() int {
+ o.t.Helper()
+ return o.rows("SELECT count(*) FROM chat_cards WHERE lane = ? AND kind = ? AND state = ?", wire.LaneAssistant, wire.CardOutcome, wire.CardOpen)
+}
+
+// settledStopped fails unless the request's job card ends stopped, in its
+// words, with nothing open in front of the person.
+func (o *teamRig) settledStopped(request string) {
+ o.t.Helper()
+ o.endUpdates()
+ card := o.jobOf(request, "stopped", func(c wire.AssistantCard) bool { return c.State != wire.JobWorking })
+ if status, detail := jobWords(wire.JobStopped); card.State != wire.JobStopped || card.Result != status || card.Detail != detail {
+ o.t.Fatalf("the job card %+v, want stopped", card)
+ }
+ if n := o.openOutcomes(); n != 0 {
+ o.t.Fatalf("%d go-ahead or Publish cards open", n)
+ }
+}
+
+// TestContractTeamJobSettledStates: Paul's sequence, for a legacy
+// hand-off and a job thread, through each way its going live can end:
+//
+// - the publish failed and was not asked again (the app name was
+// taken): stopped;
+// - the publish failed, was asked again, and the person said Not now:
+// stopped (ruling R19);
+// - the publish ended cancelled with nothing asked again: stopped, a
+// site that did not go live is not done;
+// - the merge the person gave the go-ahead for failed, leaving the task
+// ready to merge with nothing open: stopped, not "Almost ready";
+// - the Publish declined: done.
+func TestContractTeamJobSettledStates(t *testing.T) {
+ cases := []struct {
+ name string
+ run func(o *teamRig, request, id string, merge *wire.DispatchCommand)
+ }{
+ {"publish_failed", func(o *teamRig, request, id string, merge *wire.DispatchCommand) {
+ d := o.paulsPublish(id, merge)
+ o.step("pw-failed", wire.StepReport{TaskID: d.TaskID, StepID: d.StepID, Attempt: d.Attempt, State: wire.StepFailed, Reason: "publish_app_taken", CandidateSHA: d.CandidateSHA, Termination: true, Findings: []wire.Finding{}})
+ o.settledStopped(request)
+ }},
+ {"publish_failed_declined", func(o *teamRig, request, id string, merge *wire.DispatchCommand) {
+ d := o.paulsPublish(id, merge)
+ o.publishReport("pw-failed", d, wire.StepFailed, nil)
+ again := o.assistantCard("the Publish asked again", func(c wire.AssistantCard) bool { return isPublishOutcome(c) && c.State == wire.CardOpen })
+ o.endUpdates()
+ if ready := o.jobOf(request, "ready", nil); ready.State != wire.JobReady {
+ o.t.Fatalf("with the Publish asked again %+v", ready)
+ }
+ if _, err := o.a.Answer(o.ctx, again.ID, wire.ChoiceNotNow, again.Revision); err != nil {
+ o.t.Fatal(err)
+ }
+ o.settledStopped(request)
+ }},
+ {"publish_cancelled", func(o *teamRig, request, id string, merge *wire.DispatchCommand) {
+ d := o.paulsPublish(id, merge)
+ o.exec("UPDATE chat_steps SET state = ?, reason = 'withdrawn', terminated = 1 WHERE id = ?", wire.StepCancelled, d.StepID)
+ if _, err := o.client.PostThread(o.ctx, id, "For the record.", "pw-note"); err != nil {
+ o.t.Fatal(err)
+ }
+ o.settledStopped(request)
+ }},
+ {"merge_failed", func(o *teamRig, request, id string, merge *wire.DispatchCommand) {
+ o.step("pw-m-run", wire.StepReport{TaskID: merge.TaskID, StepID: merge.StepID, Attempt: merge.Attempt, State: wire.StepRunning, BaseSHA: merge.BaseSHA, CandidateSHA: merge.CandidateSHA})
+ o.step("pw-m-fail", wire.StepReport{TaskID: merge.TaskID, StepID: merge.StepID, Attempt: merge.Attempt, State: wire.StepFailed, Reason: "merge_failed", BaseSHA: merge.BaseSHA, CandidateSHA: merge.CandidateSHA, Termination: true})
+ o.wait("ready to merge again", func(c *Conversation) bool { return c.Tasks[id].Stage == wire.StageReadyToMerge })
+ o.settledStopped(request)
+ o.noteFor("the failed merge's note", blockedOn("going live failed, and they need to try it again"))
+ }},
+ {"publish_declined", func(o *teamRig, request, id string, merge *wire.DispatchCommand) {
+ o.mergedStep("pw-m", merge, strings.Repeat("e", 40))
+ o.wait("done", func(c *Conversation) bool { return c.Tasks[id].Stage == wire.StageDone })
+ publish := o.assistantCard("the Publish card", func(c wire.AssistantCard) bool { return isPublishOutcome(c) && c.State == wire.CardOpen })
+ if _, err := o.a.Answer(o.ctx, publish.ID, wire.ChoiceNotNow, publish.Revision); err != nil {
+ o.t.Fatal(err)
+ }
+ o.endUpdates()
+ card := o.jobOf(request, "done", func(c wire.AssistantCard) bool { return c.State != wire.JobWorking && c.State != wire.JobReady })
+ if status, detail := jobWords(wire.JobDone); card.State != wire.JobDone || card.Result != status || card.Detail != detail {
+ o.t.Fatalf("the job card %+v, want done", card)
+ }
+ }},
+ }
+ for _, legacy := range []bool{true, false} {
+ for _, c := range cases {
+ name := "thread/" + c.name
+ if legacy {
+ name = "legacy/" + c.name
+ }
+ t.Run(name, func(t *testing.T) {
+ o := newTeamRig(t)
+ request, id, merge := o.paulsWebsite(legacy)
+ c.run(o, request, id, merge)
+ })
+ }
+ }
+}