oficina / equipo Public

wire: protocol 2 for runners, with Encode at protocol 1

Roles, platform, capabilities (bounded, no paths), needs, the
attempt-specific lease, transfers (blob, send_pack), publish and
published, refused. New fields are omitempty so protocol 1 frames stay
the slice 4 bytes; Encode clears them and refuses protocol 2 frames at
protocol 1. Fixtures and tests for both protocols.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by claude agent, operated by paul@keymail.dev 91c535ab39e31eea5dab4c7f26a6d4fc8f283c69 parent d16ee81
16 files changed, +607 −5
  • docs/superpowers/plans/RUNNERS-PROGRESS.md +58 −0
  • internal/wire/frames.go +33 −4
  • internal/wire/runners.go +344 −0
  • internal/wire/runners_test.go +144 −0
  • internal/wire/tasks.go +17 −0
  • internal/wire/wire_test.go +1 −1
  • internal/wire/wiretest/testdata/frames/blob.json +1 −0
  • internal/wire/wiretest/testdata/frames/dispatch-needs.json +1 −0
  • internal/wire/wiretest/testdata/frames/hello-mac.json +1 −0
  • internal/wire/wiretest/testdata/frames/lease-step.json +1 −0
  • internal/wire/wiretest/testdata/frames/publish.json +1 −0
  • internal/wire/wiretest/testdata/frames/published.json +1 −0
  • internal/wire/wiretest/testdata/frames/refused.json +1 −0
  • internal/wire/wiretest/testdata/frames/send_pack.json +1 −0
  • internal/wire/wiretest/testdata/frames/step-process-group.json +1 −0
  • internal/wire/wiretest/testdata/frames/welcome-worker.json +1 −0
