Merge thin-v1-conn1 final fixes (568b51f) into thin-v1-ux1
Conflict: the internal/equipo/chat size record keeps both rounds' reasons; 8700.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
9 files changed,
+304
−68
.rastrillo/budgets.txt+1 −1docs/superpowers/plans/CONN1-PROGRESS.md+20 −0internal/equipo/chat/tools.go+76 −30internal/headless/connections_test.go+35 −0internal/runner/thin/connector.go+58 −30internal/runner/thin/connector_test.go+47 −0internal/runner/thin/judge.go+18 −5internal/runner/thin/state.go+8 −0internal/thintest/connections_contract_test.go+41 −2
CI cancelled — superseded by a newer push — run details
Intent
diff --git a/.rastrillo/budgets.txt b/.rastrillo/budgets.txt| index 23644bb2..1d3d58cf 100644 |
| --- a/.rastrillo/budgets.txt |
| +++ b/.rastrillo/budgets.txt |
| @@ -49,7 +49,7 @@ perf GET /api/v1/notebook skip Thin v1 person API: bearer-only JSON for devices; |
| perf GET /api/v1/thinking skip Thin v1 person API: bearer-only JSON for devices; the browser reads thinking words on /settings/thinking. |
| perf GET /api/v1/tasks skip Thin v1 person API: bearer-only JSON for devices; the browser reads tasks through /tasks. |
| perf GET /api/v1/tasks/{id} skip Thin v1 person API: bearer-only JSON for devices; the browser reads a task through /tasks/{id}. |
| -size internal/equipo/chat 8500 - Thin v1 UX1 thinking words adds the per-person set and its API (thinking.go, about 100 lines); measured 8305. Thin v1 UX1 round 3 adds Equipo combining duplicate tasks reversibly (duplicates.go: detection, the in-transaction fold checks, fold, Undo, about 400 lines) and headlines on findings and steps (headline.go); measured 7898. Connections slice 1 adds connection records from hello and attempts, the connect mailbox, the API, usage rows and the turn's mutation ledger (connections.go and tools.go, about 600 lines); measured 7400 after merging UX1. Thin v1 UX1 adds step activity lines, duplicates and their fold, the coordinator at work on a task, project facts from the runner catalog and open merge cards for the pages (inner.go, about 330 lines); measured 6610 with slice 4c's review fixes. Thin v1 slice 4c adds the merge policy, the merge card, the rebase round and duplicate reports (merge.go, about 380 lines). Thin v1 instance core: conversation, projects, tasks, review and, from slice 4b, questions to the specialists (questions.go, about 470 lines) share one store, transaction and event log; splitting would export the transaction internals. Measured 5514 source lines; revisit at the slice 7 sweep. |
| +size internal/equipo/chat 8700 - Thin v1 UX1 thinking words adds the per-person set and its API (thinking.go, about 100 lines); measured 8305. Connections slice 1 review round 2: the mutation ledger matches record_task by subject only and refuses an ambiguous call with the earlier operations, the preference and forget (about 120 lines); measured 8236. Thin v1 UX1 round 3 adds Equipo combining duplicate tasks reversibly (duplicates.go: detection, the in-transaction fold checks, fold, Undo, about 400 lines) and headlines on findings and steps (headline.go); measured 7898. Connections slice 1 adds connection records from hello and attempts, the connect mailbox, the API, usage rows and the turn's mutation ledger (connections.go and tools.go, about 600 lines); measured 7400 after merging UX1. Thin v1 UX1 adds step activity lines, duplicates and their fold, the coordinator at work on a task, project facts from the runner catalog and open merge cards for the pages (inner.go, about 330 lines); measured 6610 with slice 4c's review fixes. Thin v1 slice 4c adds the merge policy, the merge card, the rebase round and duplicate reports (merge.go, about 380 lines). Thin v1 instance core: conversation, projects, tasks, review and, from slice 4b, questions to the specialists (questions.go, about 470 lines) share one store, transaction and event log; splitting would export the transaction internals. Measured 5514 source lines; revisit at the slice 7 sweep. |
| 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. |
diff --git a/docs/superpowers/plans/CONN1-PROGRESS.md b/docs/superpowers/plans/CONN1-PROGRESS.md| index a10f3bf3..382bd3cc 100644 |
| --- a/docs/superpowers/plans/CONN1-PROGRESS.md |
| +++ b/docs/superpowers/plans/CONN1-PROGRESS.md |
| @@ -274,6 +274,26 @@ model output; the waiting turn was cancelled). |
| - CI flake seen once: `TestContractNoRetroactiveMerge` (4c) got a 401 on |
| an Answer; a rerun of the same commit was green. |
| +## Round: Astra round 2 (on fa3860a), the final round (2026-11-08) |
| + |
| +Eight of nine resolved; the three open items, each with a test that |
| +fails first and a mutation shown to fail it: |
| +- Durable sign-out: the cleanup record keeps the home and provider from |
| + before the binding goes until the home is deleted; logout is tried |
| + twice; signed_out is reported only once the home is gone; a replay |
| + after a stop between the binding and the home deletes the home |
| + (TestConnectorSignOutFinishesTheHomeAfterACrash, |
| + TestConnectorNeverReportsSignedOutWhileTheHomeExists). A late cancel |
| + now owes its cleanup before it runs. |
| +- record_task never maps by order: a later attempt's call is the earlier |
| + task in the same project whose title or brief reads like it; like none, |
| + it is new and made; like several, it is refused (code ambiguous) with |
| + the earlier tasks listed, so the model names one or says separate |
| + (TestContractRecordTaskNeverByOrder). separate: true skips matching. |
| +- Review filters by family first: another family's healthy connection |
| + is chosen before preference or headroom; the engineer's family, then |
| + its own account, only when none can (C5_review_other_family_first). |
| + |
| ## Round: Astra round 1 (on 7946111), the Connections page (2026-11-08) |
| Astra's nine findings, each with a test that fails first or a mutation |
diff --git a/internal/equipo/chat/tools.go b/internal/equipo/chat/tools.go| index 0279fdcf..1fecf012 100644 |
| --- a/internal/equipo/chat/tools.go |
| +++ b/internal/equipo/chat/tools.go |
| @@ -28,6 +28,7 @@ const ( |
| toolMovingIn = "While moving in or exploring you only look around and take notes: status, find, search_code, read_file, read_notes and write_note." |
| toolAskedOwner = "Nothing changed yet: the person sees a card asking whether to make this change, and one tap applies it. Do not ask again in your reply." |
| toolNoHome = "New projects have no home now, so there is nothing to clear." |
| + toolAmbiguous = "Nothing was recorded: this reads like more than one task this turn already recorded. If it is one of them, use its task id. If it is a new problem, call record_task again with separate: true." |
| ) |
| // newRepo is the hub's rule for a new repository under the forge host. |
| @@ -63,6 +64,16 @@ func (t *txn) toolCall(l Lease, v *wire.ToolCall) error { |
| } |
| if op != "" { |
| earlier, err := t.earlierOp(person, v, op) |
| + var amb ambiguousOps |
| + if errors.As(err, &amb) { |
| + res := t.reconcile(amb) |
| + res.CallID, res.Person = v.CallID, person |
| + raw, _ := json.Marshal(res) |
| + if err := t.db.Create(&toolCallRecord{CallID: v.CallID, Person: person, TurnID: v.TurnID, Attempt: v.Attempt, ArgsHash: args, Name: v.Name, Result: string(raw), CreatedAt: t.now()}).Error; err != nil { |
| + return err |
| + } |
| + return t.command(person, wire.FrameToolResult, res) |
| + } |
| if err == nil { |
| r, err := t.ownTurn(l, v.TurnID) |
| if err != nil && !errors.Is(err, ErrNotFound) && !errors.Is(err, ErrForbidden) { |
| @@ -141,11 +152,12 @@ func (t *txn) mutationOp(person string, v *wire.ToolCall) (string, error) { |
| // earlierOp is the call of the turn that already made this mutation, in |
| // any attempt. For record_task it is the task the turn recorded with the |
| -// same arguments; else, from an earlier attempt, the best title or brief |
| -// match by the rule similar open tasks use, else the first an earlier |
| -// attempt recorded that this attempt has not matched yet. Within one |
| -// attempt record_task's own similar-task answer keeps one thing one task, |
| -// and separate: true makes another on purpose. |
| +// same arguments; else, from an earlier attempt, the one task in the same |
| +// project whose title or brief reads like it by the rule similar open |
| +// tasks use, never by order alone; like none, it is new and runs; like |
| +// several, it is ambiguous and refused with the list (ambiguousOps). |
| +// Within one attempt record_task's own similar-task answer keeps one |
| +// thing one task, and separate: true makes another on purpose. |
| func (t *txn) earlierOp(person string, v *wire.ToolCall, op string) (toolCallRecord, error) { |
| var earlier toolCallRecord |
| if op != "task_record" { |
| @@ -163,24 +175,27 @@ func (t *txn) earlierOp(person string, v *wire.ToolCall, op string) (toolCallRec |
| return earlier, err |
| } |
| var in struct { |
| - Title string `json:"title"` |
| - Brief string `json:"brief"` |
| + Title string `json:"title"` |
| + Brief string `json:"brief"` |
| + Repo string `json:"repo"` |
| + Separate bool `json:"separate"` |
| } |
| _ = json.Unmarshal(v.Args, &in) |
| args := argsHash(v.Args) |
| nt, nb := significant(in.Title), significant(in.Title+" "+in.Brief) |
| - best := -1.0 |
| + var like []toolCallRecord |
| + seen := map[string]bool{} |
| for _, r := range rows { |
| if r.ArgsHash == args { |
| return r, nil |
| } |
| - if r.Attempt >= v.Attempt { |
| + if r.Attempt >= v.Attempt || in.Separate { |
| // Within an attempt, a task like an open one is answered by |
| - // record_task itself (similar tasks, or separate on purpose). |
| + // record_task itself (similar tasks); separate is on purpose. |
| continue |
| } |
| task := madeTask(r) |
| - if task == "" { |
| + if task == "" || seen[task] { |
| continue |
| } |
| k, err := t.loadTask(task) |
| @@ -190,32 +205,63 @@ func (t *txn) earlierOp(person string, v *wire.ToolCall, op string) (toolCallRec |
| if err != nil { |
| return earlier, err |
| } |
| + // The same kind of operation on the same subject: the project, |
| + // and a title or brief that reads like it. |
| + if in.Repo != "" && k.ProjectID != "" && !t.sameProject(k.ProjectID, in.Repo) { |
| + continue |
| + } |
| ts, tn := overlap(nt, significant(k.Title)) |
| bs, bn := overlap(nb, significant(k.Title+" "+k.Brief)) |
| - if score := max(ts, bs*0.9); (ts >= 0.6 && tn >= 2 || bs >= 0.5 && bn >= 3) && score > best { |
| - earlier, best = r, score |
| + if ts >= 0.6 && tn >= 2 || bs >= 0.5 && bn >= 3 { |
| + seen[task] = true |
| + like = append(like, r) |
| } |
| } |
| - if best >= 0 { |
| - return earlier, nil |
| + switch len(like) { |
| + case 0: |
| + // Like nothing the turn recorded: a new task, made. |
| + return earlier, gorm.ErrRecordNotFound |
| + case 1: |
| + return like[0], nil |
| } |
| - // A later attempt records again what the turn already recorded, in |
| - // its own words, in order: the first task earlier attempts recorded |
| - // that no call of this attempt has matched yet. |
| - if v.Attempt > 1 { |
| - claimed := map[string]bool{} |
| - for _, r := range rows { |
| - if task := madeTask(r); r.Attempt == v.Attempt && task != "" { |
| - claimed[task] = true |
| - } |
| - } |
| - for _, r := range rows { |
| - if task := madeTask(r); r.Attempt < v.Attempt && task != "" && !claimed[task] { |
| - return r, nil |
| - } |
| + return earlier, ambiguousOps{like} |
| +} |
| + |
| +// ambiguousOps: a call reads like more than one operation the turn |
| +// already made. It is refused with the list, so the model names the one |
| +// it means. |
| +type ambiguousOps struct{ ops []toolCallRecord } |
| + |
| +func (ambiguousOps) Error() string { return "the call reads like more than one earlier operation" } |
| + |
| +// reconcile is the refusal for an ambiguous call: the earlier operations |
| +// it reads like, by task, title and link. |
| +func (t *txn) reconcile(a ambiguousOps) wire.ToolResult { |
| + type earlier struct { |
| + Task string `json:"task"` |
| + Title string `json:"title"` |
| + Link string `json:"link"` |
| + } |
| + var out []earlier |
| + for _, r := range a.ops { |
| + task := madeTask(r) |
| + k, err := t.loadTask(task) |
| + if err != nil { |
| + continue |
| } |
| + out = append(out, earlier{Task: k.ID, Title: k.Title, Link: TaskLink(k.ID)}) |
| + } |
| + raw, _ := json.Marshal(map[string]any{"earlier": out, "note": toolAmbiguous}) |
| + return wire.ToolResult{IsError: true, Code: "ambiguous", Text: string(raw)} |
| +} |
| + |
| +// sameProject reports whether a task's project is the repository named. |
| +func (t *txn) sameProject(projectID, repo string) bool { |
| + var p projectRecord |
| + if t.db.Where("id = ?", projectID).First(&p).Error != nil { |
| + return true |
| } |
| - return earlier, gorm.ErrRecordNotFound |
| + return ProjectName(p.Repo) == ProjectName(repo) |
| } |
| // onceInAttempt: kinds the ledger also holds to once within an attempt |
diff --git a/internal/headless/connections_test.go b/internal/headless/connections_test.go| index e0bbabcd..ca38d769 100644 |
| --- a/internal/headless/connections_test.go |
| +++ b/internal/headless/connections_test.go |
| @@ -116,6 +116,7 @@ func TestHeadlessConnections(t *testing.T) { |
| {"C5_engineering_waits", connEngineeringWaits}, |
| {"C5_review_auth", connReviewAuth}, |
| {"P1_preference", connPreference}, |
| + {"C5_review_other_family_first", connReviewOtherFamilyFirst}, |
| {"C6_no_connection", connNoConnection}, |
| } { |
| t.Run(sc.name, func(t *testing.T) { |
| @@ -425,6 +426,40 @@ func connReviewOnCodex(t *testing.T, env *Env, inst *thintest.Instance, r *local |
| } |
| } |
| +// Astra round 2: Engineering on Claude-A, with Claude-B and Codex-C |
| +// healthy and Claude preferred: Review goes to Codex-C, the other family, |
| +// before preference and headroom are looked at. |
| +func connReviewOtherFamilyFirst(t *testing.T, env *Env, inst *thintest.Instance, r *localRunner) { |
| + r.addAccount(t, "claude", "claude-2", "claude-b@example.com") |
| + r.addAccount(t, "codex", "codex-1", second) |
| + r.start(t) |
| + s := open(t, env) |
| + s.keep() |
| + if _, err := env.Client.SetPreferences(s.ctx, wire.Preferences{Provider: "claude"}); err != nil { |
| + t.Fatal(err) |
| + } |
| + time.Sleep(2 * time.Second) |
| + text := "tool:record_task:oficina/sample|Fix the README typo|teh\ntool:start_task:$task|Fix it. edit:README.md|teh panes|the panes" |
| + sent := s.send(t, text) |
| + id := s.taskOf(t, sent.Turn.ID) |
| + var eng, review wire.Step |
| + s.wait(t, "review done", 5*time.Minute, func(c *thintest.Conversation) bool { |
| + for _, st := range c.Tasks[id].Steps { |
| + switch { |
| + case st.Specialist == wire.SpecialistEngineering: |
| + eng = c.Steps[st.ID] |
| + case st.Specialist == wire.SpecialistReview && wire.StepTerminal(c.Steps[st.ID].State): |
| + review = c.Steps[st.ID] |
| + return true |
| + } |
| + } |
| + return false |
| + }) |
| + if eng.Account != "claude-1" || review.State != wire.StepDone || review.Account != "codex-1" || review.ReviewLabel != wire.ReviewOtherFamily { |
| + t.Fatalf("engineering on %s, review %+v", eng.Account, review) |
| + } |
| +} |
| + |
| // stepUsage is a step's usage rows as attempt/outcome/connection. |
| func stepUsage(t *testing.T, inst *thintest.Instance, step string) string { |
| t.Helper() |
diff --git a/internal/runner/thin/connector.go b/internal/runner/thin/connector.go| index 499f4fca..1c6ef8f7 100644 |
| --- a/internal/runner/thin/connector.go |
| +++ b/internal/runner/thin/connector.go |
| @@ -64,6 +64,9 @@ type Connector struct { |
| type cleanup struct { |
| connection, person, local string |
| report bool |
| + // home and provider: the signed-in home the sign-out deletes, kept in |
| + // the record from before the binding goes until the home is gone. |
| + home, provider string |
| } |
| func (c *Connector) background(f func()) { |
| @@ -88,7 +91,7 @@ func owe(t *sql.Tx, k cleanup) error { |
| // signed out is marked removed so its local id, reused later, is never |
| // signed out again. |
| func (c *Connector) settle(k cleanup) { |
| - if !c.remove(k.connection, k.person, k.local, k.report) { |
| + if !c.remove(k) { |
| return |
| } |
| _, err := c.State.db.Exec("DELETE FROM connect_cleanups WHERE connection=?", k.connection) |
| @@ -133,14 +136,14 @@ func (c *Connector) Start(ctx context.Context) error { |
| if _, err = c.State.db.ExecContext(ctx, "INSERT INTO connect_cleanups(connection, person, local_id, report, created_at) SELECT id, person, local_id, 0, ? FROM connect_attempts WHERE state='done' AND cancelled=1 AND local_id<>'' ON CONFLICT(connection) DO NOTHING", now()); err != nil { |
| return err |
| } |
| - rows, err = c.State.db.QueryContext(ctx, "SELECT connection, person, local_id, report FROM connect_cleanups ORDER BY created_at") |
| + rows, err = c.State.db.QueryContext(ctx, "SELECT connection, person, local_id, report, home, provider FROM connect_cleanups ORDER BY created_at") |
| if err != nil { |
| return err |
| } |
| var owed []cleanup |
| for rows.Next() { |
| var k cleanup |
| - if err = rows.Scan(&k.connection, &k.person, &k.local, &k.report); err != nil { |
| + if err = rows.Scan(&k.connection, &k.person, &k.local, &k.report, &k.home, &k.provider); err != nil { |
| rows.Close() |
| return err |
| } |
| @@ -248,48 +251,70 @@ func (c *Connector) Disconnect(ctx context.Context, frameID string, cmd wire.Dis |
| return nil |
| } |
| -// remove signs one of the person's connections out: the harness's own |
| -// logout in its home (best effort), the binding dropped, the home |
| -// deleted, its state forgotten; then signed_out is reported. false: the |
| -// binding could not be dropped, and the cleanup is owed still. |
| -func (c *Connector) remove(connection, person, local string, report bool) bool { |
| +// remove signs one of the person's connections out: the home is recorded |
| +// in the cleanup first; then the harness's own logout in it (tried |
| +// twice), the binding dropped, the home deleted, its state forgotten; |
| +// then signed_out is reported. A cleanup replayed after a stop finds the |
| +// home in its record when the binding has gone already. false: something |
| +// is left (the binding, or the home), and the cleanup is owed still; |
| +// success is never reported while the home exists. |
| +func (c *Connector) remove(k cleanup) bool { |
| ctx, cancel := context.WithTimeout(context.Background(), time.Minute) |
| defer cancel() |
| - b, ok := c.Conns.Binding(local) |
| - if !ok || b.PersonID != person { |
| - if report { |
| - c.report(wire.ConnectionReport{Connection: connection, Person: person, LocalID: local, State: wire.ConnSignedOut}) |
| + b, bound := c.Conns.Binding(k.local) |
| + bound = bound && b.PersonID == k.person |
| + if bound { |
| + k.home, k.provider = b.ProviderHome, b.Provider |
| + if _, err := c.State.db.ExecContext(ctx, "UPDATE connect_cleanups SET home=?, provider=? WHERE connection=?", k.home, k.provider, k.connection); err != nil { |
| + c.log("disconnect record", err) |
| + return false |
| } |
| - return true |
| } |
| - if lock, err := os.Open(b.ProviderHome); err == nil { |
| - if unix.Flock(int(lock.Fd()), unix.LOCK_EX) == nil { |
| - c.logout(ctx, b) |
| + if k.home != "" && exists(k.home) { |
| + if lock, err := os.Open(k.home); err == nil { |
| + if unix.Flock(int(lock.Fd()), unix.LOCK_EX) == nil { |
| + if err := c.logout(ctx, k.provider, k.home); err != nil { |
| + c.log("disconnect logout", c.logout(ctx, k.provider, k.home)) |
| + } |
| + } |
| + lock.Close() |
| + } |
| + } |
| + if bound { |
| + if _, err := runnersetup.RemoveAccountBinding(ctx, c.Runner.AccountBindingsPath, b.ID); err != nil { |
| + c.log("disconnect binding", err) |
| + return false |
| } |
| - lock.Close() |
| + c.Conns.Forget(b.ID) |
| + c.Conns.changed() |
| } |
| - if _, err := runnersetup.RemoveAccountBinding(ctx, c.Runner.AccountBindingsPath, b.ID); err != nil { |
| - c.log("disconnect binding", err) |
| - return false |
| + if k.home != "" { |
| + c.removeHome(k.home) |
| + if exists(k.home) { |
| + c.log("disconnect home", errors.New("the home is still there")) |
| + return false |
| + } |
| } |
| - c.removeHome(b.ProviderHome) |
| - c.Conns.Forget(b.ID) |
| - c.Conns.changed() |
| - if report { |
| - c.report(wire.ConnectionReport{Connection: connection, Person: person, LocalID: local, Provider: b.Provider, State: wire.ConnSignedOut}) |
| + if k.report { |
| + c.report(wire.ConnectionReport{Connection: k.connection, Person: k.person, LocalID: k.local, Provider: k.provider, State: wire.ConnSignedOut}) |
| } |
| return true |
| } |
| +func exists(path string) bool { |
| + _, err := os.Lstat(path) |
| + return err == nil |
| +} |
| + |
| // logout runs the provider's own sign-out in the home. |
| -func (c *Connector) logout(ctx context.Context, b runner.AccountBinding) { |
| +func (c *Connector) logout(ctx context.Context, provider_, home string) error { |
| binary, args := c.Runner.ClaudePath, []string{"auth", "logout"} |
| - if b.Provider == wire.ProviderCodex { |
| + if provider_ == wire.ProviderCodex { |
| binary, args = c.Runner.CodexPath, []string{"logout"} |
| } |
| cmd := exec.CommandContext(ctx, binary, args...) |
| - cmd.Dir, cmd.Env = b.ProviderHome, provider.LoginEnvironment(b.Provider, b.ProviderHome) |
| - c.log("disconnect logout", cmd.Run()) |
| + cmd.Dir, cmd.Env = home, provider.LoginEnvironment(provider_, home) |
| + return cmd.Run() |
| } |
| // report sends progress on an attempt (durable). |
| @@ -447,7 +472,10 @@ func (c *Connector) standOrGo(cmd wire.ConnectCommand, id string, lock *os.File) |
| var cancelled int |
| _ = c.State.db.QueryRow("SELECT cancelled FROM connect_attempts WHERE id=?", cmd.Connection).Scan(&cancelled) |
| if cancelled == 1 { |
| - c.settle(cleanup{connection: cmd.Connection, person: cmd.Person, local: id}) |
| + k := cleanup{connection: cmd.Connection, person: cmd.Person, local: id} |
| + err := c.State.tx(context.Background(), func(t *sql.Tx) error { return owe(t, k) }) |
| + c.log("disconnect record", err) |
| + c.settle(k) |
| } |
| } |
diff --git a/internal/runner/thin/connector_test.go b/internal/runner/thin/connector_test.go| index 9cc65b0e..768ccff2 100644 |
| --- a/internal/runner/thin/connector_test.go |
| +++ b/internal/runner/thin/connector_test.go |
| @@ -2,6 +2,7 @@ package thin |
| import ( |
| "context" |
| + "database/sql" |
| "encoding/json" |
| "os" |
| "path/filepath" |
| @@ -191,3 +192,49 @@ func TestConnectorLateCancelLetsGoOfTheLock(t *testing.T) { |
| t.Fatal("the cancelled connection stood") |
| } |
| } |
| + |
| +// Astra round 2: a stop after the binding went and before the home did |
| +// leaves the home in the cleanup's record; the restarted connector |
| +// deletes it and only then reports signed_out. |
| +func TestConnectorSignOutFinishesTheHomeAfterACrash(t *testing.T) { |
| + r := newConnectorRig(t) |
| + if err := r.state.tx(context.Background(), func(tx *sql.Tx) error { |
| + return owe(tx, cleanup{connection: "cn_5", person: connPerson, local: "codex-1", report: true}) |
| + }); err != nil { |
| + t.Fatal(err) |
| + } |
| + if _, err := r.state.db.Exec("UPDATE connect_cleanups SET home=?, provider='codex' WHERE connection='cn_5'", r.home); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := os.WriteFile(r.bindings, []byte("[]"), 0600); err != nil { |
| + t.Fatal(err) |
| + } |
| + r.connector(false) |
| + if _, err := os.Stat(r.home); !os.IsNotExist(err) || r.signedOut() != 1 { |
| + t.Fatalf("home left %v, %d signed_out reports", err, r.signedOut()) |
| + } |
| +} |
| + |
| +// Round 2: a home that cannot be deleted is never reported signed out; |
| +// the cleanup stays owed and finishes once it can. |
| +func TestConnectorNeverReportsSignedOutWhileTheHomeExists(t *testing.T) { |
| + r := newConnectorRig(t) |
| + c := r.connector(true) |
| + if err := c.Disconnect(context.Background(), "f6", wire.DisconnectCommand{Connection: "cn_6", Person: connPerson, LocalID: "codex-1"}); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := os.Chmod(r.root, 0500); err != nil { |
| + t.Fatal(err) |
| + } |
| + r.connector(false) |
| + if err := os.Chmod(r.root, 0700); err != nil { |
| + t.Fatal(err) |
| + } |
| + if _, err := os.Stat(r.home); err != nil || r.signedOut() != 0 { |
| + t.Fatalf("home %v, %d signed_out reports while it exists", err, r.signedOut()) |
| + } |
| + r.connector(false) |
| + if _, err := os.Stat(r.home); !os.IsNotExist(err) || r.signedOut() != 1 || r.bound() { |
| + t.Fatalf("home %v, %d reports, bound %v", err, r.signedOut(), r.bound()) |
| + } |
| +} |
diff --git a/internal/runner/thin/judge.go b/internal/runner/thin/judge.go| index 0466e514..46e64994 100644 |
| --- a/internal/runner/thin/judge.go |
| +++ b/internal/runner/thin/judge.go |
| @@ -649,14 +649,27 @@ func (e *Engineer) reviewOn(ctx context.Context, person, avoid string) (runner.A |
| engineer = b |
| } |
| } |
| - b, _, err := e.Conns.Choose(ctx, person, connect.RoleReview, "", []string{engineer.ID}) |
| - if err != nil { |
| - if b, _, err = e.Conns.Choose(ctx, person, connect.RoleReview, "", nil); err != nil { |
| - return b, "", err |
| + // The family first: only when no connection of another family can |
| + // review does the choice (preference, headroom, order) look at the |
| + // engineer's family, then at its own account. |
| + var same []string |
| + for _, c := range e.Conns.Mine(person) { |
| + if c.Family == engineer.Family { |
| + same = append(same, c.ID) |
| } |
| } |
| + b, _, err := e.Conns.Choose(ctx, person, connect.RoleReview, "", same) |
| + if errors.Is(err, ErrNoConnection) { |
| + b, _, err = e.Conns.Choose(ctx, person, connect.RoleReview, "", []string{engineer.ID}) |
| + } |
| + if errors.Is(err, ErrNoConnection) { |
| + b, _, err = e.Conns.Choose(ctx, person, connect.RoleReview, "", nil) |
| + } |
| + if err != nil { |
| + return b, "", err |
| + } |
| switch { |
| - case b.Provider != engineer.Provider: |
| + case b.Family != engineer.Family: |
| return b, wire.ReviewOtherFamily, nil |
| case b.AccountID != engineer.AccountID: |
| return b, wire.ReviewSameFamily, nil |
diff --git a/internal/runner/thin/state.go b/internal/runner/thin/state.go| index b978e92a..93b749c9 100644 |
| --- a/internal/runner/thin/state.go |
| +++ b/internal/runner/thin/state.go |
| @@ -93,6 +93,14 @@ func OpenState(ctx context.Context, dir string) (*State, error) { |
| d.Close() |
| return nil, err |
| } |
| + // Added in Connections slice 1 review round 2: the home a sign-out |
| + // still has to delete, and its provider, kept until it is gone. |
| + for _, col := range []string{"home", "provider"} { |
| + if _, err = d.ExecContext(ctx, "ALTER TABLE connect_cleanups ADD COLUMN "+col+" TEXT NOT NULL DEFAULT ''"); err != nil && !strings.Contains(err.Error(), "duplicate column") { |
| + d.Close() |
| + return nil, err |
| + } |
| + } |
| s := &State{db: d} |
| if s.prefix, err = s.meta(ctx, "frame_prefix"); err != nil { |
| d.Close() |
diff --git a/internal/thintest/connections_contract_test.go b/internal/thintest/connections_contract_test.go| index 65463d34..0ee3baec 100644 |
| --- a/internal/thintest/connections_contract_test.go |
| +++ b/internal/thintest/connections_contract_test.go |
| @@ -222,7 +222,7 @@ func TestContractWritesReplayAcrossAttempts(t *testing.T) { |
| r := newToolRig(t) |
| before := r.call("s1", wire.ToolStatus, map[string]string{}) |
| added := r.call("a1", wire.ToolAddProject, map[string]string{"repo": "oficina/sample"}) |
| - recorded := r.call("r1", wire.ToolRecordTask, map[string]string{"repo": "oficina/sample", "title": "Fix the typo", "brief": "teh"}) |
| + recorded := r.call("r1", wire.ToolRecordTask, map[string]string{"repo": "oficina/sample", "title": "Fix the README typo", "brief": "The README has teh"}) |
| var rec struct{ Task string } |
| json.Unmarshal([]byte(recorded.Text), &rec) |
| asked := r.call("q1", wire.ToolAskPerson, map[string]any{"question": "Which colour?", "options": []string{"Red", "Blue"}}) |
| @@ -252,7 +252,7 @@ func TestContractWritesReplayAcrossAttempts(t *testing.T) { |
| } |
| for name, call := range map[string]func() wire.ToolResult{ |
| "record_task reworded": func() wire.ToolResult { |
| - return r.call("r2", wire.ToolRecordTask, map[string]string{"repo": "oficina/sample", "title": "Correct the README misspelling", "brief": "The README says teh."}) |
| + return r.call("r2", wire.ToolRecordTask, map[string]string{"repo": "oficina/sample", "title": "Fix the README typo", "brief": "The README says teh."}) |
| }, |
| "ask_person paraphrased": func() wire.ToolResult { |
| return r.call("q2", wire.ToolAskPerson, map[string]any{"question": "What colour would you like?", "options": []string{"Blue", "Red", "Green"}}) |
| @@ -357,3 +357,42 @@ func TestContractRecordTaskMapsBackAcrossAttempts(t *testing.T) { |
| t.Fatalf("attempt 2 mapped B to %s and A to %s (want %s, %s)", b2.Text, a2.Text, b.Text, a.Text) |
| } |
| } |
| + |
| +// Astra round 2: never by order alone. Attempt 1 records A; attempt 2 |
| +// asks for an unrelated B before repeating A: B is made, A's repeat maps |
| +// to A. A call that reads like two earlier tasks is refused with both, |
| +// so the model names the one it means. |
| +func TestContractRecordTaskNeverByOrder(t *testing.T) { |
| + r := newToolRig(t) |
| + r.call("a1", wire.ToolAddProject, map[string]string{"repo": "oficina/sample"}) |
| + aArgs := map[string]string{"repo": "oficina/sample", "title": "Fix the README typo", "brief": "The README says teh panes."} |
| + a := r.call("r1", wire.ToolRecordTask, aArgs) |
| + a2 := r.call("r2", wire.ToolRecordTask, map[string]any{"repo": "oficina/sample", "title": "Fix the README typo in the install section", "brief": "The install section of the README says teh too.", "separate": true}) |
| + if a.IsError || a2.IsError || a2.Replayed { |
| + t.Fatalf("attempt 1 %+v %+v", a, a2) |
| + } |
| + r.runner.Send(r.ctx, "r-wait", wire.FrameTurn, wire.TurnReport{TurnID: r.turn, Attempt: 1, State: wire.TurnWaiting, Reason: "limited"}) |
| + r.runner.Send(r.ctx, "r-run2", wire.FrameTurn, wire.TurnReport{TurnID: r.turn, Attempt: 2, State: wire.TurnRunning}) |
| + r.wait("attempt 2", func(c *Conversation) bool { return c.Turns[r.turn].Attempt == 2 }) |
| + r.attempt = 2 |
| + b := r.call("r3", wire.ToolRecordTask, map[string]string{"repo": "oficina/sample", "title": "Add a dark theme toggle", "brief": "Settings needs a switch for the dark theme."}) |
| + if b.IsError || b.Replayed || b.Code != "recorded" { |
| + t.Fatalf("the unrelated task was not made: %+v", b) |
| + } |
| + again := r.call("r4", wire.ToolRecordTask, aArgs) |
| + if !again.Replayed || again.Text != a.Text { |
| + t.Fatalf("A's repeat mapped to %s, want %s", again.Text, a.Text) |
| + } |
| + both := r.call("r5", wire.ToolRecordTask, map[string]string{"repo": "oficina/sample", "title": "Fix the README typo (teh)", "brief": "The README says teh in two places."}) |
| + var listed struct { |
| + Earlier []struct{ Task string } |
| + } |
| + json.Unmarshal([]byte(both.Text), &listed) |
| + if !both.IsError || both.Code != "ambiguous" || len(listed.Earlier) != 2 { |
| + t.Fatalf("an ambiguous call was not refused with both: %+v", both) |
| + } |
| + tasks, _ := r.client.Tasks(r.ctx) |
| + if len(tasks.Items) != 3 { |
| + t.Fatalf("%d tasks, want A, A2 and B", len(tasks.Items)) |
| + } |
| +} |