oficina / equipo Public

wire: protocol 14, the scheduler's frames and fields

Dispatch gains priority, by and release; a step report gains its hold;
release and priority frames (durable); a preference's until. Below 14
Encode refuses the frames, a held report and a preference with an end,
and drops the dispatch fields. Fixtures and secret guards for each.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by paul@keymail.dev 8540c36bdd610bacc2f7c0ca75c75d761e64b675 parent ee80645
20 files changed, +335 −9
  • internal/wire/connections.go +6 −0
  • internal/wire/connections_test.go +2 −2
  • internal/wire/frames.go +5 −1
  • internal/wire/mixed_protocol_test.go +1 −1
  • internal/wire/runners.go +37 −2
  • internal/wire/runners_test.go +1 −1
  • internal/wire/schedule.go +160 −0
  • internal/wire/schedule_test.go +89 −0
  • internal/wire/tasks.go +16 −0
  • internal/wire/wiretest/fixtures.go +8 −2
  • internal/wire/wiretest/testdata/api/card-held.json +1 −0
  • internal/wire/wiretest/testdata/api/priority-request.json +1 −0
  • internal/wire/wiretest/testdata/api/run-now-accepted.json +1 −0
  • internal/wire/wiretest/testdata/api/run-now-request.json +1 −0
  • internal/wire/wiretest/testdata/api/task-held.json +1 −0
  • internal/wire/wiretest/testdata/frames/dispatch-urgent.json +1 −0
  • internal/wire/wiretest/testdata/frames/preference-until.json +1 −0
  • internal/wire/wiretest/testdata/frames/priority.json +1 −0
  • internal/wire/wiretest/testdata/frames/release.json +1 −0
  • internal/wire/wiretest/testdata/frames/step-held.json +1 −0
