oficina / equipo Public

Token checks: the real one at connect and Check again only

The hourly pass asks only the CLI's local status, which spends no
request and never clears a rejection. The real check (one small
request) runs at connect and when the person taps Check again, sent to
the runner as a durable check frame; any answered turn or step on the
connection clears sign_in_again too.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by claude agent, operated by paul@keymail.dev 92105191779b2ff9be238f28e3459712b496299d parent 177eae6
21 files changed, +220 −32
  • .rastrillo/budgets.txt +3 −3
  • internal/equipo/app.go +1 −0
  • internal/equipo/chat/connections.go +20 −0
  • internal/equipo/chat/http.go +11 −0
  • internal/equipo/chat_connections.go +11 −0
  • internal/equipo/connections_view.go +4 −0
  • internal/equipo/templates/models.html +2 −2
  • internal/plan3test/person_api_contract_test.go +1 −1
  • internal/runner/thin/connector.go +28 −0
  • internal/runner/thin/conns.go +40 −7
  • internal/runner/thin/engine.go +2 −0
  • internal/runner/thin/engineer.go +3 −0
  • internal/runner/thin/failover.go +2 −0
  • internal/runner/thin/link.go +7 −0
  • internal/runner/thin/token_test.go +24 −17
  • internal/thintest/client.go +5 −0
  • internal/thintest/token_contract_test.go +38 −0
  • internal/wire/connections.go +13 −0
  • internal/wire/frames.go +3 −1
  • internal/wire/wire_test.go +1 −1
  • internal/wire/wiretest/testdata/frames/check.json +1 −0

CI cancelled — superseded by a newer push — run details

