Mac slice F task 10 fix 2: hold until proven ended or rebooted
Astra round 2, #3 (controller ruling): the restart's fallback ("a turn
can be taken and nothing carries the marker") could clear a watch while
an unseen survivor still wrote the credential. It is removed. A watch,
and the Mac's credential hold, clears only once Executor.Verify proves
the launch's recorded run ended, or the Mac has booted since the watch
began (kern.boottime behind a seam; no process outlives a boot), and a
later listing is clean.
- creds: watches record Started and their run (Ran); Abandon and
Unproven; BootTime for darwin and Linux.
- thin: every unproven end abandons its watch. Gate refuses every store
and use with errCredentialUnproven while one is unproven. Caps say
wire.UnprovenCredential ("credential_unproven"), which the Machines
page words with runner.unproven.credential_unproven (pending copy).
- Regression: an unmarked survivor writes into the Keychain after the
crashed runner's restart; the hold stays until a "reboot".
Mutations R1-R15 were killed but R4 (marker-only Verify), which agrees
with the run-based Verify wherever the turn's settle has already killed
the group. Budgets re-measured: thin 31482/28038, equipo 24018,
wire 8609.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
16 files changed,
+428
−61
.rastrillo/budgets.txt+3 −3docs/superpowers/plans/2026-11-28-mac-slice-f-copy.json+5 −0docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md+1 −0internal/equipo/copy.go+7 −6internal/equipo/mac_view_test.go+4 −0internal/equipo/runners.go+4 −1internal/runner/mac/creds/boot_darwin.go+17 −0internal/runner/mac/creds/boot_linux.go+28 −0internal/runner/mac/creds/keychain.go+59 −8internal/runner/mac/creds/keychain_test.go+53 −7internal/runner/thin/mac.go+6 −1internal/runner/thin/maccreds.go+49 −22internal/runner/thin/maccreds_fix1_test.go+19 −10internal/runner/thin/maccreds_fix2_test.go+148 −0internal/runner/thin/maccreds_test.go+19 −2internal/wire/runners.go+6 −1
diff --git a/.rastrillo/budgets.txt b/.rastrillo/budgets.txt| index 452db203..f2641e6b 100644 |
| --- a/.rastrillo/budgets.txt |
| +++ b/.rastrillo/budgets.txt |
| @@ -14,8 +14,8 @@ 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 24014 - Preview, retry, merges, kept work, check-db, notifications, places, GitHub routes, Mac waits, probe and proof codes, Mac credential copy; measured 24014. |
| -size internal/wire 8604 - Protocols 31 to 35 (facts, diffs, evidence, CI units, files, places), Mac waits, 37 Mac Engineering, probe and proof codes; measured 8604. |
| +size internal/equipo 24018 - Preview, retry, merges, kept work, check-db, notifications, places, GitHub routes, Mac waits, probe and proof codes, Mac credential copy; measured 24018. |
| +size internal/wire 8609 - Protocols 31 to 35 (facts, diffs, evidence, CI units, files, places), Mac waits, 37 Mac Engineering, probe and proof codes, credential_unproven; measured 8609. |
| size internal/equipotest - 12683 GitHub connect value search, lifecycle and sweep-log contracts; Task 21 migration fixtures and Rastrillo asset contract; measured 0/12683 source/test lines. |
| time internal/runner/checks 90s CI worker measured 44.553s (44.6s rounded); |
| time internal/runner 330s Plan 3 CI repair measured 292.120s for the full package (controller CI 472.184s). |
| @@ -38,7 +38,7 @@ time internal/runner/provider 15s Plan 3 CI repair measured 10.346s for the full |
| perf GET /releases/* skip Verified runner release file downloads, not browser GET screens. |
| 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; |
| -size internal/runner/thin 31450 27864 Protocols 31 to 35, merge credential, publication guards, kept work, scans, Mac pin, paths, bases, endpoint, Mac turns, Mac credentials; measured 31450/27864. |
| +size internal/runner/thin 31482 28038 Protocols 31 to 35, merge credential, publication guards, kept work, scans, Mac pin, paths, bases, endpoint, Mac turns, Mac credentials; measured 31482/28038. |
| time internal/thintest 240s Thin contract and page tests, the Assistant's and the models' included, share one harness. Measured 202s on a shared 16 CPU box (2026-11-13); CI runs two lanes. |
| time internal/runner/mac 45s Real processes killed and proven gone: groups, sessions, the runner-user sweep, turns, restarts; probes end to end. Measured 29.3s locally. |
| 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). |
diff --git a/docs/superpowers/plans/2026-11-28-mac-slice-f-copy.json b/docs/superpowers/plans/2026-11-28-mac-slice-f-copy.json| index 8270d5c7..3e69aa3c 100644 |
| --- a/docs/superpowers/plans/2026-11-28-mac-slice-f-copy.json |
| +++ b/docs/superpowers/plans/2026-11-28-mac-slice-f-copy.json |
| @@ -98,5 +98,10 @@ |
| "key": "runner.mac.keychain_item", |
| "where": "Machines page, a Mac holding a Keychain item a sign-in left, or one with Claude Code's name it found there; %[1]s is the item's service name, %[2]s the Mac's runner user", |
| "draft": "This Mac's Keychain has an item named %[1]s, so Equipo won't keep Claude there. Remove it in Keychain Access as %[2]s, then try again." |
| + }, |
| + { |
| + "key": "runner.unproven.credential_unproven", |
| + "where": "Machines page, a Mac's card: its Claude connections are closed because it could not prove that an earlier sign-in, token check or auth status ended (wire.UnprovenCredential); a restart of the Mac clears it", |
| + "draft": "This Mac could not prove that an earlier Claude sign-in or check ended, so it keeps its Claude connections closed. Restart the Mac to clear it." |
| } |
| ] |
diff --git a/docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md b/docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md| index 1cca79ee..04e2e06e 100644 |
| --- a/docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md |
| +++ b/docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md |
| @@ -7025,6 +7025,7 @@ records remain unchanged. |
| | `runner.mac.home_open` | Other people on this Mac can open %[1]s's home folder, so Equipo won't keep Claude there. Run chmod 700 ~ as %[1]s, then try again. | Copy specialist | COPY REVIEW PENDING | |
| | `runner.mac.home_open_folder` | Other people on this Mac can reach a folder where %[1]s keeps Claude, so Equipo won't keep Claude there. The runner's log names the folder and what to change. | Copy specialist | COPY REVIEW PENDING | |
| | `runner.mac.keychain_item` | This Mac's Keychain has an item named %[1]s, so Equipo won't keep Claude there. Remove it in Keychain Access as %[2]s, then try again. | Copy specialist | COPY REVIEW PENDING | |
| +| `runner.unproven.credential_unproven` | This Mac could not prove that an earlier Claude sign-in or check ended, so it keeps its Claude connections closed. Restart the Mac to clear it. | Copy specialist | COPY REVIEW PENDING | |
| ## Task 21 |
diff --git a/internal/equipo/copy.go b/internal/equipo/copy.go| index dcc48d28..85ad2505 100644 |
| --- a/internal/equipo/copy.go |
| +++ b/internal/equipo/copy.go |
| @@ -2108,12 +2108,13 @@ var pageCopy = map[string]string{ |
| // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| "runner.verdict.skipped": "Not run", |
| // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| - "runner.verdict.unavailable": "Unavailable", |
| - "runner.unproven.record_incomplete": "Equipo could not prove that an earlier step on this Mac stopped completely, so that step stays unfinished.", // COPY REVIEW PENDING |
| - "runner.probe_detail.turn_busy": "The Mac was busy with other work, so this was not checked.", // COPY REVIEW PENDING |
| - "runner.mac.home_open": "Other people on this Mac can open %[1]s's home folder, so Equipo won't keep Claude there. Run chmod 700 ~ as %[1]s, then try again.", // COPY REVIEW PENDING |
| - "runner.mac.home_open_folder": "Other people on this Mac can reach a folder where %[1]s keeps Claude, so Equipo won't keep Claude there. The runner's log names the folder and what to change.", // COPY REVIEW PENDING |
| - "runner.mac.keychain_item": "This Mac's Keychain has an item named %[1]s, so Equipo won't keep Claude there. Remove it in Keychain Access as %[2]s, then try again.", // COPY REVIEW PENDING |
| + "runner.verdict.unavailable": "Unavailable", |
| + "runner.unproven.record_incomplete": "Equipo could not prove that an earlier step on this Mac stopped completely, so that step stays unfinished.", // COPY REVIEW PENDING |
| + "runner.probe_detail.turn_busy": "The Mac was busy with other work, so this was not checked.", // COPY REVIEW PENDING |
| + "runner.mac.home_open": "Other people on this Mac can open %[1]s's home folder, so Equipo won't keep Claude there. Run chmod 700 ~ as %[1]s, then try again.", // COPY REVIEW PENDING |
| + "runner.mac.home_open_folder": "Other people on this Mac can reach a folder where %[1]s keeps Claude, so Equipo won't keep Claude there. The runner's log names the folder and what to change.", // COPY REVIEW PENDING |
| + "runner.unproven.credential_unproven": "This Mac could not prove that an earlier Claude sign-in or check ended, so it keeps its Claude connections closed. Restart the Mac to clear it.", // COPY REVIEW PENDING |
| + "runner.mac.keychain_item": "This Mac's Keychain has an item named %[1]s, so Equipo won't keep Claude there. Remove it in Keychain Access as %[2]s, then try again.", // COPY REVIEW PENDING |
| // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| "runner.origin": "Equipo address:", |
| // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
diff --git a/internal/equipo/mac_view_test.go b/internal/equipo/mac_view_test.go| index 2341ead6..d60967fa 100644 |
| --- a/internal/equipo/mac_view_test.go |
| +++ b/internal/equipo/mac_view_test.go |
| @@ -90,6 +90,10 @@ func TestUnprovenEndShown(t *testing.T) { |
| if got := unprovenText(wire.UnprovenRecordIncomplete); got == "" || got == wire.UnprovenRecordIncomplete || got != copyText("runner.unproven.record_incomplete") { |
| t.Fatalf("shown as %q", got) |
| } |
| + // A Mac that could not prove a credential launch ended (task 10). |
| + if got := unprovenText(wire.UnprovenCredential); got == "" || got != copyText("runner.unproven.credential_unproven") { |
| + t.Fatalf("credential_unproven shown as %q", got) |
| + } |
| if unprovenText("") != "" || unprovenText("no_such_code") != "" { |
| t.Fatal("an unknown or empty code said something") |
| } |
diff --git a/internal/equipo/runners.go b/internal/equipo/runners.go| index 4585b0f1..9cfbb4c5 100644 |
| --- a/internal/equipo/runners.go |
| +++ b/internal/equipo/runners.go |
| @@ -371,8 +371,11 @@ func probeDetail(d string) string { |
| // unprovenText words a runner's Unproven code; "" for none or one it |
| // does not know. |
| func unprovenText(code string) string { |
| - if code == wire.UnprovenRecordIncomplete { |
| + switch code { |
| + case wire.UnprovenRecordIncomplete: |
| return copyText("runner.unproven.record_incomplete") |
| + case wire.UnprovenCredential: |
| + return copyText("runner.unproven.credential_unproven") |
| } |
| return "" |
| } |
diff --git a/internal/runner/mac/creds/boot_darwin.go b/internal/runner/mac/creds/boot_darwin.go| new file mode 100644 |
| index 00000000..e76a954c |
| --- /dev/null |
| +++ b/internal/runner/mac/creds/boot_darwin.go |
| @@ -0,0 +1,17 @@ |
| +package creds |
| + |
| +import ( |
| + "time" |
| + |
| + "golang.org/x/sys/unix" |
| +) |
| + |
| +// BootTime is when this Mac last booted (kern.boottime). No process |
| +// outlives a boot, so a launch begun before it has ended. |
| +func BootTime() (time.Time, error) { |
| + tv, err := unix.SysctlTimeval("kern.boottime") |
| + if err != nil { |
| + return time.Time{}, err |
| + } |
| + return time.Unix(tv.Sec, int64(tv.Usec)*1000), nil |
| +} |
diff --git a/internal/runner/mac/creds/boot_linux.go b/internal/runner/mac/creds/boot_linux.go| new file mode 100644 |
| index 00000000..6e374d50 |
| --- /dev/null |
| +++ b/internal/runner/mac/creds/boot_linux.go |
| @@ -0,0 +1,28 @@ |
| +package creds |
| + |
| +import ( |
| + "errors" |
| + "os" |
| + "strconv" |
| + "strings" |
| + "time" |
| +) |
| + |
| +// BootTime is when this machine last booted (/proc/stat's btime; the |
| +// test build's fake Mac worker and the tests). |
| +func BootTime() (time.Time, error) { |
| + raw, err := os.ReadFile("/proc/stat") |
| + if err != nil { |
| + return time.Time{}, err |
| + } |
| + for _, line := range strings.Split(string(raw), "\n") { |
| + if v, ok := strings.CutPrefix(line, "btime "); ok { |
| + n, err := strconv.ParseInt(strings.TrimSpace(v), 10, 64) |
| + if err != nil { |
| + return time.Time{}, err |
| + } |
| + return time.Unix(n, 0), nil |
| + } |
| + } |
| + return time.Time{}, errors.New("creds: no boot time") |
| +} |
diff --git a/internal/runner/mac/creds/keychain.go b/internal/runner/mac/creds/keychain.go| index 39d2977b..c3a6adbf 100644 |
| --- a/internal/runner/mac/creds/keychain.go |
| +++ b/internal/runner/mac/creds/keychain.go |
| @@ -15,6 +15,7 @@ import ( |
| "strconv" |
| "strings" |
| "sync" |
| + "time" |
| ) |
| // The Keychain watch around a sign-in (spec §8.3; slice F task 10). The |
| @@ -209,11 +210,15 @@ type Keychain struct { |
| // record is one watch on disk: Before until the attempt's end is |
| // checked; then Left, what a listing still showed. |
| type record struct { |
| - Marker string `json:"marker"` |
| - ConfigDir string `json:"config_dir"` |
| - Before []Item `json:"before"` |
| - Checked bool `json:"checked"` |
| - Left []Item `json:"left,omitempty"` |
| + Marker string `json:"marker"` |
| + // Started is when the watch began (before its launch started); Run |
| + // is its launch's process record (mac.RecordID) once it started. |
| + Started time.Time `json:"started"` |
| + Run string `json:"run,omitempty"` |
| + ConfigDir string `json:"config_dir"` |
| + Before []Item `json:"before"` |
| + Checked bool `json:"checked"` |
| + Left []Item `json:"left,omitempty"` |
| } |
| // list is the runner user's login Keychain, listed by its path whatever |
| @@ -234,6 +239,52 @@ func (k *Keychain) list(ctx context.Context) ([]Item, error) { |
| return out, nil |
| } |
| +// Watch is a watch still waiting for its second look, as Settle asks |
| +// whether its launch has ended: its marker, its launch's process record |
| +// ("" when it never started) and when the watch began. |
| +type Watch struct { |
| + Marker, Run string |
| + Started time.Time |
| +} |
| + |
| +// Ran records marker's launch's process record (mac.RecordID) on its |
| +// watch, durably, as soon as it is known. |
| +func (k *Keychain) Ran(marker, run string) error { |
| + k.op.Lock() |
| + defer k.op.Unlock() |
| + rec, err := k.load(marker) |
| + if err != nil { |
| + return err |
| + } |
| + rec.Run = run |
| + return k.save(rec) |
| +} |
| + |
| +// Abandon gives a watch up in this process: its launch's end could not |
| +// be proven, so it stays unchecked, held and Unproven, for a restart. |
| +func (k *Keychain) Abandon(marker string) { |
| + k.mu.Lock() |
| + delete(k.live, marker) |
| + k.mu.Unlock() |
| +} |
| + |
| +// Unproven are the watches whose launch's end is not proven and that no |
| +// launch here still runs: each keeps the Mac's connections closed. |
| +func (k *Keychain) Unproven() []string { |
| + names, _ := k.names() |
| + var out []string |
| + for _, name := range names { |
| + rec, err := k.load(name) |
| + k.mu.Lock() |
| + live := k.live[name] |
| + k.mu.Unlock() |
| + if err != nil || !rec.Checked && !live { |
| + out = append(out, name) |
| + } |
| + } |
| + return out |
| +} |
| + |
| // existingRecord names the record of CLI items found already there. |
| const existingRecord = "existing" |
| @@ -263,7 +314,7 @@ func (k *Keychain) Before(ctx context.Context, marker, dir string) error { |
| if err := k.refuseExisting(list); err != nil { |
| return err |
| } |
| - if err := k.save(record{Marker: marker, ConfigDir: dir, Before: list}); err != nil { |
| + if err := k.save(record{Marker: marker, ConfigDir: dir, Before: list, Started: time.Now()}); err != nil { |
| return err |
| } |
| k.mu.Lock() |
| @@ -392,7 +443,7 @@ func (k *Keychain) Existing(ctx context.Context) error { |
| // none of it. A watch whose attempt never got its second look (the |
| // runner stopped) is checked only at a restart and once gone(marker) |
| // proves its CLI ended; it is never touched while its attempt runs here. |
| -func (k *Keychain) Settle(ctx context.Context, restart bool, gone func(string) bool) error { |
| +func (k *Keychain) Settle(ctx context.Context, restart bool, gone func(Watch) bool) error { |
| k.op.Lock() |
| defer k.op.Unlock() |
| names, err := k.names() |
| @@ -410,7 +461,7 @@ func (k *Keychain) Settle(ctx context.Context, restart bool, gone func(string) b |
| k.mu.Lock() |
| live := k.live[name] |
| k.mu.Unlock() |
| - if !restart || live || gone == nil || !gone(name) { |
| + if !restart || live || gone == nil || !gone(Watch{Marker: rec.Marker, Run: rec.Run, Started: rec.Started}) { |
| continue |
| } |
| if list == nil { |
diff --git a/internal/runner/mac/creds/keychain_test.go b/internal/runner/mac/creds/keychain_test.go| index 33eb84b4..79b6247e 100644 |
| --- a/internal/runner/mac/creds/keychain_test.go |
| +++ b/internal/runner/mac/creds/keychain_test.go |
| @@ -9,6 +9,7 @@ import ( |
| "strings" |
| "sync" |
| "testing" |
| + "time" |
| ) |
| // dump-keychain-constructed-2026-11-29-docs-t1.txt is constructed on |
| @@ -296,7 +297,7 @@ func TestKeychainWatch(t *testing.T) { |
| if err := k.Existing(ctx); !errors.Is(err, ErrExisting) { |
| t.Fatalf("a pasted token's store: %v", err) |
| } |
| - _ = k.Settle(ctx, true, func(string) bool { return true }) |
| + _ = k.Settle(ctx, true, func(Watch) bool { return true }) |
| if len(f.deleted) != 0 || !f.has(left) { |
| t.Fatal("settling deleted an item from before") |
| } |
| @@ -308,10 +309,10 @@ func TestKeychainWatch(t *testing.T) { |
| f.add(own()) |
| restarted := &Keychain{Dir: k.Dir, Login: login, User: "paulequipo", List: f.list, Delete: f.delete} |
| // Not before its CLI is proven gone. |
| - if _ = restarted.Settle(ctx, true, func(string) bool { return false }); !restarted.Held() || !f.has(own()) { |
| + if _ = restarted.Settle(ctx, true, func(Watch) bool { return false }); !restarted.Held() || !f.has(own()) { |
| t.Fatal("settled before its CLI was proven gone") |
| } |
| - if err := restarted.Settle(ctx, true, func(m string) bool { return m == "signin-1" }); err != nil || restarted.Held() || f.has(own()) { |
| + if err := restarted.Settle(ctx, true, func(w Watch) bool { return w.Marker == "signin-1" }); err != nil || restarted.Held() || f.has(own()) { |
| t.Fatalf("restart: %v held=%v", err, restarted.Held()) |
| } |
| }) |
| @@ -320,8 +321,8 @@ func TestKeychainWatch(t *testing.T) { |
| k := newWatch(t, f) |
| _ = k.Before(ctx, "signin-1", configDir) |
| f.add(own()) |
| - _ = k.Settle(ctx, true, func(string) bool { return true }) |
| - _ = k.Settle(ctx, false, func(string) bool { return true }) |
| + _ = k.Settle(ctx, true, func(Watch) bool { return true }) |
| + _ = k.Settle(ctx, false, func(Watch) bool { return true }) |
| if !f.has(own()) || !k.Held() { |
| t.Fatal("a watch still running here was settled") |
| } |
| @@ -399,12 +400,12 @@ func TestKeychainAmbiguousItems(t *testing.T) { |
| if _, err := k.After(ctx, "signin-1"); err == nil || !k.Held() { |
| t.Fatalf("after an unreadable listing: %v held=%v", err, k.Held()) |
| } |
| - _ = k.Settle(ctx, true, func(string) bool { return true }) |
| + _ = k.Settle(ctx, true, func(Watch) bool { return true }) |
| if !k.Held() { |
| t.Fatal("settling with an unreadable listing released the hold") |
| } |
| f.broken = false |
| - if err := k.Settle(ctx, true, func(string) bool { return true }); err != nil || k.Held() || f.has(own()) { |
| + if err := k.Settle(ctx, true, func(Watch) bool { return true }); err != nil || k.Held() || f.has(own()) { |
| t.Fatalf("once it lists: %v held=%v", err, k.Held()) |
| } |
| }) |
| @@ -459,3 +460,48 @@ func TestKeychainLoginByPath(t *testing.T) { |
| t.Fatalf("another keychain's item refused the sign-in: %v", err) |
| } |
| } |
| + |
| +// TestKeychainWatchUnproven (fix round 2): a watch knows when it began |
| +// and its launch's record; one whose end could not be proven here is |
| +// Unproven until a restart settles it. |
| +func TestKeychainWatchUnproven(t *testing.T) { |
| + ctx := context.Background() |
| + f := &fakeKeychain{} |
| + k := newWatch(t, f) |
| + before := time.Now() |
| + if err := k.Before(ctx, "signin-1", configDir); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := k.Ran("signin-1", "pg:4242:signin-1"); err != nil { |
| + t.Fatal(err) |
| + } |
| + if len(k.Unproven()) != 0 { |
| + t.Fatal("a running watch is unproven") |
| + } |
| + k.Abandon("signin-1") |
| + if !slices.Equal(k.Unproven(), []string{"signin-1"}) || !k.Held() { |
| + t.Fatalf("an abandoned watch: %v held=%v", k.Unproven(), k.Held()) |
| + } |
| + if err := k.Settle(ctx, false, func(Watch) bool { return true }); err != nil || !k.Held() { |
| + t.Fatal("settled without a restart") |
| + } |
| + restarted := &Keychain{Dir: k.Dir, Login: login, User: "paulequipo", List: f.list, Delete: f.delete} |
| + if !slices.Equal(restarted.Unproven(), []string{"signin-1"}) { |
| + t.Fatalf("after a restart: %v", restarted.Unproven()) |
| + } |
| + var asked Watch |
| + _ = restarted.Settle(ctx, true, func(w Watch) bool { asked = w; return false }) |
| + if asked.Run != "pg:4242:signin-1" || asked.Started.Before(before) || asked.Started.After(time.Now()) || !restarted.Held() { |
| + t.Fatalf("asked %+v", asked) |
| + } |
| + if err := restarted.Settle(ctx, true, func(Watch) bool { return true }); err != nil || restarted.Held() || len(restarted.Unproven()) != 0 { |
| + t.Fatalf("once ended: %v held=%v", err, restarted.Held()) |
| + } |
| +} |
| + |
| +func TestBootTime(t *testing.T) { |
| + boot, err := BootTime() |
| + if err != nil || !boot.Before(time.Now()) || boot.Year() < 2020 { |
| + t.Fatalf("boot %v %v", boot, err) |
| + } |
| +} |
diff --git a/internal/runner/thin/mac.go b/internal/runner/thin/mac.go| index 8868ff1b..6c8c83b0 100644 |
| --- a/internal/runner/thin/mac.go |
| +++ b/internal/runner/thin/mac.go |
| @@ -758,7 +758,7 @@ func newMacHost(c runner.Config, o Options) (h *macHost, err error) { |
| } |
| caps.Tainted = h.taint.Tainted() |
| h.credentialCaps(ctx, &caps) |
| - if h.turns.Incomplete() { |
| + if h.turns.Incomplete() && caps.Unproven == "" { |
| caps.Unproven = wire.UnprovenRecordIncomplete |
| } |
| return caps |
| @@ -774,6 +774,11 @@ func (h *macHost) credentialCaps(ctx context.Context, caps *wire.Capabilities) { |
| if h.creds.Held() { |
| h.creds.settle(ctx, false) |
| } |
| + if len(h.creds.keychain.Unproven()) > 0 { |
| + // Said before an incomplete attempt record: it closes the Mac's |
| + // connections, and a restart of the Mac clears it. |
| + caps.Unproven = wire.UnprovenCredential |
| + } |
| } |
| // simShutdownLimit bounds `simctl shutdown all` before a T cleanup. |
diff --git a/internal/runner/thin/maccreds.go b/internal/runner/thin/maccreds.go| index f59455f0..a875b206 100644 |
| --- a/internal/runner/thin/maccreds.go |
| +++ b/internal/runner/thin/maccreds.go |
| @@ -54,6 +54,9 @@ var ( |
| // errKeychain refuses a sign-in that left a Keychain item, or whose |
| // Keychain could not be listed again. |
| errKeychain = errors.New("the sign-in left an item in a Keychain") |
| + // errCredentialUnproven refuses every Claude connection while an |
| + // earlier credential launch's end is not proven. |
| + errCredentialUnproven = errors.New("an earlier launch with a Claude credential was not proven ended") |
| // errMacRefused refuses to keep a token (the guards, or a Keychain |
| // item with Claude Code's name). |
| errMacRefused = errors.New("the Mac refused to keep the token") |
| @@ -88,6 +91,8 @@ type macCreds struct { |
| configDir, runner, scratch string |
| taint *macTaint |
| keychain *creds.Keychain |
| + // boot is when the Mac last booted (creds.BootTime; tests stand in). |
| + boot func() (time.Time, error) |
| // fact reads one path's kind, mode, owner and ACL (ls -led and lstat |
| // on a Mac). |
| fact func(string) (creds.Fact, error) |
| @@ -100,7 +105,7 @@ type macCreds struct { |
| // newCreds is h's credential operations for c. |
| func (h *macHost) newCreds(c runner.Config) *macCreds { |
| m := &macCreds{turns: h.turns, exec: &mac.Executor{Turns: h.turns}, cli: h.tools.Claude, paths: h.paths, configDir: macConfigDir(c, h.paths.Home), |
| - runner: c.Executable, scratch: c.ScratchRoot, taint: h.taint, uid: -1, log: h.log} |
| + runner: c.Executable, scratch: c.ScratchRoot, taint: h.taint, boot: creds.BootTime, uid: -1, log: h.log} |
| ctx, cancel := context.WithTimeout(context.Background(), mac.QueryLimit) |
| defer cancel() |
| if a, err := mac.ReadAccount(ctx, h.run); err == nil { |
| @@ -187,6 +192,9 @@ func (m *macCreds) Gate() error { |
| if m.taint.Tainted() { |
| return errTainted |
| } |
| + if len(m.keychain.Unproven()) > 0 { |
| + return errCredentialUnproven |
| + } |
| if r := m.guard(); !r.OK() { |
| if m.log != nil { |
| m.log.Warn("other users could reach the runner's folders; no model connection is kept or used", "reason", r.Reason(), "change", strings.ReplaceAll(r.Fix(), "\n", "; ")) |
| @@ -263,22 +271,23 @@ func (m *macCreds) settle(ctx context.Context, restart bool) { |
| } |
| } |
| -// ended: nothing of marker's launch can write a Keychain item any more. |
| -// Proven over (Executor.Verify), or, for a launch whose turn record was |
| -// never completed (the runner died: task 9 never proves such an attempt |
| -// over), its turn settled (a turn can be taken, so what it left of the |
| -// runner user's was killed) and nothing carrying its marker left. |
| -func (m *macCreds) ended(marker string) bool { |
| - if m.exec.Verify(mac.RecordID(0, marker)) { |
| +// ended: the watched launch has surely ended, so its watch may take its |
| +// second look. Only two things say so (spec §8.8; the controller's ruling |
| +// for task 10, fix round 2): Executor.Verify proves its end by its |
| +// process record, or the Mac has booted since the watch began (no |
| +// process outlives a boot). Anything else (an incomplete turn record, |
| +// obligations still owed, a boot time that cannot be read) keeps the |
| +// watch, the hold and the Mac's connections closed. |
| +func (m *macCreds) ended(w creds.Watch) bool { |
| + run := w.Run |
| + if run == "" { |
| + run = mac.RecordID(0, w.Marker) |
| + } |
| + if m.exec.Verify(run) { |
| return true |
| } |
| - u, ok := m.turns.TryTake(mac.OpRecover) |
| - if !ok { |
| - return false |
| - } |
| - u.Give() |
| - left, err := mac.Marked(marker) |
| - return err == nil && len(left) == 0 |
| + boot, err := m.boot() |
| + return err == nil && !w.Started.IsZero() && boot.After(w.Started) |
| } |
| // place makes a launch's own CLAUDE_CONFIG_DIR under the runtime root |
| @@ -388,9 +397,12 @@ func (m *macCreds) authStatus(ctx context.Context, b provider.Binding) (provider |
| return provider.Identity{}, err |
| } |
| out := &capped{} |
| - run, err := m.start(ctx, dir, marker, mac.Command{Env: m.env(dir, marker, true), Stdout: out}, raw, func(string) error { return nil }, "auth", "status", "--json") |
| + ran := func(id string) error { return m.keychain.Ran(marker, id) } |
| + run, err := m.start(ctx, dir, marker, mac.Command{Env: m.env(dir, marker, true), Stdout: out}, raw, ran, "auth", "status", "--json") |
| if err != nil { |
| - if !errors.Is(err, mac.ErrUnproven) { |
| + if errors.Is(err, mac.ErrUnproven) { |
| + m.keychain.Abandon(marker) |
| + } else { |
| err = errors.Join(err, m.after(marker)) |
| os.RemoveAll(dir) |
| } |
| @@ -404,7 +416,9 @@ func (m *macCreds) authStatus(ctx context.Context, b provider.Binding) (provider |
| proven := run.Stop() |
| run.Finish(context.WithoutCancel(ctx)) |
| if !proven { |
| - // Not success: the watch and the turn's record stay. |
| + // Not success: the watch and the turn's record stay, and the |
| + // Mac's connections are closed until its end is proven. |
| + m.keychain.Abandon(marker) |
| return provider.Identity{}, mac.ErrUnproven |
| } |
| kerr := m.after(marker) |
| @@ -506,9 +520,12 @@ func (m *macCreds) checkToken(ctx context.Context, o ClaudeOptions, b runner.Acc |
| pctx, kill := context.WithCancel(context.WithoutCancel(tctx)) |
| defer kill() |
| s := &mac.Starter{Exec: m.exec, CLI: m.cli, Input: in, Token: bytes.Clone(token)} |
| - proc, err := s.StartRecorded(pctx, launch, claude.DarwinArgv(policy), func(context.Context, containment.Record) error { return nil }) |
| + ran := func(_ context.Context, r containment.Record) error { return m.keychain.Ran(in.Attempt, r.ID) } |
| + proc, err := s.StartRecorded(pctx, launch, claude.DarwinArgv(policy), ran) |
| if err != nil { |
| - if !errors.Is(err, mac.ErrUnproven) { |
| + if errors.Is(err, mac.ErrUnproven) { |
| + m.keychain.Abandon(in.Attempt) |
| + } else { |
| err = errors.Join(err, m.after(in.Attempt)) |
| } |
| return nil, nil, false, err |
| @@ -524,6 +541,7 @@ func (m *macCreds) checkToken(ctx context.Context, o ClaudeOptions, b runner.Acc |
| stop() |
| kill() |
| if werr := <-waited; werr != nil { |
| + m.keychain.Abandon(in.Attempt) |
| return rows, nil, false, errors.Join(mac.ErrUnproven, werr) |
| } |
| if kerr := m.after(in.Attempt); kerr != nil { |
| @@ -578,11 +596,19 @@ func (m *macCreds) terminal(ctx context.Context, record func(string) error) (con |
| return nil, err |
| } |
| env := m.env(dir, marker, false, "TERM=xterm-256color", "BROWSER="+provider.SignInBrowser) |
| - run, err := m.start(u.Context(ctx), dir, marker, mac.Command{Env: env, TTY: tty}, nil, record, "setup-token") |
| + ran := func(id string) error { |
| + if err := m.keychain.Ran(marker, id); err != nil { |
| + return err |
| + } |
| + return record(id) |
| + } |
| + run, err := m.start(u.Context(ctx), dir, marker, mac.Command{Env: env, TTY: tty}, nil, ran, "setup-token") |
| tty.Close() |
| if err != nil { |
| pty.Close() |
| - if !errors.Is(err, mac.ErrUnproven) { |
| + if errors.Is(err, mac.ErrUnproven) { |
| + m.keychain.Abandon(marker) |
| + } else { |
| unstarted() |
| } |
| return nil, err |
| @@ -617,6 +643,7 @@ func (t *macTerminal) Stop() error { |
| t.run.Finish(context.Background()) |
| t.pty.Close() |
| if !proven { |
| + t.m.keychain.Abandon(t.marker) |
| t.err = errUnproven |
| return |
| } |
diff --git a/internal/runner/thin/maccreds_fix1_test.go b/internal/runner/thin/maccreds_fix1_test.go| index d8a8e350..dcb6964f 100644 |
| --- a/internal/runner/thin/maccreds_fix1_test.go |
| +++ b/internal/runner/thin/maccreds_fix1_test.go |
| @@ -123,7 +123,7 @@ func TestDarwinCheckKeychainWatch(t *testing.T) { |
| t.Fatalf("after the cancel: deleted %+v held=%v", r.kc.deleted, r.m.Held()) |
| } |
| }) |
| - t.Run("a crashed check's watch is settled at the restart", func(t *testing.T) { |
| + t.Run("a crashed check's watch is held until a reboot", func(t *testing.T) { |
| r := newDarwinRig(t) |
| local, _ := connected(t, r, fakeclaude.Token("a@example.com")) |
| if err := os.WriteFile(filepath.Join(r.dir, "hang"), nil, 0o600); err != nil { |
| @@ -145,10 +145,15 @@ func TestDarwinCheckKeychainWatch(t *testing.T) { |
| r.kc.mu.Lock() |
| delete(r.kc.created, pid) |
| r.kc.mu.Unlock() |
| + // The restart cannot prove it over (fix round 2): held. |
| r.connector() |
| - |
| - if r.m.Held() || len(r.kc.deleted) != 1 || pidAlive(pid) { |
| - t.Fatalf("after the restart: held=%v deleted %+v CLI alive=%v", r.m.Held(), r.kc.deleted, pidAlive(pid)) |
| + if !r.m.Held() || len(r.kc.deleted) != 0 { |
| + t.Fatalf("after a restart without a reboot: held=%v deleted %+v", r.m.Held(), r.kc.deleted) |
| + } |
| + r.rebooted() |
| + r.connector() |
| + if r.m.Held() || len(r.kc.deleted) != 1 { |
| + t.Fatalf("after a reboot: held=%v deleted %+v", r.m.Held(), r.kc.deleted) |
| } |
| }) |
| } |
| @@ -178,18 +183,22 @@ func TestDarwinCheckUnprovenIsNotSuccess(t *testing.T) { |
| if _, err := os.Stat(filepath.Join(r.cfg.StateDir, "mac-gate.lock.turn")); err != nil { |
| t.Fatalf("the turn's record was dropped: %v", err) |
| } |
| - // Control: proven, the same check reads the profile. |
| + // Control: once a restart proves it over, the check reads the |
| + // profile. |
| os.Remove(filepath.Join(r.dir, "linger")) |
| - r.m.exec.Settle = 10 * time.Second |
| - if _, err := r.opts.CheckToken(r.ctx, b); err != nil || fake.count() != 1 { |
| + again := darwinRigAt(t, r.dir) |
| + again.m.keychain.List, again.m.keychain.Delete = r.kc.list, r.kc.delete |
| + again.opts.Profile = fake.reader(&clock) |
| + again.connector() |
| + if _, err := again.opts.CheckToken(again.ctx, b); err != nil || fake.count() != 1 { |
| t.Fatalf("a proven check: %v, %d profile reads", err, fake.count()) |
| } |
| t.Run("auth status", func(t *testing.T) { |
| r := newDarwinRig(t) |
| local, home := connected(t, r, fakeclaude.Token("a@example.com")) |
| r.lingering(t, "auth") |
| - if _, err := r.m.authStatus(r.ctx, statusBinding(local, home)); !errors.Is(err, mac.ErrUnproven) || !r.m.Held() { |
| - t.Fatalf("an unproven auth status: %v held=%v", err, r.m.Held()) |
| + if _, err := r.m.authStatus(r.ctx, statusBinding(local, home)); !errors.Is(err, mac.ErrUnproven) || !r.m.Held() || len(r.m.keychain.Unproven()) != 1 { |
| + t.Fatalf("an unproven auth status: %v held=%v unproven=%v", err, r.m.Held(), r.m.keychain.Unproven()) |
| } |
| }) |
| } |
| @@ -286,7 +295,7 @@ func TestDarwinSignInUnprovenKeepsTheWatch(t *testing.T) { |
| r.waitFor(func() bool { return r.turnFree() }, "the sign-in to stop") |
| var state string |
| _ = r.state.db.QueryRow("SELECT state FROM connect_attempts WHERE id='s1'").Scan(&state) |
| - if !r.m.Held() || state != "running" { |
| + if !r.m.Held() || state != "running" || len(r.m.keychain.Unproven()) != 1 { |
| t.Fatalf("an unproven sign-in: held=%v state=%s", r.m.Held(), state) |
| } |
| } |
diff --git a/internal/runner/thin/maccreds_fix2_test.go b/internal/runner/thin/maccreds_fix2_test.go| new file mode 100644 |
| index 00000000..bbdcb7a7 |
| --- /dev/null |
| +++ b/internal/runner/thin/maccreds_fix2_test.go |
| @@ -0,0 +1,148 @@ |
| +//go:build testbuild |
| + |
| +package thin |
| + |
| +import ( |
| + "errors" |
| + "os" |
| + "os/exec" |
| + "path/filepath" |
| + "strconv" |
| + "strings" |
| + "syscall" |
| + "testing" |
| + "time" |
| + |
| + "amadan.net/oficina/equipo/internal/fakeclaude" |
| + "amadan.net/oficina/equipo/internal/runner/mac/creds" |
| + "amadan.net/oficina/equipo/internal/wire" |
| +) |
| + |
| +// Task 10 fix round 2 (Astra round 2): a watch clears only once its |
| +// launch's end is proven (Executor.Verify) or the Mac has booted since |
| +// the watch began; until then the Mac keeps its Claude connections |
| +// closed and says so. |
| + |
| +// rebooted makes the Mac's boot time now: later than every watch so far. |
| +func (r *darwinRig) rebooted() { |
| + r.m.boot = func() (time.Time, error) { return time.Now(), nil } |
| +} |
| + |
| +// crashCheck starts a check in a second runner process and SIGKILLs it |
| +// while the check's CLI runs (steered by the hang file); it returns the |
| +// hung CLI's pid. |
| +func (r *darwinRig) crashCheck(t *testing.T, local string) int { |
| + t.Helper() |
| + if err := os.WriteFile(filepath.Join(r.dir, "hang"), nil, 0o600); err != nil { |
| + t.Fatal(err) |
| + } |
| + helper := exec.Command(os.Args[0], "-test.run=^TestDarwinTokenCheckCrashHelper$", "-test.count=1") |
| + helper.Env = append(os.Environ(), "EQUIPO_DARWIN_CRASH_DIR="+r.dir, "EQUIPO_DARWIN_CRASH_LOCAL="+local) |
| + if err := helper.Start(); err != nil { |
| + t.Fatal(err) |
| + } |
| + pid := waitPid(t, filepath.Join(r.dir, "hang.pid")) |
| + _ = helper.Process.Kill() |
| + _ = helper.Wait() |
| + os.Remove(filepath.Join(r.dir, "hang")) |
| + return pid |
| +} |
| + |
| +// TestDarwinCrashedWatchHeldUntilReboot: a runner dies during a check, |
| +// and something of that launch the runner cannot see survives (an |
| +// unmarked process in a session of its own: on a Mac, say, a descendant |
| +// that changed its real uid, which no turn's sweep reaches; started here |
| +// by the test, since a test cannot change uid). It writes a credential |
| +// into the Keychain a moment later. The restart |
| +// cannot prove the launch ended, so the hold stays (and the Mac's |
| +// connections stay closed) through the late write; once the Mac has |
| +// booted since, the watch's second look finds the item and deletes it. |
| +func TestDarwinCrashedWatchHeldUntilReboot(t *testing.T) { |
| + r := newDarwinRig(t) |
| + local, _ := connected(t, r, fakeclaude.Token("a@example.com")) |
| + var item creds.Item |
| + r.kc.appear = func() []creds.Item { |
| + if _, err := os.Stat(filepath.Join(r.dir, "wrote")); err != nil { |
| + return nil |
| + } |
| + raw, _ := os.ReadFile(filepath.Join(r.dir, "hang.pid")) |
| + for _, l := range r.launches() { |
| + if strconv.Itoa(l.pid) == strings.TrimSpace(string(raw)) { |
| + item = r.own(l.env["CLAUDE_CONFIG_DIR"]) |
| + return []creds.Item{item} |
| + } |
| + } |
| + return nil |
| + } |
| + r.crashCheck(t, local) |
| + survivor := exec.Command("/bin/sh", "-c", "sleep 1; touch "+filepath.Join(r.dir, "wrote")) |
| + survivor.SysProcAttr = &syscall.SysProcAttr{Setsid: true} |
| + if err := survivor.Start(); err != nil { |
| + t.Fatal(err) |
| + } |
| + defer func() { _ = survivor.Wait() }() |
| + r.connector() |
| + if !r.m.Held() || len(r.m.keychain.Unproven()) != 1 { |
| + t.Fatalf("the restart let go of a launch it could not prove ended: held=%v unproven=%v", r.m.Held(), r.m.keychain.Unproven()) |
| + } |
| + b, _ := r.binding(local) |
| + if _, err := r.opts.CheckToken(r.ctx, b); !errors.Is(err, errCredentialUnproven) { |
| + t.Fatalf("a check with an unproven launch on record: %v", err) |
| + } |
| + r.waitFor(func() bool { _, err := os.Stat(filepath.Join(r.dir, "wrote")); return err == nil }, "the survivor's late write") |
| + // The write lands in the Keychain (the fake stores it at a listing). |
| + _, _ = r.kc.list(r.ctx, r.m.keychain.Login) |
| + r.m.settle(r.ctx, true) |
| + if !r.m.Held() || item == (creds.Item{}) || !r.kc.has(item) { |
| + t.Fatalf("after the late write: held=%v item %+v", r.m.Held(), item) |
| + } |
| + // The boot time earlier than the watch: still held. |
| + r.m.settle(r.ctx, true) |
| + if !r.m.Held() { |
| + t.Fatal("released with the Mac booted before the watch began") |
| + } |
| + r.rebooted() |
| + r.m.settle(r.ctx, true) |
| + if r.kc.has(item) || len(r.m.keychain.Unproven()) != 0 { |
| + t.Fatalf("after a reboot: item kept=%v unproven=%v", r.kc.has(item), r.m.keychain.Unproven()) |
| + } |
| + r.m.settle(r.ctx, false) |
| + if r.m.Held() { |
| + t.Fatal("held after a reboot and a listing showing the item gone") |
| + } |
| +} |
| + |
| +// TestDarwinUnprovenClosesConnections: an unproven credential launch in |
| +// this process closes the Mac's connections and says why |
| +// (credential_unproven); a restart opens them again once Verify proves |
| +// the launch over (its leftover killed by its record). |
| +func TestDarwinUnprovenClosesConnections(t *testing.T) { |
| + r := newDarwinRig(t) |
| + c := r.connector() |
| + home, _ := r.paste(c, "c1", fakeclaude.Token("a@example.com")) |
| + b, _ := r.binding(filepath.Base(home)) |
| + r.lingering(t, "-p") |
| + if _, err := r.opts.CheckToken(r.ctx, b); err == nil { |
| + t.Fatal("an unproven check passed") |
| + } |
| + os.Remove(filepath.Join(r.dir, "linger")) |
| + if _, err := r.opts.CheckToken(r.ctx, b); !errors.Is(err, errCredentialUnproven) { |
| + t.Fatalf("a check after an unproven one: %v", err) |
| + } |
| + if _, end := r.paste(c, "c2", fakeclaude.Token("b@example.com")); end.Reason != "provider_refused" || r.seals("c2") != 0 { |
| + t.Fatalf("a token stored after an unproven launch: %+v", end) |
| + } |
| + h := &macHost{creds: r.m, taint: r.m.taint, turns: r.m.turns} |
| + caps := wire.Capabilities{} |
| + h.credentialCaps(r.ctx, &caps) |
| + if caps.Unproven != wire.UnprovenCredential || wire.ValidCapabilities(caps) != nil { |
| + t.Fatalf("caps %+v", caps) |
| + } |
| + // The restart proves it over: the leftover carries its record. |
| + again := darwinRigAt(t, r.dir) |
| + again.m.keychain.List, again.m.keychain.Delete = r.kc.list, r.kc.delete |
| + again.connector() |
| + if _, err := again.opts.CheckToken(again.ctx, b); err != nil { |
| + t.Fatalf("after the restart proved it over: %v", err) |
| + } |
| +} |
diff --git a/internal/runner/thin/maccreds_test.go b/internal/runner/thin/maccreds_test.go| index adb7d250..a4a170d0 100644 |
| --- a/internal/runner/thin/maccreds_test.go |
| +++ b/internal/runner/thin/maccreds_test.go |
| @@ -72,7 +72,10 @@ type keychainFake struct { |
| asked []string |
| create func(launched) []creds.Item |
| created map[int]bool |
| - r *darwinRig |
| + // appear, when set, is asked at each listing; what it returns is |
| + // stored once (a write that comes later). |
| + appear func() []creds.Item |
| + r *darwinRig |
| } |
| func (f *keychainFake) list(_ context.Context, keychain string) ([]creds.Item, error) { |
| @@ -94,6 +97,11 @@ func (f *keychainFake) list(_ context.Context, keychain string) ([]creds.Item, e |
| } |
| } |
| } |
| + if f.appear != nil { |
| + if more := f.appear(); len(more) > 0 { |
| + f.items, f.appear = append(f.items, more...), nil |
| + } |
| + } |
| var out []creds.Item |
| for _, i := range append(slices.Clone(f.items), f.ghost...) { |
| if i.Keychain == keychain { |
| @@ -232,6 +240,7 @@ func darwinRigAt(t *testing.T, dir string) *darwinRig { |
| configDir: filepath.Join(dir, "config"), runner: proxy, scratch: r.cfg.ScratchRoot, taint: loadTaint(filepath.Join(r.cfg.StateDir, "tainted")), |
| user: r.user, uid: os.Getuid(), log: slog.New(slog.NewTextHandler(&r.logs, nil))} |
| m.fact = func(p string) (creds.Fact, error) { return creds.Read(p, nil) } |
| + m.boot = creds.BootTime |
| m.keychain = &creds.Keychain{Dir: filepath.Join(r.cfg.StateDir, "keychain"), Login: filepath.Join(dir, "Library", "Keychains", "login.keychain-db"), User: r.user, List: r.kc.list, Delete: r.kc.delete} |
| r.m = m |
| r.opts = ClaudeOptions{Runner: r.cfg, State: r.state, Mac: m, LockWait: 5 * time.Second} |
| @@ -461,9 +470,17 @@ func TestDarwinTokenCheck(t *testing.T) { |
| } |
| os.Remove(filepath.Join(r.dir, "hang")) |
| b, _ := r.binding(local) |
| - if _, err := r.opts.CheckToken(context.Background(), b); err != nil { |
| + // Its end can never be proven (its turn's record is incomplete): |
| + // connections stay closed until the Mac has booted since (fix |
| + // round 2). |
| + if _, err := r.opts.CheckToken(context.Background(), b); !errors.Is(err, errCredentialUnproven) { |
| t.Fatalf("the check after the crash: %v", err) |
| } |
| + r.rebooted() |
| + r.connector() |
| + if _, err := r.opts.CheckToken(context.Background(), b); err != nil { |
| + t.Fatalf("the check after a reboot: %v", err) |
| + } |
| if pidAlive(pid) { |
| t.Fatal("the next turn left the dead runner's CLI running") |
| } |
diff --git a/internal/wire/runners.go b/internal/wire/runners.go| index 1d35a45f..a096eb12 100644 |
| --- a/internal/wire/runners.go |
| +++ b/internal/wire/runners.go |
| @@ -338,6 +338,11 @@ type Capabilities struct { |
| // never proven. |
| const UnprovenRecordIncomplete = "record_incomplete" |
| +// UnprovenCredential: a Mac could not prove that an earlier launch that |
| +// had a model credential (a sign-in, a token check) ended, so it keeps |
| +// its Claude connections closed until it restarts. |
| +const UnprovenCredential = "credential_unproven" |
| + |
| // PreviewHost is a preview host a runner pairs with: its kind (an |
| // adapter: CARLOS devbox on the tailnet, or Carloku temporary sites) and |
| // the domain its links live under, "" until known. |
| @@ -435,7 +440,7 @@ func ValidCapabilities(c Capabilities) error { |
| if h := c.PreviewHost; h != nil && (!c.Previews || h.Kind != PreviewHostDevbox && h.Kind != PreviewHostCarlokuTemp || h.Domain != "" && (len(h.Domain) > 253 || !previewHostDomain.MatchString(h.Domain))) { |
| return ErrCapabilities |
| } |
| - if h := c.Tools; h != nil && !validToolHealth(*h) || c.Unproven != "" && c.Unproven != UnprovenRecordIncomplete { |
| + if h := c.Tools; h != nil && !validToolHealth(*h) || c.Unproven != "" && c.Unproven != UnprovenRecordIncomplete && c.Unproven != UnprovenCredential { |
| return ErrCapabilities |
| } |
| if r := c.Reach; r != nil && !validReach(*r) { |