Gate 1b: failure kinds, sign-out, cancel defeats a late success
Claude failures are classified from the stream: an assistant error that
is an auth error (authentication_failed, oauth_org_not_allowed,
account_on_hold, billing_error) makes the connection sign_in_again and
moves the turn or step; rate-limit retries that run out are quota with
no reset reported. Codex: usageLimitExceeded is quota, unauthorized is
auth, anything else transient (no move).
DELETE /api/v1/connections/{id} signs a connection out: a durable
disconnect frame, the provider's own logout in the home, the binding
dropped, the home deleted, signed_out reported. A cancel recorded
before a sign-in finishes wins; one that arrives after signs the new
connection out on the runner, so nothing the person cancelled stands.
sync carries the runner's connections like hello.
Copy: limited without a reset reads 'Limited, no reset time reported';
the switched line is 'Switched to %s; %s resets %s' (never 'weekly').
Headless A5 (cancel and sign-out), A6/A7 (no reset, auth).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
22 files changed,
+449
−21
internal/equipo/chat/connections.go+36 −1internal/equipo/chat/http.go+12 −0internal/equipo/chat/runner.go+3 −0internal/equipo/copy.go+2 −2internal/fakeclaude/fake.go+15 −0internal/headless/connections_test.go+106 −2internal/runner/connect/choose_test.go+5 −0internal/runner/connect/limits.go+25 −0internal/runner/setup/account_bindings.go+67 −0internal/runner/thin/claude.go+16 −1internal/runner/thin/connector.go+99 −4internal/runner/thin/engineer.go+24 −4internal/runner/thin/link.go+10 −0internal/runner/thin/state.go+1 −1internal/thintest/client.go+5 −0internal/thintest/connections_contract_test.go+1 −1internal/wire/connections.go+11 −0internal/wire/connections_test.go+2 −2internal/wire/frames.go+6 −1internal/wire/wire_test.go+1 −1internal/wire/wiretest/testdata/frames/disconnect.json+1 −0internal/wire/wiretest/testdata/frames/sync.json+1 −1
CI failed — run details
diff --git a/internal/equipo/chat/connections.go b/internal/equipo/chat/connections.go| index 84d9268e..73a55d6a 100644 |
| --- a/internal/equipo/chat/connections.go |
| +++ b/internal/equipo/chat/connections.go |
| @@ -190,7 +190,7 @@ func (t *txn) helloConnections(l Lease, held []wire.HeldConnection) error { |
| // connectionReport applies the runner's word on one of its person's |
| // connection attempts. |
| func (t *txn) connectionReport(l Lease, v *wire.ConnectionReport) error { |
| - if !wire.ConnectReasons[v.Reason] || !slices.Contains([]string{wire.ConnConnecting, wire.ConnHealthy, wire.ConnError, wire.ConnLimited}, v.State) { |
| + if !wire.ConnectReasons[v.Reason] || !slices.Contains([]string{wire.ConnConnecting, wire.ConnHealthy, wire.ConnError, wire.ConnLimited, wire.ConnSignedOut}, v.State) { |
| return ErrInvalid |
| } |
| var r connectionRecord |
| @@ -201,6 +201,14 @@ func (t *txn) connectionReport(l Lease, v *wire.ConnectionReport) error { |
| if err != nil { |
| return err |
| } |
| + if v.State == wire.ConnSignedOut { |
| + // Signed out on the runner: its home and binding are gone. |
| + if r.State == wire.ConnSignedOut { |
| + return nil |
| + } |
| + r.State, r.Reason, r.Prompt, r.Headroom = wire.ConnSignedOut, "", "", "" |
| + return t.saveConnection(&r, false) |
| + } |
| // An attempt that ended stays ended: a late frame changes nothing. |
| if r.State != wire.ConnConnecting { |
| return nil |
| @@ -341,6 +349,33 @@ func (s *Store) CancelConnection(ctx context.Context, person, id string) (out wi |
| return out, err |
| } |
| +// SignOut signs one of the person's connections out (DELETE |
| +// /api/v1/connections/{id}): the runner runs the harness's own logout, |
| +// deletes the home and reports signed_out. An attempt still connecting |
| +// is cancelled instead. |
| +func (s *Store) SignOut(ctx context.Context, person, id string) (out wire.Connection, err error) { |
| + err = s.tx(ctx, func(t *txn) error { |
| + if err := s.authority.CurrentPerson(ctx, t.db); err != nil { |
| + return err |
| + } |
| + var r connectionRecord |
| + if err := t.db.Where("id = ? AND person = ?", id, person).First(&r).Error; errors.Is(err, gorm.ErrRecordNotFound) { |
| + return ErrNotFound |
| + } else if err != nil { |
| + return err |
| + } |
| + out = connectionView(r) |
| + if r.State == wire.ConnSignedOut || r.LocalID == "" { |
| + return nil |
| + } |
| + return t.command(person, wire.FrameDisconnect, wire.DisconnectCommand{Connection: r.ID, Person: person, LocalID: r.LocalID}) |
| + }) |
| + if err == nil && out.State == wire.ConnConnecting { |
| + return s.CancelConnection(ctx, person, id) |
| + } |
| + return out, err |
| +} |
| + |
| // expireAttempts ends attempts that made no progress (a runner that went |
| // away mid-attempt reports nothing). |
| func (t *txn) expireAttempts() error { |
diff --git a/internal/equipo/chat/http.go b/internal/equipo/chat/http.go| index 7c95c70f..bbb25531 100644 |
| --- a/internal/equipo/chat/http.go |
| +++ b/internal/equipo/chat/http.go |
| @@ -85,6 +85,7 @@ func (h *HTTP) Mount(r chi.Router) { |
| r.Post("/connections", h.bearer(h.connect)) |
| r.Get("/connections/{id}", h.thinOr("GET /connections/{id}", thinConnection, h.bearer(h.connection))) |
| r.Post("/connections/{id}/cancel", h.bearer(h.cancelConnection)) |
| + r.Delete("/connections/{id}", h.thinOr("DELETE /connections/{id}", thinConnection, h.bearer(h.signOut))) |
| r.Get("/events", h.events) |
| } |
| @@ -124,6 +125,17 @@ func (h *HTTP) connect(w http.ResponseWriter, r *http.Request, p personapi.Perso |
| writeJSON(w, http.StatusAccepted, out) |
| } |
| +// signOut is DELETE /api/v1/connections/{id}: 202, signed out once the |
| +// runner reports it. |
| +func (h *HTTP) signOut(w http.ResponseWriter, r *http.Request, p personapi.PersonPrincipal) { |
| + out, err := h.Store.SignOut(r.Context(), p.Address, chi.URLParam(r, "id")) |
| + if err != nil { |
| + h.fail(w, r, err) |
| + return |
| + } |
| + writeJSON(w, http.StatusAccepted, out) |
| +} |
| + |
| func (h *HTTP) cancelConnection(w http.ResponseWriter, r *http.Request, p personapi.PersonPrincipal) { |
| out, err := h.Store.CancelConnection(r.Context(), p.Address, chi.URLParam(r, "id")) |
| if err != nil { |
diff --git a/internal/equipo/chat/runner.go b/internal/equipo/chat/runner.go| index 5f6c0451..b86f8536 100644 |
| --- a/internal/equipo/chat/runner.go |
| +++ b/internal/equipo/chat/runner.go |
| @@ -413,6 +413,9 @@ func (t *txn) sync(l Lease, v *wire.Sync) error { |
| if err != nil || primary != l.Runner.RunnerID { |
| return err |
| } |
| + if err := t.helloConnections(l, v.Connections); err != nil { |
| + return err |
| + } |
| if err := t.syncSteps(l, v.Steps); err != nil { |
| return err |
| } |
diff --git a/internal/equipo/copy.go b/internal/equipo/copy.go| index 3d00264f..a5b6694c 100644 |
| --- a/internal/equipo/copy.go |
| +++ b/internal/equipo/copy.go |
| @@ -600,7 +600,7 @@ var pageCopy = map[string]string{ |
| "chat.connections.same_machine": "I am at this machine", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| "chat.connections.cancel": "Cancel", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| "chat.connections.healthy": "Healthy", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| - "chat.connections.limited": "Limited", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| + "chat.connections.limited": "Limited, no reset time reported", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| "chat.connections.limited_until": "Limited until %s", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| "chat.connections.signed_out": "Signed out", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| "chat.connections.sign_in_again": "Needs signing in again", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| @@ -613,7 +613,7 @@ var pageCopy = map[string]string{ |
| "chat.connections.reason.already_connected": "That account is already connected.", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| "chat.connections.offline": "Your runner is offline. Start it to add a connection.", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| "chat.switched": "Switched to %s", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| - "chat.switched_reset": "Switched to %s; %s's limit resets %s", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| + "chat.switched_reset": "Switched to %s; %s resets %s", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| "chat.no_connection": "Nothing can answer right now. %s", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| "chat.no_connection.resets": "%s resets %s", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| "chat.no_connection.limited": "%s is limited", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
diff --git a/internal/fakeclaude/fake.go b/internal/fakeclaude/fake.go| index 0e34724b..9f9bd174 100644 |
| --- a/internal/fakeclaude/fake.go |
| +++ b/internal/fakeclaude/fake.go |
| @@ -661,6 +661,18 @@ func (f *fake) serve(stdin io.Reader, stdout, stderr io.Writer) int { |
| refuse() |
| continue |
| } |
| + // limitnoreset:<email> is a refusal with no reset time reported; |
| + // authrefused:<email> the provider refusing the credential. |
| + if m := noResetWord.FindStringSubmatch(newest); m != nil && m[1] == accountEmail() { |
| + emit(map[string]any{"type": "rate_limit_event", "rate_limit_info": map[string]any{"status": "rejected"}, "uuid": fmt.Sprintf("limit-%d", turn), "session_id": f.session}) |
| + emit(map[string]any{"type": "result", "subtype": "success", "is_error": true, "result": "limit reached", "session_id": session, "num_turns": 1, "usage": map[string]int{"input_tokens": 0, "output_tokens": 0}, "terminal_reason": "completed", "result_index": turn - 1, "uuid": fmt.Sprintf("result-%d", turn)}) |
| + continue |
| + } |
| + if m := authWord.FindStringSubmatch(newest); m != nil && m[1] == accountEmail() { |
| + emit(map[string]any{"type": "assistant", "session_id": f.session, "parent_tool_use_id": nil, "message": map[string]any{"model": f.model, "id": fmt.Sprintf("msg_auth_%d", turn), "type": "message", "role": "assistant", "content": []any{map[string]string{"type": "text", "text": "Invalid API key"}}}, "error": "authentication_failed", "uuid": fmt.Sprintf("assistant-%d", turn)}) |
| + emit(map[string]any{"type": "result", "subtype": "success", "is_error": true, "result": "Invalid API key", "session_id": session, "num_turns": 1, "usage": map[string]int{"input_tokens": 0, "output_tokens": 0}, "terminal_reason": "completed", "result_index": turn - 1, "uuid": fmt.Sprintf("result-%d", turn)}) |
| + continue |
| + } |
| if m := stepLimitWord.FindStringSubmatch(prompt); m != nil && m[1] == accountEmail() && strings.HasPrefix(prompt, "[Equipo: engineering]") { |
| refuse() |
| continue |
| @@ -781,6 +793,9 @@ var moveInPause = regexp.MustCompile(`movein-pause:([0-9]+)`) |
| // limitWord is limit:<email>. |
| var limitWord = regexp.MustCompile(`\blimit:([^\s|]+@[^\s|]+[a-z])`) |
| +var noResetWord = regexp.MustCompile(`\blimitnoreset:([^\s|]+@[^\s|]+[a-z])`) |
| +var authWord = regexp.MustCompile(`\bauthrefused:([^\s|]+@[^\s|]+[a-z])`) |
| + |
| // reviewLimitWord is reviewlimit:<email>, for a Review step only. |
| var reviewLimitWord = regexp.MustCompile(`\breviewlimit:([^\s|]+@[^\s|]+[a-z])`) |
diff --git a/internal/headless/connections_test.go b/internal/headless/connections_test.go| index ce93599d..85b01fe2 100644 |
| --- a/internal/headless/connections_test.go |
| +++ b/internal/headless/connections_test.go |
| @@ -90,7 +90,7 @@ func replyOf(t *testing.T, s *session, turn string) wire.Message { |
| } |
| }) |
| if n != 1 { |
| - t.Fatalf("turn %s has %d replies", turn, n) |
| + t.Fatalf("turn %s has %d replies: %+v", turn, n, s.conv.Turns[turn]) |
| } |
| return out |
| } |
| @@ -102,6 +102,8 @@ func TestHeadlessConnections(t *testing.T) { |
| }{ |
| {"U_usage_rows", connUsageRows}, |
| {"C1_claude_failover", connClaudeFailover}, |
| + {"A6_A7_failure_kinds", connFailureKinds}, |
| + {"A5_cancel_and_sign_out", connCancelAndSignOut}, |
| {"C2_codex_coordinator", connCodexCoordinator}, |
| {"C3_codex_device_code", connCodexDeviceCode}, |
| {"C4_claude_sign_in", connClaudeSignIn}, |
| @@ -137,7 +139,7 @@ func connClaudeFailover(t *testing.T, env *Env, inst *thintest.Instance, r *loca |
| t.Fatalf("not a fresh session on the second account: %q", m.Text) |
| } |
| page := inst.Get(t, "/conversation") |
| - if !strings.Contains(page, "data-switched") || !strings.Contains(page, "Switched to Claude; Claude's limit resets") { |
| + if !strings.Contains(page, "data-switched") || !strings.Contains(page, "Switched to Claude; Claude resets") { |
| t.Fatal("no switched line on the page") |
| } |
| next := s.send(t, "And now?") |
| @@ -473,3 +475,105 @@ func connUsageRows(t *testing.T, env *Env, inst *thintest.Instance, r *localRunn |
| t.Fatalf("cancelled rows %+v", got) |
| } |
| } |
| + |
| +// A6, A7: a refusal with no reset time reported marks the connection |
| +// limited with no reset shown anywhere; the provider refusing the |
| +// credential marks it sign_in_again, never limited; both move the turn. |
| +func connFailureKinds(t *testing.T, env *Env, inst *thintest.Instance, r *localRunner) { |
| + r.addAccount(t, "claude", "claude-2", second) |
| + r.addAccount(t, "claude", "claude-3", "third@example.com") |
| + r.start(t) |
| + s := open(t, env) |
| + sent := s.send(t, "Hello. limitnoreset:"+thintest.Owner) |
| + m := replyOf(t, s, sent.Turn.ID) |
| + if m.Switched == nil || m.Switched.ResetsAt != nil || s.conv.Turns[sent.Turn.ID].Connection != "claude-2" { |
| + t.Fatalf("no-reset switch %+v %+v", m.Switched, s.conv.Turns[sent.Turn.ID]) |
| + } |
| + page := inst.Get(t, "/conversation") |
| + if !strings.Contains(page, ">Switched to Claude</p>") { |
| + t.Fatal("the switched line names a reset that was not reported") |
| + } |
| + auth := s.send(t, "Hello again. authrefused:"+second) |
| + a := replyOf(t, s, auth.Turn.ID) |
| + if a.Switched == nil || a.Switched.ResetsAt != nil || s.conv.Turns[auth.Turn.ID].Connection != "claude-3" { |
| + t.Fatalf("auth switch %+v %+v", a.Switched, s.conv.Turns[auth.Turn.ID]) |
| + } |
| + state := map[string]wire.Connection{} |
| + s.wait(t, "states", time.Minute, func(c *thintest.Conversation) bool { |
| + for _, v := range c.Connections { |
| + state[v.LocalID] = v |
| + } |
| + return state["claude-1"].State == wire.ConnLimited && state["claude-2"].State == wire.ConnSignInAgain |
| + }) |
| + if h := state["claude-1"].Headroom; h != nil && h.ResetsAt != nil { |
| + t.Fatalf("a reset time was invented: %+v", h) |
| + } |
| + page = inst.Get(t, "/conversation/connections") |
| + if !strings.Contains(page, "Limited, no reset time reported") || !strings.Contains(page, "Needs signing in again") { |
| + t.Fatal("connection states not on the page") |
| + } |
| +} |
| + |
| +// codexHomes lists the codex-* homes under the accounts root. |
| +func (r *localRunner) codexHomes() []string { |
| + m, _ := filepath.Glob(filepath.Join(r.root, "accounts", "codex-*")) |
| + return m |
| +} |
| + |
| +func (r *localRunner) hasBinding(t *testing.T, provider string) bool { |
| + for _, b := range r.bindings(t) { |
| + if b["provider"] == provider { |
| + return true |
| + } |
| + } |
| + return false |
| +} |
| + |
| +// A5 and sign-out: a cancel while the person approves at the same moment |
| +// leaves no connection, binding or home behind, whichever came first; a |
| +// connection signed out from the app is gone from the runner and shown |
| +// signed out. |
| +func connCancelAndSignOut(t *testing.T, env *Env, inst *thintest.Instance, r *localRunner) { |
| + r.start(t) |
| + s := open(t, env) |
| + approve := filepath.Join(r.root, "accounts", ".fake-device.json") |
| + c, err := env.Client.Connect(s.ctx, wire.Connect{Provider: "codex"}) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + s.wait(t, "device code", time.Minute, func(cv *thintest.Conversation) bool { return cv.Connections[c.ID].Prompt != nil }) |
| + writeJSON(t, approve, map[string]any{"email": second, "plan": "pro"}) |
| + if _, err = env.Client.CancelConnection(s.ctx, c.ID); err != nil { |
| + t.Fatal(err) |
| + } |
| + deadline := time.Now().Add(30 * time.Second) |
| + for (r.hasBinding(t, "codex") || len(r.codexHomes()) > 0) && time.Now().Before(deadline) { |
| + time.Sleep(200 * time.Millisecond) |
| + } |
| + if r.hasBinding(t, "codex") || len(r.codexHomes()) > 0 { |
| + t.Fatalf("a cancelled attempt left a connection: %v", r.codexHomes()) |
| + } |
| + time.Sleep(time.Second) |
| + if v, _ := env.Client.Connection(s.ctx, c.ID); v.State != wire.ConnError || v.Reason != "cancelled" { |
| + t.Fatalf("cancelled attempt %+v", v) |
| + } |
| + list, _ := env.Client.Connections(s.ctx) |
| + for _, v := range list.Items { |
| + if v.Provider == "codex" && v.State == wire.ConnHealthy { |
| + t.Fatalf("a cancelled Codex connection appeared: %+v", v) |
| + } |
| + } |
| + // Connected, then signed out from the app. |
| + c2, err := env.Client.Connect(s.ctx, wire.Connect{Provider: "codex"}) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + s.wait(t, "healthy", time.Minute, func(cv *thintest.Conversation) bool { return cv.Connections[c2.ID].State == wire.ConnHealthy }) |
| + if _, err = env.Client.SignOut(s.ctx, c2.ID); err != nil { |
| + t.Fatal(err) |
| + } |
| + s.wait(t, "signed out", time.Minute, func(cv *thintest.Conversation) bool { return cv.Connections[c2.ID].State == wire.ConnSignedOut }) |
| + if r.hasBinding(t, "codex") || len(r.codexHomes()) > 0 { |
| + t.Fatal("signed out, but the binding or home stayed") |
| + } |
| +} |
diff --git a/internal/runner/connect/choose_test.go b/internal/runner/connect/choose_test.go| index 754dd44a..bb737935 100644 |
| --- a/internal/runner/connect/choose_test.go |
| +++ b/internal/runner/connect/choose_test.go |
| @@ -110,6 +110,11 @@ func TestCodexRateLimits(t *testing.T) { |
| t.Fatalf("%s: %s, want %s", raw, got, want) |
| } |
| } |
| + for raw, want := range map[string]string{`{"type":"assistant","message":{},"error":"authentication_failed","session_id":"s"}`: FailAuth, `{"type":"assistant","message":{},"error":"billing_error","session_id":"s"}`: FailAuth, `{"type":"assistant","message":{},"error":"server_error","session_id":"s"}`: "", `{"type":"system","subtype":"api_retry","error":"rate_limit","retry_delay_ms":500,"session_id":"s"}`: FailQuota, `{"type":"system","subtype":"api_retry","error":"server_error","session_id":"s"}`: ""} { |
| + if got := ClaudeSignal([]byte(raw)); got != want { |
| + t.Fatalf("%s: %q, want %q", raw, got, want) |
| + } |
| + } |
| if !CodexQuotaError([]byte(`{"message":"x","codexErrorInfo":"usageLimitExceeded"}`)) || CodexQuotaError([]byte(`{"message":"x","codexErrorInfo":"rateLimitExceeded"}`)) || CodexQuotaError([]byte(`{"message":"x","codexErrorInfo":{"httpConnectionFailed":{}}}`)) { |
| t.Fatal("quota error") |
| } |
diff --git a/internal/runner/connect/limits.go b/internal/runner/connect/limits.go| index 2b2b492c..0da15ce7 100644 |
| --- a/internal/runner/connect/limits.go |
| +++ b/internal/runner/connect/limits.go |
| @@ -143,6 +143,31 @@ const ( |
| FailTransient = "transient" |
| ) |
| +// claudeAuth are the assistant message errors that mean the provider |
| +// refused the credential or the account. |
| +var claudeAuth = map[string]bool{"authentication_failed": true, "oauth_org_not_allowed": true, "account_on_hold": true, "billing_error": true} |
| + |
| +// ClaudeSignal reads what a stream-json frame says about the turn's |
| +// failure class: an assistant message whose error is an auth error, or a |
| +// system/api_retry for a rate limit (quota once the retries run out). |
| +func ClaudeSignal(raw []byte) string { |
| + var v struct { |
| + Type string `json:"type"` |
| + Subtype string `json:"subtype"` |
| + Error string `json:"error"` |
| + } |
| + if json.Unmarshal(raw, &v) != nil { |
| + return "" |
| + } |
| + switch { |
| + case v.Type == "assistant" && claudeAuth[v.Error]: |
| + return FailAuth |
| + case v.Type == "system" && v.Subtype == "api_retry" && v.Error == "rate_limit": |
| + return FailQuota |
| + } |
| + return "" |
| +} |
| + |
| // CodexFailure classifies a failed turn's error (codexErrorInfo). |
| func CodexFailure(turnError json.RawMessage) string { |
| var e struct { |
diff --git a/internal/runner/setup/account_bindings.go b/internal/runner/setup/account_bindings.go| index d194ddca..75519557 100644 |
| --- a/internal/runner/setup/account_bindings.go |
| +++ b/internal/runner/setup/account_bindings.go |
| @@ -101,3 +101,70 @@ func SaveAccountBinding(ctx context.Context, path, person, model string, s runne |
| } |
| return f.Sync() |
| } |
| + |
| +// RemoveAccountBinding drops one binding (by id) from the bindings file, |
| +// under the same directory lock and atomic replacement as saving. It |
| +// reports whether the binding was there. |
| +func RemoveAccountBinding(ctx context.Context, path, id string) (bool, error) { |
| + if err := ctx.Err(); err != nil { |
| + return false, err |
| + } |
| + dir := filepath.Dir(path) |
| + f, err := os.Open(dir) |
| + if err != nil { |
| + return false, provider.ErrPolicy |
| + } |
| + defer f.Close() |
| + if err = unix.Flock(int(f.Fd()), unix.LOCK_EX|unix.LOCK_NB); err != nil { |
| + return false, provider.ErrAccountBusy |
| + } |
| + defer unix.Flock(int(f.Fd()), unix.LOCK_UN) |
| + st, err := os.Lstat(path) |
| + if err != nil || !st.Mode().IsRegular() || st.Mode().Perm() != 0600 || st.Size() > 1<<20 { |
| + return false, provider.ErrPolicy |
| + } |
| + in, err := os.Open(path) |
| + if err != nil { |
| + return false, provider.ErrPolicy |
| + } |
| + var rows []AccountBinding |
| + err = runnerproto.DecodeLimit(io.LimitReader(in, 1<<20), &rows, 1<<20) |
| + in.Close() |
| + if err != nil { |
| + return false, provider.ErrIdentity |
| + } |
| + keep := rows[:0] |
| + found := false |
| + for _, row := range rows { |
| + if row.ID == id { |
| + found = true |
| + continue |
| + } |
| + keep = append(keep, row) |
| + } |
| + if !found { |
| + return false, nil |
| + } |
| + out, err := os.CreateTemp(dir, ".accounts-") |
| + if err != nil { |
| + return false, provider.ErrAccountMaintenance |
| + } |
| + defer os.Remove(out.Name()) |
| + defer out.Close() |
| + if err = json.NewEncoder(out).Encode(keep); err == nil { |
| + err = out.Sync() |
| + } |
| + if err == nil { |
| + err = out.Chmod(0600) |
| + } |
| + if err == nil { |
| + err = out.Close() |
| + } |
| + if err == nil { |
| + err = os.Rename(out.Name(), path) |
| + } |
| + if err != nil { |
| + return false, provider.ErrAccountMaintenance |
| + } |
| + return true, f.Sync() |
| +} |
diff --git a/internal/runner/thin/claude.go b/internal/runner/thin/claude.go| index 195fe0dd..b221391e 100644 |
| --- a/internal/runner/thin/claude.go |
| +++ b/internal/runner/thin/claude.go |
| @@ -364,8 +364,10 @@ func (c *claudeCoordinator) Turn(ctx context.Context, in TurnInput, emit func(st |
| c.stop(false) |
| return c.ended(ctx, tctx) |
| } |
| - // seen is the newest rate-limit word from the provider in this turn. |
| + // seen is the newest rate-limit word from the provider in this turn; |
| + // signal the failure class the stream showed (auth or quota). |
| var seen *connect.Limit |
| + signal := "" |
| for { |
| select { |
| case <-tctx.Done(): |
| @@ -390,6 +392,9 @@ func (c *claudeCoordinator) Turn(ctx context.Context, in TurnInput, emit func(st |
| c.stop(false) |
| return TurnResult{Reason: "policy_rejected"} |
| } |
| + if sig := connect.ClaudeSignal(ev.Payload); sig != "" { |
| + signal = sig |
| + } |
| switch ev.Kind { |
| case "session.init": |
| if err := claude.ValidateInit(p.policy, c.account.Model, ev.Payload); err != nil { |
| @@ -421,6 +426,16 @@ func (c *claudeCoordinator) Turn(ctx context.Context, in TurnInput, emit func(st |
| case "turn.completed", "turn.failed": |
| res, ok := claude.ParseResult(ev.Payload) |
| rows := connect.ClaudeRows(ev.Payload) |
| + if !ok || res.Failed { |
| + if signal == connect.FailQuota && (seen == nil || !seen.Limited) { |
| + // Rate-limit retries ran out: quota, no reset reported. |
| + seen = &connect.Limit{Limited: true} |
| + } |
| + if signal == connect.FailAuth { |
| + proven := c.stop(false) |
| + return TurnResult{Reason: "sign_in_again", SignIn: true, Proven: proven, Usage: rows} |
| + } |
| + } |
| if !ok || res.Failed { |
| proven := c.stop(false) |
| // Refused on quota: the provider said so with a |
diff --git a/internal/runner/thin/connector.go b/internal/runner/thin/connector.go| index 1f7be2d4..13415f07 100644 |
| --- a/internal/runner/thin/connector.go |
| +++ b/internal/runner/thin/connector.go |
| @@ -6,6 +6,7 @@ import ( |
| "errors" |
| "log/slog" |
| "os" |
| + "os/exec" |
| "path/filepath" |
| "slices" |
| "sync" |
| @@ -14,12 +15,13 @@ import ( |
| "amadan.net/oficina/equipo/internal/runner" |
| "amadan.net/oficina/equipo/internal/runner/connect" |
| "amadan.net/oficina/equipo/internal/runner/provider" |
| + runnersetup "amadan.net/oficina/equipo/internal/runner/setup" |
| "amadan.net/oficina/equipo/internal/wire" |
| "golang.org/x/sys/unix" |
| ) |
| const connectSchema = ` |
| -CREATE TABLE IF NOT EXISTS connect_attempts (id TEXT PRIMARY KEY, person TEXT NOT NULL, provider TEXT NOT NULL, same_machine INTEGER NOT NULL DEFAULT 0, state TEXT NOT NULL, home TEXT NOT NULL DEFAULT '', created_at TEXT NOT NULL); |
| +CREATE TABLE IF NOT EXISTS connect_attempts (id TEXT PRIMARY KEY, person TEXT NOT NULL, provider TEXT NOT NULL, same_machine INTEGER NOT NULL DEFAULT 0, state TEXT NOT NULL, home TEXT NOT NULL DEFAULT '', local_id TEXT NOT NULL DEFAULT '', cancelled INTEGER NOT NULL DEFAULT 0, created_at TEXT NOT NULL); |
| ` |
| // ConnectLimit ends an attempt the person did not finish (spec §2.1: ten |
| @@ -129,14 +131,85 @@ func (c *Connector) Cancel(ctx context.Context, frameID string, cmd wire.CancelC |
| if err != nil || !fresh { |
| return err |
| } |
| + // Recorded first, so an attempt that succeeds at the same moment sees |
| + // it before it saves the connection. |
| + if _, err = c.State.db.ExecContext(ctx, "UPDATE connect_attempts SET cancelled=1 WHERE id=?", cmd.Connection); err != nil { |
| + return err |
| + } |
| c.mu.Lock() |
| - defer c.mu.Unlock() |
| - if cancel := c.attempts[cmd.Connection]; cancel != nil { |
| + cancel := c.attempts[cmd.Connection] |
| + c.mu.Unlock() |
| + if cancel != nil { |
| cancel() |
| + return nil |
| + } |
| + // Ended already: a success the person cancelled does not stand (its |
| + // report was dropped by the instance); it is signed out here. |
| + var state, local, person string |
| + err = c.State.db.QueryRowContext(ctx, "SELECT state, local_id, person FROM connect_attempts WHERE id=?", cmd.Connection).Scan(&state, &local, &person) |
| + if err == nil && state == "done" && local != "" { |
| + go c.remove(cmd.Connection, person, local, false) |
| + } |
| + return nil |
| +} |
| + |
| +// Disconnect signs a connection out (DELETE /connections/{id}). |
| +func (c *Connector) Disconnect(ctx context.Context, frameID string, cmd wire.DisconnectCommand) error { |
| + fresh := false |
| + err := c.State.tx(ctx, func(t *sql.Tx) error { |
| + var err error |
| + fresh, err = seen(t, frameID) |
| + return err |
| + }) |
| + if err != nil || !fresh { |
| + return err |
| } |
| + go c.remove(cmd.Connection, cmd.Person, cmd.LocalID, true) |
| 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. |
| +func (c *Connector) remove(connection, person, local string, report 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}) |
| + } |
| + return |
| + } |
| + if lock, err := os.Open(b.ProviderHome); err == nil { |
| + if unix.Flock(int(lock.Fd()), unix.LOCK_EX) == nil { |
| + c.logout(ctx, b) |
| + } |
| + lock.Close() |
| + } |
| + if _, err := runnersetup.RemoveAccountBinding(ctx, c.Runner.AccountBindingsPath, b.ID); err != nil { |
| + c.log("disconnect binding", err) |
| + return |
| + } |
| + 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}) |
| + } |
| +} |
| + |
| +// logout runs the provider's own sign-out in the home. |
| +func (c *Connector) logout(ctx context.Context, b runner.AccountBinding) { |
| + binary, args := c.Runner.ClaudePath, []string{"auth", "logout"} |
| + if b.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()) |
| +} |
| + |
| // report sends progress on an attempt (durable). |
| func (c *Connector) report(r wire.ConnectionReport) { |
| err := c.State.tx(context.Background(), func(t *sql.Tx) error { return c.State.enqueue(t, wire.FrameConnection, "", r) }) |
| @@ -149,7 +222,7 @@ func (c *Connector) report(r wire.ConnectionReport) { |
| // finish reports an attempt's end and marks it done, in one transaction. |
| func (c *Connector) finish(id string, r wire.ConnectionReport) { |
| err := c.State.tx(context.Background(), func(t *sql.Tx) error { |
| - if _, err := t.Exec("UPDATE connect_attempts SET state='done' WHERE id=?", id); err != nil { |
| + if _, err := t.Exec("UPDATE connect_attempts SET state='done', local_id=? WHERE id=?", r.LocalID, id); err != nil { |
| return err |
| } |
| return c.State.enqueue(t, wire.FrameConnection, "", r) |
| @@ -248,6 +321,14 @@ func (c *Connector) run(ctx context.Context, cancel context.CancelFunc, cmd wire |
| fail(reasonOf(err)) |
| return |
| } |
| + // A cancel that came while the sign-in finished wins: nothing is saved. |
| + var cancelled int |
| + _ = c.State.db.QueryRow("SELECT cancelled FROM connect_attempts WHERE id=?", cmd.Connection).Scan(&cancelled) |
| + if cancelled == 1 || ctx.Err() != nil { |
| + c.removeHome(home) |
| + fail(reasonOf(firstErr(ctx.Err(), context.Canceled))) |
| + return |
| + } |
| // The same account connected twice would only split one limit. |
| observed, err := c.identify(ctx, cmd, id, home) |
| if err != nil { |
| @@ -273,6 +354,20 @@ func (c *Connector) run(ctx context.Context, cancel context.CancelFunc, cmd wire |
| r.Headroom = acct.Limits.Headroom |
| } |
| c.finish(cmd.Connection, r) |
| + // Cancelled while it was being saved: it does not stand. |
| + _ = c.State.db.QueryRow("SELECT cancelled FROM connect_attempts WHERE id=?", cmd.Connection).Scan(&cancelled) |
| + if cancelled == 1 { |
| + c.remove(cmd.Connection, cmd.Person, id, false) |
| + } |
| +} |
| + |
| +func firstErr(errs ...error) error { |
| + for _, e := range errs { |
| + if e != nil { |
| + return e |
| + } |
| + } |
| + return nil |
| } |
| var errAlreadyConnected = errors.New("already connected") |
diff --git a/internal/runner/thin/engineer.go b/internal/runner/thin/engineer.go| index afe37bac..4caa40bf 100644 |
| --- a/internal/runner/thin/engineer.go |
| +++ b/internal/runner/thin/engineer.go |
| @@ -195,12 +195,19 @@ func (e *Engineer) Exec(ctx context.Context, r stepRow, progress func(wire.StepR |
| e.observe(b.ID, res) |
| // Refused on quota: only once the namespace's exit is proven does |
| // the step move on, on another connection, from a fresh tree. |
| - if res.limit == nil || !res.terminated || ctx.Err() != nil || e.Conns == nil { |
| + if res.limit == nil && !res.auth || !res.terminated || ctx.Err() != nil || e.Conns == nil { |
| break |
| } |
| - e.Conns.Limit(b.ID, *res.limit) |
| - if rep.Switched == nil { |
| - rep.Switched = e.Conns.LimitedFrom(b.ID) |
| + if res.auth { |
| + e.Conns.SignInAgain(b.ID) |
| + if rep.Switched == nil { |
| + rep.Switched = &wire.Switched{From: b.Provider} |
| + } |
| + } else { |
| + e.Conns.Limit(b.ID, *res.limit) |
| + if rep.Switched == nil { |
| + rep.Switched = e.Conns.LimitedFrom(b.ID) |
| + } |
| } |
| rep.Usage = append(rep.Usage, res.usage(b, r.Attempt)...) |
| avoid = append(avoid, b.ID) |
| @@ -459,6 +466,9 @@ type stepResult struct { |
| // seen is headroom it reported otherwise; tokens what the run used. |
| limit, seen *connect.Limit |
| tokens []wire.Usage |
| + // auth: the provider refused the credential (the connection needs |
| + // signing in again); the step moves like a quota refusal. |
| + auth bool |
| } |
| // usage is the run's usage rows for the step attempt. |
| @@ -654,6 +664,7 @@ func (e *Engineer) converse(ctx context.Context, proc provider.Process, session |
| } |
| written := 0 |
| var seen *connect.Limit |
| + signal := "" |
| for { |
| select { |
| case <-tctx.Done(): |
| @@ -681,6 +692,9 @@ func (e *Engineer) converse(ctx context.Context, proc provider.Process, session |
| if ev.SessionID != session { |
| return stepResult{reason: "policy_rejected", tail: tail.String()} |
| } |
| + if sig := connect.ClaudeSignal(ev.Payload); sig != "" { |
| + signal = sig |
| + } |
| switch ev.Kind { |
| case "session.init": |
| if err := claude.ValidateInit(policy, model, ev.Payload); err != nil { |
| @@ -701,6 +715,12 @@ func (e *Engineer) converse(ctx context.Context, proc provider.Process, session |
| res, ok := claude.ParseResult(ev.Payload) |
| rows := connect.ClaudeRows(ev.Payload) |
| if !ok || res.Failed { |
| + if signal == connect.FailAuth { |
| + return stepResult{reason: "sign_in_again", auth: true, tail: tail.String(), tokens: rows} |
| + } |
| + if signal == connect.FailQuota && (seen == nil || !seen.Limited) { |
| + seen = &connect.Limit{Limited: true} |
| + } |
| if seen != nil && seen.Limited { |
| return stepResult{reason: "limited", limit: seen, tail: tail.String(), tokens: rows} |
| } |
diff --git a/internal/runner/thin/link.go b/internal/runner/thin/link.go| index c0e64f4e..35ba7497 100644 |
| --- a/internal/runner/thin/link.go |
| +++ b/internal/runner/thin/link.go |
| @@ -307,6 +307,9 @@ func (l *Link) session(ctx context.Context) (time.Duration, error) { |
| return 0, err |
| } |
| sync, err := l.State.Sync(ctx) |
| + if err == nil && l.Hello != nil { |
| + sync.Connections = l.Hello().Connections |
| + } |
| if err != nil { |
| return 0, err |
| } |
| @@ -462,6 +465,13 @@ func (l *Link) read(ctx context.Context, c *websocket.Conn) (time.Duration, erro |
| if err = l.Connector.Accept(ctx, f.ID, *v); err != nil { |
| return 0, err |
| } |
| + case *wire.DisconnectCommand: |
| + if l.Connector == nil { |
| + continue |
| + } |
| + if err = l.Connector.Disconnect(ctx, f.ID, *v); err != nil { |
| + return 0, err |
| + } |
| case *wire.CancelConnectCommand: |
| if l.Connector == nil { |
| continue |
diff --git a/internal/runner/thin/state.go b/internal/runner/thin/state.go| index 4a773a1d..595b3b11 100644 |
| --- a/internal/runner/thin/state.go |
| +++ b/internal/runner/thin/state.go |
| @@ -512,7 +512,7 @@ func (s *State) Supersede(ctx context.Context) error { |
| // Sync is the runner's view sent on every connect: runs not yet acked as |
| // finished, and the durable coordinator sessions. |
| func (s *State) Sync(ctx context.Context) (wire.Sync, error) { |
| - out := wire.Sync{Sessions: []wire.SessionState{}, Runs: []wire.Run{}, Steps: []wire.StepRun{}, Asks: []wire.AskRun{}} |
| + out := wire.Sync{Sessions: []wire.SessionState{}, Runs: []wire.Run{}, Steps: []wire.StepRun{}, Asks: []wire.AskRun{}, Connections: []wire.HeldConnection{}} |
| steps, err := s.syncSteps(ctx) |
| if err != nil { |
| return out, err |
diff --git a/internal/thintest/client.go b/internal/thintest/client.go| index 5bb3797b..3e84da0b 100644 |
| --- a/internal/thintest/client.go |
| +++ b/internal/thintest/client.go |
| @@ -178,6 +178,11 @@ func (c *Client) Connection(ctx context.Context, id string) (out wire.Connection |
| return out, c.do(ctx, "GET", "/api/v1/connections/"+id, nil, &out) |
| } |
| +// SignOut signs a connection out. |
| +func (c *Client) SignOut(ctx context.Context, id string) (out wire.Connection, err error) { |
| + return out, c.do(ctx, "DELETE", "/api/v1/connections/"+id, nil, &out) |
| +} |
| + |
| // CancelConnection ends an attempt. |
| func (c *Client) CancelConnection(ctx context.Context, id string) (out wire.Connection, err error) { |
| return out, c.do(ctx, "POST", "/api/v1/connections/"+id+"/cancel", nil, &out) |
diff --git a/internal/thintest/connections_contract_test.go b/internal/thintest/connections_contract_test.go| index f327af98..0be35899 100644 |
| --- a/internal/thintest/connections_contract_test.go |
| +++ b/internal/thintest/connections_contract_test.go |
| @@ -198,7 +198,7 @@ func TestContractHeldTurnAndSwitch(t *testing.T) { |
| t.Fatalf("turn %+v", v) |
| } |
| page = r.inst.Get(t, "/conversation") |
| - if !strings.Contains(page, "Switched to Codex; Claude's limit resets Tue 10:00 UTC") || strings.Contains(page, "data-no-connection") { |
| + if !strings.Contains(page, "Switched to Codex; Claude resets Tue 10:00 UTC") || strings.Contains(page, "data-no-connection") { |
| t.Fatalf("switched line missing from the page") |
| } |
| var rows, input, cached, reasoning int64 |
diff --git a/internal/wire/connections.go b/internal/wire/connections.go| index c731e46e..baa92844 100644 |
| --- a/internal/wire/connections.go |
| +++ b/internal/wire/connections.go |
| @@ -119,8 +119,19 @@ const ( |
| // FrameConnection (runner to instance, durable) reports an attempt's |
| // progress or a connection's change of state. |
| FrameConnection = "connection" |
| + // FrameDisconnect (instance to runner, durable) signs a connection out. |
| + FrameDisconnect = "disconnect" |
| ) |
| +// DisconnectCommand signs one of the person's connections out: the |
| +// harness's own logout, the home deleted, the binding gone. The runner |
| +// answers with a connection report in state signed_out. |
| +type DisconnectCommand struct { |
| + Connection string `json:"connection"` |
| + Person string `json:"person"` |
| + LocalID string `json:"local_id"` |
| +} |
| + |
| // ConnectCommand asks the runner to connect a new account for Person. |
| type ConnectCommand struct { |
| Connection string `json:"connection"` |
diff --git a/internal/wire/connections_test.go b/internal/wire/connections_test.go| index 592d7559..e3654f4a 100644 |
| --- a/internal/wire/connections_test.go |
| +++ b/internal/wire/connections_test.go |
| @@ -38,7 +38,7 @@ func fieldNames(t reflect.Type, seen map[reflect.Type]bool, out *[]string) { |
| func TestConnectionTypesCarryNoSecrets(t *testing.T) { |
| var names []string |
| seen := map[reflect.Type]bool{} |
| - for _, v := range []any{wire.Connection{}, wire.ConnectionList{}, wire.Connect{}, wire.ConnectCommand{}, wire.CancelConnectCommand{}, wire.ConnectionReport{}, wire.Hello{}, wire.Reply{}, wire.TurnReport{}, wire.Snapshot{}, wire.StepReport{}, wire.AnswerReport{}, wire.UsageReport{}} { |
| + for _, v := range []any{wire.Connection{}, wire.ConnectionList{}, wire.Connect{}, wire.ConnectCommand{}, wire.CancelConnectCommand{}, wire.ConnectionReport{}, wire.Hello{}, wire.Reply{}, wire.TurnReport{}, wire.Snapshot{}, wire.StepReport{}, wire.AnswerReport{}, wire.UsageReport{}, wire.DisconnectCommand{}, wire.Sync{}} { |
| fieldNames(reflect.TypeOf(v), seen, &names) |
| } |
| allowed := map[string]bool{"Usage.input_tokens": true, "Usage.output_tokens": true, "Usage.cached_input_tokens": true, "Usage.cache_write_tokens": true, "Usage.reasoning_output_tokens": true} |
| @@ -63,7 +63,7 @@ func TestConnectionTypesCarryNoSecrets(t *testing.T) { |
| // TestConnectionFixturesCarryNoSecrets: the recorded documents a native |
| // app replays hold no secret-shaped key either. |
| func TestConnectionFixturesCarryNoSecrets(t *testing.T) { |
| - for _, name := range []string{"api/connections.json", "api/connection-connecting-codex.json", "api/connect-request.json", "api/event-connection.json", "frames/connect.json", "frames/cancel_connect.json", "frames/connection.json", "frames/hello.json", "frames/reply-usage.json", "frames/usage.json"} { |
| + for _, name := range []string{"api/connections.json", "api/connection-connecting-codex.json", "api/connect-request.json", "api/event-connection.json", "frames/connect.json", "frames/cancel_connect.json", "frames/connection.json", "frames/hello.json", "frames/reply-usage.json", "frames/usage.json", "frames/disconnect.json", "frames/sync.json"} { |
| raw := strings.ToLower(string(wiretest.Fixture(name))) |
| for _, bad := range []string{"token\"", "secret", "credential", "password", "sealed", "_key", "api_key", "access_token", "refresh"} { |
| if strings.Contains(raw, bad) { |
diff --git a/internal/wire/frames.go b/internal/wire/frames.go| index a390297c..b7d4dbc5 100644 |
| --- a/internal/wire/frames.go |
| +++ b/internal/wire/frames.go |
| @@ -59,7 +59,7 @@ type Frame struct { |
| // Durable reports whether a frame must be acked and resent until acked. |
| func (f Frame) Durable() bool { |
| switch f.Type { |
| - case FrameMessage, FrameCancel, FrameReply, FrameTurn, FrameToolCall, FrameToolResult, FrameMoveIn, FrameNotebook, FrameReset, FrameDispatch, FrameCancelStep, FrameStep, FrameRecheck, FrameWatchMerge, FrameMerged, FrameAsk, FrameCancelAsk, FrameAnswer, FrameForgetTask, FrameBranch, FrameConnect, FrameCancelConnect, FrameConnection, FrameUsage: |
| + case FrameMessage, FrameCancel, FrameReply, FrameTurn, FrameToolCall, FrameToolResult, FrameMoveIn, FrameNotebook, FrameReset, FrameDispatch, FrameCancelStep, FrameStep, FrameRecheck, FrameWatchMerge, FrameMerged, FrameAsk, FrameCancelAsk, FrameAnswer, FrameForgetTask, FrameBranch, FrameConnect, FrameCancelConnect, FrameConnection, FrameUsage, FrameDisconnect: |
| return true |
| } |
| return false |
| @@ -142,6 +142,8 @@ func (f Frame) Decode() (any, error) { |
| v = &ConnectionReport{} |
| case FrameUsage: |
| v = &UsageReport{} |
| + case FrameDisconnect: |
| + v = &DisconnectCommand{} |
| default: |
| return nil, fmt.Errorf("%w: frame type %q", ErrStrict, f.Type) |
| } |
| @@ -281,6 +283,9 @@ type Sync struct { |
| Steps []StepRun `json:"steps"` |
| // Asks are the question attempts the runner holds, likewise. |
| Asks []AskRun `json:"asks"` |
| + // Connections are the connections the runner holds, as in hello, so |
| + // a reconnect reconciles them. |
| + Connections []HeldConnection `json:"connections"` |
| } |
| // DeltaReport is streamed coordinator text. |
diff --git a/internal/wire/wire_test.go b/internal/wire/wire_test.go| index 26be3955..c84b1ac3 100644 |
| --- a/internal/wire/wire_test.go |
| +++ b/internal/wire/wire_test.go |
| @@ -33,7 +33,7 @@ func TestFrameFixturesRoundTrip(t *testing.T) { |
| t.Fatalf("%s: round trip\n got %s\nwant %s", name, out, raw) |
| } |
| } |
| - for _, kind := range []string{wire.FrameWelcome, wire.FrameMessage, wire.FrameCancel, wire.FrameDrain, wire.FrameAck, wire.FrameHello, wire.FrameSync, wire.FrameDelta, wire.FrameReply, wire.FrameTurn, wire.FrameLease, wire.FrameToolCall, wire.FrameToolResult, wire.FrameActivity, wire.FrameMoveIn, wire.FrameNotebook, wire.FrameReset, wire.FrameDispatch, wire.FrameCancelStep, wire.FrameStep, wire.FrameRecheck, wire.FrameWatchMerge, wire.FrameMerged, wire.FrameAsk, wire.FrameCancelAsk, wire.FrameAnswer, wire.FrameForgetTask, wire.FrameBranch, wire.FrameConnect, wire.FrameCancelConnect, wire.FrameConnection, wire.FrameUsage} { |
| + for _, kind := range []string{wire.FrameWelcome, wire.FrameMessage, wire.FrameCancel, wire.FrameDrain, wire.FrameAck, wire.FrameHello, wire.FrameSync, wire.FrameDelta, wire.FrameReply, wire.FrameTurn, wire.FrameLease, wire.FrameToolCall, wire.FrameToolResult, wire.FrameActivity, wire.FrameMoveIn, wire.FrameNotebook, wire.FrameReset, wire.FrameDispatch, wire.FrameCancelStep, wire.FrameStep, wire.FrameRecheck, wire.FrameWatchMerge, wire.FrameMerged, wire.FrameAsk, wire.FrameCancelAsk, wire.FrameAnswer, wire.FrameForgetTask, wire.FrameBranch, wire.FrameConnect, wire.FrameCancelConnect, wire.FrameConnection, wire.FrameUsage, wire.FrameDisconnect} { |
| if !seen[kind] { |
| t.Fatalf("no fixture for frame %s", kind) |
| } |
diff --git a/internal/wire/wiretest/testdata/frames/disconnect.json b/internal/wire/wiretest/testdata/frames/disconnect.json| new file mode 100644 |
| index 00000000..9c848c7c |
| --- /dev/null |
| +++ b/internal/wire/wiretest/testdata/frames/disconnect.json |
| @@ -0,0 +1 @@ |
| +{"id":"c43","type":"disconnect","data":{"connection":"cn_0002","person":"owner@example.com","local_id":"codex-1"}} |
diff --git a/internal/wire/wiretest/testdata/frames/sync.json b/internal/wire/wiretest/testdata/frames/sync.json| index 6d5a0f49..676d2ce2 100644 |
| --- a/internal/wire/wiretest/testdata/frames/sync.json |
| +++ b/internal/wire/wiretest/testdata/frames/sync.json |
| @@ -1 +1 @@ |
| -{"id":"r-sync-1","type":"sync","data":{"sessions":[{"person":"owner@example.com","provider":"claude","account":"claude-a","session_id":"00000000-0000-4000-8000-000000000001","last_turn":"t_0001"}],"runs":[{"turn_id":"t_0001","attempt":1,"state":"running"}],"steps":[{"task_id":"tk0001","step_id":"s_0001","attempt":1,"state":"running","candidate_sha":""}],"asks":[{"question_id":"q_0001","attempt":1,"state":"running"}]}} |
| +{"id":"r-sync-1","type":"sync","data":{"sessions":[{"person":"owner@example.com","provider":"claude","account":"claude-a","session_id":"00000000-0000-4000-8000-000000000001","last_turn":"t_0001"}],"runs":[{"turn_id":"t_0001","attempt":1,"state":"running"}],"steps":[{"task_id":"tk0001","step_id":"s_0001","attempt":1,"state":"running","candidate_sha":""}],"asks":[{"question_id":"q_0001","attempt":1,"state":"running"}],"connections":[{"local_id":"claude-a","person":"owner@example.com","provider":"claude","kind":"subscription","label":"owner@example.com","state":"healthy","plan":"","headroom":null}]}} |