diff --git a/.rastrillo/budgets.txt b/.rastrillo/budgets.txt
index 76e7f0d2..7fdb338c 100644
--- a/.rastrillo/budgets.txt
+++ b/.rastrillo/budgets.txt
@@ -14,7 +14,7 @@ perf GET /* skip Unknown private paths render 404; this fallback contains no scr
time internal/equipo/team 60s Plan 3 loaded CI measured 45.985s; niced serial reruns measured 18.079s and 22.031s. Keep migration, recovery, accounting and concurrency assertions; 60s leaves 30 percent headroom above loaded CI.
time internal/equipotest 300s Final fix package rerun measured 187.035s (review 172.4s); 300s gives 60 percent headroom for HTTP, sandbox, authority and final regression coverage.
-size internal/equipo 15300 - Mac runners (Darwin worker) add the one-tap enrolment link, the runners view's self-probes, /install.sh, the outside-the-sandbox label and their copy (about 90 lines); measured 15058. Mac runners add the runner role, the protocol route and the placement minute, then two-phase removal, Remove now and Recover (about 110 lines). Housekeeping slice 1 adds the Housekeeping view beside the Notebook, the digest line and their copy (housekeeping_page.go, about 170 lines); measured 14513. Thin v1 UX1 thinking words adds the settings page and the set registry wiring (thinking_words.go) and 55 strings of phrases; measured 14411. The Connections page to Paul's approved mockup (connections_view.go: what is answering, the preference, rows with headroom, roles, usage and the recovery action, about 300 lines); measured 14268. Merged with UX1 round 3 (duplicate combining with Undo, timeline headlines) beside the Connections page; measured 13895. Connections slice 1 adds the Connections page, the switched line and the no_connection card and their copy (chat_connections.go, about 220 lines). Measured 12269. Thin v1 UX1 adds the inner screens' view model (work_views.go: stage track, badges, timeline, decisions, project facts, about 830 lines), the rich page handlers and their copy (about 170 lines); measured 13263. Thin v1 slice 4c adds the merged line, the merge card and its copy (about 60 lines). Thin v1 slice 4 adds the thin sidebar (rail.go), review and checks lines on the task card and pages, and their copy (about 190 lines). Thin v1 slice 3 adds the task card, the thin Tasks and Projects pages and their actions over the chat store, and their copy (about 280 lines). Thin v1 slice 2 adds activity labels, card copy and card rendering on the chat page (about 250 lines); slice 1 added the chat wiring and page (about 180 lines) beside code its slice 7 sweep deletes (the live hub, the old coordinator); lower then. Task 7 keeps the existing ceiling by moving transaction-bound event lookup into conversation. Measured 10796 source and 437 test lines; roster, database, pending copy and execution wiring remain here.
+size internal/equipo 15400 - Claude token Check again (the page's action and its route); measured 15313. Mac runners (Darwin worker) add the one-tap enrolment link, the runners view's self-probes, /install.sh, the outside-the-sandbox label and their copy (about 90 lines); measured 15058. Mac runners add the runner role, the protocol route and the placement minute, then two-phase removal, Remove now and Recover (about 110 lines). Housekeeping slice 1 adds the Housekeeping view beside the Notebook, the digest line and their copy (housekeeping_page.go, about 170 lines); measured 14513. Thin v1 UX1 thinking words adds the settings page and the set registry wiring (thinking_words.go) and 55 strings of phrases; measured 14411. The Connections page to Paul's approved mockup (connections_view.go: what is answering, the preference, rows with headroom, roles, usage and the recovery action, about 300 lines); measured 14268. Merged with UX1 round 3 (duplicate combining with Undo, timeline headlines) beside the Connections page; measured 13895. Connections slice 1 adds the Connections page, the switched line and the no_connection card and their copy (chat_connections.go, about 220 lines). Measured 12269. Thin v1 UX1 adds the inner screens' view model (work_views.go: stage track, badges, timeline, decisions, project facts, about 830 lines), the rich page handlers and their copy (about 170 lines); measured 13263. Thin v1 slice 4c adds the merged line, the merge card and its copy (about 60 lines). Thin v1 slice 4 adds the thin sidebar (rail.go), review and checks lines on the task card and pages, and their copy (about 190 lines). Thin v1 slice 3 adds the task card, the thin Tasks and Projects pages and their actions over the chat store, and their copy (about 280 lines). Thin v1 slice 2 adds activity labels, card copy and card rendering on the chat page (about 250 lines); slice 1 added the chat wiring and page (about 180 lines) beside code its slice 7 sweep deletes (the live hub, the old coordinator); lower then. Task 7 keeps the existing ceiling by moving transaction-bound event lookup into conversation. Measured 10796 source and 437 test lines; roster, database, pending copy and execution wiring remain here.
size internal/equipotest - 13400 Task 21 repairs historical migration and conversation fixtures after Plan 3. Measured 13024 test lines; the 300s time ceiling is unchanged.
time internal/runner/checks 90s CI worker measured 44.553s (44.6s rounded); 60s gives 34 percent headroom. Shared baseline capture reduces repeated Go runs; retain the CI allowance for sandbox sentinels, timeout and child cleanup. 2026-11-07: loaded CI (host load about 24) measured 66.5s with the package unchanged by thin v1 slice 4 beyond optional check mounts; 90s keeps 35 percent headroom.
time internal/runner 330s Plan 3 CI repair measured 292.120s for the full package (controller CI 472.184s). Parallel plan graphs and removal of repeated progress floods reduced their local targeted run from 146.920s to 30.784s; the original bug graph retains volume coverage. Keep 330s for journal, proxy, recovery and namespace integration, with 13 percent headroom.
@@ -36,7 +36,7 @@ perf GET /releases/* skip Verified runner release file downloads, not browser GE
perf GET /install.sh skip Mac runners: the one-line bootstrap a terminal pipes to sh, not a browser screen.
time internal/runner/containment 15s Plan 3 loaded CI measured 10.817s; niced serial reruns measured 5.773s and 5.750s. The added coordinator mount check has no repeated launches to remove; 15s leaves 38 percent headroom for namespace, process-exit and recovery assertions.
time internal/tryequipo 30s Release starter-set controller K3 records CI runs of 10.8s and 13.1s; 30s retains the guide integration checks with headroom on the shared runner.
-size internal/runner/thin 15000 - Claude token review round 1 adds the token check (tokencheck.go: one minimal turn through the contained launch, because the CLI's status cannot tell a good token from a bad one, about 150 lines) and the saved-binding recovery with its durable undo in token.go; measured 14948. Mac runners slices A and B add protocol negotiation (link.go), the capability report, the start authorization, the pack relay (relay.go), the primary's publication, the worker executor (worker.go) and the test-build fake worker, about 2700 lines on the same step engine. Composer attachments add the chunked receipt with exactly-once writes, the read-only desk delivery and its checks (files.go, about 230 lines), image blocks and localImage inputs, the attachment read through read_file; measured 11736. Connections slice 1 Astra round 1 adds the Codex step path (codexstep.go: Engineering and Review on the pinned app-server in the implement and inspect containment, about 300 lines); measured 11345. Connections slice 1 (after Astra round 1) also keeps a durable ledger of each turn's write tools so a later attempt never repeats one (effects.go), the waiting state between attempts and usage rows per attempt, about 500 lines more; measured 10590 before gate 1d. Connections slice 1 adds the Codex coordinator beside the Claude one (codex.go: the pinned app-server over JSON-RPC in the converse containment, sharing the coordinator base, desk, tool socket and session table), the connection registry over the bindings with health and provider limits (conns.go), in-app sign-in attempts (connector.go) and turn failover and holding (failover.go), about 1500 lines; the pure parts (the choice function, limit parsing, the app-server client, the sign-in flows) live in internal/runner/connect. Measured 10097. Thin v1 UX1 adds step activity lines from the specialist's stream, the repository head and checks gate in the index and project-tagged notes (about 120 lines); measured 8615 with slice 4c's review fixes. Thin v1 slice 4c adds the merge step (mergestep.go, about 190 lines) and the rebase round beside the slice 4b ask fixes. Thin v1 slice 3 adds Engineering steps beside the coordinator: the durable step state and engine (step.go) and the executor that checks out the task tree, runs the CLI in the implement containment, commits and pushes (engineer.go), about 800 lines sharing the coordinator's launch, tool socket and account selection. Measured 5686 source lines. Splitting would export the launch internals; revisit at the slice 7 sweep. Slice 4 adds checks and review on a candidate (judge.go) and the merge watch (merge.go), about 800 lines, sharing the Engineer launch path; measured 6808, 7035 after review round 1 (branch head watch, deadlines, streamed outputs). Slice 4b keeps Engineering and Review sessions and answers the creator's questions from them (ask.go: kept-session and ask state, read-only git tools, the answer stream), about 700 lines on the same launch path.
+size internal/runner/thin 15100 - Claude token round 1 follow-up: the hourly pass stays local, Check again runs the real check; measured 15023. Claude token review round 1 adds the token check (tokencheck.go: one minimal turn through the contained launch, because the CLI's status cannot tell a good token from a bad one, about 150 lines) and the saved-binding recovery with its durable undo in token.go; measured 14948. Mac runners slices A and B add protocol negotiation (link.go), the capability report, the start authorization, the pack relay (relay.go), the primary's publication, the worker executor (worker.go) and the test-build fake worker, about 2700 lines on the same step engine. Composer attachments add the chunked receipt with exactly-once writes, the read-only desk delivery and its checks (files.go, about 230 lines), image blocks and localImage inputs, the attachment read through read_file; measured 11736. Connections slice 1 Astra round 1 adds the Codex step path (codexstep.go: Engineering and Review on the pinned app-server in the implement and inspect containment, about 300 lines); measured 11345. Connections slice 1 (after Astra round 1) also keeps a durable ledger of each turn's write tools so a later attempt never repeats one (effects.go), the waiting state between attempts and usage rows per attempt, about 500 lines more; measured 10590 before gate 1d. Connections slice 1 adds the Codex coordinator beside the Claude one (codex.go: the pinned app-server over JSON-RPC in the converse containment, sharing the coordinator base, desk, tool socket and session table), the connection registry over the bindings with health and provider limits (conns.go), in-app sign-in attempts (connector.go) and turn failover and holding (failover.go), about 1500 lines; the pure parts (the choice function, limit parsing, the app-server client, the sign-in flows) live in internal/runner/connect. Measured 10097. Thin v1 UX1 adds step activity lines from the specialist's stream, the repository head and checks gate in the index and project-tagged notes (about 120 lines); measured 8615 with slice 4c's review fixes. Thin v1 slice 4c adds the merge step (mergestep.go, about 190 lines) and the rebase round beside the slice 4b ask fixes. Thin v1 slice 3 adds Engineering steps beside the coordinator: the durable step state and engine (step.go) and the executor that checks out the task tree, runs the CLI in the implement containment, commits and pushes (engineer.go), about 800 lines sharing the coordinator's launch, tool socket and account selection. Measured 5686 source lines. Splitting would export the launch internals; revisit at the slice 7 sweep. Slice 4 adds checks and review on a candidate (judge.go) and the merge watch (merge.go), about 800 lines, sharing the Engineer launch path; measured 6808, 7035 after review round 1 (branch head watch, deadlines, streamed outputs). Slice 4b keeps Engineering and Review sessions and answers the creator's questions from them (ask.go: kept-session and ask state, read-only git tools, the answer stream), about 700 lines on the same launch path.
time internal/thintest 180s Mac runners slices A and B add role, scoping, migration, placement, withdrawal, transfer and publication contracts, and Astra round 1 eight transition contracts (about 15s; the package measured 126s locally under load). Housekeeping slice 1 adds six contract tests (combine, Undo round trips and the race, Pause, auto-disable, quiet hours, restart while claimed; about 6s); the package measured 67.7s beside other packages locally, so 75s. Thin v1 slice 4c adds the merge, adoption, cancel and retention contract tests (CI measured 35.7s). Thin v1 contract tests: a real instance and a scripted runner per test, fixtures replayed against every request, frame and event. Slice 3 adds the task, step-sync and grant contracts; CI measured 14.805s. 30s keeps room for the slice 4 review contracts. UX1 adds step activity, task source and duplicates, coordinator merging and project facts (four contracts, about 6s); the package measured 34s locally under load, so 40s. UX1's inner screens gallery (two owners, seven tasks, every page) adds about 3s; measured 40.9s locally under load, so 60s.
time internal/runner/mac 30s Mac runners (Darwin worker): real process groups killed after a grace and proven gone (SIGTERM, SIGKILL, the marker sweep), and the probes run end to end with fake srt and xcodebuild, P6 killing a waiting test two seconds after it starts. About 6s alone; loaded CI measured 12.5s.
time internal/runner/thin 45s Thin v1 slice 4 review: real git repositories for the merge and squash checks, a stalled fetch, and a 16 MiB candidate streamed through the review diff and the checks pack (about 5s). Measured 17.8s locally under load. Slice 4b review adds a 16 MiB git output bound, an injected index-pack failure and stall (3s deadline) and held-answer tests; measured 30.3s locally under load. 45s keeps 33 percent headroom.
@@ -63,4 +63,4 @@ perf GET /conversation/attachments/{id} skip Composer attachments: the bytes of
perf GET /conversation/attachments/{id}/preview skip Composer attachments: an image thumbnail inside the conversation; a file, not a screen.
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 Mac runners slice B: TestReleaseRunnerHasNoFakeWorker builds the release runner exactly as make release-runner does and the thin package under the testbuild tag (measured 11.9s locally with a warm cache).
-size internal/thintest - 9000 Mac runners add the role, scoping, migration, placement, withdrawal, transfer and publication contracts (about 900 test lines) beside the thin v1 contracts; one package keeps one instance harness.
+size internal/thintest - 9100 Claude token Check again contract (TestContractCheckAgain); measured 9036. Mac runners add the role, scoping, migration, placement, withdrawal, transfer and publication contracts (about 900 test lines) beside the thin v1 contracts; one package keeps one instance harness.
diff --git a/internal/equipo/app.go b/internal/equipo/app.go
index ba1f85cc..2cc75ca5 100644
--- a/internal/equipo/app.go
+++ b/internal/equipo/app.go
@@ -261,6 +261,7 @@ func RouterWithStore(d *db.DB, cfg Config, mailer mail.Sender, logger *slog.Logg
r.Post("/conversation/connections/{id}/secret", a.connectionsSecret)
r.Post("/conversation/connections/{id}/sign-out", a.connectionsSignOut)
r.Post("/conversation/connections/{id}/forget", a.connectionsForget)
+ r.Post("/conversation/connections/{id}/check", a.connectionsCheck)
r.Post("/conversation/connections/prefer", a.connectionsPrefer)
a.conversationHandler().Routes(r)
a.planHandler().Routes(r)
diff --git a/internal/equipo/chat/connections.go b/internal/equipo/chat/connections.go
index 1b62185d..5b3b7f3e 100644
--- a/internal/equipo/chat/connections.go
+++ b/internal/equipo/chat/connections.go
@@ -487,6 +487,26 @@ func (s *Store) CancelConnection(ctx context.Context, person, id string) (out wi
// /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.
+// CheckConnection is the person's Check again on a connection the runner
+// holds: its real check runs there (for a token, one small request).
+func (s *Store) CheckConnection(ctx context.Context, person, id string) error {
+ return 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
+ }
+ if r.LocalID == "" || r.State == wire.ConnSignedOut || r.State == wire.ConnConnecting {
+ return ErrConflict
+ }
+ return t.commandTo(r.RunnerID, person, wire.FrameCheck, wire.CheckCommand{Connection: r.ID, Person: person, LocalID: r.LocalID})
+ })
+}
+
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 {
diff --git a/internal/equipo/chat/http.go b/internal/equipo/chat/http.go
index f40f69d1..bcad38cc 100644
--- a/internal/equipo/chat/http.go
+++ b/internal/equipo/chat/http.go
@@ -96,6 +96,7 @@ func (h *HTTP) Mount(r chi.Router) {
r.Post("/connections/{id}/secret", h.bearer(h.secret))
r.Delete("/connections/{id}", h.thinOr("DELETE /connections/{id}", thinConnection, h.bearer(h.signOut)))
r.Post("/connections/{id}/forget", h.bearer(h.forget))
+ r.Post("/connections/{id}/check", h.bearer(h.checkConnection))
r.Get("/thinking", h.bearer(h.thinking))
r.Put("/thinking", h.bearer(h.setThinking))
r.Get("/connections/preference", h.bearer(h.preferences))
@@ -151,6 +152,16 @@ func (h *HTTP) signOut(w http.ResponseWriter, r *http.Request, p personapi.Perso
writeJSON(w, http.StatusAccepted, out)
}
+// checkConnection is POST /api/v1/connections/{id}/check: 202, the
+// runner checks it; the state follows in the stream.
+func (h *HTTP) checkConnection(w http.ResponseWriter, r *http.Request, p personapi.PersonPrincipal) {
+ if err := h.Store.CheckConnection(r.Context(), p.Address, chi.URLParam(r, "id")); err != nil {
+ h.fail(w, r, err)
+ return
+ }
+ w.WriteHeader(http.StatusAccepted)
+}
+
// forget is POST /api/v1/connections/{id}/forget: a signed-out record,
// or an attempt that ended, goes from the list (204).
func (h *HTTP) forget(w http.ResponseWriter, r *http.Request, p personapi.PersonPrincipal) {
diff --git a/internal/equipo/chat_connections.go b/internal/equipo/chat_connections.go
index 075a7b4e..5943e109 100644
--- a/internal/equipo/chat_connections.go
+++ b/internal/equipo/chat_connections.go
@@ -260,6 +260,17 @@ func (a *application) connectionsPrefer(w http.ResponseWriter, r *http.Request)
})
}
+// connectionsCheck is a connection's Check again.
+func (a *application) connectionsCheck(w http.ResponseWriter, r *http.Request) {
+ a.chatActionTo(w, r, "/conversation/connections", func(ctx context.Context, address string) error {
+ err := a.store.Chat().CheckConnection(ctx, address, chi.URLParam(r, "id"))
+ if errors.Is(err, chat.ErrConflict) {
+ return nil
+ }
+ return err
+ })
+}
+
// connectionsForget removes a signed-out connection, or an ended
// attempt, from the list.
func (a *application) connectionsForget(w http.ResponseWriter, r *http.Request) {
diff --git a/internal/equipo/connections_view.go b/internal/equipo/connections_view.go
index 52da75ac..747a8f54 100644
--- a/internal/equipo/connections_view.go
+++ b/internal/equipo/connections_view.go
@@ -39,6 +39,9 @@ type connRow struct {
Needs string
Preferred, MakePreferred bool
SignOut, Forget bool
+ // CheckAgain: a token connection that needs signing in again can be
+ // checked again (one small request on the runner).
+ CheckAgain bool
// Note: an attempt that ended, said once.
Note string
}
@@ -145,6 +148,7 @@ func connectionsPage(snap wire.Snapshot, today map[string]int64, prefer wire.Pre
row.Needs, row.Forget = copyText("chat.connections.connect_again"), true
case wire.ConnSignInAgain:
row.Needs, row.RolesNote = copyText("chat.connections.sign_in_again_action"), copyText("chat.connections.roles.sign_in_first")
+ row.CheckAgain = c.Kind == wire.KindToken && c.LocalID != ""
case wire.ConnLimited:
row.RolesNote = copyText("chat.connections.roles.resting_none")
if healthy != "" {
diff --git a/internal/equipo/templates/models.html b/internal/equipo/templates/models.html
index e7e3edb7..0a0ce631 100644
--- a/internal/equipo/templates/models.html
+++ b/internal/equipo/templates/models.html
@@ -67,11 +67,11 @@
{{if .Roles}}<p equipo-conn-roles><span equipo-conn-roles-label>{{copy "chat.connections.serving"}}</span>{{range .Roles}}<span equipo-conn-chip{{if .Live}} data-live{{end}}>{{if .Live}}{{template "conn-star"}}{{end}}{{.Name}}</span>{{end}}</p>{{else}}{{with .RolesNote}}<p equipo-conn-roles><span equipo-conn-roles-note>{{.}}</span></p>{{end}}{{end}}
</div>
<div equipo-conn-side>
-<div equipo-conn-actions>{{if .Needs}}<form method="post" action="/conversation/connections" data-add-form equipo-inline-form><input type="hidden" name="provider" value="{{.Provider}}">{{if eq .Kind "token"}}<input type="hidden" name="kind" value="token">{{end}}<button rst-btn type="submit" data-recover="{{.Provider}}">{{.Needs}}</button></form>{{end}}{{if or .MakePreferred .SignOut .Forget}}<span equipo-conn-quiet>{{template "conn-quiet" .}}</span><details equipo-conn-more><summary aria-label="{{copy "chat.connections.more"}}">{{icon "more-horizontal"}}</summary><div>{{template "conn-quiet" .}}</div></details>{{end}}</div>
+<div equipo-conn-actions>{{if .Needs}}<form method="post" action="/conversation/connections" data-add-form equipo-inline-form><input type="hidden" name="provider" value="{{.Provider}}">{{if eq .Kind "token"}}<input type="hidden" name="kind" value="token">{{end}}<button rst-btn type="submit" data-recover="{{.Provider}}">{{.Needs}}</button></form>{{end}}{{if or .MakePreferred .SignOut .Forget .CheckAgain}}<span equipo-conn-quiet>{{template "conn-quiet" .}}</span><details equipo-conn-more><summary aria-label="{{copy "chat.connections.more"}}">{{icon "more-horizontal"}}</summary><div>{{template "conn-quiet" .}}</div></details>{{end}}</div>
<p equipo-conn-usage>{{if eq .State "signed_out"}}{{printf (copy "chat.connections.tokens_before") .Usage}}{{else}}<b>{{.Usage}}</b>{{.UsageTail}}{{end}}</p>
</div>
</article>{{end}}
-{{define "conn-quiet"}}{{if .MakePreferred}}<form method="post" action="/conversation/connections/prefer" equipo-inline-form><input type="hidden" name="provider" value="{{.Provider}}"><input type="hidden" name="revision" value="{{.PreferRevision}}"><button type="submit" data-make-preferred>{{copy "chat.connections.make_preferred"}}</button></form>{{end}}{{if .SignOut}}<form method="post" action="/conversation/connections/{{.ID}}/sign-out" equipo-inline-form><button type="submit" data-danger data-sign-out>{{copy "chat.connections.sign_out"}}</button></form>{{end}}{{if .Forget}}<form method="post" action="/conversation/connections/{{.ID}}/forget" equipo-inline-form><button type="submit" data-danger data-forget>{{copy "chat.connections.forget"}}</button></form>{{end}}{{end}}
+{{define "conn-quiet"}}{{if .CheckAgain}}<form method="post" action="/conversation/connections/{{.ID}}/check" equipo-inline-form><button type="submit" data-check-again>{{copy "chat.connections.check_again"}}</button></form>{{end}}{{if .MakePreferred}}<form method="post" action="/conversation/connections/prefer" equipo-inline-form><input type="hidden" name="provider" value="{{.Provider}}"><input type="hidden" name="revision" value="{{.PreferRevision}}"><button type="submit" data-make-preferred>{{copy "chat.connections.make_preferred"}}</button></form>{{end}}{{if .SignOut}}<form method="post" action="/conversation/connections/{{.ID}}/sign-out" equipo-inline-form><button type="submit" data-danger data-sign-out>{{copy "chat.connections.sign_out"}}</button></form>{{end}}{{if .Forget}}<form method="post" action="/conversation/connections/{{.ID}}/forget" equipo-inline-form><button type="submit" data-danger data-forget>{{copy "chat.connections.forget"}}</button></form>{{end}}{{end}}
{{define "content"}}
<section equipo-connections data-connections data-cursor="{{.Models.Cursor}}" data-connected="{{copy "chat.connections.connected_big"}}" data-connected-next="{{copy "chat.connections.connected_next"}}">
<header equipo-conn-page-head><h1>{{copy "chat.connections.title"}}</h1>{{if .Models.Rows}}<p>{{copy "chat.connections.lede"}}</p>{{end}}</header>
diff --git a/internal/plan3test/person_api_contract_test.go b/internal/plan3test/person_api_contract_test.go
index c46b9d6a..c0189265 100644
--- a/internal/plan3test/person_api_contract_test.go
+++ b/internal/plan3test/person_api_contract_test.go
@@ -56,7 +56,7 @@ func personAPIContractCoverage(t *testing.T) {
f := newFixture(t)
registered := map[string]bool{}
// Thin v1 conversation routes are contracted by internal/wire fixtures.
- thin := map[string]bool{"GET /messages": true, "POST /messages": true, "GET /turns/{id}": true, "POST /turns/{id}/cancel": true, "GET /snapshot": true, "GET /events": true, "DELETE /projects/{id}": true, "POST /cards/{id}/answer": true, "GET /notebook": true, "POST /notebook/reset": true, "POST /tasks/{id}/retry": true, "POST /tasks/{id}/recover": true, "POST /tasks/{id}/merge": true, "POST /tasks/{id}/duplicate": true, "POST /tasks/{id}/uncombine": true, "GET /thinking": true, "PUT /thinking": true, "POST /tasks/{id}/thread": true, "GET /steps/{id}/log": true, "POST /tasks/{id}/questions": true, "POST /questions/{id}/cancel": true, "POST /connections": true, "POST /connections/{id}/cancel": true, "POST /connections/{id}/secret": true, "POST /connections/{id}/forget": true, "GET /connections/preference": true, "PUT /connections/preference": true, "GET /housekeeping": true, "PUT /housekeeping": true, "PUT /housekeeping/detectors/{id}": true, "GET /housekeeping/actions": true, "POST /housekeeping/actions/{id}/undo": true, "POST /attachments": true, "GET /attachments/{id}": true, "GET /attachments/{id}/preview": true}
+ thin := map[string]bool{"GET /messages": true, "POST /messages": true, "GET /turns/{id}": true, "POST /turns/{id}/cancel": true, "GET /snapshot": true, "GET /events": true, "DELETE /projects/{id}": true, "POST /cards/{id}/answer": true, "GET /notebook": true, "POST /notebook/reset": true, "POST /tasks/{id}/retry": true, "POST /tasks/{id}/recover": true, "POST /tasks/{id}/merge": true, "POST /tasks/{id}/duplicate": true, "POST /tasks/{id}/uncombine": true, "GET /thinking": true, "PUT /thinking": true, "POST /tasks/{id}/thread": true, "GET /steps/{id}/log": true, "POST /tasks/{id}/questions": true, "POST /questions/{id}/cancel": true, "POST /connections": true, "POST /connections/{id}/cancel": true, "POST /connections/{id}/secret": true, "POST /connections/{id}/forget": true, "POST /connections/{id}/check": true, "GET /connections/preference": true, "PUT /connections/preference": true, "GET /housekeeping": true, "PUT /housekeeping": true, "PUT /housekeeping/detectors/{id}": true, "GET /housekeeping/actions": true, "POST /housekeeping/actions/{id}/undo": true, "POST /attachments": true, "GET /attachments/{id}": true, "GET /attachments/{id}/preview": true}
must(t, chi.Walk(f.Store.PersonAPIHandler().(chi.Routes), func(method, path string, _ http.Handler, _ ...func(http.Handler) http.Handler) error {
if thin[method+" "+path] {
return nil
diff --git a/internal/runner/thin/connector.go b/internal/runner/thin/connector.go
index 262d4c3c..c5b7aa3a 100644
--- a/internal/runner/thin/connector.go
+++ b/internal/runner/thin/connector.go
@@ -268,6 +268,34 @@ func (c *Connector) Cancel(ctx context.Context, frameID string, cmd wire.CancelC
return nil
}
+// Check is the person's Check again, once per frame: the connection's
+// real check runs in the background (a token's is a request that takes
+// seconds); its outcome reaches the instance in the next hello.
+func (c *Connector) Check(ctx context.Context, frameID string, cmd wire.CheckCommand) 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
+ }
+ b, ok := c.Conns.Binding(cmd.LocalID)
+ if !ok || b.PersonID != cmd.Person {
+ return nil
+ }
+ c.background(func() {
+ ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
+ defer cancel()
+ c.Conns.CheckAgain(ctx, b.ID)
+ if c.Notify != nil {
+ c.Notify()
+ }
+ })
+ 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
diff --git a/internal/runner/thin/conns.go b/internal/runner/thin/conns.go
index b422ed5d..186a1343 100644
--- a/internal/runner/thin/conns.go
+++ b/internal/runner/thin/conns.go
@@ -412,9 +412,11 @@ func (c *Conns) expiries() map[string]time.Time {
// Loop refreshes each Claude and Codex home on start and hourly under its
// lock, with the same CLI-native refresh the runs use: a refresh that
// fails marks the connection sign_in_again (the provider revoked it) or
-// error; one that succeeds clears both. A token connection is checked
-// with a real request instead (Verify), and only an answer clears its
-// sign_in_again.
+// error; one that succeeds clears both. A token connection gets only the
+// CLI's local status here, which costs nothing and says signed in for
+// any token: it never clears a rejection. Its real check (Verify, one
+// small request) runs at connect and when the person asks (CheckAgain),
+// and any answer on it (Answered) clears sign_in_again too.
func (c *Conns) Loop(ctx context.Context) {
// The first check waits a little so it does not contend with a first
// turn (a turn checks a connection it would choose itself).
@@ -448,10 +450,6 @@ func (c *Conns) Check(ctx context.Context) {
// checkOne refreshes one connection with its CLI under the source lock.
func (c *Conns) checkOne(ctx context.Context, b runner.AccountBinding) {
- if b.Kind == wire.KindToken {
- c.checkToken(ctx, b)
- return
- }
direct, err := c.Runner.DirectBinding(b)
if err == nil {
var lease *provider.AccountLease
@@ -463,9 +461,44 @@ func (c *Conns) checkOne(ctx context.Context, b runner.AccountBinding) {
if ctx.Err() != nil {
return
}
+ if b.Kind == wire.KindToken && err == nil {
+ // The CLI's status for a token proves only that it is there.
+ c.mu.Lock()
+ unknown := c.live[b.ID].State == ""
+ c.mu.Unlock()
+ if !unknown {
+ return
+ }
+ }
c.checked(b.ID, err)
}
+// CheckAgain is the person's Check again: the connection's real check
+// (for a token, one small request), which alone can clear a rejection.
+func (c *Conns) CheckAgain(ctx context.Context, id string) {
+ if c.load(ctx) != nil {
+ return
+ }
+ b, ok := c.Binding(id)
+ if !ok {
+ return
+ }
+ if b.Kind == wire.KindToken {
+ c.checkToken(ctx, b)
+ return
+ }
+ c.checkOne(ctx, b)
+}
+
+// Answered records that a run on the connection got an answer from the
+// provider: its credential works, whatever a check said before.
+func (c *Conns) Answered(id string) {
+ if c.load(context.Background()) != nil {
+ return
+ }
+ c.checked(id, nil)
+}
+
// checkToken checks a token connection (a busy home proves nothing).
func (c *Conns) checkToken(ctx context.Context, b runner.AccountBinding) {
if c.Verify == nil {
diff --git a/internal/runner/thin/engine.go b/internal/runner/thin/engine.go
index 01c87f8b..657942d4 100644
--- a/internal/runner/thin/engine.go
+++ b/internal/runner/thin/engine.go
@@ -71,6 +71,8 @@ type ConnChooser interface {
Observe(id string, l connect.Limit, plan string)
LimitedFrom(id string) *wire.Switched
SignInAgain(id string)
+ // Answered: a run on the connection got the provider's answer.
+ Answered(id string)
NextCheck(person string) time.Time
}
diff --git a/internal/runner/thin/engineer.go b/internal/runner/thin/engineer.go
index df61a7e3..c556341e 100644
--- a/internal/runner/thin/engineer.go
+++ b/internal/runner/thin/engineer.go
@@ -574,6 +574,9 @@ func (e *Engineer) observe(id string, res stepResult) {
if e.Conns != nil && res.seen != nil {
e.Conns.Observe(id, *res.seen, "")
}
+ if e.Conns != nil && res.reason == "" && res.limit == nil && !res.auth && res.terminated {
+ e.Conns.Answered(id)
+ }
}
// run starts the CLI for the step in containment and waits for its
diff --git a/internal/runner/thin/failover.go b/internal/runner/thin/failover.go
index 61865681..0b78c5f5 100644
--- a/internal/runner/thin/failover.go
+++ b/internal/runner/thin/failover.go
@@ -92,6 +92,8 @@ func (e *Engine) converse(ctx context.Context, person string, w *worker, r *run,
res.rows = usageRows(res.Usage, b, r.Attempt, wire.OutcomeReplied)
if res.Limit == nil && !res.SignIn || !res.Proven || ctx.Err() != nil || e.Conns == nil {
if res.Reason == "" && e.Conns != nil {
+ // An answer proves the credential, whatever a check said.
+ e.Conns.Answered(b.ID)
e.log("runner session", e.State.setMeta(context.WithoutCancel(ctx), "conn:"+person, b.ID))
}
diff --git a/internal/runner/thin/link.go b/internal/runner/thin/link.go
index 3f42e7ea..6b7360a4 100644
--- a/internal/runner/thin/link.go
+++ b/internal/runner/thin/link.go
@@ -728,6 +728,13 @@ func (l *Link) read(ctx context.Context, c *websocket.Conn) (time.Duration, erro
if err = l.Connector.Disconnect(ctx, f.ID, *v); err != nil {
return 0, err
}
+ case *wire.CheckCommand:
+ if l.Connector == nil || l.Connector.Conns == nil {
+ continue
+ }
+ if err = l.Connector.Check(ctx, f.ID, *v); err != nil {
+ return 0, err
+ }
case *wire.PreferenceCommand:
if l.Connector == nil || l.Connector.Conns == nil {
continue
diff --git a/internal/runner/thin/token_test.go b/internal/runner/thin/token_test.go
index f959b44c..cf4d13d1 100644
--- a/internal/runner/thin/token_test.go
+++ b/internal/runner/thin/token_test.go
@@ -357,10 +357,11 @@ func TestTokenCheckUnfinished(t *testing.T) {
}
}
-// The hourly pass never clears a real rejection. A turn's refusal marks
-// a token connection sign_in_again; the CLI's status, which says signed
-// in for any token, is not asked; a check that fails for another reason
-// keeps the rejection too; only a check the provider answers clears it.
+// The hourly pass never clears a real rejection, and never spends a
+// request: it asks only the CLI's local status, which says signed in for
+// any token. A turn's refusal marks a token connection sign_in_again; a
+// Check again (one small request) that fails for any reason keeps it;
+// one the provider answers clears it, and so does any answered run.
func TestTokenRejectionSurvivesHourlyCheck(t *testing.T) {
r := newTokenRig(t)
c := r.connector()
@@ -379,47 +380,53 @@ func TestTokenRejectionSurvivesHourlyCheck(t *testing.T) {
if state() != wire.ConnHealthy {
t.Fatalf("state %s", state())
}
- // The provider revokes the token (a token naming no account, so the
- // CLI's status names the same identity before and after): a turn is
- // refused.
+ // The provider revokes the token: a turn is refused.
if err := os.WriteFile(filepath.Join(home, provider.TokenFile), []byte("sk-ant-oat01-revoked-later"), 0600); err != nil {
t.Fatal(err)
}
r.conns.SignInAgain(local)
// The hourly pass, with the CLI's own status as the refresh: it says
- // signed in, and must not be what decides.
+ // signed in, spends no request and decides nothing.
paths := provider.LoginOptions{ClaudePath: r.cfg.ClaudePath, CodexPath: r.cfg.CodexPath}
r.conns.Refresh = func(ctx context.Context, b provider.Binding) (provider.Identity, error) {
return provider.RefreshLogin(ctx, b, paths)
}
before := r.checks.Load()
- r.conns.Check(r.ctx)
- if state() != wire.ConnSignInAgain || r.checks.Load() != before+1 {
- t.Fatalf("after the hourly pass: %s, %d checks", state(), r.checks.Load()-before)
+ for i := 0; i < 3; i++ {
+ r.conns.Check(r.ctx)
+ }
+ if state() != wire.ConnSignInAgain || r.checks.Load() != before {
+ t.Fatalf("after the hourly passes: %s, %d real checks", state(), r.checks.Load()-before)
}
+ // Check again that does not finish, or with no checker: unchanged.
busy := errors.New("the check did not finish")
r.refuse.Store(&busy)
- r.conns.Check(r.ctx)
- if state() != wire.ConnSignInAgain {
+ r.conns.CheckAgain(r.ctx, local)
+ if state() != wire.ConnSignInAgain || r.checks.Load() != before+1 {
t.Fatalf("an unfinished check changed the rejection: %s", state())
}
- // No checker at all: nothing can prove the token.
verify := r.conns.Verify
r.conns.Verify = nil
- r.conns.Check(r.ctx)
+ r.conns.CheckAgain(r.ctx, local)
if state() != wire.ConnSignInAgain {
t.Fatalf("without a check: %s", state())
}
- // The provider answers again: the check clears it.
+ // The provider answers again: Check again clears it.
r.conns.Verify = verify
r.refuse.Store(nil)
if err := os.WriteFile(filepath.Join(home, provider.TokenFile), []byte(fakeclaude.Token("")), 0600); err != nil {
t.Fatal(err)
}
- r.conns.Check(r.ctx)
+ r.conns.CheckAgain(r.ctx, local)
if state() != wire.ConnHealthy {
t.Fatalf("after an answered check: %s", state())
}
+ // Refused again, then a run on it is answered: that clears it too.
+ r.conns.SignInAgain(local)
+ r.conns.Answered(local)
+ if state() != wire.ConnHealthy {
+ t.Fatalf("after an answered run: %s", state())
+ }
}
// A stop after the binding is saved and before the attempt is marked
diff --git a/internal/thintest/client.go b/internal/thintest/client.go
index 2359efc9..5ec58b32 100644
--- a/internal/thintest/client.go
+++ b/internal/thintest/client.go
@@ -268,6 +268,11 @@ func (c *Client) SetPreferences(ctx context.Context, in wire.Preferences) (out w
return out, c.do(ctx, "PUT", "/api/v1/connections/preference", in, &out)
}
+// CheckConnection is a connection's Check again.
+func (c *Client) CheckConnection(ctx context.Context, id string) error {
+ return c.do(ctx, "POST", "/api/v1/connections/"+id+"/check", nil, nil)
+}
+
// Forget removes a signed-out connection's record.
func (c *Client) Forget(ctx context.Context, id string) error {
return c.do(ctx, "POST", "/api/v1/connections/"+id+"/forget", nil, nil)
diff --git a/internal/thintest/token_contract_test.go b/internal/thintest/token_contract_test.go
index 02397498..6482b30f 100644
--- a/internal/thintest/token_contract_test.go
+++ b/internal/thintest/token_contract_test.go
@@ -340,3 +340,41 @@ func waitFor(t *testing.T, what string, cond func() bool) {
time.Sleep(25 * time.Millisecond)
}
}
+
+// Check again on a token connection that needs signing in again goes to
+// the runner as a durable check frame naming the connection; a
+// connection still connecting, or signed out, is refused.
+func TestContractCheckAgain(t *testing.T) {
+ r := newRig(t)
+ runner, err := DialRunnerHello(r.ctx, r.inst.URL, r.runner, held(wire.HeldConnection{LocalID: "claude-9", Person: Owner, Provider: "claude", Kind: wire.KindToken, Label: "tok@example.com", State: wire.ConnSignInAgain}))
+ if err != nil {
+ t.Fatal(err)
+ }
+ t.Cleanup(runner.Close)
+ var id string
+ r.wait("the token connection", func(c *Conversation) bool {
+ for _, v := range c.Connections {
+ if v.LocalID == "claude-9" {
+ id = v.ID
+ }
+ }
+ return id != ""
+ })
+ if err = r.client.CheckConnection(r.ctx, id); err != nil {
+ t.Fatal(err)
+ }
+ _, body, err := runner.Expect(r.ctx, wire.FrameCheck)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if v := body.(*wire.CheckCommand); v.Connection != id || v.LocalID != "claude-9" || v.Person != Owner {
+ t.Fatalf("check %+v", v)
+ }
+ attempt, err := r.client.Connect(r.ctx, wire.Connect{Provider: "claude", Kind: wire.KindToken})
+ if err != nil {
+ t.Fatal(err)
+ }
+ if err = r.client.CheckConnection(r.ctx, attempt.ID); Status(err) != 409 {
+ t.Fatalf("check on an attempt: %v", err)
+ }
+}
diff --git a/internal/wire/connections.go b/internal/wire/connections.go
index ac9825d0..d4f02824 100644
--- a/internal/wire/connections.go
+++ b/internal/wire/connections.go
@@ -294,3 +294,16 @@ type SecretCommand struct {
Person string `json:"person"`
Sealed Sealed `json:"sealed"`
}
+
+// FrameCheck (instance to runner, durable) is the person's Check again on
+// a connection: the runner runs its real check (for a token, one small
+// request), the only thing that clears a rejection besides an answered
+// run. The outcome comes back as the connection's state in hello.
+const FrameCheck = "check"
+
+// CheckCommand names the connection to check.
+type CheckCommand struct {
+ Connection string `json:"connection"`
+ Person string `json:"person"`
+ LocalID string `json:"local_id"`
+}
diff --git a/internal/wire/frames.go b/internal/wire/frames.go
index f6153817..7d92a0ad 100644
--- a/internal/wire/frames.go
+++ b/internal/wire/frames.go
@@ -60,7 +60,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, FrameAttachment, FrameCancel, FrameReply, FrameTurn, FrameToolCall, FrameToolResult, FrameMoveIn, FrameNotebook, FrameReset, FrameDispatch, FrameCancelStep, FrameStep, FrameRecheck, FrameWatchMerge, FrameMerged, FrameAsk, FrameCancelAsk, FrameAnswer, FrameForgetTask, FrameBranch, FrameBlob, FrameSendPack, FramePublish, FramePublished, FrameConnect, FrameCancelConnect, FrameConnection, FrameUsage, FrameDisconnect, FramePreference, FrameSecret:
+ case FrameMessage, FrameAttachment, FrameCancel, FrameReply, FrameTurn, FrameToolCall, FrameToolResult, FrameMoveIn, FrameNotebook, FrameReset, FrameDispatch, FrameCancelStep, FrameStep, FrameRecheck, FrameWatchMerge, FrameMerged, FrameAsk, FrameCancelAsk, FrameAnswer, FrameForgetTask, FrameBranch, FrameBlob, FrameSendPack, FramePublish, FramePublished, FrameConnect, FrameCancelConnect, FrameConnection, FrameUsage, FrameDisconnect, FramePreference, FrameSecret, FrameCheck:
return true
}
return false
@@ -151,6 +151,8 @@ func (f Frame) Decode() (any, error) {
v = &PreferenceCommand{}
case FrameSecret:
v = &SecretCommand{}
+ case FrameCheck:
+ v = &CheckCommand{}
case FrameStepActivity:
v = &StepActivityReport{}
case FrameBlob:
diff --git a/internal/wire/wire_test.go b/internal/wire/wire_test.go
index 69ba9bae..ab0a02ef 100644
--- a/internal/wire/wire_test.go
+++ b/internal/wire/wire_test.go
@@ -73,7 +73,7 @@ func TestParseFrameRefusesUnknownFieldsAndTypes(t *testing.T) {
}
func TestDurableFrames(t *testing.T) {
- for kind, want := range map[string]bool{wire.FrameMessage: true, wire.FrameCancel: true, wire.FrameReply: true, wire.FrameTurn: true, wire.FrameToolCall: true, wire.FrameToolResult: true, wire.FrameActivity: false, wire.FrameDelta: false, wire.FrameHello: false, wire.FrameSync: false, wire.FrameAck: false, wire.FrameWelcome: false, wire.FrameDrain: false, wire.FramePreference: true, wire.FrameSecret: true} {
+ for kind, want := range map[string]bool{wire.FrameMessage: true, wire.FrameCancel: true, wire.FrameReply: true, wire.FrameTurn: true, wire.FrameToolCall: true, wire.FrameToolResult: true, wire.FrameActivity: false, wire.FrameDelta: false, wire.FrameHello: false, wire.FrameSync: false, wire.FrameAck: false, wire.FrameWelcome: false, wire.FrameDrain: false, wire.FramePreference: true, wire.FrameSecret: true, wire.FrameCheck: true} {
if (wire.Frame{Type: kind}).Durable() != want {
t.Fatalf("%s durable=%v", kind, !want)
}
diff --git a/internal/wire/wiretest/testdata/frames/check.json b/internal/wire/wiretest/testdata/frames/check.json
new file mode 100644
index 00000000..720402e3
--- /dev/null
+++ b/internal/wire/wiretest/testdata/frames/check.json
@@ -0,0 +1 @@
+{"id":"c46","type":"check","data":{"connection":"cn_0003","person":"owner@example.com","local_id":"claude-2"}}