Mac slice F task 11 fix 1: complete inventory, sync hold, 37 gates
Astra round 1, findings 1 to 4, tests first:
1. A worker's hello after the welcome carries an inventory mark
(Hello.Inventory, 37). Only a marked, non-handshake hello with a
valid capability report signs a connection out or releases the
credential hold; the hello before the welcome never does.
2. A worker's sync at 37 records its connections and holds the Mac in
the same transaction; it never signs one out or releases.
3. Below 37 the instance delivers no connection command to a worker and
refuses its connection reports; the worker neither acts on nor acks
them and keeps its connection and usage reports in its outbox.
4. chat_usage.runner_id stays NULL below 37; a worker below 37 has no
usage recorded.
Tests written after their code in the first pass (exceptions, finding
5), with the mutation that killed each:
- TestWorkerProfileAtStartGated: P1, no Gate() in readProfilesAtStart
("a tainted Mac read 1 profiles").
- TestEncodeDropsEmptyMacEngineeringKeysBelow37 "hello hold": W1, the
hold kept below 37 ("kept the empty model_hold").
- TestEncodeDropsEmptyMacEngineeringKeysBelow37 "disconnect",
"disconnect named": W2, the disconnect's runner kept below 37 ("kept
the empty runner_id").
- TestHoldingItemsBounded: W3, holding items unbounded ("more than
MaxHoldingItems taken").
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
14 files changed,
+433
−52
.rastrillo/budgets.txt+4 −4internal/equipo/chat/connections.go+24 −8internal/equipo/chat/models_store_test.go+1 −1internal/equipo/chat/runner.go+21 −8internal/equipo/chat/worker_connections.go+27 −20internal/runner/thin/link.go+12 −0internal/runner/thin/worker_conns.go+3 −1internal/runner/thin/worker_conns_test.go+70 −4internal/thintest/worker_connections_contract_test.go+3 −3internal/thintest/worker_connections_fix1_contract_test.go+252 −0internal/wire/connections.go+5 −0internal/wire/frames.go+5 −0internal/wire/mac_engineering.go+5 −3internal/wire/mac_engineering_test.go+1 −0
diff --git a/.rastrillo/budgets.txt b/.rastrillo/budgets.txt| index adff68b7..3d9886fb 100644 |
| --- a/.rastrillo/budgets.txt |
| +++ b/.rastrillo/budgets.txt |
| @@ -15,7 +15,7 @@ time internal/equipo/team 60s Plan 3 loaded CI measured 45.985s; niced serial re |
| 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 24117 - Preview, retry, merges, kept work, check-db, notifications, places, GitHub routes, Mac waits, probe and proof codes, Mac credential copy, Mac connections; measured 24117. |
| -size internal/wire 8635 - Protocols 31 to 35 (facts, diffs, evidence, CI units, files, places), Mac waits, 37 Mac Engineering, probe and proof codes, credential_unproven, model hold; measured 8635. |
| +size internal/wire 8647 - Protocols 31 to 35 (facts, diffs, evidence, CI units, files, places), Mac waits, 37 Mac Engineering, probe and proof codes, credential_unproven, model hold; measured 8647. |
| 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 31676 28599 Protocols 31 to 35, merge credential, publication guards, kept work, scans, Mac pin, paths, bases, endpoint, Mac turns, Mac credentials, worker conns; measured 31676/28599. |
| +size internal/runner/thin 31690 28665 Protocols 31 to 35, merge credential, publication guards, kept work, scans, Mac pin, paths, bases, endpoint, Mac turns, Mac credentials, worker conns; measured 31690/28665. |
| 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). |
| @@ -56,7 +56,7 @@ perf GET /api/v1/tasks/{id} skip Thin v1 person API: bearer-only JSON for device |
| perf GET /api/v1/assistant/snapshot skip Assistant person API: bearer-only JSON for Base's chat, not a browser screen. |
| perf GET /api/v1/assistant/messages skip Assistant person API: bearer-only JSON for Base's chat, not a browser screen. |
| perf GET /api/v1/assistant/events skip Assistant event stream (Server-Sent Events), bearer-only and long-lived; not a screen. |
| -size internal/equipo/chat 39154 12096 File facts/diffs, previews, merge authority, unfinished work, CI feedback, notification receipts, Assistant files, places, waiting cards, Mac waits, Mac Engineering, Mac conns; measured 39154/12096. |
| +size internal/equipo/chat 39190 12096 File facts/diffs, previews, merge authority, unfinished work, CI feedback, notification receipts, Assistant files, places, waiting cards, Mac waits, Mac Engineering, Mac conns; measured 39190/12096. |
| perf GET /api/v1/questions/{id} skip Thin v1 person API: bearer-only JSON for devices; the browser reads questions on /tasks/{id}. |
| perf GET /api/v1/steps/{id}/log skip Thin v1 person API: bearer-only JSON for devices; the browser shows the log tail on /tasks/{id}. |
| perf GET /api/v1/connections/preference skip Connections slice 1 person API: bearer-only JSON for devices; the browser shows the preference on /conversation/connections. |
| @@ -71,7 +71,7 @@ perf GET /tasks/{id}/files/{file} skip Research kept images: the bytes of one im |
| perf GET /api/v1/runners skip Mac runners person API: bearer-only JSON for devices; the browser shows runners in the Team section. |
| time cmd/equipo-runner 60s TestReleaseRunnerHasNoFakeWorker builds the release runner and the thin package under testbuild (about 12s locally). |
| size internal/headless - 11977 Grant scenarios (#48); sign-in email at 1280 and 390; Assistant files end to end; the restart wait; the live site waits for a place; a card answer settles at the bottom; measured 11977 test lines. |
| -size internal/thintest - 39336 Protocol 31 contracts, 35 diffs, stuck tasks, no-access merges, held retries, unfinished work, free rounds, previews, Assistant files, places, Mac waits, Mac Engineering, Mac conns; measured 39336. |
| +size internal/thintest - 39588 Protocol 31 contracts, 35 diffs, stuck tasks, no-access merges, held retries, unfinished work, free rounds, previews, Assistant files, places, Mac waits, Mac Engineering, Mac conns; measured 39588. |
| perf GET /api/v1/projects/{id}/merge-policy skip Merge authority person API: bearer-only JSON for devices; the browser reads the policy on /projects/{id}. |
| perf GET /api/v1/usage skip Thin v1 person API: bearer-only JSON for devices; the browser reads usage through /usage. |
diff --git a/internal/equipo/chat/connections.go b/internal/equipo/chat/connections.go| index f2af1f7b..fdae1b66 100644 |
| --- a/internal/equipo/chat/connections.go |
| +++ b/internal/equipo/chat/connections.go |
| @@ -92,8 +92,8 @@ type usageRecord struct { |
| Person string `gorm:"index:chat_usage_person,priority:1"` |
| // RunnerID is the runner that reported the row: a connection is its |
| // runner and local id (local ids repeat across runners). Rows before |
| - // slice F name none: the main runner's. |
| - RunnerID string |
| + // slice F, and rows below 37, name none (NULL): the main runner's. |
| + RunnerID *string |
| Connection string `gorm:"uniqueIndex:chat_usage_key,priority:4"` |
| Provider string |
| Model string `gorm:"uniqueIndex:chat_usage_key,priority:5"` |
| @@ -284,10 +284,10 @@ func (t *txn) connections(person string) ([]connectionRecord, error) { |
| // helloConnections records what the person's runner holds: new |
| // connections appear, changed ones update (headroom at most once a |
| -// minute), and one the runner no longer holds is signed out. A |
| -// teammate's connection in the same hello is never recorded for this |
| -// person: only the runner's own person's. |
| -func (t *txn) helloConnections(l Lease, held []wire.HeldConnection) error { |
| +// minute), and, when the report is complete, one the runner no longer |
| +// holds is signed out. A teammate's connection in the same hello is |
| +// never recorded for this person: only the runner's own person's. |
| +func (t *txn) helloConnections(l Lease, held []wire.HeldConnection, complete bool) error { |
| person, runner := l.Runner.Person, l.Runner.RunnerID |
| rows, err := t.connections(person) |
| if err != nil { |
| @@ -356,7 +356,8 @@ func (t *txn) helloConnections(l Lease, held []wire.HeldConnection) error { |
| } |
| } |
| for _, r := range rows { |
| - if r.RunnerID == runner && r.LocalID != "" && !seen[r.LocalID] && r.State != wire.ConnSignedOut && r.State != wire.ConnConnecting { |
| + // Only a complete report says a connection is gone. |
| + if complete && r.RunnerID == runner && r.LocalID != "" && !seen[r.LocalID] && r.State != wire.ConnSignedOut && r.State != wire.ConnConnecting { |
| r.State, r.Headroom = wire.ConnSignedOut, "" |
| if err := t.saveConnection(&r, false); err != nil { |
| return err |
| @@ -411,6 +412,11 @@ func validChoices(cs []wire.ModelChoice) bool { |
| // 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 l.Role == wire.RoleWorker && l.Protocol < wire.ProtocolMacEngineering { |
| + // A worker below 37 holds no connection: what it replays is not |
| + // applied. |
| + return ErrRefused |
| + } |
| if !wire.ConnectReasons[v.Reason] || !slices.Contains([]string{wire.ConnConnecting, wire.ConnHealthy, wire.ConnError, wire.ConnLimited, wire.ConnSignedOut}, v.State) { |
| return ErrInvalid |
| } |
| @@ -1049,12 +1055,20 @@ var usageOutcomes = map[string]bool{wire.OutcomeReplied: true, wire.OutcomeFaile |
| // question; round the step's fix round. |
| func (t *txn) recordUsage(l Lease, person, role, task, step, turn string, round int, rows []wire.Usage) error { |
| protocol := l.Protocol |
| + // Below 37 a row keeps its legacy form (no runner), and a worker has |
| + // no connection usage to record. |
| + var runner *string |
| + if protocol >= wire.ProtocolMacEngineering { |
| + runner = &l.Runner.RunnerID |
| + } else if l.Role == wire.RoleWorker { |
| + return nil |
| + } |
| settle := map[int64]bool{} |
| for _, u := range rows { |
| if !usageOutcomes[u.Outcome] || u.Attempt < 1 || len(u.Model) > 200 || len(u.Connection) > 200 || u.Turns != nil && *u.Turns < 0 || u.CostMicros != nil && *u.CostMicros < 0 || u.CostReportedMicros != nil && *u.CostReportedMicros < 0 || len(u.Currency) > 8 || len(u.PriceVersion) > 64 || len(u.Family) > 64 || len(u.Tier) > 16 || len(u.TierVersion) > 64 { |
| return ErrInvalid |
| } |
| - r := usageRecord{Person: person, RunnerID: l.Runner.RunnerID, Connection: u.Connection, Provider: u.Provider, Model: u.Model, Role: role, TaskID: task, StepID: step, TurnID: turn, Attempt: u.Attempt, Outcome: u.Outcome, Complete: u.Complete, InputTokens: u.InputTokens, CachedInputTokens: u.CachedInputTokens, CacheWriteTokens: u.CacheWriteTokens, OutputTokens: u.OutputTokens, ReasoningOutputTokens: u.ReasoningOutputTokens, Round: round, Turns: u.Turns, Overcount: protocol < wire.ProtocolSpend && u.Provider == "claude" && (role == "coordinator" || role == "ask"), CostMicros: u.CostMicros, Currency: u.Currency, PriceVersion: u.PriceVersion, CostReportedMicros: u.CostReportedMicros, Family: u.Family, Tier: u.Tier, TierVersion: u.TierVersion, ModelMismatch: u.ModelMismatch, RecordedAt: t.now()} |
| + r := usageRecord{Person: person, RunnerID: runner, Connection: u.Connection, Provider: u.Provider, Model: u.Model, Role: role, TaskID: task, StepID: step, TurnID: turn, Attempt: u.Attempt, Outcome: u.Outcome, Complete: u.Complete, InputTokens: u.InputTokens, CachedInputTokens: u.CachedInputTokens, CacheWriteTokens: u.CacheWriteTokens, OutputTokens: u.OutputTokens, ReasoningOutputTokens: u.ReasoningOutputTokens, Round: round, Turns: u.Turns, Overcount: protocol < wire.ProtocolSpend && u.Provider == "claude" && (role == "coordinator" || role == "ask"), CostMicros: u.CostMicros, Currency: u.Currency, PriceVersion: u.PriceVersion, CostReportedMicros: u.CostReportedMicros, Family: u.Family, Tier: u.Tier, TierVersion: u.TierVersion, ModelMismatch: u.ModelMismatch, RecordedAt: t.now()} |
| if err := t.db.Clauses(clause.OnConflict{DoNothing: true}).Create(&r).Error; err != nil { |
| return err |
| } |
| @@ -1085,6 +1099,8 @@ func (t *txn) stepRound(id string) (int, error) { |
| // usageReport records the rows of attempts that produced no reply, for |
| // one of the person's own turns, steps or questions. |
| func (t *txn) usageReport(l Lease, v *wire.UsageReport) error { |
| + // A worker below 37 has none of its connections' usage recorded |
| + // (recordUsage). |
| person := l.Runner.Person |
| switch { |
| case v.TurnID != "" && v.StepID == "" && v.QuestionID == "": |
diff --git a/internal/equipo/chat/models_store_test.go b/internal/equipo/chat/models_store_test.go| index 5fb8dd09..53835ebd 100644 |
| --- a/internal/equipo/chat/models_store_test.go |
| +++ b/internal/equipo/chat/models_store_test.go |
| @@ -93,7 +93,7 @@ func TestModelsWritesCheckOwnerRosterAndRevision(t *testing.T) { |
| t.Helper() |
| h := wire.HeldConnection{LocalID: "tensorx-abc", Person: "owner@example.com", Provider: wire.ProviderTensorX, Kind: wire.KindAPIKey, State: wire.ConnHealthy, Billing: wire.BillingMetered, Model: "z-ai/glm-5.3", Budget: &wire.Budget{Day: 1000000, Month: 10000000, Currency: "USD", Revision: 1}, Spend: &wire.Spend{Currency: "USD"}, Models: []wire.ModelState{{ID: "z-ai/glm-5.3", State: wire.ModelHealthy}}, ModelsRevision: rev} |
| l := Lease{Runner: RunnerPrincipal{RunnerID: "RUNNER1", Person: "owner@example.com"}, Protocol: wire.ProtocolModels} |
| - if err := r.s.tx(ctx, func(t *txn) error { return t.helloConnections(l, []wire.HeldConnection{h}) }); err != nil { |
| + if err := r.s.tx(ctx, func(t *txn) error { return t.helloConnections(l, []wire.HeldConnection{h}, true) }); err != nil { |
| t.Fatal(err) |
| } |
| got, _ := r.s.Connection(ctx, "owner@example.com", "cn_made") |
diff --git a/internal/equipo/chat/runner.go b/internal/equipo/chat/runner.go| index f264f1a9..214681fc 100644 |
| --- a/internal/equipo/chat/runner.go |
| +++ b/internal/equipo/chat/runner.go |
| @@ -107,10 +107,10 @@ func (s *Store) Connect(ctx context.Context, p RunnerPrincipal, process string, |
| if err := t.resolveAccess(p.Person, hello); err != nil { |
| return err |
| } |
| - if err := t.helloConnections(lease, hello.Connections); err != nil { |
| + if err := t.helloConnections(lease, hello.Connections, true); err != nil { |
| return err |
| } |
| - } else if err := t.workerHello(lease, hello); err != nil { |
| + } else if err := t.workerHello(lease, hello, true); err != nil { |
| return err |
| } |
| if err := t.runnerEvent(p.Person, r); err != nil { |
| @@ -232,7 +232,7 @@ func (s *Store) Heartbeat(ctx context.Context, l Lease, hello wire.Hello) error |
| if err := t.resolveAccess(l.Runner.Person, hello); err != nil { |
| return err |
| } |
| - if err := t.helloConnections(l, hello.Connections); err != nil { |
| + if err := t.helloConnections(l, hello.Connections, true); err != nil { |
| return err |
| } |
| if err := t.recordAddresses(l, hello, nil); err != nil { |
| @@ -243,7 +243,7 @@ func (s *Store) Heartbeat(ctx context.Context, l Lease, hello wire.Hello) error |
| return err |
| } |
| } |
| - } else if err := t.workerHello(l, hello); err != nil { |
| + } else if err := t.workerHello(l, hello, false); err != nil { |
| return err |
| } |
| if !online { |
| @@ -302,6 +302,12 @@ func (s *Store) Pending(ctx context.Context, l Lease, after int64) (out []wire.F |
| } |
| for _, r := range rows { |
| body := r.Body |
| + if l.Role == wire.RoleWorker && l.Protocol < wire.ProtocolMacEngineering && wire.ConnectionCommands[r.Kind] { |
| + // A worker below 37 is given nothing of its connections; |
| + // the command waits, unacked, for a connection at 37. |
| + last = r.Seq |
| + continue |
| + } |
| if r.Kind == wire.FrameAttachment { |
| // The chunk's bytes come from the stored file as it goes. |
| if body, err = hydrate(tx, body); err != nil { |
| @@ -640,14 +646,21 @@ func (t *txn) sync(l Lease, v *wire.Sync) error { |
| return err |
| } |
| if primary != l.Runner.RunnerID { |
| - // A worker's own connections (37): the sync carries them as a |
| - // hello does; nothing else of the primary's is its to settle. |
| + // A worker's own connections (37): what the sync reports is |
| + // recorded and holds the Mac at once; it never says one is gone |
| + // (only a complete hello does). Nothing else of the primary's is |
| + // its to settle. |
| if l.Role == wire.RoleWorker && l.Protocol >= wire.ProtocolMacEngineering { |
| - return t.helloConnections(l, v.Connections) |
| + if err := t.helloConnections(l, v.Connections, false); err != nil { |
| + return err |
| + } |
| + if len(v.Connections) > 0 { |
| + return t.holdCredential(l.Runner.RunnerID) |
| + } |
| } |
| return nil |
| } |
| - if err := t.helloConnections(l, v.Connections); err != nil { |
| + if err := t.helloConnections(l, v.Connections, true); err != nil { |
| return err |
| } |
| if err := t.advanceAll(l.Runner.Person); err != nil { |
diff --git a/internal/equipo/chat/worker_connections.go b/internal/equipo/chat/worker_connections.go| index e6ecac4e..7ccc473b 100644 |
| --- a/internal/equipo/chat/worker_connections.go |
| +++ b/internal/equipo/chat/worker_connections.go |
| @@ -142,25 +142,29 @@ func (t *txn) holdCredential(runner string) error { |
| } |
| // helloHold applies a worker's hello (protocol 37) to its credential |
| -// hold: held while the hello says anything of a credential may be there, |
| -// says nothing it can be judged by (no valid capability report), or the |
| -// instance has an attempt connecting there or a connect or secret frame |
| -// the Mac has not taken; released only when none of that is so. |
| -func (t *txn) helloHold(l Lease, h wire.Hello) error { |
| +// hold. Anything of a credential it reports holds. Only the Mac's |
| +// complete report (the inventory mark, after the welcome, with a valid |
| +// capability report) may release it, and only when the instance has no |
| +// attempt connecting there and no connect or secret frame the Mac has |
| +// not taken. Any other hello changes nothing. |
| +func (t *txn) helloHold(l Lease, h wire.Hello, handshake bool) error { |
| runner := l.Runner.RunnerID |
| c := cleanHello(h).Capabilities |
| - held := c == nil || c.ModelHold || len(c.HoldingItems) > 0 || c.Unproven == wire.UnprovenCredential || len(h.Connections) > 0 |
| - if !held { |
| - var connecting, untaken int64 |
| - if err := t.db.Model(&connectionRecord{}).Where("runner_id = ? AND state = ?", runner, wire.ConnConnecting).Count(&connecting).Error; err != nil { |
| - return err |
| - } |
| - if err := t.db.Model(&commandRecord{}).Where("runner_id = ? AND kind IN ? AND acked_at IS NULL", runner, []string{wire.FrameConnect, wire.FrameSecret}).Count(&untaken).Error; err != nil { |
| - return err |
| - } |
| - held = connecting+untaken > 0 |
| + if c != nil && (c.ModelHold || len(c.HoldingItems) > 0 || c.Unproven == wire.UnprovenCredential) || len(h.Connections) > 0 { |
| + return t.holdCredential(runner) |
| + } |
| + if handshake || !h.Inventory || c == nil { |
| + // Not the Mac's complete word: it changes nothing. |
| + return nil |
| + } |
| + var connecting, untaken int64 |
| + if err := t.db.Model(&connectionRecord{}).Where("runner_id = ? AND state = ?", runner, wire.ConnConnecting).Count(&connecting).Error; err != nil { |
| + return err |
| + } |
| + if err := t.db.Model(&commandRecord{}).Where("runner_id = ? AND kind IN ? AND acked_at IS NULL", runner, []string{wire.FrameConnect, wire.FrameSecret}).Count(&untaken).Error; err != nil { |
| + return err |
| } |
| - if held { |
| + if connecting+untaken > 0 { |
| return t.holdCredential(runner) |
| } |
| return t.db.Exec(`UPDATE runners SET credential_held_at = NULL WHERE id = ?`, runner).Error |
| @@ -168,15 +172,18 @@ func (t *txn) helloHold(l Lease, h wire.Hello) error { |
| // workerHello records what a worker's hello says of its connections: |
| // below ProtocolMacEngineering nothing (its hello was read without them); |
| -// from it, that worker's connections and its credential hold. |
| -func (t *txn) workerHello(l Lease, h wire.Hello) error { |
| +// from it, that worker's connections and its credential hold. Only the |
| +// complete report (the inventory mark, after the welcome) signs a |
| +// connection out or releases the hold: the hello before the welcome |
| +// (handshake) never does, whatever it says. |
| +func (t *txn) workerHello(l Lease, h wire.Hello, handshake bool) error { |
| if l.Role != wire.RoleWorker || l.Protocol < wire.ProtocolMacEngineering { |
| return nil |
| } |
| - if err := t.helloConnections(l, h.Connections); err != nil { |
| + if err := t.helloConnections(l, h.Connections, h.Inventory && !handshake); err != nil { |
| return err |
| } |
| - return t.helloHold(l, h) |
| + return t.helloHold(l, h, handshake) |
| } |
| // preferenceRunners are the runners a preference goes to: the main |
diff --git a/internal/runner/thin/link.go b/internal/runner/thin/link.go| index de22abe5..67142292 100644 |
| --- a/internal/runner/thin/link.go |
| +++ b/internal/runner/thin/link.go |
| @@ -479,6 +479,11 @@ func (l *Link) send(ctx context.Context, c *websocket.Conn, f wire.Frame) error |
| l.mu.Lock() |
| proto, role := l.proto, l.role |
| l.mu.Unlock() |
| + if (f.Type == wire.FrameConnection || f.Type == wire.FrameUsage) && (l.WorkerOnly || role == wire.RoleWorker) && proto < wire.ProtocolMacEngineering { |
| + // A worker says nothing of its connections below 37: kept in |
| + // the outbox for a connection that speaks it. |
| + return nil |
| + } |
| if f.Type == wire.FrameToolCall { |
| body, err := f.Decode() |
| if err != nil { |
| @@ -775,6 +780,13 @@ func (l *Link) read(ctx context.Context, c *websocket.Conn) (time.Duration, erro |
| if err != nil { |
| return 0, err |
| } |
| + if wire.ConnectionCommands[f.Type] { |
| + if proto, role := l.Spoken(); (l.WorkerOnly || role == wire.RoleWorker) && proto < wire.ProtocolMacEngineering { |
| + // A worker takes no connection command below 37: not acted |
| + // on and not acked, it waits for a connection that speaks it. |
| + continue |
| + } |
| + } |
| switch v := body.(type) { |
| case *wire.AttachmentChunk: |
| // Written and recorded before the ack; chunks precede the |
diff --git a/internal/runner/thin/worker_conns.go b/internal/runner/thin/worker_conns.go| index 4c74b818..e7999d43 100644 |
| --- a/internal/runner/thin/worker_conns.go |
| +++ b/internal/runner/thin/worker_conns.go |
| @@ -94,7 +94,9 @@ func (w *workerConns) hello(spoken int, h *wire.Hello) { |
| if spoken < wire.ProtocolMacEngineering { |
| return |
| } |
| - h.Connections, h.SealKey = w.conns.Held(), w.sealKey |
| + // After the welcome, and only then, this is the whole inventory: the |
| + // instance may release a hold on it. |
| + h.Connections, h.SealKey, h.Inventory = w.conns.Held(), w.sealKey, true |
| if h.Capabilities == nil { |
| return |
| } |
diff --git a/internal/runner/thin/worker_conns_test.go b/internal/runner/thin/worker_conns_test.go| index c0549508..3f3d7d2b 100644 |
| --- a/internal/runner/thin/worker_conns_test.go |
| +++ b/internal/runner/thin/worker_conns_test.go |
| @@ -6,6 +6,7 @@ import ( |
| "context" |
| "crypto/ed25519" |
| "crypto/rand" |
| + "database/sql" |
| "encoding/base64" |
| "encoding/json" |
| "log/slog" |
| @@ -225,8 +226,8 @@ func TestWorkerHelloConnections(t *testing.T) { |
| inst := newWorkerInstance(t) |
| stop := r.runWorker(inst, 0) |
| first := inst.welcome(wire.ProtocolMacEngineering) |
| - if len(first.Connections) != 0 || first.SealKey != "" { |
| - t.Fatalf("the first hello, before the welcome: %+v %q", first.Connections, first.SealKey) |
| + if len(first.Connections) != 0 || first.SealKey != "" || first.Inventory { |
| + t.Fatalf("the first hello, before the welcome: %+v %q inventory=%v", first.Connections, first.SealKey, first.Inventory) |
| } |
| inst.next(wire.FrameHello, func(b any) bool { return b.(*wire.Hello).SealKey == key }) |
| inst.send(wire.FrameConnect, wire.ConnectCommand{Connection: "cn_w1", Person: connPerson, Provider: wire.ProviderClaude, Kind: wire.KindToken}) |
| @@ -244,6 +245,9 @@ func TestWorkerHelloConnections(t *testing.T) { |
| if c := h.Connections[0]; c.LocalID != end.LocalID || c.Kind != wire.KindToken || c.Person != connPerson || h.SealKey != key { |
| t.Fatalf("hello at 37: %+v %q", h.Connections, h.SealKey) |
| } |
| + if !h.Inventory { |
| + t.Fatal("the hello after the welcome does not say it is the whole inventory") |
| + } |
| if h.Capabilities == nil || !h.Capabilities.ModelHold { |
| t.Fatalf("a worker holding a token said it holds none: %+v", h.Capabilities) |
| } |
| @@ -287,12 +291,74 @@ func TestWorkerHelloConnections(t *testing.T) { |
| if len(first.Connections) != 0 || len(sync.Connections) != 0 || len(h.Connections) != 0 || h.SealKey != "" || first.SealKey != "" { |
| t.Fatalf("at 35: first %+v, sync %+v, hello %+v %q", first.Connections, sync.Connections, h.Connections, h.SealKey) |
| } |
| - if h.Capabilities != nil && (h.Capabilities.ModelHold || len(h.Capabilities.HoldingItems) > 0) { |
| - t.Fatalf("the hold said below 37: %+v", h.Capabilities) |
| + if h.Capabilities != nil && (h.Capabilities.ModelHold || len(h.Capabilities.HoldingItems) > 0) || h.Inventory { |
| + t.Fatalf("the hold or the inventory said below 37: %+v inventory=%v", h.Capabilities, h.Inventory) |
| + } |
| + // Below 37 a worker acts on no connection command, acks none, and |
| + // replays nothing of its connections (fix round 1, #3). |
| + local := filepath.Base(r.homeOf(t, "cn_w3")) |
| + launches := len(r.launches()) |
| + var prefer string |
| + _ = r.state.db.QueryRow("SELECT value FROM meta WHERE key=?", "prefer:"+connPerson).Scan(&prefer) |
| + if err := r.state.tx(r.ctx, func(t *sql.Tx) error { |
| + return r.state.enqueue(t, wire.FrameConnection, "", wire.ConnectionReport{Connection: "cn_w3", Person: connPerson, LocalID: local, Provider: wire.ProviderClaude, State: wire.ConnSignedOut}) |
| + }); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := r.state.ReportCheck(r.ctx, []wire.Usage{{Provider: wire.ProviderClaude, Connection: local, Model: "claude-opus-5-5", Attempt: 1, Outcome: wire.OutcomeReplied, Complete: true}}); err != nil { |
| + t.Fatal(err) |
| + } |
| + again.send(wire.FrameConnect, wire.ConnectCommand{Connection: "cn_w4", Person: connPerson, Provider: wire.ProviderClaude, Kind: wire.KindToken}) |
| + again.send(wire.FrameSecret, r.sealed("cn_w4", fakeclaude.Token("w4@example.com"), nil)) |
| + again.send(wire.FrameCheck, wire.CheckCommand{Connection: "cn_w3", Person: connPerson, LocalID: local}) |
| + again.send(wire.FramePreference, wire.PreferenceCommand{Person: connPerson, Provider: wire.ProviderCodex, Revision: 9}) |
| + again.send(wire.FrameCancelConnect, wire.CancelConnectCommand{Connection: "cn_w3", Person: connPerson}) |
| + again.send(wire.FrameDisconnect, wire.DisconnectCommand{Connection: "cn_w3", Person: connPerson, LocalID: local, RunnerID: tokenRunner}) |
| + again.quiet(3*time.Second, func(w workerFrame) bool { |
| + switch w.f.Type { |
| + case wire.FrameConnection, wire.FrameUsage, wire.FrameAck: |
| + return true |
| + } |
| + return false |
| + }) |
| + var attempts int |
| + _ = r.state.db.QueryRow("SELECT count(*) FROM connect_attempts WHERE id='cn_w4'").Scan(&attempts) |
| + var now string |
| + _ = r.state.db.QueryRow("SELECT value FROM meta WHERE key=?", "prefer:"+connPerson).Scan(&now) |
| + if _, ok := r.conns.Binding(local); !ok || attempts != 0 || r.seals("cn_w4") != 0 || len(r.launches()) != launches || now != prefer { |
| + t.Fatalf("below 37: bound=%v attempts=%d seals=%d launches %d->%d preference %q->%q", ok, attempts, r.seals("cn_w4"), launches, len(r.launches()), prefer, now) |
| } |
| stop() |
| } |
| +// homeOf is the home an attempt made. |
| +func (r *darwinRig) homeOf(t *testing.T, id string) string { |
| + t.Helper() |
| + var home string |
| + if err := r.state.db.QueryRow("SELECT home FROM connect_attempts WHERE id=?", id).Scan(&home); err != nil || home == "" { |
| + t.Fatalf("no home for %s: %v", id, err) |
| + } |
| + return home |
| +} |
| + |
| +// quiet fails if, within d, the worker sends a frame bad says is one it |
| +// must not send. |
| +func (i *workerInstance) quiet(d time.Duration, bad func(workerFrame) bool) { |
| + i.t.Helper() |
| + deadline := time.After(d) |
| + for { |
| + select { |
| + case w := <-i.frames: |
| + if bad(w) { |
| + raw, _ := json.Marshal(w.body) |
| + i.t.Fatalf("below 37 the worker sent %s: %s", w.f.Type, raw) |
| + } |
| + case <-deadline: |
| + return |
| + } |
| + } |
| +} |
| + |
| // TestWorkerTokenConnectionStored: a pasted token on a worker rests in a |
| // 0600 file in a 0700 home inside a 0700 accounts root; with the home |
| // guard failing nothing is stored. |
diff --git a/internal/thintest/worker_connections_contract_test.go b/internal/thintest/worker_connections_contract_test.go| index c84f9670..54fa61ad 100644 |
| --- a/internal/thintest/worker_connections_contract_test.go |
| +++ b/internal/thintest/worker_connections_contract_test.go |
| @@ -16,11 +16,11 @@ import ( |
| // until the Mac says its files, its Keychain items and any unproven |
| // launch are all gone. |
| -// workerConnHello is a Mac worker's hello at 37 with its seal key and |
| -// connections. |
| +// workerConnHello is a Mac worker's hello at 37 after the welcome: its |
| +// seal key and connections, the whole inventory. |
| func workerConnHello(key string, conns ...wire.HeldConnection) wire.Hello { |
| h := macEngineerHello("Tito Studio", wire.EngineeringNoConnection, wire.ProtocolMacEngineering, false) |
| - h.SealKey, h.Connections = key, append([]wire.HeldConnection{}, conns...) |
| + h.SealKey, h.Connections, h.Inventory = key, append([]wire.HeldConnection{}, conns...), true |
| return h |
| } |
diff --git a/internal/thintest/worker_connections_fix1_contract_test.go b/internal/thintest/worker_connections_fix1_contract_test.go| new file mode 100644 |
| index 00000000..14ce776f |
| --- /dev/null |
| +++ b/internal/thintest/worker_connections_fix1_contract_test.go |
| @@ -0,0 +1,252 @@ |
| +package thintest |
| + |
| +import ( |
| + "testing" |
| + "time" |
| + |
| + "amadan.net/oficina/equipo/internal/wire" |
| +) |
| + |
| +// Task 11, fix round 1 (Astra round 1): a worker's reconnect never lets |
| +// the credential hold lapse (#1), a sync that reports a connection holds |
| +// in its own transaction (#2), nothing of a worker's connections moves |
| +// below 37 in either direction (#3), and usage keeps its legacy form |
| +// below 37 (#4). |
| + |
| +// heldNow is the instance's hold on runner, read from the store as it |
| +// is now. |
| +func (r *runnersRig) heldNow(runner string) bool { |
| + r.t.Helper() |
| + held, err := r.inst.Store.Chat().MacCredentialHeld(r.ctx, runner) |
| + if err != nil { |
| + r.t.Fatal(err) |
| + } |
| + return held |
| +} |
| + |
| +// inventoryHello is a worker's hello after the welcome, which says its |
| +// connections and hold in full: change sets the hold's fields. |
| +func inventoryHello(key string, change func(*wire.Capabilities), conns ...wire.HeldConnection) wire.Hello { |
| + h := workerConnHello(key, conns...) |
| + h.Inventory = true |
| + if change != nil { |
| + caps := *h.Capabilities |
| + change(&caps) |
| + h.Capabilities = &caps |
| + } |
| + return h |
| +} |
| + |
| +// handshakeHello is what a real worker says before the welcome: no |
| +// connections, no seal key, no hold and none of the protocol 37 |
| +// capability fields (WithoutMacEngineering), though it offers 37. |
| +func handshakeHello() wire.Hello { |
| + h := workerConnHello("") |
| + wire.WithoutMacEngineering(&h) |
| + return h |
| +} |
| + |
| +// workerSync is a worker's sync after the welcome, saying conns. |
| +func workerSync(conns ...wire.HeldConnection) wire.Sync { |
| + return wire.Sync{Sessions: []wire.SessionState{}, Runs: []wire.Run{}, Steps: []wire.StepRun{}, Asks: []wire.AskRun{}, Connections: append([]wire.HeldConnection{}, conns...)} |
| +} |
| + |
| +// TestContractWorkerReconnectKeepsHold (#1): the real reconnect sequence |
| +// (the hello before the welcome, the sync, the full hello after it) |
| +// never releases the hold nor signs a connection out: with a token on |
| +// disk, and with only a Keychain item left. Only a full report saying |
| +// nothing is left releases it; a later hello that does not say it is |
| +// full never does. |
| +func TestContractWorkerReconnectKeepsHold(t *testing.T) { |
| + claude1 := wire.HeldConnection{LocalID: "claude-1", Person: Owner, Provider: wire.ProviderClaude, Kind: wire.KindToken, Label: "w@example.com", State: wire.ConnHealthy} |
| + holds := func(c *wire.Capabilities) { c.ModelHold = true } |
| + residue := func(c *wire.Capabilities) { |
| + c.ModelHold, c.HoldingItems = true, []string{"Claude Code-credentials-1a2b3c4d"} |
| + } |
| + t.Run("a token on disk", func(t *testing.T) { |
| + r := newMacRig(t) |
| + key := sealKeys(t).PublicString() |
| + w := r.newMacEngineer("Tito Studio", wire.EngineeringNoConnection) |
| + wid := w.fr.Welcome.RunnerID |
| + w.heartbeat(inventoryHello(key, holds, claude1)) |
| + if c, ok := r.connRow(wid, "claude-1"); !ok || c.State != wire.ConnHealthy || !r.heldNow(wid) { |
| + t.Fatalf("setup: %+v %v held=%v", c, ok, r.heldNow(wid)) |
| + } |
| + stillThere := func(when string) { |
| + t.Helper() |
| + if c, _ := r.connRow(wid, "claude-1"); c.State != wire.ConnHealthy || !r.heldNow(wid) { |
| + t.Fatalf("%s: row %s, held=%v", when, c.State, r.heldNow(wid)) |
| + } |
| + } |
| + // A hello before the welcome is never the inventory, whatever it |
| + // says. |
| + claims := handshakeHello() |
| + claims.Inventory = true |
| + w = r.redialMac(w, claims) |
| + w.lease("", 0) |
| + stillThere("a hello before the welcome claiming to be the inventory") |
| + w = r.redialMac(w, handshakeHello()) |
| + w.lease("", 0) |
| + stillThere("the hello before the welcome") |
| + w.send(wire.FrameSync, workerSync(claude1)) |
| + stillThere("the sync") |
| + w.heartbeat(inventoryHello(key, holds, claude1)) |
| + stillThere("the full hello") |
| + // A hello that does not say it is full says nothing is gone. |
| + partial := workerConnHello(key) |
| + partial.Inventory = false |
| + w.heartbeat(partial) |
| + stillThere("a hello without its inventory") |
| + w.heartbeat(inventoryHello(key, nil)) |
| + if c, _ := r.connRow(wid, "claude-1"); c.State != wire.ConnSignedOut || r.heldNow(wid) { |
| + t.Fatalf("a full report of nothing: row %s, held=%v", c.State, r.heldNow(wid)) |
| + } |
| + }) |
| + t.Run("only a Keychain item", func(t *testing.T) { |
| + r := newMacRig(t) |
| + key := sealKeys(t).PublicString() |
| + w := r.newMacEngineer("Tito Studio", wire.EngineeringNoConnection) |
| + wid := w.fr.Welcome.RunnerID |
| + w.heartbeat(inventoryHello(key, nil)) |
| + a, err := r.client.Connect(r.ctx, wire.Connect{Provider: wire.ProviderClaude, RunnerID: wid}) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + w.expect(wire.FrameConnect) |
| + w.send(wire.FrameConnection, wire.ConnectionReport{Connection: a.ID, Person: Owner, Provider: wire.ProviderClaude, State: wire.ConnError, Reason: "provider_refused"}) |
| + w.heartbeat(inventoryHello(key, residue)) |
| + if !r.heldNow(wid) { |
| + t.Fatal("setup: not held with an item left") |
| + } |
| + w = r.redialMac(w, handshakeHello()) |
| + w.lease("", 0) |
| + if !r.heldNow(wid) { |
| + t.Fatal("the hello before the welcome released the hold") |
| + } |
| + w.send(wire.FrameSync, workerSync()) |
| + if !r.heldNow(wid) { |
| + t.Fatal("an empty sync released the hold") |
| + } |
| + w.heartbeat(inventoryHello(key, residue)) |
| + if !r.heldNow(wid) { |
| + t.Fatal("the full hello naming the item released the hold") |
| + } |
| + w.heartbeat(inventoryHello(key, nil)) |
| + if r.heldNow(wid) { |
| + t.Fatal("still held once the Mac said in full that nothing is left") |
| + } |
| + }) |
| +} |
| + |
| +// TestContractWorkerSyncHolds (#2): a worker's sync that reports a |
| +// connection records it and holds the Mac in the same transaction; an |
| +// empty sync neither releases the hold nor signs the connection out. |
| +func TestContractWorkerSyncHolds(t *testing.T) { |
| + r := newMacRig(t) |
| + key := sealKeys(t).PublicString() |
| + w := r.newMacEngineer("Tito Studio", wire.EngineeringNoConnection) |
| + wid := w.fr.Welcome.RunnerID |
| + w.heartbeat(inventoryHello(key, nil)) |
| + if r.heldNow(wid) { |
| + t.Fatal("held with nothing there") |
| + } |
| + w.send(wire.FrameSync, workerSync(wire.HeldConnection{LocalID: "claude-2", Person: Owner, Provider: wire.ProviderClaude, Kind: wire.KindToken, State: wire.ConnHealthy})) |
| + if c, ok := r.connRow(wid, "claude-2"); !ok || c.State != wire.ConnHealthy || !r.heldNow(wid) { |
| + t.Fatalf("after the sync: %+v %v held=%v", c, ok, r.heldNow(wid)) |
| + } |
| + w.send(wire.FrameSync, workerSync()) |
| + if c, _ := r.connRow(wid, "claude-2"); c.State != wire.ConnHealthy || !r.heldNow(wid) { |
| + t.Fatalf("an empty sync: row %s, held=%v", c.State, r.heldNow(wid)) |
| + } |
| +} |
| + |
| +// TestContractWorkerConnectionCommandsBelow37 (#3): a Mac that comes |
| +// back below 37 is delivered none of the connection commands queued for |
| +// it, and what it replays of its connections (a report, a check's usage) |
| +// changes nothing; back at 37 the queued command goes. |
| +func TestContractWorkerConnectionCommandsBelow37(t *testing.T) { |
| + r := newMacRig(t) |
| + key := sealKeys(t).PublicString() |
| + w := r.newMacEngineer("Tito Studio", wire.EngineeringNoConnection) |
| + wid := w.fr.Welcome.RunnerID |
| + w.heartbeat(inventoryHello(key, nil)) |
| + a, err := r.client.Connect(r.ctx, wire.Connect{Provider: wire.ProviderClaude, Kind: wire.KindToken, RunnerID: wid}) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + old := r.redialMac(w, macEngineerHello("Tito Studio", wire.EngineeringNoConnection, wire.ProtocolChangeDiffs, false)) |
| + if old.fr.Welcome.Protocol != wire.ProtocolChangeDiffs { |
| + t.Fatalf("welcome %+v", old.fr.Welcome) |
| + } |
| + old.lease("", 0) |
| + time.Sleep(300 * time.Millisecond) |
| + old.lease("", 0) |
| + for _, h := range old.held { |
| + switch h.f.Type { |
| + case wire.FrameConnect, wire.FrameSecret, wire.FrameCancelConnect, wire.FrameDisconnect, wire.FrameCheck, wire.FramePreference: |
| + t.Fatalf("delivered below 37: %s", h.raw) |
| + } |
| + } |
| + if r.unacked(wid, wire.FrameConnect) != 1 { |
| + t.Fatal("the queued connect did not wait") |
| + } |
| + // What it replays from before changes nothing. |
| + old.send(wire.FrameConnection, wire.ConnectionReport{Connection: a.ID, Person: Owner, LocalID: "claude-1", Provider: wire.ProviderClaude, State: wire.ConnHealthy, Label: "w@example.com"}) |
| + if c, err := r.client.Connection(r.ctx, a.ID); err != nil || c.State != wire.ConnConnecting || c.LocalID != "" { |
| + t.Fatalf("a report below 37 applied: %+v %v", c, err) |
| + } |
| + old.send(wire.FrameUsage, wire.UsageReport{CheckID: "chk_old", Rows: []wire.Usage{{Provider: wire.ProviderClaude, Connection: "claude-1", Model: "claude-opus-5-5", Attempt: 1, Outcome: wire.OutcomeReplied, Complete: true}}}) |
| + if n := r.count("SELECT count(*) FROM chat_usage WHERE step_id = 'chk_old'"); n != 0 { |
| + t.Fatalf("%d usage rows from a worker below 37", n) |
| + } |
| + // Back at 37: the queued connect goes. |
| + back := r.redialMac(old, inventoryHello(key, nil)) |
| + if _, body := back.expect(wire.FrameConnect); body.(*wire.ConnectCommand).Connection != a.ID { |
| + t.Fatalf("connect %+v", body) |
| + } |
| +} |
| + |
| +// TestContractUsageBelow37 (#4): below 37 a usage row keeps the legacy |
| +// form (no runner) and a worker's connection usage is refused; at 37 the |
| +// row names the runner that reported it. |
| +func TestContractUsageBelow37(t *testing.T) { |
| + report := func(id string) wire.UsageReport { |
| + return wire.UsageReport{CheckID: id, Rows: []wire.Usage{{Provider: wire.ProviderClaude, Connection: "claude-1", Model: "claude-opus-5-5", Attempt: 1, Outcome: wire.OutcomeReplied, Complete: true, InputTokens: i64(10), OutputTokens: i64(5)}}} |
| + } |
| + runnerOf := func(r *runnersRig, check string) (string, int) { |
| + t.Helper() |
| + var n int |
| + var runner *string |
| + if err := r.inst.DB.Writer().QueryRow("SELECT count(*), max(runner_id) FROM chat_usage WHERE step_id = ?", check).Scan(&n, &runner); err != nil { |
| + t.Fatal(err) |
| + } |
| + if runner == nil { |
| + return "<null>", n |
| + } |
| + return *runner, n |
| + } |
| + t.Run("36", func(t *testing.T) { |
| + r := newMacRigAt(t, 36) |
| + w := r.newMacEngineerAt("Tito Studio", wire.EngineeringNoConnection, 36, false) |
| + r.primary.send(wire.FrameUsage, report("chk_p36")) |
| + if got, n := runnerOf(r, "chk_p36"); n != 1 || got != "<null>" { |
| + t.Fatalf("the primary's row at 36: %d rows, runner %s", n, got) |
| + } |
| + w.send(wire.FrameUsage, report("chk_w36")) |
| + if _, n := runnerOf(r, "chk_w36"); n != 0 { |
| + t.Fatalf("%d rows of a worker's connection usage at 36", n) |
| + } |
| + }) |
| + t.Run("37", func(t *testing.T) { |
| + r := newMacRig(t) |
| + w := r.newMacEngineer("Tito Studio", wire.EngineeringNoConnection) |
| + r.primary.send(wire.FrameUsage, report("chk_p37")) |
| + if got, n := runnerOf(r, "chk_p37"); n != 1 || got != r.primary.fr.Welcome.RunnerID { |
| + t.Fatalf("the primary's row at 37: %d rows, runner %s", n, got) |
| + } |
| + w.send(wire.FrameUsage, report("chk_w37")) |
| + if got, n := runnerOf(r, "chk_w37"); n != 1 || got != w.fr.Welcome.RunnerID { |
| + t.Fatalf("the worker's row at 37: %d rows, runner %s", n, got) |
| + } |
| + }) |
| +} |
diff --git a/internal/wire/connections.go b/internal/wire/connections.go| index 35d4c009..52fe896f 100644 |
| --- a/internal/wire/connections.go |
| +++ b/internal/wire/connections.go |
| @@ -68,6 +68,11 @@ var ConnectReasons = map[string]bool{ |
| ReasonMacClaudeOnly: true, |
| } |
| +// ConnectionCommands are the instance's commands about a runner's |
| +// connections. A worker takes them, and says anything of its |
| +// connections, only at ProtocolMacEngineering. |
| +var ConnectionCommands = map[string]bool{FrameConnect: true, FrameCancelConnect: true, FrameDisconnect: true, FrameSecret: true, FrameCheck: true, FramePreference: true, FrameModel: true, FrameModels: true, FrameBudget: true, FrameResumeSpend: true} |
| + |
| // ReasonMacClaudeOnly ends an attempt a Mac worker does not take: only |
| // Claude, by a pasted token or its own sign-in, runs on a Mac. |
| const ReasonMacClaudeOnly = "mac_claude_only" |
diff --git a/internal/wire/frames.go b/internal/wire/frames.go| index 7b581569..49f161ca 100644 |
| --- a/internal/wire/frames.go |
| +++ b/internal/wire/frames.go |
| @@ -363,6 +363,11 @@ type Hello struct { |
| Label string `json:"label,omitempty"` |
| Sandbox string `json:"sandbox,omitempty"` |
| Capabilities *Capabilities `json:"capabilities,omitempty"` |
| + // Inventory (ProtocolMacEngineering): a worker's hello sent after the |
| + // welcome says its connections and its credential hold in full. A |
| + // hello without it (the one before the welcome) says nothing of them |
| + // the instance may release a hold on. |
| + Inventory bool `json:"inventory,omitempty"` |
| } |
| // Catalog bounds. |
diff --git a/internal/wire/mac_engineering.go b/internal/wire/mac_engineering.go| index 5492a2fa..eb36de0e 100644 |
| --- a/internal/wire/mac_engineering.go |
| +++ b/internal/wire/mac_engineering.go |
| @@ -254,19 +254,21 @@ const ( |
| ) |
| // WithoutMacEngineering drops a hello's Engineering status, Unproven, the |
| -// credential hold and F probes |
| +// credential hold, the inventory mark and F probes |
| // (in new values; the caller's are untouched). The runner's first hello |
| // on a connection goes out before the welcome names the protocol, and an |
| // older instance's ValidCapabilities refuses an F probe; the runner sends |
| // them once the welcome says 37. It reports whether anything changed. |
| func WithoutMacEngineering(h *Hello) bool { |
| + inventory := h.Inventory |
| + h.Inventory = false |
| c := h.Capabilities |
| if c == nil { |
| - return false |
| + return inventory |
| } |
| isF := func(p Probe) bool { _, ok := engineeringProbeSuccess[p.ID]; return ok } |
| if c.Engineering == nil && c.Unproven == "" && !c.ModelHold && c.HoldingItems == nil && !slices.ContainsFunc(c.Probes, isF) { |
| - return false |
| + return inventory |
| } |
| out := *c |
| out.Engineering, out.Unproven, out.ModelHold, out.HoldingItems = nil, "", false, nil |
diff --git a/internal/wire/mac_engineering_test.go b/internal/wire/mac_engineering_test.go| index af8c2563..de035074 100644 |
| --- a/internal/wire/mac_engineering_test.go |
| +++ b/internal/wire/mac_engineering_test.go |
| @@ -263,6 +263,7 @@ func TestEncodeDropsEmptyMacEngineeringKeysBelow37(t *testing.T) { |
| // Slice F task 11: the credential hold, and the runner a sign-out |
| // names, set or empty. |
| {"hello hold", with("frames/hello-mac-probes.json", []string{"capabilities"}, map[string]any{"model_hold": true, "holding_items": []string{"Claude Code-credentials"}}), []string{"model_hold", "holding_items"}}, |
| + {"hello inventory", with("frames/hello-mac-probes.json", nil, map[string]any{"inventory": true}), []string{"inventory"}}, |
| {"disconnect", with("frames/disconnect.json", nil, map[string]any{"runner_id": ""}), []string{"runner_id"}}, |
| {"disconnect named", with("frames/disconnect.json", nil, map[string]any{"runner_id": "run_1"}), []string{"runner_id"}}, |
| } { |