diff --git a/docs/superpowers/plans/RUNNERS-PROGRESS.md b/docs/superpowers/plans/RUNNERS-PROGRESS.md
new file mode 100644
index 00000000..b2d92b62
--- /dev/null
+++ b/docs/superpowers/plans/RUNNERS-PROGRESS.md
@@ -0,0 +1,58 @@
+# Runners progress: Mac runners groundwork (slices A and B)
+
+Branch `thin-v1-runners` from `thin-v1-slice4c` (2d1edaf), with
+`design-mac-runner` (b5f7259) merged so the spec is on the branch. Spec:
+`docs/superpowers/specs/2026-11-07-equipo-mac-runners.md` rev 4
+(accepted), slices A and B, Linux only. No Darwin code and no Mac probe:
+those need tito-studio and a person (slice C onwards). Conventions and
+scripts as in `SLICE1-PROGRESS.md` to `SLICE4C-PROGRESS.md`.
+
+## Done
+
+1. Wire, protocol 2 (`internal/wire/runners.go`): `Protocol1`,
+ `Protocol2`; roles `primary`, `worker`; sandboxes; the fixed tag set;
+ `Platform`, `Capabilities` (xcode, simulators, toolchains, harness,
+ tags) with `ValidCapabilities` (40 simulators, 300 bytes a string,
+ 8 KB in all, no path separator, newline, `~` or `=` in any string);
+ `Covers`; placement, publication and termination kinds; transfers
+ (`TransferHeader`, `Blob`, `SendPackCommand`), `PublishCommand`,
+ `PublishedReport`, `Refused`. `hello` gained `protocol`, `platform`,
+ `label`, `sandbox`, `capabilities`; `welcome` `protocol`, `role`,
+ `release`; `dispatch` `needs`, `runner_id`; `lease` `step_id`,
+ `attempt`; `step` `termination_kind`, `have`, `phase`. Every new field
+ is `omitempty`, so a protocol 1 frame is byte for byte the slice 4
+ frame. `wire.Encode(frame, protocol)` clears the protocol 2 fields and
+ refuses protocol 2 frame types at protocol 1. New step reasons
+ `placement_refused`, `withdrawn`, `transfer_refused`,
+ `runner_offline`. Fixtures `frames/hello-mac.json`,
+ `welcome-worker.json`, `dispatch-needs.json`, `lease-step.json`,
+ `blob.json`, `send_pack.json`, `publish.json`, `published.json`,
+ `refused.json`, `step-process-group.json`. Tests:
+ `TestEncodeProtocol1IsTheSlice4Wire` (each new frame at protocol 1 has
+ the slice 4 fixture's keys and parses; the slice 4 fixtures pass
+ through byte for byte), `TestEncodeProtocol1RefusesNewFrames`,
+ `TestProtocolNegotiation`, `TestDurableRunnerFrames`,
+ `TestCapabilitiesGuard`, `TestCovers`. Mutations: Encode without the
+ downgrade, and without the protocol 2 frame refusal, each failed a
+ test.
+
+## Decisions
+
+- New wire fields are `omitempty` rather than always present: the slice
+ 4 fixtures stay byte-identical, and `Encode` at protocol 1 only has to
+ clear fields.
+- `refused{id, reason}` answers a start authorization the instance will
+ not grant; the spec names the refusal but no frame for it.
+- `send_pack` (instance to primary, durable) asks the primary to upload
+ an inbound transfer's pack; the spec says the primary sends the pack
+ but not how it is asked.
+- Blob frames carry the whole transfer header, so the receiver checks
+ repository, task, step, attempt, base, candidate and direction against
+ its own step row on every chunk; `sha256` is the whole pack's digest.
+- The capability report keeps `accounts` where it is today, in `hello`.
+
+## Open issues
+
+## Blockers
+
+None.
diff --git a/internal/wire/frames.go b/internal/wire/frames.go
index f489d824..ee79f449 100644
--- a/internal/wire/frames.go
+++ b/internal/wire/frames.go
@@ -11,9 +11,10 @@ const StreamPath = "/api/runner/stream"
// Frame types. Instance to runner: welcome, message, cancel, drain, ack,
// tool_result, reset, dispatch, cancel_step, recheck, watch_merge, ask,
-// cancel_ask, forget_task. Runner to instance: hello, sync, lease, delta,
-// activity, tool_call, reply, turn, move_in, notebook, step, merged,
-// answer, ack.
+// cancel_ask, forget_task, and at protocol 2 blob, send_pack, publish and
+// refused. Runner to instance: hello, sync, lease, delta, activity,
+// tool_call, reply, turn, move_in, notebook, step, merged, answer, ack,
+// and at protocol 2 blob and published.
const (
FrameToolCall = "tool_call"
FrameToolResult = "tool_result"
@@ -59,7 +60,7 @@ type Frame struct {
// Durable reports whether a frame must be acked and resent until acked.
func (f Frame) Durable() bool {
switch f.Type {
- case FrameMessage, FrameCancel, FrameReply, FrameTurn, FrameToolCall, FrameToolResult, FrameMoveIn, FrameNotebook, FrameReset, FrameDispatch, FrameCancelStep, FrameStep, FrameRecheck, FrameWatchMerge, FrameMerged, FrameAsk, FrameCancelAsk, FrameAnswer, FrameForgetTask, FrameBranch:
+ case FrameMessage, FrameCancel, FrameReply, FrameTurn, FrameToolCall, FrameToolResult, FrameMoveIn, FrameNotebook, FrameReset, FrameDispatch, FrameCancelStep, FrameStep, FrameRecheck, FrameWatchMerge, FrameMerged, FrameAsk, FrameCancelAsk, FrameAnswer, FrameForgetTask, FrameBranch, FrameBlob, FrameSendPack, FramePublish, FramePublished:
return true
}
return false
@@ -134,6 +135,16 @@ func (f Frame) Decode() (any, error) {
v = &ForgetTaskCommand{}
case FrameBranch:
v = &BranchReport{}
+ case FrameBlob:
+ v = &Blob{}
+ case FrameSendPack:
+ v = &SendPackCommand{}
+ case FramePublish:
+ v = &PublishCommand{}
+ case FramePublished:
+ v = &PublishedReport{}
+ case FrameRefused:
+ v = &Refused{}
default:
return nil, fmt.Errorf("%w: frame type %q", ErrStrict, f.Type)
}
@@ -164,6 +175,11 @@ func ParseFrame(raw []byte) (Frame, any, error) {
type Welcome struct {
Generation int64 `json:"generation"`
RunnerID string `json:"runner_id"`
+ // Protocol 2: the protocol the instance speaks on this connection,
+ // the runner's role, and the runner release this instance serves.
+ Protocol int `json:"protocol,omitempty"`
+ Role string `json:"role,omitempty"`
+ Release string `json:"release,omitempty"`
}
// TailMessage is prior conversation, for a fresh coordinator session only.
@@ -229,6 +245,14 @@ type Hello struct {
Catalog []RepoInfo `json:"catalog"`
Accounts []Account `json:"accounts"`
Versions map[string]string `json:"versions"`
+ // Protocol 2: the protocol the runner speaks (absent: 1), its
+ // platform, its label (the machine's name), how it confines steps and
+ // what it can do.
+ Protocol int `json:"protocol,omitempty"`
+ Platform *Platform `json:"platform,omitempty"`
+ Label string `json:"label,omitempty"`
+ Sandbox string `json:"sandbox,omitempty"`
+ Capabilities *Capabilities `json:"capabilities,omitempty"`
}
// Catalog bounds.
@@ -270,6 +294,11 @@ type Run struct {
// connection still holds Generation. The instance acks it only then.
type LeaseCheck struct {
Generation int64 `json:"generation"`
+ // Protocol 2: the start authorization of one step attempt. The
+ // instance acks it only while the attempt is assigned to this runner
+ // and not withdrawn, and records that it started.
+ StepID string `json:"step_id,omitempty"`
+ Attempt int64 `json:"attempt,omitempty"`
}
// Sync is sent on every connect, after hello.
diff --git a/internal/wire/runners.go b/internal/wire/runners.go
new file mode 100644
index 00000000..ae12540e
--- /dev/null
+++ b/internal/wire/runners.go
@@ -0,0 +1,344 @@
+package wire
+
+import (
+ "encoding/json"
+ "errors"
+ "fmt"
+ "reflect"
+ "slices"
+ "strings"
+ "time"
+)
+
+// Runner stream protocols. 1 is the slice 4 wire: a hello without
+// protocol. 2 adds roles, capabilities, placement, the attempt-specific
+// start authorization, pack transfers and publication (Mac runners spec
+// §3.3). The instance speaks the lower of the two on each connection and
+// encodes every frame for it with Encode; nothing a protocol 1 runner
+// does not know ever reaches it.
+const (
+ Protocol1 = 1
+ Protocol2 = 2
+ ProtocolCurrent = Protocol2
+)
+
+// Runner roles. A person's first runner is the primary: the coordinator,
+// the forge credential, publication and merges live there. Later runners
+// are workers and run steps placed on them.
+const (
+ RolePrimary = "primary"
+ RoleWorker = "worker"
+)
+
+// Sandboxes a runner reports: how it confines a step.
+const (
+ SandboxBubblewrap = "bubblewrap"
+ SandboxSeatbelt = "seatbelt"
+ // SandboxNone is the test-build fake worker only: it runs checks in a
+ // process group without a sandbox.
+ SandboxNone = "none"
+)
+
+// Capability tags, a fixed set. A step's needs are a subset.
+const (
+ TagLinux = "linux"
+ TagMacOS = "macos"
+ TagXcode = "xcode"
+ TagIOSSimulator = "ios_simulator"
+ TagClaude = "claude"
+ TagCodex = "codex"
+ TagGo = "go"
+)
+
+// Tags is the whole tag set.
+var Tags = []string{TagLinux, TagMacOS, TagXcode, TagIOSSimulator, TagClaude, TagCodex, TagGo}
+
+// Capability bounds.
+const (
+ MaxSimulators = 40
+ MaxCapabilityString = 300
+ MaxCapabilityBytes = 8 << 10
+)
+
+// Platform is a runner's operating system and architecture, as Go names
+// them (linux/amd64, darwin/arm64).
+type Platform struct {
+ OS string `json:"os"`
+ Arch string `json:"arch"`
+}
+
+// Capabilities is what a runner can do, computed at start, re-probed
+// hourly and sent with every heartbeat. No path, credential or raw tool
+// output: ValidCapabilities checks every field.
+type Capabilities struct {
+ Xcode Xcode `json:"xcode"`
+ Simulators []Simulator `json:"simulators"`
+ Toolchains Toolchains `json:"toolchains"`
+ Harness Harness `json:"harness"`
+ Tags []string `json:"tags"`
+}
+
+// Xcode is xcodebuild -version's two lines; empty on Linux.
+type Xcode struct {
+ Version string `json:"version"`
+ Build string `json:"build"`
+}
+
+// Simulator is one available simulator device.
+type Simulator struct {
+ Name string `json:"name"`
+ Runtime string `json:"runtime"`
+ UDID string `json:"udid"`
+ State string `json:"state"`
+}
+
+// Toolchains are versions, "" when absent.
+type Toolchains struct {
+ Go string `json:"go"`
+ Swift string `json:"swift"`
+ Node string `json:"node"`
+}
+
+// Harness are the coding harnesses' versions, "" when absent.
+type Harness struct {
+ Claude string `json:"claude"`
+ Codex string `json:"codex"`
+ SRT string `json:"srt"`
+}
+
+// ErrCapabilities refuses a capability report out of bounds.
+var ErrCapabilities = errors.New("wire: capability report out of bounds")
+
+// ValidCapabilities checks the bounds and that no string could be a path,
+// a credential or tool output: short, one line, no path separator.
+func ValidCapabilities(c Capabilities) error {
+ if len(c.Simulators) > MaxSimulators {
+ return ErrCapabilities
+ }
+ for _, t := range c.Tags {
+ if !slices.Contains(Tags, t) {
+ return ErrCapabilities
+ }
+ }
+ if err := checkStrings(reflect.ValueOf(c)); err != nil {
+ return err
+ }
+ raw, _ := json.Marshal(c)
+ if len(raw) > MaxCapabilityBytes {
+ return ErrCapabilities
+ }
+ return nil
+}
+
+func checkStrings(v reflect.Value) error {
+ switch v.Kind() {
+ case reflect.String:
+ s := v.String()
+ if len(s) > MaxCapabilityString || strings.ContainsAny(s, "/\\~\n\r\t\x00=") {
+ return ErrCapabilities
+ }
+ case reflect.Struct:
+ for i := range v.NumField() {
+ if err := checkStrings(v.Field(i)); err != nil {
+ return err
+ }
+ }
+ case reflect.Slice:
+ for i := range v.Len() {
+ if err := checkStrings(v.Index(i)); err != nil {
+ return err
+ }
+ }
+ default:
+ return ErrCapabilities
+ }
+ return nil
+}
+
+// Covers reports whether tags include every need.
+func Covers(tags, needs []string) bool {
+ for _, n := range needs {
+ if !slices.Contains(tags, n) {
+ return false
+ }
+ }
+ return true
+}
+
+// Placement of a step: "" placed on its runner; waiting_runner while the
+// only runners that fit are offline.
+const PlacementWaiting = "waiting_runner"
+
+// Publication of a worker's Engineering candidate: only the primary
+// publishes (pushes) it.
+const (
+ PublicationNone = "none"
+ PublicationPending = "pending"
+ PublicationPublished = "published"
+ PublicationFailed = "failed"
+)
+
+// Termination kinds: how a step attempt's end was proven.
+const (
+ TerminationNamespace = "namespace"
+ TerminationProcessGroup = "process_group"
+)
+
+// Transfer directions: inbound (primary to worker) carries the candidate
+// a worker judges; outbound (worker to primary) carries a worker's commit.
+const (
+ TransferInbound = "inbound"
+ TransferOutbound = "outbound"
+)
+
+// Transfer bounds: a chunk's data is base64 under 192 KB so a frame stays
+// under MaxFrameBytes; a transfer is at most 64 MB.
+const (
+ MaxBlobData = 192 << 10
+ MaxBlobChunk = MaxBlobData / 4 * 3
+ MaxTransferBytes = 64 << 20
+ TransferTTL = 24 * time.Hour
+)
+
+// Protocol 2 frames.
+const (
+ // FrameBlob is one chunk of a transfer, both ways, durable.
+ FrameBlob = "blob"
+ // FrameSendPack asks the primary to upload an inbound transfer's pack.
+ FrameSendPack = "send_pack"
+ // FramePublish asks the primary to publish a worker's commit;
+ // FramePublished is its answer. Both durable.
+ FramePublish = "publish"
+ FramePublished = "published"
+ // FrameRefused answers a lease the instance will not grant (the start
+ // authorization of a withdrawn or superseded attempt). Not durable.
+ FrameRefused = "refused"
+)
+
+// TransferHeader binds a transfer to one attempt of one step. The
+// receiver checks it against its own step row before index-pack.
+type TransferHeader struct {
+ ID string `json:"id"`
+ Direction string `json:"direction"`
+ Repo string `json:"repo"`
+ TaskID string `json:"task_id"`
+ StepID string `json:"step_id"`
+ Attempt int64 `json:"attempt"`
+ BaseSHA string `json:"base_sha"`
+ CandidateSHA string `json:"candidate_sha"`
+}
+
+// Blob is one chunk of a transfer's pack: Index of Total, SHA256 of the
+// whole pack (hex), Data base64.
+type Blob struct {
+ Transfer TransferHeader `json:"transfer"`
+ Index int `json:"index"`
+ Total int `json:"total"`
+ SHA256 string `json:"sha256"`
+ Data string `json:"data"`
+}
+
+// SendPackCommand asks the primary for the pack of CandidateSHA, which
+// it uploads as the transfer's blobs (Have: commits the receiver holds).
+type SendPackCommand struct {
+ Transfer TransferHeader `json:"transfer"`
+ Have []string `json:"have"`
+}
+
+// PublishCommand asks the primary to push a worker's commit, received in
+// Transfer, onto the task branch.
+type PublishCommand struct {
+ Publication string `json:"publication"`
+ TaskID string `json:"task_id"`
+ StepID string `json:"step_id"`
+ Attempt int64 `json:"attempt"`
+ Repo string `json:"repo"`
+ Branch string `json:"branch"`
+ Person string `json:"person"`
+ BaseSHA string `json:"base_sha"`
+ CandidateSHA string `json:"candidate_sha"`
+ Transfer string `json:"transfer"`
+}
+
+// PublishedReport is the primary's answer to a publish: Pushed, or the
+// reason it was not (push_failed, push_conflict, candidate_unavailable,
+// cancelled).
+type PublishedReport struct {
+ Publication string `json:"publication"`
+ TaskID string `json:"task_id"`
+ StepID string `json:"step_id"`
+ Attempt int64 `json:"attempt"`
+ CandidateSHA string `json:"candidate_sha"`
+ Pushed bool `json:"pushed"`
+ Reason string `json:"reason"`
+}
+
+// Refused answers a lease frame (ID) the instance would not grant.
+type Refused struct {
+ ID string `json:"id"`
+ Reason string `json:"reason"`
+}
+
+// protocol2Only are the frame types a protocol 1 runner never receives
+// or sends.
+var protocol2Only = map[string]bool{FrameBlob: true, FrameSendPack: true, FramePublish: true, FramePublished: true, FrameRefused: true}
+
+// ErrProtocol means a frame cannot be spoken at the connection's protocol.
+var ErrProtocol = errors.New("wire: frame not in this protocol")
+
+// Encode returns f as the given protocol speaks it. At protocol 1 it is
+// exactly the slice 4 frame and field set: protocol 2 fields are dropped
+// and a protocol 2 frame type is refused (ErrProtocol).
+func Encode(f Frame, protocol int) (Frame, error) {
+ if protocol >= Protocol2 {
+ return f, nil
+ }
+ if protocol2Only[f.Type] {
+ return Frame{}, fmt.Errorf("%w: %s at protocol %d", ErrProtocol, f.Type, protocol)
+ }
+ body, err := f.Decode()
+ if err != nil {
+ return Frame{}, err
+ }
+ if !downgrade(body) {
+ return f, nil
+ }
+ raw, err := json.Marshal(body)
+ if err != nil {
+ return Frame{}, err
+ }
+ f.Data = raw
+ return f, nil
+}
+
+// downgrade clears a body's protocol 2 fields (all omitempty, so they
+// are absent once zero). It reports whether the body has any.
+func downgrade(body any) bool {
+ switch v := body.(type) {
+ case *Hello:
+ v.Protocol, v.Platform, v.Label, v.Sandbox, v.Capabilities = 0, nil, "", "", nil
+ case *Welcome:
+ v.Protocol, v.Role, v.Release = 0, "", ""
+ case *DispatchCommand:
+ v.Needs, v.RunnerID = nil, ""
+ case *LeaseCheck:
+ v.StepID, v.Attempt = "", 0
+ case *StepReport:
+ v.TerminationKind, v.Have, v.Phase = "", nil, ""
+ default:
+ return false
+ }
+ return true
+}
+
+// HelloProtocol is the protocol a hello speaks: absent means 1.
+func HelloProtocol(h Hello) int {
+ if h.Protocol <= Protocol1 {
+ return Protocol1
+ }
+ return h.Protocol
+}
+
+// Spoken is the protocol both ends speak: the lower of the runner's and
+// this build's.
+func Spoken(runner int) int { return max(Protocol1, min(runner, ProtocolCurrent)) }
diff --git a/internal/wire/runners_test.go b/internal/wire/runners_test.go
new file mode 100644
index 00000000..aee8e90b
--- /dev/null
+++ b/internal/wire/runners_test.go
@@ -0,0 +1,144 @@
+package wire_test
+
+import (
+ "bytes"
+ "encoding/json"
+ "errors"
+ "strings"
+ "testing"
+
+ "amadan.net/oficina/equipo/internal/wire"
+ "amadan.net/oficina/equipo/internal/wire/wiretest"
+)
+
+// Every frame protocol 2 changes, encoded for a protocol 1 runner, is
+// exactly the slice 4 frame: the same keys as the slice 4 fixture, and a
+// slice 4 strict decoder (the v1 fixture's own key set) accepts it.
+func TestEncodeProtocol1IsTheSlice4Wire(t *testing.T) {
+ for v2, v1 := range map[string]string{
+ "frames/hello-mac.json": "frames/hello.json",
+ "frames/welcome-worker.json": "frames/welcome.json",
+ "frames/dispatch-needs.json": "frames/dispatch.json",
+ "frames/lease-step.json": "frames/lease.json",
+ "frames/step-process-group.json": "frames/step.json",
+ } {
+ f, _, err := wire.ParseFrame(wiretest.Fixture(v2))
+ if err != nil {
+ t.Fatalf("%s: %v", v2, err)
+ }
+ same, err := wire.Encode(f, wire.Protocol2)
+ if err != nil || !bytes.Equal(same.Data, f.Data) {
+ t.Fatalf("%s: protocol 2 changed the frame: %v", v2, err)
+ }
+ old, err := wire.Encode(f, wire.Protocol1)
+ if err != nil {
+ t.Fatalf("%s at protocol 1: %v", v2, err)
+ }
+ raw, _ := json.Marshal(old)
+ if err := wiretest.SameShape(wiretest.Fixture(v1), raw); err != nil {
+ t.Fatalf("%s at protocol 1 is not the slice 4 %s: %v\n%s", v2, v1, err, raw)
+ }
+ if _, _, err := wire.ParseFrame(raw); err != nil {
+ t.Fatalf("%s at protocol 1 does not parse: %v", v2, err)
+ }
+ }
+ // The protocol 1 fixtures themselves pass through unchanged.
+ for _, name := range []string{"frames/hello.json", "frames/welcome.json", "frames/dispatch.json", "frames/lease.json", "frames/step.json", "frames/message.json"} {
+ f, _, err := wire.ParseFrame(wiretest.Fixture(name))
+ if err != nil {
+ t.Fatal(err)
+ }
+ out, err := wire.Encode(f, wire.Protocol1)
+ raw, _ := json.Marshal(out)
+ if err != nil || !bytes.Equal(raw, wiretest.Fixture(name)) {
+ t.Fatalf("%s changed at protocol 1: %v\n%s", name, err, raw)
+ }
+ }
+}
+
+// Frames protocol 1 does not have are never encoded for it.
+func TestEncodeProtocol1RefusesNewFrames(t *testing.T) {
+ for _, name := range []string{"frames/blob.json", "frames/send_pack.json", "frames/publish.json", "frames/published.json", "frames/refused.json"} {
+ f, _, err := wire.ParseFrame(wiretest.Fixture(name))
+ if err != nil {
+ t.Fatal(err)
+ }
+ if _, err := wire.Encode(f, wire.Protocol1); !errors.Is(err, wire.ErrProtocol) {
+ t.Fatalf("%s encoded at protocol 1: %v", name, err)
+ }
+ if _, err := wire.Encode(f, wire.Protocol2); err != nil {
+ t.Fatalf("%s at protocol 2: %v", name, err)
+ }
+ }
+}
+
+func TestProtocolNegotiation(t *testing.T) {
+ if wire.HelloProtocol(wire.Hello{}) != 1 || wire.HelloProtocol(wire.Hello{Protocol: 2}) != 2 {
+ t.Fatal("hello protocol")
+ }
+ if wire.Spoken(1) != 1 || wire.Spoken(2) != 2 || wire.Spoken(9) != wire.ProtocolCurrent || wire.Spoken(0) != 1 {
+ t.Fatal("spoken protocol is not the lower of the two")
+ }
+}
+
+func TestDurableRunnerFrames(t *testing.T) {
+ for kind, want := range map[string]bool{wire.FrameBlob: true, wire.FrameSendPack: true, wire.FramePublish: true, wire.FramePublished: true, wire.FrameRefused: false} {
+ if (wire.Frame{Type: kind}).Durable() != want {
+ t.Fatalf("%s durable=%v", kind, !want)
+ }
+ }
+}
+
+// The capability report carries no path, credential or tool output, and
+// stays inside its bounds: every string field is checked.
+func TestCapabilitiesGuard(t *testing.T) {
+ _, body, err := wire.ParseFrame(wiretest.Fixture("frames/hello-mac.json"))
+ if err != nil {
+ t.Fatal(err)
+ }
+ good := *body.(*wire.Hello).Capabilities
+ if err := wire.ValidCapabilities(good); err != nil {
+ t.Fatalf("fixture refused: %v", err)
+ }
+ if err := wire.ValidCapabilities(wire.Capabilities{}); err != nil {
+ t.Fatalf("empty report refused: %v", err)
+ }
+ clone := func() wire.Capabilities {
+ raw, _ := json.Marshal(good)
+ var c wire.Capabilities
+ _ = json.Unmarshal(raw, &c)
+ return c
+ }
+ for name, bad := range map[string]func(*wire.Capabilities){
+ "path in xcode": func(c *wire.Capabilities) { c.Xcode.Version = "/Applications/Xcode.app" },
+ "home path": func(c *wire.Capabilities) { c.Toolchains.Go = "~/go/bin/go" },
+ "windows path": func(c *wire.Capabilities) { c.Harness.Claude = `C:\claude` },
+ "raw output": func(c *wire.Capabilities) { c.Xcode.Build = "Build version 16C5032a\nXcode 16.2" },
+ "credential shaped": func(c *wire.Capabilities) { c.Harness.Codex = "OPENAI_API_KEY=sk-x" },
+ "long string": func(c *wire.Capabilities) { c.Simulators[0].Name = strings.Repeat("i", wire.MaxCapabilityString+1) },
+ "path in simulator": func(c *wire.Capabilities) { c.Simulators[0].Runtime = "/Library/Developer/CoreSimulator" },
+ "unknown tag": func(c *wire.Capabilities) { c.Tags = append(c.Tags, "gpu") },
+ "too many simulators": func(c *wire.Capabilities) { c.Simulators = make([]wire.Simulator, wire.MaxSimulators+1) },
+ "over the total bound": func(c *wire.Capabilities) { c.Simulators = bigSimulators() },
+ } {
+ c := clone()
+ bad(&c)
+ if err := wire.ValidCapabilities(c); !errors.Is(err, wire.ErrCapabilities) {
+ t.Fatalf("%s accepted", name)
+ }
+ }
+}
+
+func bigSimulators() []wire.Simulator {
+ out := make([]wire.Simulator, wire.MaxSimulators)
+ for i := range out {
+ out[i] = wire.Simulator{Name: strings.Repeat("n", 250), Runtime: "iOS 18.2", UDID: strings.Repeat("u", 36), State: "Shutdown"}
+ }
+ return out
+}
+
+func TestCovers(t *testing.T) {
+ if !wire.Covers([]string{"macos", "xcode"}, nil) || !wire.Covers([]string{"macos", "xcode"}, []string{"xcode"}) || wire.Covers([]string{"linux"}, []string{"macos"}) {
+ t.Fatal("covers")
+ }
+}
diff --git a/internal/wire/tasks.go b/internal/wire/tasks.go
index b790d6ce..cbb1937f 100644
--- a/internal/wire/tasks.go
+++ b/internal/wire/tasks.go
@@ -421,6 +421,10 @@ type DispatchCommand struct {
// runner takes the tip), resolving any conflicts.
Rebase bool `json:"rebase"`
FromBase string `json:"from_base"`
+ // Protocol 2: the tags the step needs and the runner it is placed on;
+ // a runner lacking a need refuses it (placement_refused).
+ Needs []string `json:"needs,omitempty"`
+ RunnerID string `json:"runner_id,omitempty"`
}
// WatchMergeCommand watches a task's branch for its candidate landing on
@@ -489,6 +493,12 @@ type StepReport struct {
MergeSHA string `json:"merge_sha"`
Into string `json:"into"`
Strategy string `json:"strategy"`
+ // Protocol 2: how termination was proven (namespace or
+ // process_group), the commits a worker holds for thin packs, and the
+ // phase (committed: a worker's candidate, not pushed).
+ TerminationKind string `json:"termination_kind,omitempty"`
+ Have []string `json:"have,omitempty"`
+ Phase string `json:"phase,omitempty"`
}
// RecheckCommand asks the runner to check now what its agent reaches.
@@ -540,6 +550,13 @@ var StepReasons = map[string]bool{
"amadan_ci_failed": true,
"merge_forbidden": true,
"merge_failed": true,
+ // Runners (protocol 2): the runner lacks a need of the step; the
+ // attempt was withdrawn before it started; a pack transfer was
+ // refused; the runner that fits was offline too long (checks).
+ "placement_refused": true,
+ "withdrawn": true,
+ "transfer_refused": true,
+ "runner_offline": true,
// ReasonUnknown is what the instance records for a reason it does not
// know (a newer runner), rather than refusing the report.
ReasonUnknown: true,
diff --git a/internal/wire/wire_test.go b/internal/wire/wire_test.go
index 87f6c8a4..0ef979b2 100644
--- a/internal/wire/wire_test.go
+++ b/internal/wire/wire_test.go
@@ -33,7 +33,7 @@ func TestFrameFixturesRoundTrip(t *testing.T) {
t.Fatalf("%s: round trip\n got %s\nwant %s", name, out, raw)
}
}
- for _, kind := range []string{wire.FrameWelcome, wire.FrameMessage, wire.FrameCancel, wire.FrameDrain, wire.FrameAck, wire.FrameHello, wire.FrameSync, wire.FrameDelta, wire.FrameReply, wire.FrameTurn, wire.FrameLease, wire.FrameToolCall, wire.FrameToolResult, wire.FrameActivity, wire.FrameMoveIn, wire.FrameNotebook, wire.FrameReset, wire.FrameDispatch, wire.FrameCancelStep, wire.FrameStep, wire.FrameRecheck, wire.FrameWatchMerge, wire.FrameMerged, wire.FrameAsk, wire.FrameCancelAsk, wire.FrameAnswer, wire.FrameForgetTask, wire.FrameBranch} {
+ for _, kind := range []string{wire.FrameWelcome, wire.FrameMessage, wire.FrameCancel, wire.FrameDrain, wire.FrameAck, wire.FrameHello, wire.FrameSync, wire.FrameDelta, wire.FrameReply, wire.FrameTurn, wire.FrameLease, wire.FrameToolCall, wire.FrameToolResult, wire.FrameActivity, wire.FrameMoveIn, wire.FrameNotebook, wire.FrameReset, wire.FrameDispatch, wire.FrameCancelStep, wire.FrameStep, wire.FrameRecheck, wire.FrameWatchMerge, wire.FrameMerged, wire.FrameAsk, wire.FrameCancelAsk, wire.FrameAnswer, wire.FrameForgetTask, wire.FrameBranch, wire.FrameBlob, wire.FrameSendPack, wire.FramePublish, wire.FramePublished, wire.FrameRefused} {
if !seen[kind] {
t.Fatalf("no fixture for frame %s", kind)
}
diff --git a/internal/wire/wiretest/testdata/frames/blob.json b/internal/wire/wiretest/testdata/frames/blob.json
new file mode 100644
index 00000000..6645a936
--- /dev/null
+++ b/internal/wire/wiretest/testdata/frames/blob.json
@@ -0,0 +1 @@
+{"id":"c11","type":"blob","data":{"transfer":{"id":"tr_0001","direction":"inbound","repo":"amadan.net/oficina/sample","task_id":"tk0001","step_id":"s_0002","attempt":1,"base_sha":"1111111111111111111111111111111111111111","candidate_sha":"2222222222222222222222222222222222222222"},"index":0,"total":1,"sha256":"9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08","data":"UEFDSwAAAAIAAAAA"}}
\ No newline at end of file
diff --git a/internal/wire/wiretest/testdata/frames/dispatch-needs.json b/internal/wire/wiretest/testdata/frames/dispatch-needs.json
new file mode 100644
index 00000000..3fa86888
--- /dev/null
+++ b/internal/wire/wiretest/testdata/frames/dispatch-needs.json
@@ -0,0 +1 @@
+{"id":"c10","type":"dispatch","data":{"person":"owner@example.com","task_id":"tk0001","step_id":"s_0002","attempt":1,"specialist":"checks","repo":"amadan.net/oficina/sample","branch":"equipo/tk0001-swipe-back-from-the-edge-does-nothing","base_sha":"1111111111111111111111111111111111111111","title":"Swipe back from the edge does nothing","brief":"Swiping from the left edge should go back a pane.","findings":[],"candidate_sha":"2222222222222222222222222222222222222222","republish":false,"from_attempt":0,"avoid_account":"","round":0,"rebase":false,"from_base":"","needs":["macos","xcode"],"runner_id":"RUNNER2"}}
\ No newline at end of file
diff --git a/internal/wire/wiretest/testdata/frames/hello-mac.json b/internal/wire/wiretest/testdata/frames/hello-mac.json
new file mode 100644
index 00000000..6009174e
--- /dev/null
+++ b/internal/wire/wiretest/testdata/frames/hello-mac.json
@@ -0,0 +1 @@
+{"id":"r-hello-mac","type":"hello","data":{"generation":3,"repos":[],"create_in":[],"home":"","agent":"","catalog":[],"accounts":[{"id":"claude-a","provider":"claude","email":"owner@example.com","healthy":true,"headroom":null}],"versions":{"claude":"2.1.312","runner":"5eae410"},"protocol":2,"platform":{"os":"darwin","arch":"arm64"},"label":"Tito Studio","sandbox":"seatbelt","capabilities":{"xcode":{"version":"16.2","build":"16C5032a"},"simulators":[{"name":"iPhone 16 Pro","runtime":"iOS 18.2","udid":"5C0A1E2B-3D4F-4A5B-9C6D-7E8F90A1B2C3","state":"Shutdown"}],"toolchains":{"go":"go1.26.10","swift":"6.0.3","node":"v22.12.0"},"harness":{"claude":"2.1.312","codex":"","srt":"0.0.81"},"tags":["macos","xcode","ios_simulator","claude"]}}}
\ No newline at end of file
diff --git a/internal/wire/wiretest/testdata/frames/lease-step.json b/internal/wire/wiretest/testdata/frames/lease-step.json
new file mode 100644
index 00000000..732689bf
--- /dev/null
+++ b/internal/wire/wiretest/testdata/frames/lease-step.json
@@ -0,0 +1 @@
+{"id":"r-lease-2","type":"lease","data":{"generation":4,"step_id":"s_0002","attempt":1}}
\ No newline at end of file
diff --git a/internal/wire/wiretest/testdata/frames/publish.json b/internal/wire/wiretest/testdata/frames/publish.json
new file mode 100644
index 00000000..18c32fec
--- /dev/null
+++ b/internal/wire/wiretest/testdata/frames/publish.json
@@ -0,0 +1 @@
+{"id":"c13","type":"publish","data":{"publication":"pb_0001","task_id":"tk0001","step_id":"s_0001","attempt":1,"repo":"amadan.net/oficina/sample","branch":"equipo/tk0001-swipe-back-from-the-edge-does-nothing","person":"owner@example.com","base_sha":"1111111111111111111111111111111111111111","candidate_sha":"2222222222222222222222222222222222222222","transfer":"tr_0002"}}
\ No newline at end of file
diff --git a/internal/wire/wiretest/testdata/frames/published.json b/internal/wire/wiretest/testdata/frames/published.json
new file mode 100644
index 00000000..20625cec
--- /dev/null
+++ b/internal/wire/wiretest/testdata/frames/published.json
@@ -0,0 +1 @@
+{"id":"r-13","type":"published","data":{"publication":"pb_0001","task_id":"tk0001","step_id":"s_0001","attempt":1,"candidate_sha":"2222222222222222222222222222222222222222","pushed":true,"reason":""}}
\ No newline at end of file
diff --git a/internal/wire/wiretest/testdata/frames/refused.json b/internal/wire/wiretest/testdata/frames/refused.json
new file mode 100644
index 00000000..7ba6ccaa
--- /dev/null
+++ b/internal/wire/wiretest/testdata/frames/refused.json
@@ -0,0 +1 @@
+{"id":"i-refused-1","type":"refused","data":{"id":"r-lease-2","reason":"withdrawn"}}
\ No newline at end of file
diff --git a/internal/wire/wiretest/testdata/frames/send_pack.json b/internal/wire/wiretest/testdata/frames/send_pack.json
new file mode 100644
index 00000000..7bbcd7ef
--- /dev/null
+++ b/internal/wire/wiretest/testdata/frames/send_pack.json
@@ -0,0 +1 @@
+{"id":"c12","type":"send_pack","data":{"transfer":{"id":"tr_0001","direction":"inbound","repo":"amadan.net/oficina/sample","task_id":"tk0001","step_id":"s_0002","attempt":1,"base_sha":"1111111111111111111111111111111111111111","candidate_sha":"2222222222222222222222222222222222222222"},"have":["3333333333333333333333333333333333333333"]}}
\ No newline at end of file
diff --git a/internal/wire/wiretest/testdata/frames/step-process-group.json b/internal/wire/wiretest/testdata/frames/step-process-group.json
new file mode 100644
index 00000000..dc9ba41c
--- /dev/null
+++ b/internal/wire/wiretest/testdata/frames/step-process-group.json
@@ -0,0 +1 @@
+{"id":"r-14","type":"step","data":{"task_id":"tk0001","step_id":"s_0002","attempt":1,"state":"done","reason":"","base_sha":"1111111111111111111111111111111111111111","candidate_sha":"2222222222222222222222222222222222222222","pushed":false,"termination":true,"summary":"","log_tail":"","family":"","account":"","verdict":"","review_label":"","findings":[],"checks":"passed","gate":"xcodebuild test","exit_code":0,"output":"** TEST SUCCEEDED **","askable":false,"merge_sha":"","into":"","strategy":"","termination_kind":"process_group","have":["2222222222222222222222222222222222222222"]}}
\ No newline at end of file
diff --git a/internal/wire/wiretest/testdata/frames/welcome-worker.json b/internal/wire/wiretest/testdata/frames/welcome-worker.json
new file mode 100644
index 00000000..0f360bd1
--- /dev/null
+++ b/internal/wire/wiretest/testdata/frames/welcome-worker.json
@@ -0,0 +1 @@
+{"id":"i-welcome-4","type":"welcome","data":{"generation":4,"runner_id":"RUNNER2","protocol":2,"role":"worker","release":"98ce7a0"}}
\ No newline at end of file