Keep jobs stopped short of the end in the Assistant snapshot
Ruling R27: the snapshot also keeps a stopped job card past the newest-50 cutoff while its request is not cancelled and a task it follows is unfinished (a research approval, a retry), with the cards open under it. A cancelled job still drops with the history. TestContractTeamJobSnapshotKeepsActiveJobs adds a job stopped on a research approval beyond the cutoff (kept) beside the cancelled one (dropped); the research stop is shared with TestContractTeamJobStoppedBeforeWork (stoppedOnResearch). Budgets: internal/equipo/chat 26967 source, internal/thintest 27920 test lines.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
3 files changed,
+38
−20
.rastrillo/budgets.txt+2 −2internal/equipo/chat/lane.go+8 −3internal/thintest/assistant_job_track_contract_test.go+28 −15
CI failed — run details
Intent
diff --git a/.rastrillo/budgets.txt b/.rastrillo/budgets.txt| index f37f2e07..1020a70f 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 26962 - The instance store shares transaction and authority helpers. Adds job threads, titles, action ledger, notes, cards, team_reply, team_nudge and job tracking. Measured 26962 source lines. |
| +size internal/equipo/chat 26967 - The instance store shares transaction and authority helpers. Adds job threads, titles, action ledger, notes, cards, team_reply, team_nudge and job tracking. Measured 26967 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 - 10637 End-to-end scenarios through a real runner and instance, browser drives and the Assistant's job threads included (answered and nudged jobs). Measured 10637 test lines. |
| -size internal/thintest - 27907 Contract and browser tests share one instance harness. Adds the job thread, card lane, page, title, note, job card, tracking, team_reply and team_nudge contracts. Measured 27907 test lines. |
| +size internal/thintest - 27920 Contract and browser tests share one instance harness. Adds the job thread, card lane, page, title, note, job card, tracking, team_reply and team_nudge contracts. Measured 27920 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/lane.go b/internal/equipo/chat/lane.go| index 280ec603..969f65e4 100644 |
| --- a/internal/equipo/chat/lane.go |
| +++ b/internal/equipo/chat/lane.go |
| @@ -213,14 +213,19 @@ func (l *LaneStore) Snapshot(ctx context.Context, person string) (out wire.Assis |
| } |
| // withActiveJobs is the Assistant lane's newest cards (rows, newest |
| -// first) with every unfinished job card (working, asking or ready) and |
| +// first) with every unfinished job card (working, asking, ready, or |
| +// stopped short of the end) and |
| // each card open under one (D2), however old, newest first: newer cards |
| // never push a job that still moves, or its go-ahead, off the snapshot. |
| func (t *txn) withActiveJobs(person string, rows []cardRecord) ([]cardRecord, error) { |
| - active := []string{wire.JobWorking, wire.JobAsking, wire.JobReady} |
| + // Ruling R27: stopped too while its request is not cancelled and a |
| + // task it follows is unfinished (a research approval, a retry). |
| + active := t.db.Model(&cardRecord{}).Select("handoff_id").Where("person = ? AND lane = ? AND kind = ?", person, wire.LaneAssistant, wire.CardJob). |
| + Where("(state IN ? OR state = ? AND handoff_id IN (SELECT h.id FROM chat_handoffs h JOIN chat_handoff_tasks ht ON ht.handoff_id = h.id JOIN chat_tasks k ON k.id = ht.task_id WHERE h.state <> ? AND k.stage NOT IN ?))", |
| + []string{wire.JobWorking, wire.JobAsking, wire.JobReady}, wire.JobStopped, handoffCancelled, []string{wire.StageDone, wire.StageCancelled}) |
| var more []cardRecord |
| err := t.db.Where("person = ? AND lane = ? AND (held IS NULL OR held = ?)", person, wire.LaneAssistant, false). |
| - Where("(kind = ? AND state IN ? OR state = ? AND coalesce(source_card, '') <> '' AND handoff_id IN (SELECT handoff_id FROM chat_cards WHERE person = ? AND lane = ? AND kind = ? AND state IN ?))", wire.CardJob, active, wire.CardOpen, person, wire.LaneAssistant, wire.CardJob, active). |
| + Where("(kind = ? OR state = ? AND coalesce(source_card, '') <> '') AND handoff_id IN (?)", wire.CardJob, wire.CardOpen, active). |
| Find(&more).Error |
| if err != nil { |
| return nil, err |
diff --git a/internal/thintest/assistant_job_track_contract_test.go b/internal/thintest/assistant_job_track_contract_test.go| index 43a36098..52416395 100644 |
| --- a/internal/thintest/assistant_job_track_contract_test.go |
| +++ b/internal/thintest/assistant_job_track_contract_test.go |
| @@ -78,16 +78,17 @@ func TestContractHandoffExploreBuildFollowed(t *testing.T) { |
| } |
| } |
| -// TestContractTeamJobStoppedBeforeWork (D5, D6, ruling P5j): a job whose |
| -// research waits for the person to approve its sources before any work |
| -// starts is stopped, as its note says, once the Assistant's team_update |
| -// about it ends, and not before; working again once they approve. |
| -func TestContractTeamJobStoppedBeforeWork(t *testing.T) { |
| - o := newTeamRig(t) |
| +// stoppedOnResearch hands the barber shop's mockups to the team, whose |
| +// thread records a task and asks for research with a source the person |
| +// must approve, before any work starts: once the Assistant's team_update |
| +// about it ends (the job card working until then), the job is stopped. |
| +// It returns the request, the task and the stopped job card. |
| +func (o *teamRig) stoppedOnResearch() (request, id string, stopped wire.AssistantCard) { |
| + t := o.t |
| + t.Helper() |
| o.in(o.own("Bring in research"), func() { o.researchOn() }) |
| o.ask(personWords) |
| request, cmd := o.handoff("rb1", "Make mockups for the barber shop.", "") |
| - var id string |
| o.in(cmd.TurnID, func() { |
| id = o.shopTask("rb") |
| if res := o.research("rb-r", id, "https://maps.example.org/place/barber-shop-on-main-street"); res.IsError { |
| @@ -105,7 +106,17 @@ func TestContractTeamJobStoppedBeforeWork(t *testing.T) { |
| t.Fatalf("while the Assistant's turn runs %+v", now) |
| } |
| o.reply(u.TurnID) |
| - stopped := o.jobOf(request, "stopped", func(c wire.AssistantCard) bool { return c.State == wire.JobStopped }) |
| + stopped = o.jobOf(request, "stopped", func(c wire.AssistantCard) bool { return c.State == wire.JobStopped }) |
| + return request, id, stopped |
| +} |
| + |
| +// TestContractTeamJobStoppedBeforeWork (D5, D6, ruling P5j): a job whose |
| +// research waits for the person to approve its sources before any work |
| +// starts is stopped, as its note says, once the Assistant's team_update |
| +// about it ends, and not before; working again once they approve. |
| +func TestContractTeamJobStoppedBeforeWork(t *testing.T) { |
| + o := newTeamRig(t) |
| + request, id, stopped := o.stoppedOnResearch() |
| if status, detail := jobWords(wire.JobStopped); stopped.Result != status || stopped.Detail != detail { |
| t.Fatalf("stopped %+v", stopped) |
| } |
| @@ -159,12 +170,14 @@ func TestContractTeamJobPreviewExpires(t *testing.T) { |
| } |
| } |
| -// TestContractTeamJobSnapshotKeepsActiveJobs: an unfinished job and the |
| -// go-ahead open under it stay in the Assistant's snapshot however many |
| -// newer cards there are, oldest first as ever; a stopped job older than |
| -// the newest cards does not. |
| +// TestContractTeamJobSnapshotKeepsActiveJobs (ruling R27): an unfinished |
| +// job (one stopped on a research approval too) and the go-ahead open |
| +// under one stay in the Assistant's snapshot however many newer cards |
| +// there are, oldest first as ever; a cancelled job older than the newest |
| +// cards does not. |
| func TestContractTeamJobSnapshotKeepsActiveJobs(t *testing.T) { |
| o := newTeamRig(t) |
| + _, _, research := o.stoppedOnResearch() |
| o.ask("Can we fix a bug in Tito? Login is broken") |
| request, cmd := o.handoff("sk1", "Login is broken", "") |
| base, cand := strings.Repeat("1", 40), strings.Repeat("2", 40) |
| @@ -185,11 +198,11 @@ func TestContractTeamJobSnapshotKeepsActiveJobs(t *testing.T) { |
| if err != nil { |
| t.Fatal(err) |
| } |
| - if n := len(snap.Cards); n != wire.MaxProjectCards+2 || snap.Cards[0].ID != job.ID || snap.Cards[1].ID != ahead.ID || snap.Cards[n-1].ID != "c_newer"+itoa(wire.MaxProjectCards-1) { |
| - t.Fatalf("%d cards, the first %+v %+v; the job %s and its go-ahead %s", n, snap.Cards[0], snap.Cards[1], job.ID, ahead.ID) |
| + if n := len(snap.Cards); n != wire.MaxProjectCards+3 || snap.Cards[0].ID != research.ID || snap.Cards[1].ID != job.ID || snap.Cards[2].ID != ahead.ID || snap.Cards[n-1].ID != "c_newer"+itoa(wire.MaxProjectCards-1) { |
| + t.Fatalf("%d cards, the first %+v %+v %+v; the stopped job %s, the job %s and its go-ahead %s", n, snap.Cards[0], snap.Cards[1], snap.Cards[2], research.ID, job.ID, ahead.ID) |
| } |
| if slices.ContainsFunc(snap.Cards, func(c wire.AssistantCard) bool { return c.ID == stopped.ID }) { |
| - t.Fatalf("a stopped job beyond the newest cards %+v", stopped) |
| + t.Fatalf("a cancelled job beyond the newest cards %+v", stopped) |
| } |
| } |