Refuse a job-thread answer when the runner is too old
Answering a question raised in a job thread makes a turn there. If the person's primary came back below protocol 21 after Connect's fencing ran, nothing could carry that turn. answerQuestion now checks jobRunner first, for the person API and the Assistant's card alike: 409 runner_too_old, the card stays open at its revision, and no message or turn is made. No other person action makes a job-thread turn yet. Budgets re-measured: internal/equipo/chat 25406, internal/thintest 25070.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
3 files changed,
+52
−2
.rastrillo/budgets.txt+2 −2internal/equipo/chat/projects.go+8 −0internal/thintest/assistant_team_contract_test.go+42 −0
Intent
diff --git a/.rastrillo/budgets.txt b/.rastrillo/budgets.txt| index cdb149ac..6fd398e1 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 25398 - The instance store shares transaction and authority helpers. Adds job threads beside the person's own lane. Measured 25398 source lines. |
| +size internal/equipo/chat 25406 - The instance store shares transaction and authority helpers. Adds job threads beside the person's own lane. Measured 25406 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 - 10352 End-to-end scenarios through a real runner and instance, browser drives and the Assistant's included. Measured 10352 test lines. |
| -size internal/thintest - 25028 Contract and browser tests share one instance harness. Adds the job thread hand-off contracts. Measured 25028 test lines. |
| +size internal/thintest - 25070 Contract and browser tests share one instance harness. Adds the job thread hand-off contracts. Measured 25070 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/projects.go b/internal/equipo/chat/projects.go| index 5a0717e3..d6dedef9 100644 |
| --- a/internal/equipo/chat/projects.go |
| +++ b/internal/equipo/chat/projects.go |
| @@ -724,6 +724,14 @@ func (t *txn) answerQuestion(person string, c cardRecord, in wire.AnswerCard) (o |
| if len(options) > 0 && !slices.Contains(options, in.Choice) || c.Kind == wire.CardProject && len(options) == 0 { |
| return out, current, ErrInvalid |
| } |
| + // An answer in a job thread is a turn there: it needs a primary that |
| + // can carry it, now (it may have come back older since the question, |
| + // after Connect's fencing ran). Refused, the card stays open. |
| + if _, job := wire.JobOf(c.Lane); job { |
| + if err := t.jobRunner(person); err != nil { |
| + return out, current, err |
| + } |
| + } |
| // The card points at its answer before the answer is dispatched, so |
| // the coordinator gets the question (or the replaced project) with it. |
| sent, _, err := t.send(c.Lane, person, "card:"+c.ID, in.Choice, nil, func(m messageRecord) error { |
diff --git a/internal/thintest/assistant_team_contract_test.go b/internal/thintest/assistant_team_contract_test.go| index e5308d91..ef391df2 100644 |
| --- a/internal/thintest/assistant_team_contract_test.go |
| +++ b/internal/thintest/assistant_team_contract_test.go |
| @@ -2,6 +2,7 @@ package thintest |
| import ( |
| "encoding/json" |
| + "net/http" |
| "regexp" |
| "slices" |
| "strings" |
| @@ -1343,3 +1344,44 @@ func TestContractHandoffLegacyKeepsItsRoute(t *testing.T) { |
| return o.rows(update, stopped, wire.TurnTeamUpdate, equipo.RunnerCopy("assistant.team.stopped")) == 1 |
| }) |
| } |
| + |
| +// TestContractHandoffAnswerNeedsJobsRunner: a thread's question asked at |
| +// protocol 21 and answered after the primary came back at 20 is refused |
| +// (409 runner_too_old), through the person API and the Assistant's card |
| +// alike: the card stays open at its revision, and no message or turn is |
| +// made that no runner could carry. |
| +func TestContractHandoffAnswerNeedsJobsRunner(t *testing.T) { |
| + o := newTeamRig(t) |
| + o.ask("Can we fix a bug in Tito? Login is broken") |
| + request, cmd := o.handoff("na1", "Login is broken", "") |
| + o.in(cmd.TurnID, func() { |
| + if res := o.call("na-ask", wire.ToolAskPerson, map[string]any{"question": "Which login page?", "options": []string{"Web", "App"}}); res.Code != "asked" { |
| + t.Fatalf("ask %+v", res) |
| + } |
| + }) |
| + o.reply(cmd.TurnID) |
| + card, revision := o.threadQuestion(request) |
| + mirror := o.assistantCard("the question card", func(c wire.AssistantCard) bool { return c.Kind == wire.CardQuestion }) |
| + o.runner.Close() |
| + o.wait("offline", func(c *Conversation) bool { return !c.Runner.Online }) |
| + o.dialAt(wire.Protocol20) |
| + lane := wire.JobLane(request) |
| + before := o.rows("SELECT (SELECT count(*) FROM chat_messages WHERE lane = ?) + (SELECT count(*) FROM chat_turns WHERE lane = ?)", lane, lane) |
| + refusedTooOld := func(what string, err error) { |
| + t.Helper() |
| + var e wire.Error |
| + if s, ok := err.(*ErrStatus); !ok || s.Status != http.StatusConflict || json.Unmarshal(s.Body, &e) != nil || e.Code != "runner_too_old" { |
| + t.Fatalf("%s at 20: %v", what, err) |
| + } |
| + if n := o.rows("SELECT count(*) FROM chat_cards WHERE id = ? AND state = ? AND revision = ?", card, wire.CardOpen, revision); n != 1 { |
| + t.Fatalf("%s at 20: the card changed", what) |
| + } |
| + if n := o.rows("SELECT (SELECT count(*) FROM chat_messages WHERE lane = ?) + (SELECT count(*) FROM chat_turns WHERE lane = ?)", lane, lane); n != before { |
| + t.Fatalf("%s at 20: %d thread rows, %d before", what, n, before) |
| + } |
| + } |
| + _, err := o.client.Answer(o.ctx, card, "Web", revision) |
| + refusedTooOld("the person's answer", err) |
| + _, err = o.a.Answer(o.ctx, mirror.ID, "Web", mirror.Revision) |
| + refusedTooOld("the Assistant card's answer", err) |
| +} |