diff --git a/internal/wire/connections.go b/internal/wire/connections.go
index 11dfe37c..ff723041 100644
--- a/internal/wire/connections.go
+++ b/internal/wire/connections.go
@@ -192,6 +192,9 @@ const (
type Preferences struct {
Provider string `json:"provider"`
Revision int64 `json:"revision"`
+ // Until ends the preference by itself (protocol 14); absent: no end.
+ // Once it passes the preference is Automatic again.
+ Until *time.Time `json:"until,omitempty"`
}
// PreferenceProviders are the values Preferences.Provider may take.
@@ -207,6 +210,9 @@ type PreferenceCommand struct {
Person string `json:"person"`
Provider string `json:"provider"`
Revision int64 `json:"revision"`
+ // Until (protocol 14): the preference ends by itself then. Encode
+ // refuses a preference with an end below 14.
+ Until *time.Time `json:"until,omitempty"`
}
// DisconnectCommand signs one of the person's connections out: the
diff --git a/internal/wire/connections_test.go b/internal/wire/connections_test.go
index 75c9de5d..6151a514 100644
--- a/internal/wire/connections_test.go
+++ b/internal/wire/connections_test.go
@@ -38,7 +38,7 @@ func fieldNames(t reflect.Type, seen map[reflect.Type]bool, out *[]string) {
func TestConnectionTypesCarryNoSecrets(t *testing.T) {
var names []string
seen := map[reflect.Type]bool{}
- for _, v := range []any{wire.Connection{}, wire.ConnectionList{}, wire.Connect{}, wire.ConnectCommand{}, wire.CancelConnectCommand{}, wire.ConnectionReport{}, wire.Hello{}, wire.Reply{}, wire.TurnReport{}, wire.Snapshot{}, wire.StepReport{}, wire.AnswerReport{}, wire.UsageReport{}, wire.DisconnectCommand{}, wire.Sync{}, wire.ModelCommand{}, wire.BudgetCommand{}, wire.ResumeSpendCommand{}, wire.SetBudget{}, wire.ResumeSpend{}, wire.ChooseModel{}, wire.Budget{}, wire.Spend{}} {
+ for _, v := range []any{wire.Connection{}, wire.ConnectionList{}, wire.Connect{}, wire.ConnectCommand{}, wire.CancelConnectCommand{}, wire.ConnectionReport{}, wire.Hello{}, wire.Reply{}, wire.TurnReport{}, wire.Snapshot{}, wire.StepReport{}, wire.AnswerReport{}, wire.UsageReport{}, wire.DisconnectCommand{}, wire.Sync{}, wire.ModelCommand{}, wire.BudgetCommand{}, wire.ResumeSpendCommand{}, wire.SetBudget{}, wire.ResumeSpend{}, wire.ChooseModel{}, wire.Budget{}, wire.Spend{}, wire.DispatchCommand{}, wire.ReleaseCommand{}, wire.PriorityCommand{}, wire.SetPriority{}, wire.RunNow{}, wire.RunNowAccepted{}, wire.StepHold{}, wire.TaskPriority{}, wire.Preferences{}, wire.PreferenceCommand{}} {
fieldNames(reflect.TypeOf(v), seen, &names)
}
// seal_key is the runner's public key (spec §2.4): public by design.
@@ -64,7 +64,7 @@ func TestConnectionTypesCarryNoSecrets(t *testing.T) {
// TestConnectionFixturesCarryNoSecrets: the recorded documents a native
// app replays hold no secret-shaped key either.
func TestConnectionFixturesCarryNoSecrets(t *testing.T) {
- for _, name := range []string{"api/connections.json", "api/connection-connecting-codex.json", "api/connection-signing-in-claude.json", "api/connect-request.json", "api/event-connection.json", "frames/connect.json", "frames/cancel_connect.json", "frames/connection.json", "frames/hello.json", "frames/reply-usage.json", "frames/usage.json", "frames/disconnect.json", "frames/sync.json", "frames/preference.json", "api/preferences.json", "api/event-preference.json", "api/connection-metered.json", "api/connection-choose-model.json", "api/connect-request-api-key.json", "api/budget.json", "api/resume-request.json", "api/model-request.json", "frames/budget.json", "frames/model.json", "frames/resume_spend.json", "frames/connect-api-key.json", "frames/usage-probe.json", "frames/hello-metered.json"} {
+ for _, name := range []string{"api/connections.json", "api/connection-connecting-codex.json", "api/connection-signing-in-claude.json", "api/connect-request.json", "api/event-connection.json", "frames/connect.json", "frames/cancel_connect.json", "frames/connection.json", "frames/hello.json", "frames/reply-usage.json", "frames/usage.json", "frames/disconnect.json", "frames/sync.json", "frames/preference.json", "api/preferences.json", "api/event-preference.json", "api/connection-metered.json", "api/connection-choose-model.json", "api/connect-request-api-key.json", "api/budget.json", "api/resume-request.json", "api/model-request.json", "frames/budget.json", "frames/model.json", "frames/resume_spend.json", "frames/connect-api-key.json", "frames/usage-probe.json", "frames/hello-metered.json", "frames/release.json", "frames/priority.json", "frames/step-held.json", "frames/preference-until.json", "frames/dispatch-urgent.json", "api/task-held.json", "api/priority-request.json", "api/run-now-request.json", "api/run-now-accepted.json", "api/card-held.json"} {
// seal_key is public (spec §2.4); api_key is a connection's kind
// and its card's, never a field (connectors spec §10).
raw := strings.ReplaceAll(strings.ToLower(string(wiretest.Fixture(name))), `"seal_key"`, "")
diff --git a/internal/wire/frames.go b/internal/wire/frames.go
index 3421bee9..f0170072 100644
--- a/internal/wire/frames.go
+++ b/internal/wire/frames.go
@@ -60,7 +60,7 @@ type Frame struct {
// Durable reports whether a frame must be acked and resent until acked.
func (f Frame) Durable() bool {
switch f.Type {
- case FrameMessage, FrameAttachment, FrameCancel, FrameReply, FrameTurn, FrameToolCall, FrameToolResult, FrameMoveIn, FrameNotebook, FrameReset, FrameDispatch, FrameCancelStep, FrameStep, FrameRecheck, FrameWatchMerge, FrameMerged, FrameAsk, FrameCancelAsk, FrameAnswer, FrameForgetTask, FrameBranch, FrameBlob, FrameSendPack, FramePublish, FramePublished, FrameConnect, FrameCancelConnect, FrameConnection, FrameUsage, FrameDisconnect, FramePreference, FrameSecret, FrameCheck, FrameModel, FrameBudget, FrameResumeSpend, FrameResearchFile:
+ case FrameMessage, FrameAttachment, FrameCancel, FrameReply, FrameTurn, FrameToolCall, FrameToolResult, FrameMoveIn, FrameNotebook, FrameReset, FrameDispatch, FrameCancelStep, FrameStep, FrameRecheck, FrameWatchMerge, FrameMerged, FrameAsk, FrameCancelAsk, FrameAnswer, FrameForgetTask, FrameBranch, FrameBlob, FrameSendPack, FramePublish, FramePublished, FrameConnect, FrameCancelConnect, FrameConnection, FrameUsage, FrameDisconnect, FramePreference, FrameSecret, FrameCheck, FrameModel, FrameBudget, FrameResumeSpend, FrameResearchFile, FrameRelease, FramePriority:
return true
}
return false
@@ -173,6 +173,10 @@ func (f Frame) Decode() (any, error) {
v = &Refused{}
case FrameResearchFile:
v = &ResearchFile{}
+ case FrameRelease:
+ v = &ReleaseCommand{}
+ case FramePriority:
+ v = &PriorityCommand{}
default:
return nil, fmt.Errorf("%w: frame type %q", ErrStrict, f.Type)
}
diff --git a/internal/wire/mixed_protocol_test.go b/internal/wire/mixed_protocol_test.go
index 0aea7f99..c5fc2f6b 100644
--- a/internal/wire/mixed_protocol_test.go
+++ b/internal/wire/mixed_protocol_test.go
@@ -15,7 +15,7 @@ import (
// both go out whole; at 11 both are downgraded. The numbers are written
// out so that pointing ProtocolResearch back at 12 fails here.
func TestEncodeMixedMeteredAndResearch(t *testing.T) {
- if wire.ProtocolMetered != wire.Protocol12 || wire.ProtocolResearch != wire.Protocol13 || wire.ProtocolCurrent != wire.Protocol13 {
+ if wire.ProtocolMetered != wire.Protocol12 || wire.ProtocolResearch != wire.Protocol13 || wire.ProtocolCurrent != wire.Protocol14 {
t.Fatalf("metered %d, research %d, current %d", wire.ProtocolMetered, wire.ProtocolResearch, wire.ProtocolCurrent)
}
metered := wire.HeldConnection{LocalID: "tensorx-1", Person: "p", Provider: wire.ProviderTensorX, Kind: wire.KindAPIKey, State: wire.ConnHealthy, Harness: wire.HarnessPi, Upstream: "https://api.tensorx.ai", Billing: wire.BillingMetered, Model: "z-ai/glm-5.3", Budget: &wire.Budget{Day: 1, Month: 2, Currency: "USD"}, Spend: &wire.Spend{Currency: "USD"}}
diff --git a/internal/wire/runners.go b/internal/wire/runners.go
index 4ba82df9..0454c2d1 100644
--- a/internal/wire/runners.go
+++ b/internal/wire/runners.go
@@ -39,6 +39,7 @@ const (
Protocol11 = 11
Protocol12 = 12
Protocol13 = 13
+ Protocol14 = 14
// ProtocolSpend is the first protocol with a fix round's Feedback and
// a usage row's Turns; Encode drops both below it.
ProtocolSpend = Protocol3
@@ -96,7 +97,14 @@ const (
// below (downgradeResearch); the runner answers the coordinator's
// research tools itself on an older connection.
ProtocolResearch = Protocol13
- ProtocolCurrent = ProtocolResearch
+ // ProtocolScheduler is the first protocol with the scheduler
+ // (connectors spec 2026-11-12, S3): a dispatch's priority, deadline
+ // and release, a held step's hold, the release and priority frames and
+ // a preference's end. Below it Encode refuses the frames, a held
+ // report and a preference with an end, and drops the dispatch fields:
+ // an older runner has no leave to spend, so it is never handed one.
+ ProtocolScheduler = Protocol14
+ ProtocolCurrent = ProtocolScheduler
)
// Runner roles. A person's first runner is the primary: the coordinator,
@@ -493,12 +501,24 @@ func Encode(f Frame, protocol int) (Frame, error) {
return Frame{}, err
}
changed := false
+ if protocol < ProtocolScheduler {
+ if schedulerOnly[f.Type] {
+ return Frame{}, fmt.Errorf("%w: %s at protocol %d", ErrProtocol, f.Type, protocol)
+ }
+ if r, ok := body.(*StepReport); ok && r.Hold != nil {
+ return Frame{}, fmt.Errorf("%w: a held step at protocol %d", ErrProtocol, protocol)
+ }
+ if p, ok := body.(*PreferenceCommand); ok && p.Until != nil {
+ return Frame{}, fmt.Errorf("%w: a preference with an end at protocol %d", ErrProtocol, protocol)
+ }
+ changed = downgradeScheduler(body)
+ }
if protocol < ProtocolResearch {
dropped, err := downgradeResearch(body, protocol)
if err != nil {
return Frame{}, err
}
- changed = dropped
+ changed = dropped || changed
}
if protocol < ProtocolMetered {
if meteredOnly[f.Type] {
@@ -573,6 +593,21 @@ func meteredReport(body any) bool {
return false
}
+// schedulerOnly are the frame types below ProtocolScheduler never carries.
+var schedulerOnly = map[string]bool{FrameRelease: true, FramePriority: true}
+
+// downgradeScheduler clears a dispatch's scheduler fields (an older
+// runner runs every step as before and never spends). It reports whether
+// anything changed.
+func downgradeScheduler(body any) bool {
+ if d, ok := body.(*DispatchCommand); ok {
+ set := d.Priority != "" || d.By != nil || d.Release != ""
+ d.Priority, d.By, d.Release = "", nil, ""
+ return set
+ }
+ return false
+}
+
// meteredOnly are the frame types below ProtocolMetered never carries.
var meteredOnly = map[string]bool{FrameModel: true, FrameBudget: true, FrameResumeSpend: true}
diff --git a/internal/wire/runners_test.go b/internal/wire/runners_test.go
index f396f4ec..fa024371 100644
--- a/internal/wire/runners_test.go
+++ b/internal/wire/runners_test.go
@@ -413,7 +413,7 @@ func TestEncodeBelowProtocol9DropsPreviews(t *testing.T) {
if _, err := wire.Encode(d, wire.ProtocolPreview); err != nil {
t.Fatal(err)
}
- if wire.ProtocolCurrent != wire.ProtocolResearch || wire.ProtocolResearch != 13 || wire.ProtocolMetered != 12 || wire.ProtocolPreviewHost != 11 || wire.ProtocolExplore != 10 || wire.ProtocolPreview != 9 {
+ if wire.ProtocolCurrent != wire.ProtocolScheduler || wire.ProtocolScheduler != 14 || wire.ProtocolResearch != 13 || wire.ProtocolMetered != 12 || wire.ProtocolPreviewHost != 11 || wire.ProtocolExplore != 10 || wire.ProtocolPreview != 9 {
t.Fatalf("current %d", wire.ProtocolCurrent)
}
}
diff --git a/internal/wire/schedule.go b/internal/wire/schedule.go
new file mode 100644
index 00000000..7fe3eed5
--- /dev/null
+++ b/internal/wire/schedule.go
@@ -0,0 +1,160 @@
+package wire
+
+import "time"
+
+// The scheduler (connectors spec 2026-11-12 rev 3.1, §6 to §8, slice S3):
+// a task's priority and deadline, a held step's hold, Run now's release,
+// a priority change for a step already sent, and a preference that ends
+// by itself. ProtocolScheduler carries them; Encode refuses or drops all
+// of them below it (downgradeScheduler).
+
+// Task priorities (§6). The coordinator may set low or normal, and by,
+// only when it creates a task; every later change and every urgent is
+// the task creator's own tap.
+const (
+ PriorityUrgent = "urgent"
+ PriorityNormal = "normal"
+ PriorityLow = "low"
+)
+
+// ValidPriority reports whether p is a priority ("" is not: it is read as
+// normal where a priority is optional).
+func ValidPriority(p string) bool {
+ return p == PriorityUrgent || p == PriorityNormal || p == PriorityLow
+}
+
+// CoordinatorPriority reports whether the coordinator may set p when it
+// creates a task: low or normal, never urgent.
+func CoordinatorPriority(p string) bool { return p == PriorityLow || p == PriorityNormal }
+
+// Who set a task's priority and deadline: the coordinator from the
+// person's message (shown "set from your message"), or the person.
+const (
+ PrioritySetByCoordinator = "coordinator"
+ PrioritySetByPerson = "person"
+)
+
+// Hold reasons a held step reports (§7 rule 5): waiting for headroom on
+// a subscription, a metered connection at its budget, its spend unknown,
+// its one slot taken (a kept session held on it), or nothing that can
+// run the step.
+// (HoldBusy, HoldBudget and HoldSpendUnknown are the metered guard's,
+// ProtocolMetered.)
+const (
+ HoldHeadroom = "headroom"
+ HoldNoConnection = ReasonNoConnection
+)
+
+// HoldReasons are the values StepHold.Reason may take.
+var HoldReasons = map[string]bool{HoldHeadroom: true, HoldBudget: true, HoldSpendUnknown: true, HoldBusy: true, HoldNoConnection: true}
+
+// What a held step needs from its person (§8, Needs you): the deadline
+// check fired, no reset in sight, or nothing can run it.
+const (
+ HoldNeedsDeadline = "deadline"
+ HoldNeedsNoReset = "no_reset"
+ HoldNeedsNoConnection = "no_connection"
+)
+
+// HoldNeeds are the values StepHold.NeedsPerson may take.
+var HoldNeeds = map[string]bool{"": true, HoldNeedsDeadline: true, HoldNeedsNoReset: true, HoldNeedsNoConnection: true}
+
+// NeedsHeld is Task.NeedsYou for a step the scheduler holds where the
+// person's input changes the outcome.
+const NeedsHeld = "held"
+
+// CardHeld is the Needs you card for a held step: Equipo's
+// recommendation, with Wait and Run it now.
+const CardHeld = "held"
+
+// Routing reasons the scheduler adds (§10): a kept session, metered work
+// for an urgent task or a release, and a hold.
+const (
+ RoutingSticky = "sticky"
+ RoutingMeteredUrgent = "metered_urgent"
+ RoutingMeteredRelease = "metered_release"
+ RoutingHeld = "held"
+)
+
+// StepHold is why the runner holds a step (§8): reason, the connection
+// it names (the runner's local id and its provider, "" for none), that
+// connection's reported reset, when the runner looks again on its own
+// (null: only a fact change wakes it), what it needs from the person,
+// and the step revision a Run now must name. A step report carries it
+// while the step is held, with state running (queued on the instance
+// until it starts); a report without it ends the hold.
+type StepHold struct {
+ Reason string `json:"reason"`
+ Connection string `json:"connection,omitempty"`
+ Provider string `json:"provider,omitempty"`
+ ResetsAt *time.Time `json:"resets_at,omitempty"`
+ WakeAt *time.Time `json:"wake_at"`
+ NeedsPerson string `json:"needs_person,omitempty"`
+ StepRevision int64 `json:"step_revision"`
+}
+
+// FrameRelease is Run now (instance to runner, durable, consumed once):
+// leave for one step revision to start now, metered connections
+// included, the bars still applying. The runner consumes it atomically
+// with the admission it causes; it becomes a grant for (step,
+// step_revision) that covers that revision's failover attempts and ends
+// with the step. A stale or consumed release is acked and ignored.
+const FrameRelease = "release"
+
+// ReleaseCommand is a release. StepRevision is the dispatch it is for:
+// the attempt the instance sent (failover attempts the runner makes keep
+// it).
+type ReleaseCommand struct {
+ ID string `json:"id"`
+ Person string `json:"person"`
+ TaskID string `json:"task_id"`
+ StepID string `json:"step_id"`
+ StepRevision int64 `json:"step_revision"`
+}
+
+// FramePriority tells the runner a task's priority or deadline changed
+// (instance to runner, durable): the steps of the task it holds take it.
+// A revision at or below the one held changes nothing.
+const FramePriority = "priority"
+
+// PriorityCommand is a priority change for the runner.
+type PriorityCommand struct {
+ Person string `json:"person"`
+ TaskID string `json:"task_id"`
+ Priority string `json:"priority"`
+ By *time.Time `json:"by"`
+ Revision int64 `json:"revision"`
+}
+
+// SetPriority is PUT /api/v1/tasks/{id}/priority: the task creator's
+// priority and deadline (by null clears it), against the task's
+// revision.
+type SetPriority struct {
+ Priority string `json:"priority"`
+ By *time.Time `json:"by"`
+ Revision int64 `json:"revision"`
+}
+
+// RunNow is POST /api/v1/tasks/{id}/run-now: the task creator's leave
+// for the held step at the revision its hold shows.
+type RunNow struct {
+ Step string `json:"step"`
+ StepRevision int64 `json:"step_revision"`
+}
+
+// RunNowAccepted answers Run now: the release written (202), or the one
+// already written for that step revision.
+type RunNowAccepted struct {
+ Release string `json:"release"`
+}
+
+// TaskPriority is a task's priority on its read shape: the priority,
+// the deadline, who set them and whether the deadline check fired.
+type TaskPriority struct {
+ Priority string `json:"priority"`
+ By *time.Time `json:"by"`
+ SetBy string `json:"set_by"`
+}
+
+// MaxByAhead bounds a deadline: at most a year ahead.
+const MaxByAhead = 366 * 24 * time.Hour
diff --git a/internal/wire/schedule_test.go b/internal/wire/schedule_test.go
new file mode 100644
index 00000000..98eb3df2
--- /dev/null
+++ b/internal/wire/schedule_test.go
@@ -0,0 +1,89 @@
+package wire_test
+
+import (
+ "bytes"
+ "encoding/json"
+ "errors"
+ "strings"
+ "testing"
+ "time"
+
+ "amadan.net/oficina/equipo/internal/wire"
+)
+
+// Mixed versions (the scheduler at 14): at 14 every scheduler frame and
+// field goes out whole; at 13 the release and priority frames, a held
+// report and a preference with an end are refused (an older runner is
+// refused anything that spends, never handed it), and a dispatch loses
+// its priority, deadline and release; what 13 already had is unchanged.
+func TestEncodeBelowProtocol14DropsScheduler(t *testing.T) {
+ if wire.ProtocolScheduler != wire.Protocol14 || wire.ProtocolCurrent != wire.Protocol14 {
+ t.Fatalf("scheduler %d, current %d", wire.ProtocolScheduler, wire.ProtocolCurrent)
+ }
+ by := time.Date(2026, 11, 20, 17, 0, 0, 0, time.UTC)
+ wake := time.Date(2026, 11, 13, 10, 0, 0, 0, time.UTC)
+ plain := wire.DispatchCommand{Person: "p", TaskID: "tk", StepID: "s", Attempt: 1, Specialist: wire.SpecialistEngineering, Findings: []wire.Finding{}}
+ urgent := plain
+ urgent.Priority, urgent.By, urgent.Release = wire.PriorityUrgent, &by, "rl_1"
+ dispatch, _ := wire.NewFrame("d", wire.FrameDispatch, urgent)
+ release, _ := wire.NewFrame("r", wire.FrameRelease, wire.ReleaseCommand{ID: "rl_1", Person: "p", TaskID: "tk", StepID: "s", StepRevision: 1})
+ priority, _ := wire.NewFrame("p", wire.FramePriority, wire.PriorityCommand{Person: "p", TaskID: "tk", Priority: wire.PriorityUrgent, Revision: 2})
+ held, _ := wire.NewFrame("h", wire.FrameStep, wire.StepReport{TaskID: "tk", StepID: "s", Attempt: 1, State: wire.StepRunning, Findings: []wire.Finding{}, Hold: &wire.StepHold{Reason: wire.HoldHeadroom, Connection: "claude-a", Provider: "claude", WakeAt: &wake, StepRevision: 1}})
+ until, _ := wire.NewFrame("u", wire.FramePreference, wire.PreferenceCommand{Person: "p", Provider: "codex", Revision: 3, Until: &by})
+ forever, _ := wire.NewFrame("f", wire.FramePreference, wire.PreferenceCommand{Person: "p", Provider: "codex", Revision: 3})
+ started, _ := wire.NewFrame("s", wire.FrameStep, wire.StepReport{TaskID: "tk", StepID: "s", Attempt: 1, State: wire.StepRunning, Findings: []wire.Finding{}})
+
+ for _, f := range []wire.Frame{dispatch, release, priority, held, until, forever, started} {
+ if same, err := wire.Encode(f, wire.Protocol14); err != nil || !bytes.Equal(same.Data, f.Data) {
+ t.Fatalf("%s changed at 14: %v", f.Type, err)
+ }
+ }
+ for _, f := range []wire.Frame{release, priority, held, until} {
+ if _, err := wire.Encode(f, wire.Protocol13); !errors.Is(err, wire.ErrProtocol) {
+ t.Fatalf("%s %s encoded at 13: %v", f.Type, f.Data, err)
+ }
+ }
+ for _, f := range []wire.Frame{forever, started} {
+ if same, err := wire.Encode(f, wire.Protocol13); err != nil || !bytes.Equal(same.Data, f.Data) {
+ t.Fatalf("%s changed at 13: %v", f.Type, err)
+ }
+ }
+ got, err := wire.Encode(dispatch, wire.Protocol13)
+ want, _ := wire.NewFrame("d", wire.FrameDispatch, plain)
+ if err != nil || !bytes.Equal(got.Data, want.Data) {
+ t.Fatalf("dispatch at 13: %v\n got %s\nwant %s", err, got.Data, want.Data)
+ }
+ // What a protocol 13 peer reads strictly: no scheduler field survives.
+ for _, p := range []int{wire.Protocol13, wire.Protocol12, wire.Protocol1} {
+ got, err := wire.Encode(dispatch, p)
+ if err != nil {
+ t.Fatal(err)
+ }
+ for _, field := range []string{`"priority"`, `"by"`, `"release"`} {
+ if strings.Contains(string(got.Data), field) {
+ t.Fatalf("%s reached protocol %d: %s", field, p, got.Data)
+ }
+ }
+ }
+}
+
+// The scheduler's frames are durable and decode strictly.
+func TestSchedulerFramesStrict(t *testing.T) {
+ for _, kind := range []string{wire.FrameRelease, wire.FramePriority} {
+ if !(wire.Frame{Type: kind}).Durable() {
+ t.Fatalf("%s is not durable", kind)
+ }
+ }
+ bad, _ := json.Marshal(map[string]any{"id": "r", "person": "p", "task_id": "t", "step_id": "s", "step_revision": 1, "api_key": "x"})
+ if _, err := (wire.Frame{ID: "r", Type: wire.FrameRelease, Data: bad}).Decode(); err == nil {
+ t.Fatal("an unknown field in a release decoded")
+ }
+ for _, p := range []string{wire.PriorityUrgent, wire.PriorityNormal, wire.PriorityLow} {
+ if !wire.ValidPriority(p) {
+ t.Fatalf("%s invalid", p)
+ }
+ }
+ if wire.ValidPriority("") || wire.ValidPriority("high") || wire.CoordinatorPriority(wire.PriorityUrgent) || !wire.CoordinatorPriority(wire.PriorityLow) {
+ t.Fatal("priority values")
+ }
+}
diff --git a/internal/wire/tasks.go b/internal/wire/tasks.go
index b0dac7ae..dd63ac83 100644
--- a/internal/wire/tasks.go
+++ b/internal/wire/tasks.go
@@ -299,6 +299,9 @@ type Step struct {
// Research: a done Research step's findings, fetch log and kept
// images, on the task's read shape only.
Research *StepResearch `json:"research,omitempty"`
+ // Hold is why the scheduler holds the step now (absent when it does
+ // not).
+ Hold *StepHold `json:"hold,omitempty"`
}
// Task is one piece of work under a project. Branch is the task's own
@@ -402,6 +405,9 @@ type Task struct {
// Direction is what the direction card shows while an exploration
// waits for its person's choice.
Direction *TaskDirection `json:"direction,omitempty"`
+ // Priority is the task's priority and deadline (the scheduler); absent
+ // on shapes that predate it.
+ Priority *TaskPriority `json:"priority,omitempty"`
}
// TaskRef names another task.
@@ -676,6 +682,12 @@ type DispatchCommand struct {
// ResearchNote (protocol 13) is an Engineering or Review step's view of
// the task's latest Research findings: quoted data, never instructions.
ResearchNote *ResearchHandoff `json:"research_note,omitempty"`
+ // Protocol 14 (the scheduler): the task's priority and deadline, and
+ // a Run now not yet consumed for this step revision (its id). Encode
+ // drops all three for an older runner, which never spends.
+ Priority string `json:"priority,omitempty"`
+ By *time.Time `json:"by,omitempty"`
+ Release string `json:"release,omitempty"`
}
// WatchMergeCommand watches a task's branch for its candidate landing on
@@ -782,6 +794,10 @@ type StepReport struct {
// its fetch log and the images it kept (their bytes travel first, in
// research_file frames).
Research *ResearchResult `json:"research,omitempty"`
+ // Protocol 14. Hold: the scheduler holds the step (state running;
+ // the instance keeps it queued until it starts). A report without it
+ // ends the hold. Encode refuses a held report below 14.
+ Hold *StepHold `json:"hold,omitempty"`
}
// ReasonRunnerOutdated settles a preview step whose primary connected
diff --git a/internal/wire/wiretest/fixtures.go b/internal/wire/wiretest/fixtures.go
index fd1b22b7..28ec9fcc 100644
--- a/internal/wire/wiretest/fixtures.go
+++ b/internal/wire/wiretest/fixtures.go
@@ -69,7 +69,7 @@ func APIType(name string) any {
return &wire.ProjectList{}
case "add-project-request.json":
return &wire.AddProject{}
- case "card.json", "card-merge.json":
+ case "card.json", "card-merge.json", "card-held.json":
return &wire.Card{}
case "answer-request.json":
return &wire.AnswerCard{}
@@ -81,7 +81,7 @@ func APIType(name string) any {
return &wire.Notebook{}
case "snapshot.json":
return &wire.Snapshot{}
- case "task.json", "task-ready.json", "task-merged.json":
+ case "task.json", "task-ready.json", "task-merged.json", "task-held.json":
return &wire.Task{}
case "tasks.json", "needs-you.json":
return &wire.TaskList{}
@@ -111,6 +111,12 @@ func APIType(name string) any {
return &wire.ChooseModel{}
case "preferences.json":
return &wire.Preferences{}
+ case "priority-request.json":
+ return &wire.SetPriority{}
+ case "run-now-request.json":
+ return &wire.RunNow{}
+ case "run-now-accepted.json":
+ return &wire.RunNowAccepted{}
case "connection-secret.json", "connection-code.json":
return &wire.Sealed{}
case "duplicate-request.json":
diff --git a/internal/wire/wiretest/testdata/api/card-held.json b/internal/wire/wiretest/testdata/api/card-held.json
new file mode 100644
index 00000000..40e48a2b
--- /dev/null
+++ b/internal/wire/wiretest/testdata/api/card-held.json
@@ -0,0 +1 @@
+{"id":"c_0002","revision":1,"kind":"held","state":"open","turn_id":"","project_id":"p_0001","name":"Swipe back on iOS","question":"I’d wait: Claude resets Thu 10:00, before Friday.","options":["wait","run_now"],"choice":"","task_id":"tk0001","created_at":"2026-11-06T10:00:00Z","updated_at":"2026-11-06T10:00:00Z"}
diff --git a/internal/wire/wiretest/testdata/api/priority-request.json b/internal/wire/wiretest/testdata/api/priority-request.json
new file mode 100644
index 00000000..7a57a2a9
--- /dev/null
+++ b/internal/wire/wiretest/testdata/api/priority-request.json
@@ -0,0 +1 @@
+{"priority":"urgent","by":null,"revision":4}
diff --git a/internal/wire/wiretest/testdata/api/run-now-accepted.json b/internal/wire/wiretest/testdata/api/run-now-accepted.json
new file mode 100644
index 00000000..a9599f60
--- /dev/null
+++ b/internal/wire/wiretest/testdata/api/run-now-accepted.json
@@ -0,0 +1 @@
+{"release":"rl_0001"}
diff --git a/internal/wire/wiretest/testdata/api/run-now-request.json b/internal/wire/wiretest/testdata/api/run-now-request.json
new file mode 100644
index 00000000..6ba4c4bd
--- /dev/null
+++ b/internal/wire/wiretest/testdata/api/run-now-request.json
@@ -0,0 +1 @@
+{"step":"s_0002","step_revision":1}
diff --git a/internal/wire/wiretest/testdata/api/task-held.json b/internal/wire/wiretest/testdata/api/task-held.json
new file mode 100644
index 00000000..a046469b
--- /dev/null
+++ b/internal/wire/wiretest/testdata/api/task-held.json
@@ -0,0 +1 @@
+{"id":"tk0001","revision":5,"project_id":"p_0001","project":"Sample","repo":"amadan.net/oficina/sample","title":"Swipe back from the edge does nothing","brief":"Swiping from the left edge should go back a pane.","stage":"in_progress","branch":"equipo/tk0001-swipe-back-from-the-edge-does-nothing","base_sha":"1111111111111111111111111111111111111111","url":"https://amadan.net/oficina/sample?branch=equipo/tk0001-swipe-back-from-the-edge-does-nothing","creator":"owner@example.com","turn_id":"t_0001","findings":[{"id":"f_0001","headline":"Found it: the edge swipe never reaches the back handler.","text":"The edge-swipe handler returns false, so back never fires.","repo":"amadan.net/oficina/sample","path":"panes/swipe.go","line":4,"at":"2026-11-07T10:00:02Z"}],"steps":[{"id":"s_0001","revision":3,"task_id":"tk0001","index":1,"specialist":"engineering","state":"done","reason":"","attempt":1,"base_sha":"1111111111111111111111111111111111111111","candidate_sha":"2222222222222222222222222222222222222222","pushed":true,"terminated":true,"summary":"EdgeSwipe now goes back on a swipe from the edge.","headline":"Fixed swipe-back from the edge.","log_tail":"Edit panes/swipe.go\nDone.","started_at":"2026-11-07T10:00:03Z","finished_at":"2026-11-07T10:01:40Z","round":0,"family":"claude","account":"claude-a","verdict":"","review_label":"","findings":[],"checks":"","gate":"","exit_code":null,"askable":true,"rebase":false,"merge_sha":"","into":"","strategy":"","without_checks":false,"switched":null,"activity":[{"kind":"read","subject":"panes/swipe.go","at":"2026-11-07T10:00:20Z"},{"kind":"edit","subject":"panes/swipe.go","at":"2026-11-07T10:01:02Z"},{"kind":"run","subject":"go test ./panes","at":"2026-11-07T10:01:20Z"}],"runner_id":"RUNNER1","runner_label":"","needs":[],"placement":"","publication":"","termination_kind":"namespace"},{"id":"s_0001","revision":3,"task_id":"tk0001","index":1,"specialist":"engineering","state":"queued","reason":"","attempt":1,"base_sha":"1111111111111111111111111111111111111111","candidate_sha":"2222222222222222222222222222222222222222","pushed":true,"terminated":true,"summary":"EdgeSwipe now goes back on a swipe from the edge.","headline":"Fixed swipe-back from the edge.","log_tail":"Edit panes/swipe.go\nDone.","started_at":"2026-11-07T10:00:03Z","finished_at":"2026-11-07T10:01:40Z","round":0,"family":"claude","account":"claude-a","verdict":"","review_label":"","findings":[],"checks":"","gate":"","exit_code":null,"askable":true,"rebase":false,"merge_sha":"","into":"","strategy":"","without_checks":false,"switched":null,"activity":[{"kind":"read","subject":"panes/swipe.go","at":"2026-11-07T10:00:20Z"},{"kind":"edit","subject":"panes/swipe.go","at":"2026-11-07T10:01:02Z"},{"kind":"run","subject":"go test ./panes","at":"2026-11-07T10:01:20Z"}],"runner_id":"RUNNER1","runner_label":"","needs":[],"placement":"","publication":"","termination_kind":"namespace","hold":{"reason":"headroom","connection":"claude-a","provider":"claude","resets_at":"2026-11-13T10:00:00Z","wake_at":"2026-11-13T10:00:00Z","step_revision":1}}],"thread":[{"id":"e_0001","author":"owner@example.com","text":"It happens on the iPhone only.","at":"2026-11-07T10:00:30Z"}],"created_at":"2026-11-07T10:00:01Z","updated_at":"2026-11-07T10:01:40Z","candidate_sha":"2222222222222222222222222222222222222222","checks":"","checks_reason":"","verdict":"","review_label":"","needs_you":"held","fix_rounds":0,"branch_head":"","questions":[{"id":"q_0001","revision":3,"task_id":"tk0001","step_id":"s_0001","specialist":"engineering","asker":"owner@example.com","text":"What did you change and why?","state":"answered","reason":"","attempt":1,"answer":"I made the edge swipe return true, so a swipe from the left edge goes back a pane. Before, the handler always said no.","created_at":"2026-11-07T10:05:00Z","updated_at":"2026-11-07T10:05:09Z","timing":null}],"merged":null,"reports":0,"ask_open":false,"merge_offered":false,"creator_name":"Owner","source_message_id":"m_0001","source_at":"2026-11-07T09:59:58Z","duplicate_of":null,"coordinator":null,"folded":null,"combined":null,"engineering_runner":"RUNNER1","priority":{"priority":"low","by":"2026-11-20T17:00:00Z","set_by":"coordinator"}}
diff --git a/internal/wire/wiretest/testdata/frames/dispatch-urgent.json b/internal/wire/wiretest/testdata/frames/dispatch-urgent.json
new file mode 100644
index 00000000..8f91e897
--- /dev/null
+++ b/internal/wire/wiretest/testdata/frames/dispatch-urgent.json
@@ -0,0 +1 @@
+{"id":"c65","type":"dispatch","data":{"person":"owner@example.com","task_id":"tk0001","step_id":"s_0001","attempt":1,"specialist":"engineering","repo":"amadan.net/oficina/sample","branch":"equipo/tk0001-swipe-back-from-the-edge-does-nothing","base_sha":"","title":"Swipe back from the edge does nothing","brief":"Swiping from the left edge should go back a pane.","findings":[{"id":"f_0001","headline":"Found it: the edge swipe never reaches the back handler.","text":"The edge-swipe handler returns false, so back never fires.","repo":"amadan.net/oficina/sample","path":"panes/swipe.go","line":4,"at":"2026-11-07T10:00:02Z"}],"candidate_sha":"","republish":false,"from_attempt":0,"avoid_account":"","round":0,"rebase":false,"from_base":"","priority":"urgent","by":"2026-11-20T17:00:00Z","release":"rl_0001"}}
diff --git a/internal/wire/wiretest/testdata/frames/preference-until.json b/internal/wire/wiretest/testdata/frames/preference-until.json
new file mode 100644
index 00000000..3f9f48f4
--- /dev/null
+++ b/internal/wire/wiretest/testdata/frames/preference-until.json
@@ -0,0 +1 @@
+{"id":"c64","type":"preference","data":{"person":"owner@example.com","provider":"codex","revision":3,"until":"2026-11-14T10:00:00Z"}}
diff --git a/internal/wire/wiretest/testdata/frames/priority.json b/internal/wire/wiretest/testdata/frames/priority.json
new file mode 100644
index 00000000..c420474e
--- /dev/null
+++ b/internal/wire/wiretest/testdata/frames/priority.json
@@ -0,0 +1 @@
+{"id":"c62","type":"priority","data":{"person":"owner@example.com","task_id":"tk0001","priority":"urgent","by":"2026-11-20T17:00:00Z","revision":4}}
diff --git a/internal/wire/wiretest/testdata/frames/release.json b/internal/wire/wiretest/testdata/frames/release.json
new file mode 100644
index 00000000..1ea581c3
--- /dev/null
+++ b/internal/wire/wiretest/testdata/frames/release.json
@@ -0,0 +1 @@
+{"id":"c61","type":"release","data":{"id":"rl_0001","person":"owner@example.com","task_id":"tk0001","step_id":"s_0002","step_revision":1}}
diff --git a/internal/wire/wiretest/testdata/frames/step-held.json b/internal/wire/wiretest/testdata/frames/step-held.json
new file mode 100644
index 00000000..7a1a6e48
--- /dev/null
+++ b/internal/wire/wiretest/testdata/frames/step-held.json
@@ -0,0 +1 @@
+{"id":"r63","type":"step","data":{"task_id":"tk0001","step_id":"s_0002","attempt":1,"state":"running","reason":"","base_sha":"","candidate_sha":"","pushed":false,"termination":false,"summary":"","headline":"","log_tail":"","family":"","account":"","verdict":"","review_label":"","findings":[],"checks":"","gate":"","exit_code":null,"output":"","askable":false,"merge_sha":"","into":"","strategy":"","usage":null,"switched":null,"hold":{"reason":"headroom","connection":"claude-a","provider":"claude","resets_at":"2026-11-13T10:00:00Z","wake_at":"2026-11-13T10:00:00Z","step_revision":1}}}