Retry one task per nudge and word team_nudge's quote refusal
A nudge on a failed job now tries again exactly one task (ruling R22): the hand-off's earliest one held by a retryable failed step that the person, an owner, created; others wait for the next nudge, and an ineligible task no longer rolls back a retry. Words found in none of the person's messages to the Assistant get a refusal of their own that does not say "in this turn". Budgets re-measured.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
4 files changed,
+63
−23
.rastrillo/budgets.txt+2 −2internal/equipo/chat/handoff.go+17 −18internal/equipo/chat/tools.go+3 −0internal/thintest/assistant_reply_contract_test.go+41 −3
Intent
diff --git a/.rastrillo/budgets.txt b/.rastrillo/budgets.txt| index 9195a8b2..3c4e7254 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 26798 - The instance store shares transaction and authority helpers. Adds job threads, pages, titles, action ledger, job notes, cards, team_reply and team_nudge. Measured 26798 source lines. |
| +size internal/equipo/chat 26800 - The instance store shares transaction and authority helpers. Adds job threads, pages, titles, action ledger, job notes, cards, team_reply and team_nudge. Measured 26800 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 - 27592 Contract and browser tests share one instance harness. Adds the job thread, card lane, page, title, job note, job card, team_reply and team_nudge contracts. Measured 27592 test lines. |
| +size internal/thintest - 27630 Contract and browser tests share one instance harness. Adds the job thread, card lane, page, title, job note, job card, team_reply and team_nudge contracts. Measured 27630 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 bb3ff135..32837760 100644 |
| --- a/internal/equipo/chat/handoff.go |
| +++ b/internal/equipo/chat/handoff.go |
| @@ -354,7 +354,7 @@ func (t *txn) quote(r turnRecord, words string) (string, error) { |
| // maxQuoted messages to the Assistant, compared as quote does, and the |
| // message quoted: the newest that holds them. |
| func (t *txn) quoteAny(person, words string) (text string, from messageRecord, err error) { |
| - refuse := assist.Failure{Code: "not_their_words"} |
| + refuse := teamRefusal{"not_their_words", toolNudgeWords} |
| w, _, _ := folded(words) |
| w = strings.TrimSpace(w) |
| if utf8.RuneCountInString(w) < minQuote { |
| @@ -1585,39 +1585,38 @@ func (s *Store) teamNudge(ctx context.Context, call toolCallRecord, input json.R |
| return out, nil |
| } |
| -// retryFailed tries again each of the hand-off's tasks that a failed step |
| -// the instance can retry holds (needsYou retry), as the person's Retry |
| -// would (retryStep). Only an owner's own task is tried again; anything |
| -// else, or none, is the person's (errNeedsPerson). |
| +// retryFailed tries again exactly one task (ruling R22), as the person's |
| +// Retry would (retryStep): the hand-off's earliest that a failed step the |
| +// instance can retry holds (needsYou retry) and that the person, an |
| +// owner, created. With none, the job is the person's (errNeedsPerson). |
| func (t *txn) retryFailed(h handoffRecord) error { |
| + if err := t.isOwner(h.Person); errors.Is(err, ErrForbidden) { |
| + return errNeedsPerson |
| + } else if err != nil { |
| + return err |
| + } |
| tasks, err := t.handoffTasks(h) |
| if err != nil { |
| return err |
| } |
| - n := 0 |
| for _, k := range tasks { |
| + if k.Creator != h.Person || wire.FinalStage(k.Stage) { |
| + continue |
| + } |
| steps, err := t.steps(k.ID) |
| if err != nil { |
| return err |
| } |
| - if wire.FinalStage(k.Stage) || progressFor(k, steps).needsYou(k) != wire.NeedsRetry { |
| + if progressFor(k, steps).needsYou(k) != wire.NeedsRetry { |
| continue |
| } |
| - if err := t.isOwner(h.Person); errors.Is(err, ErrForbidden) || err == nil && k.Creator != h.Person { |
| - return errNeedsPerson |
| - } else if err != nil { |
| - return err |
| - } |
| switch _, err := t.retryStep(&k, h.Person); { |
| case errors.Is(err, ErrNotRetryable), errors.Is(err, ErrForbidden): |
| - return errNeedsPerson |
| + continue |
| case err != nil: |
| return err |
| } |
| - n++ |
| - } |
| - if n == 0 { |
| - return errNeedsPerson |
| + return nil |
| } |
| - return nil |
| + return errNeedsPerson |
| } |
diff --git a/internal/equipo/chat/tools.go b/internal/equipo/chat/tools.go| index b39cc468..f00c887d 100644 |
| --- a/internal/equipo/chat/tools.go |
| +++ b/internal/equipo/chat/tools.go |
| @@ -62,6 +62,9 @@ const ( |
| toolNotStopped = "That job is not stopped. Nothing needs pushing." |
| toolNeedsPerson = "Only the person can move that job on. Tell them plainly what is needed." |
| toolNudgeLimit = "That job has been nudged twice already. Tell the person in one line that it stopped." |
| + // toolNudgeWords: team_nudge's words found in none of the person's |
| + // messages to the Assistant (quoteAny). |
| + toolNudgeWords = "Not nudged: words must quote something the person said to you in this conversation, word for word, and be more than a couple of letters. Quote them; put anything of yours in context." |
| // nudgeReference is the reference a nudge's message carries in the |
| // thread when the Assistant gave no context (handoffContext). |
| nudgeReference = "this stopped before any work started; the person still wants it." |
diff --git a/internal/thintest/assistant_reply_contract_test.go b/internal/thintest/assistant_reply_contract_test.go| index f70df23d..c2d6466c 100644 |
| --- a/internal/thintest/assistant_reply_contract_test.go |
| +++ b/internal/thintest/assistant_reply_contract_test.go |
| @@ -756,9 +756,7 @@ func TestContractTeamNudgeWords(t *testing.T) { |
| messages := len(o.thread(request)) |
| o.in(update, func() { |
| for i, words := range []string{"make it purple", "make it blue", "qu"} { |
| - if res := o.teamNudge("tw-"+itoa(i), request, words); !res.IsError || res.Code != "not_their_words" { |
| - t.Fatalf("%q: %+v", words, res) |
| - } |
| + refusedWith(t, o.teamNudge("tw-"+itoa(i), request, words), "not_their_words", "Not nudged: words must quote something the person said to you in this conversation, word for word, and be more than a couple of letters. Quote them; put anything of yours in context.") |
| } |
| }) |
| if n := len(o.thread(request)); n != messages || o.nudges(request) != 0 { |
| @@ -929,3 +927,43 @@ func TestContractTeamNudgeToldAgain(t *testing.T) { |
| t.Fatalf("told again %+v", again) |
| } |
| } |
| + |
| +// TestContractTeamNudgeRetryOne (ruling R22): one nudge tries again |
| +// exactly one task: the hand-off's earliest one a failed step the |
| +// instance can retry holds. With two failed, the first nudge retries |
| +// only the first; once the first is done, a second nudge retries the |
| +// second. |
| +func TestContractTeamNudgeRetryOne(t *testing.T) { |
| + o := newTeamRig(t) |
| + request, first, d1 := o.startedInThread("n1") |
| + var second string |
| + var d2 *wire.DispatchCommand |
| + o.in(o.handoffTurn(request), func() { |
| + second = o.record("n1-rec2", "Fix the logo") |
| + if res := o.call("n1-start2", wire.ToolStartTask, map[string]string{"task": second, "brief": "Fix it."}); res.IsError { |
| + t.Fatalf("start %+v", res) |
| + } |
| + _, body := o.expect(wire.FrameDispatch) |
| + d2 = body.(*wire.DispatchCommand) |
| + }) |
| + o.step("n1-fail1", wire.StepReport{TaskID: first, StepID: d1.StepID, Attempt: 1, State: wire.StepFailed, Reason: "provider_failed", Termination: true}) |
| + o.step("n1-fail2", wire.StepReport{TaskID: second, StepID: d2.StepID, Attempt: 1, State: wire.StepFailed, Reason: "provider_failed", Termination: true}) |
| + o.noteFor("the failed note", failedStep(request, 2)) |
| + o.reply(o.turn) |
| + u := o.message(wire.LaneAssistant) |
| + attempts := func(want1, want2 int) { |
| + t.Helper() |
| + if o.rows("SELECT attempt FROM chat_steps WHERE id = ?", d1.StepID) != want1 || o.rows("SELECT attempt FROM chat_steps WHERE id = ?", d2.StepID) != want2 { |
| + t.Fatalf("attempts %d and %d, want %d and %d", o.rows("SELECT attempt FROM chat_steps WHERE id = ?", d1.StepID), o.rows("SELECT attempt FROM chat_steps WHERE id = ?", d2.StepID), want1, want2) |
| + } |
| + } |
| + o.in(u.TurnID, func() { nudged(t, o.teamNudge("n1-nudge1", request, "Login is broken"), request, 1) }) |
| + attempts(2, 1) |
| + o.reply(u.TurnID) |
| + // The first is done; the second still waits on its failed step. |
| + o.exec("UPDATE chat_steps SET state = ?, terminated = 1 WHERE id = ?", wire.StepDone, d1.StepID) |
| + o.exec("UPDATE chat_tasks SET stage = ? WHERE id = ?", wire.StageDone, first) |
| + o.ask("Try the logo again please") |
| + nudged(t, o.teamNudge("n1-nudge2", request, "Login is broken"), request, 0) |
| + attempts(2, 2) |
| +} |