Tell cancelled jobs apart from done ones; say a job's publish in its thread
A job whose followed tasks all ended cancelled is stopped (D5), not done: jobNote gives the Assistant noteCancelled (speak only if the person did not cancel it) instead of noteDone. The R18 rule that a stale project card does not stop an ended job is now commented where it applies. publishEnded writes its result in the task's lane, so a job's publish is said in its thread, never in the person's own conversation; tasks of lane "" are unchanged.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
5 files changed,
+70
−10
.rastrillo/budgets.txt+2 −2internal/equipo/chat/handoff.go+16 −4internal/equipo/chat/publish.go+2 −1internal/equipo/chat/tools.go+1 −0internal/thintest/assistant_team_contract_test.go+49 −3
Intent
diff --git a/.rastrillo/budgets.txt b/.rastrillo/budgets.txt| index c28f4180..a68c1cd3 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 26106 - The instance store shares transaction and authority helpers. Adds job threads, their pages, titles, action ledger and job notes. Measured 26106 source lines. |
| +size internal/equipo/chat 26120 - The instance store shares transaction and authority helpers. Adds job threads, their pages, titles, action ledger and job notes. Measured 26120 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 - 10368 End-to-end scenarios through a real runner and instance, browser drives and the Assistant's job threads included. Measured 10368 test lines. |
| -size internal/thintest - 25998 Contract and browser tests share one instance harness. Adds the job thread, card lane, page, title and job note contracts. Measured 25998 test lines. |
| +size internal/thintest - 26044 Contract and browser tests share one instance harness. Adds the job thread, card lane, page, title and job note contracts. Measured 26044 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 e4aa9303..43d24f7e 100644 |
| --- a/internal/equipo/chat/handoff.go |
| +++ b/internal/equipo/chat/handoff.go |
| @@ -746,6 +746,8 @@ const ( |
| stopNoWork = "no_work" |
| // stopBlocked: only the person can move it on. |
| stopBlocked = "blocked" |
| + // stopCancelled: every followed task ended cancelled (D5): not done. |
| + stopCancelled = "cancelled" |
| // maxNudges is how many times the Assistant pushes a job through |
| // before it tells the person it stopped (D7). |
| maxNudges = 2 |
| @@ -772,7 +774,8 @@ func (t *txn) stopReason(h handoffRecord) (string, error) { |
| // jobStop is stopReason's reason, its cause (blockedLine's: a card's kind, |
| // a task's need, or causeGoingLive) and whether the work ended (settled, |
| -// every followed task final, none of them failing to go live). A task's |
| +// every followed task final, at least one done, none of them failing to |
| +// go live; all of them cancelled is stopCancelled). A task's |
| // need only the person meets comes first; then an open card that stops |
| // the work, which blocks the job whether or not it has settled (it waits |
| // on the person from the moment it is raised), unless the work ended: a |
| @@ -782,7 +785,7 @@ func (t *txn) jobStop(h handoffRecord, settled bool) (reason, cause string, ende |
| if err != nil { |
| return "", "", false, err |
| } |
| - failed := false |
| + failed, done := false, false |
| ended = settled && len(tasks) > 0 |
| for _, k := range tasks { |
| if !settled { |
| @@ -803,6 +806,7 @@ func (t *txn) jobStop(h handoffRecord, settled bool) (reason, cause string, ende |
| if live && newest.Specialist == wire.SpecialistPublish && newest.State == wire.StepFailed { |
| return stopBlocked, causeGoingLive, false, nil |
| } |
| + done = done || k.Stage == wire.StageDone |
| continue |
| } |
| ended = false |
| @@ -815,8 +819,13 @@ func (t *txn) jobStop(h handoffRecord, settled bool) (reason, cause string, ende |
| return stopBlocked, needs, false, nil |
| } |
| } |
| - if ended { |
| + // Ruling R18: once every followed task ended, a project's card left |
| + // open (a stale ships question) is not the job's stop. |
| + switch { |
| + case ended && done: |
| return "", "", true, nil |
| + case ended: |
| + return stopCancelled, "", false, nil |
| } |
| if cause, err = t.blockingCard(h); err != nil || cause != "" { |
| return stopBlocked, cause, false, err |
| @@ -952,7 +961,8 @@ func (t *txn) jobTitle(h handoffRecord) (title, words string, err error) { |
| // jobNote is what a team_update turn tells the Assistant of the job, a |
| // line each: which job, the person's words, then what happened, the |
| // first that holds: a question for it (answer it, or ask the person |
| -// once); a go-ahead or Publish in front of the person; done; stopped |
| +// once); a go-ahead or Publish in front of the person; done; cancelled |
| +// (said only if the person did not cancel it themselves); stopped |
| // with no work, or on a step that can be tried again (push it through |
| // while nudges are left; else tell the person); only the person can |
| // move it on (in plain words, never to be nudged). Then where it stands |
| @@ -999,6 +1009,8 @@ func (t *txn) jobNote(h handoffRecord) (string, error) { |
| lines = append(lines, noteReady) |
| case ended: |
| lines = append(lines, noteDone) |
| + case reason == stopCancelled: |
| + lines = append(lines, noteCancelled) |
| case (reason == stopNoWork || reason == stopFailed) && left <= 0: |
| lines = append(lines, noteNoNudges) |
| case reason == stopNoWork: |
diff --git a/internal/equipo/chat/publish.go b/internal/equipo/chat/publish.go| index 46445b1a..70b68635 100644 |
| --- a/internal/equipo/chat/publish.go |
| +++ b/internal/equipo/chat/publish.go |
| @@ -450,7 +450,8 @@ func (t *txn) publishEnded(k *taskRecord, s *stepRecord) error { |
| return err |
| } |
| if n == 0 { |
| - m := messageRecord{ID: newID("m_"), Person: k.Creator, IdempotencyKey: idem, Role: wire.RoleCoordinator, Text: text, Revision: 1, CreatedAt: t.now()} |
| + // In the task's lane: a job's result is said in its thread. |
| + m := messageRecord{ID: newID("m_"), Person: k.Creator, IdempotencyKey: idem, Role: wire.RoleCoordinator, Text: text, Revision: 1, CreatedAt: t.now(), Lane: k.Lane} |
| if err := t.db.Create(&m).Error; err != nil { |
| return err |
| } |
diff --git a/internal/equipo/chat/tools.go b/internal/equipo/chat/tools.go| index d9b11d69..2eefbe26 100644 |
| --- a/internal/equipo/chat/tools.go |
| +++ b/internal/equipo/chat/tools.go |
| @@ -71,6 +71,7 @@ const ( |
| noteAnswerIt = "If the conversation already holds the answer, answer it yourself with use team_reply {\"request\": %q, \"answer\": ...} and say nothing to the person. If it does not, ask the person once, in your own words, and pass their reply on with team_reply in the turn that receives it." |
| noteReady = "It is ready for the person to try. Tell them in one short line; the go-ahead or Publish is already in front of them." |
| noteDone = "It is done. Tell the person in one short line, with the address if where it stands has one." |
| + noteCancelled = "It was cancelled before it was finished. If the person cancelled it themselves, say nothing; otherwise tell them in one short line that it was cancelled." |
| noteNoWork = "It stopped before any work started. Push it through yourself: use team_nudge {\"request\": %q, \"words\": ...} with words quoted from what the person asked. Nudges left: %d. Say nothing to the person." |
| noteFailed = "A step of it failed and can be tried again. Push it through yourself: use team_nudge {\"request\": %q, \"words\": ...} to have it tried again. Nudges left: %d. Say nothing to the person." |
| noteNoNudges = "It stopped again and no nudges are left. Tell the person in one line that it stopped, and what would help if you know." |
diff --git a/internal/thintest/assistant_team_contract_test.go b/internal/thintest/assistant_team_contract_test.go| index c6a191e5..005d52bb 100644 |
| --- a/internal/thintest/assistant_team_contract_test.go |
| +++ b/internal/thintest/assistant_team_contract_test.go |
| @@ -676,8 +676,9 @@ func TestContractTeamCancel(t *testing.T) { |
| // TestContractTeamUpdate: when the hand-off's work stops, is cancelled |
| // or is done, one team_update turn is queued with the job's note as its |
| -// text (where it stands is the summary); a change while it waits |
| -// rewrites it; a change that leaves the note as it was queues nothing. |
| +// text (where it stands is the summary; cancelled work is never done); a |
| +// change while it waits rewrites it; a change that leaves the note as it |
| +// was queues nothing. |
| // That turn only looks and tells. |
| func TestContractTeamUpdate(t *testing.T) { |
| o := newTeamRig(t) |
| @@ -708,7 +709,10 @@ func TestContractTeamUpdate(t *testing.T) { |
| } |
| summary := o.status("u-status", map[string]any{"request": request})[0].Summary |
| again, notes, dispatched := o.updates() |
| - if !slices.Equal(again, ids) || dispatched[0] || !strings.HasSuffix(notes[0], "\nWhere it stands:\n"+summary) || !strings.HasPrefix(notes[0], jobLine("Login is broken", request, "Login is broken")) || !strings.Contains(summary, equipo.RunnerCopy("assistant.team.stage.cancelled")) { |
| + // Every followed task cancelled is not done (D5): the Assistant hears |
| + // it was cancelled, and speaks only if the person did not cancel it. |
| + cancelled := jobLine("Login is broken", request, "Login is broken") + "It was cancelled before it was finished. If the person cancelled it themselves, say nothing; otherwise tell them in one short line that it was cancelled.\nWhere it stands:\n" + summary |
| + if !slices.Equal(again, ids) || dispatched[0] || notes[0] != cancelled || !strings.Contains(summary, equipo.RunnerCopy("assistant.team.stage.cancelled")) { |
| t.Fatalf("after the cancel %v %q %v (summary %q)", again, notes, dispatched, summary) |
| } |
| o.reply(o.turn) |
| @@ -1934,3 +1938,45 @@ func TestContractTeamOpenQuestionsNote(t *testing.T) { |
| t.Fatalf("with none open %q", plain.Text) |
| } |
| } |
| + |
| +// TestContractOutcomePublishInThread: what became of a job's publish is |
| +// said in the job's thread (the task's lane), never in the person's own |
| +// conversation (/api/v1/messages). |
| +func TestContractOutcomePublishInThread(t *testing.T) { |
| + o := newTeamRig(t) |
| + id, _, _, _ := o.mergedWebsite("pt", true) |
| + request := o.requestOf(id) |
| + card := o.assistantCard("the publish outcome", isPublishOutcome) |
| + if _, err := o.a.Answer(o.ctx, card.ID, wire.ChoicePublish, card.Revision); err != nil { |
| + t.Fatal(err) |
| + } |
| + d := o.publishDispatch() |
| + if refused := o.lease(o.runner, "pt-start", wire.LeaseCheck{StepID: d.StepID, Attempt: d.Attempt}); refused != "" { |
| + t.Fatalf("start refused %q", refused) |
| + } |
| + o.publishReport("pt-built", d, wire.StepRunning, &wire.PublishResult{Phase: wire.PublishBuilt, Digest: digestA, Files: 2, Bytes: 40}) |
| + if refused := o.lease(o.runner, "pt-deploy", wire.LeaseCheck{StepID: d.StepID, Attempt: d.Attempt, Purpose: wire.LeasePurposePublish, Digest: digestA}); refused != "" { |
| + t.Fatalf("deploy refused %q", refused) |
| + } |
| + site := "https://" + d.Publish.App + ".bds.oncarlos.com/" |
| + o.publishReport("pt-published", d, wire.StepDone, &wire.PublishResult{Phase: wire.PublishDone, App: d.Publish.App, URL: site, Version: "s-eeeeeeeeeeee-x-1", Digest: digestA, Outcome: wire.PublishPublished}) |
| + var said, lane string |
| + o.until("the publish result", func() bool { |
| + return o.inst.DB.Writer().QueryRow("SELECT id, coalesce(lane, '') FROM chat_messages WHERE idempotency_key = ?", "publish:"+d.StepID+":"+itoa(int(d.Attempt))).Scan(&said, &lane) == nil |
| + }) |
| + if lane != wire.JobLane(request) { |
| + t.Fatalf("the publish result is in %q, not the job's thread", lane) |
| + } |
| + page, err := o.client.Messages(o.ctx, "", 50) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + for _, m := range page.Items { |
| + if m.ID == said || strings.Contains(m.Text, site) { |
| + t.Fatalf("the job's publish result in their conversation %+v", m) |
| + } |
| + } |
| + if !slices.ContainsFunc(o.thread(request), func(m wire.Message) bool { return m.ID == said }) { |
| + t.Fatal("the publish result is not in the thread") |
| + } |
| +} |