oficina / equipo Public

Warm the Assistant when Base opens it, protocol 24

Paul's "Yo." waited 5.2 s for a fresh process: his Assistant had closed
after idling, 39 minutes after his last message.

- Wire: warm command {person}, instance to runner, durable; protocol 24
  (ProtocolWarm, ProtocolCurrent); Encode refuses it below 24.
- Instance: GET /api/v1/assistant/snapshot and opening its events
  stream write one warm command to the person's primary, at most once
  per 5 minutes per person (in-process gate), and only when that
  primary is online at 24 or later; nothing is written otherwise.
- Runner: on the command (at 24 only) the engine warms that person's
  Assistant under the sync rule (used within 7 days) on its own worker,
  and its glance within the glance slots. A harness already up is not
  warmed or logged again; only its glance may be.
- DefaultWarmIdle 30 min -> 4 h, now also the Assistant's idle after a
  turn (Coordinator and job lanes keep Idle, 10 min). Reason in the
  comment.

No API doc change: the routes and shapes are unchanged.
Tests: TestEncodeWarmBelow24, TestAssistantWarmOnOpen, TestLinkWarmsOnOpen,
TestAssistantWarmSkipsUpHarness, TestAssistantIdleCloseFourHours,
TestContractAssistantWarmOnOpen; mutations of each guard failed a test.
Budgets re-measured for wire, thin, chat, headless and thintest.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by paul@keymail.dev 5302ca50fa9b7ec2c692488179662dd9100bcc2b parent a9af383
22 files changed, +479 −28
  • .rastrillo/budgets.txt +5 −5
  • internal/equipo/chat/assistant_http.go +11 −0
  • internal/equipo/chat/store.go +2 −0
  • internal/equipo/chat/warm.go +55 −0
  • internal/runner/thin/claude.go +21 −4
  • internal/runner/thin/codex.go +2 −1
  • internal/runner/thin/link.go +7 −0
  • internal/runner/thin/warm.go +26 −1
  • internal/runner/thin/warm_test.go +183 −0
  • internal/thintest/assistant_warm_contract_test.go +91 −0
  • internal/wire/assistant_test.go +4 −4
  • internal/wire/frames.go +13 −1
  • internal/wire/glance_test.go +1 −1
  • internal/wire/mixed_protocol_test.go +1 −1
  • internal/wire/models_test.go +1 −1
  • internal/wire/opencode_test.go +1 −1
  • internal/wire/publish_test.go +1 −1
  • internal/wire/runners.go +10 −4
  • internal/wire/runners_test.go +1 −1
  • internal/wire/schedule_test.go +1 −1
  • internal/wire/usage_test.go +1 −1
  • internal/wire/warm_test.go +41 −0

CI cancelled — superseded by a newer push — run details

diff --git a/.rastrillo/budgets.txt b/.rastrillo/budgets.txt
index 76d05a0f..a8c8c017 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 20392 - The web view models and templates share rendering; Roster adds bylines, fact details, sub-chat views, Stop and compact reports. Measured 20392 source lines.
-size internal/wire 6352 - Runner and person API types share Encode. 21 adds Copy fields, 22 job lanes and cards, 23 the glance frame and its guard. Measured 6352 source lines.
+size internal/wire 6370 - Runner and person API types share Encode. 21 adds Copy fields, 22 job lanes and cards, 23 the glance frame, 24 the warm command. Measured 6370 source lines.
size internal/equipotest - 13400 Task 21 repairs historical migration and conversation fixtures after Plan 3. Measured 13024 test lines; the 300s time ceiling is unchanged.
time internal/runner/checks 90s CI worker measured 44.553s (44.6s rounded);
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 26229 18538 Runner state, connections and execution share private helpers: Copy, job lanes, the Assistant's warm-up and glance. Measured 26229 source, 18538 test lines.
+size internal/runner/thin 26357 18776 Runner state, connections and execution share private helpers: Copy, job lanes, the Assistant's warm-ups and glance. Measured 26357 source, 18776 test lines.
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 30s Mac runners (Darwin worker): real process groups killed after a grace and proven gone (SIGTERM, SIGKILL, the marker sweep), and the probes run end to end with fake srt and xcodebuild, P6 killing.
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 28778 - Transactional conversation store shares authority and dispatch helpers; roster reads; legacy mirrors; the glance relay. Measured 28778 source lines.
+size internal/equipo/chat 28846 - Transactional conversation store shares authority and dispatch helpers; roster reads; legacy mirrors; glance relay, warm on open. Measured 28846 source lines.
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.
@@ -70,8 +70,8 @@ perf GET /api/v1/tasks/{id}/files/{file} skip Research kept images: bearer-only
perf GET /tasks/{id}/files/{file} skip Research kept images: the bytes of one image, shown on the task page; a file, not a screen.
perf GET /api/v1/runners skip Mac runners person API: bearer-only JSON for devices; the browser shows runners in the Team section.
time cmd/equipo-runner 60s TestReleaseRunnerHasNoFakeWorker builds the release runner and the thin package under testbuild (about 12s locally).
-size internal/headless - 11058 End-to-end scenarios through a real runner and instance: Copy setting, the Assistant's job threads, streamed replies, warm start, glance. Measured 11058 test lines.
-size internal/thintest - 29150 Contract and browser tests share one instance harness: Assistant hand-off, outcome, job, legacy question and glance contracts, Roster guards. Measured 29150 test lines.
+size internal/headless - 11062 End-to-end scenarios through a real runner and instance: Copy setting, the Assistant's job threads, streamed replies, warm start, glance. Measured 11062 test lines.
+size internal/thintest - 29241 Contract and browser tests share one instance harness: Assistant hand-off, outcome, job, legacy question, glance and warm contracts, Roster guards. Measured 29241 test lines.
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.
perf GET /api/v1/advice skip Thin v1 person API: bearer-only JSON for devices; the browser reads advice through /usage and /conversation.
diff --git a/internal/equipo/chat/assistant_http.go b/internal/equipo/chat/assistant_http.go
index b74258c4..b6b65f93 100644
--- a/internal/equipo/chat/assistant_http.go
+++ b/internal/equipo/chat/assistant_http.go
@@ -18,6 +18,7 @@ import (
func (h *HTTP) MountAssistant(r chi.Router) {
lane := h.Store.Lane(wire.LaneAssistant)
r.Get("/snapshot", h.bearer(func(w http.ResponseWriter, r *http.Request, p personapi.PersonPrincipal) {
+ h.warmAssistant(r, p)
out, err := lane.Snapshot(r.Context(), p.Address)
if err != nil {
h.fail(w, r, err)
@@ -38,6 +39,7 @@ func (h *HTTP) MountAssistant(r chi.Router) {
h.assistantAnswer(w, r, p, lane)
}))
r.Get("/events", h.bearer(func(w http.ResponseWriter, r *http.Request, p personapi.PersonPrincipal) {
+ h.warmAssistant(r, p)
h.stream(w, r, p, lane.lane, lane.Events)
}))
r.Put("/host", h.bearer(func(w http.ResponseWriter, r *http.Request, p personapi.PersonPrincipal) {
@@ -45,6 +47,15 @@ func (h *HTTP) MountAssistant(r chi.Router) {
}))
}
+// warmAssistant asks the person's runner to warm their Assistant: Base
+// read its snapshot or opened its stream, so they are about to use it.
+// The read never waits on it failing.
+func (h *HTTP) warmAssistant(r *http.Request, p personapi.PersonPrincipal) {
+ if err := h.Store.WarmAssistant(r.Context(), p.Address); err != nil && h.Logger != nil {
+ h.Logger.Warn("assistant warm", "err", err)
+ }
+}
+
// assistantHost is PUT host {origin, token}: 200 {origin, revision}, the
// token never given back; 403 host_not_allowed for an origin the
// operator has not allowed.
diff --git a/internal/equipo/chat/store.go b/internal/equipo/chat/store.go
index cda18f97..ac4cab33 100644
--- a/internal/equipo/chat/store.go
+++ b/internal/equipo/chat/store.go
@@ -110,6 +110,8 @@ type Store struct {
remote chan struct{}
// logger reports what ServeRemoteCalls could not do (SetLogger).
logger atomic.Pointer[slog.Logger]
+ // warm limits how often opening Base warms an Assistant (warm.go).
+ warm warmGate
}
// SetFrameTap sees every frame the instance sends a runner, as sent
diff --git a/internal/equipo/chat/warm.go b/internal/equipo/chat/warm.go
new file mode 100644
index 00000000..2abae55c
--- /dev/null
+++ b/internal/equipo/chat/warm.go
@@ -0,0 +1,55 @@
+package chat
+
+import (
+ "context"
+ "sync"
+ "time"
+
+ "amadan.net/oficina/equipo/internal/wire"
+)
+
+// warmEvery is how often opening Base may warm one person's Assistant:
+// reading its snapshot or opening its stream asks at most this often.
+const warmEvery = 5 * time.Minute
+
+// warmGate remembers when each person's Assistant was last asked to
+// warm, in this process. Another process (an overlapping deploy) may
+// ask once more; a warm-up of a harness already up does nothing.
+type warmGate struct {
+ mu sync.Mutex
+ last map[string]time.Time
+}
+
+// WarmAssistant asks the person's primary runner to warm their
+// Assistant now (warm command, protocol 24): they opened Base, so the
+// first message should find the harness up. At most once per warmEvery
+// per person, and only to a primary online at 24 or later; nothing for
+// an older or offline one (an offline one warms on its own sync). The
+// runner decides whether the person used their Assistant lately.
+func (s *Store) WarmAssistant(ctx context.Context, person string) error {
+ now := s.now()
+ s.warm.mu.Lock()
+ if last, ok := s.warm.last[person]; ok && now.Sub(last) < warmEvery {
+ s.warm.mu.Unlock()
+ return nil
+ }
+ if s.warm.last == nil {
+ s.warm.last = map[string]time.Time{}
+ }
+ s.warm.last[person] = now
+ s.warm.mu.Unlock()
+ err := s.tx(ctx, func(t *txn) error {
+ online, protocol, err := t.primaryState(person)
+ if err != nil || !online || protocol < wire.ProtocolWarm {
+ return err
+ }
+ return t.command(person, wire.FrameWarm, wire.WarmCommand{Person: person})
+ })
+ if err != nil {
+ // Asked again on the next opening.
+ s.warm.mu.Lock()
+ delete(s.warm.last, person)
+ s.warm.mu.Unlock()
+ }
+ return err
+}
diff --git a/internal/runner/thin/claude.go b/internal/runner/thin/claude.go
index 90c64b79..59d104e8 100644
--- a/internal/runner/thin/claude.go
+++ b/internal/runner/thin/claude.go
@@ -36,8 +36,14 @@ const (
DefaultMaxTurn = 20 * time.Minute
DefaultMargin = 2 * time.Minute
DefaultIdle = 10 * time.Minute
- // DefaultWarmIdle closes a warmed process no turn used.
- DefaultWarmIdle = 30 * time.Minute
+ // DefaultWarmIdle closes a warmed process no turn used, and an
+ // Assistant's after its last turn. Four hours, not 30 minutes: Paul's
+ // live check (2026-11-14) found his Assistant closed 39 minutes after
+ // his last message, so a one-word reply waited 5.2 s for a fresh
+ // process. A person comes back to Base within an afternoon; the cost
+ // is one idle process per recent person (and its glance), and the
+ // credential copy still rotates in the background (scheduleWarm).
+ DefaultWarmIdle = 4 * time.Hour
DefaultLockWait = 90 * time.Second
minTurn = time.Minute
transcriptLimit = 64 << 20
@@ -56,7 +62,7 @@ type ClaudeOptions struct {
Refresh func(context.Context, provider.Binding) (provider.Identity, error)
MaxTurn, Margin, Idle, LockWait time.Duration
// WarmIdle is how long a process started ahead of a turn (Warm)
- // waits for one before it closes.
+ // waits for one before it closes, and an Assistant's after a turn.
WarmIdle time.Duration
Logger *slog.Logger
// Tools runs the coordinator's Equipo tools for a turn. Nil serves no
@@ -527,7 +533,8 @@ func (c *claudeCoordinator) Turn(ctx context.Context, in TurnInput, emit func(st
if err := c.o.State.saveSession(context.Background(), c.person, c.lane, "claude", c.sessionAccount(), p.sessionID, in.TurnID); err != nil {
c.log("coordinator session", err)
}
- c.idle, c.idleAt = time.AfterFunc(c.o.Idle, c.idleExit), time.Now().Add(c.o.Idle)
+ idle := c.idleAfterTurn()
+ c.idle, c.idleAt = time.AfterFunc(idle, c.idleExit), time.Now().Add(idle)
c.scheduleWarm()
timing.ResultMs = max(time.Since(stdin).Milliseconds(), 1)
return TurnResult{Text: res.Text, Usage: rows, Timing: timing, Seen: seen}
@@ -597,6 +604,16 @@ func (c *claudeCoordinator) initMismatch(raw []byte) {
c.o.Logger.Warn("coordinator init refused", "version", v.Version, "permission", v.Permission, "tools", strings.Join(v.Tools, ","), "servers", strings.Join(servers, ","))
}
+// idleAfterTurn is how long the process waits for the next turn: an
+// Assistant's as long as a warmed one's (DefaultWarmIdle), a
+// Coordinator's or a job's Idle.
+func (c *coordBase) idleAfterTurn() time.Duration {
+ if c.lane == wire.LaneAssistant {
+ return c.o.WarmIdle
+ }
+ return c.o.Idle
+}
+
func (c *claudeCoordinator) idleExit() {
c.mu.Lock()
defer c.mu.Unlock()
diff --git a/internal/runner/thin/codex.go b/internal/runner/thin/codex.go
index b82e4196..824c52b1 100644
--- a/internal/runner/thin/codex.go
+++ b/internal/runner/thin/codex.go
@@ -353,7 +353,8 @@ func (c *codexCoordinator) Turn(ctx context.Context, in TurnInput, emit func(str
if err := c.o.State.saveSession(context.Background(), c.person, c.lane, "codex", c.sessionAccount(), p.thread, in.TurnID); err != nil {
c.log("codex coordinator session", err)
}
- c.idle, c.idleAt = time.AfterFunc(c.o.Idle, c.idleExit), time.Now().Add(c.o.Idle)
+ idle := c.idleAfterTurn()
+ c.idle, c.idleAt = time.AfterFunc(idle, c.idleExit), time.Now().Add(idle)
timing.ResultMs = max(time.Since(start).Milliseconds(), 1)
return TurnResult{Text: final, Usage: usage(), Timing: timing, Seen: seen, Plan: plan}
}
diff --git a/internal/runner/thin/link.go b/internal/runner/thin/link.go
index 6fe45c9c..62ea6b6b 100644
--- a/internal/runner/thin/link.go
+++ b/internal/runner/thin/link.go
@@ -969,6 +969,13 @@ func (l *Link) read(ctx context.Context, c *websocket.Conn) (time.Duration, erro
if err = l.Connector.Cancel(ctx, f.ID, *v); err != nil {
return 0, err
}
+ case *wire.WarmCommand:
+ // The person opened Base: warm their Assistant now. Below 24
+ // the instance has no such command, so one is not acted on.
+ if proto, _ := l.Spoken(); proto < wire.ProtocolWarm {
+ continue
+ }
+ l.Engine.WarmAssistant(v.Person)
case *wire.Drain:
return time.Duration(max(v.RetryAfter, 1)) * time.Second, nil
default:
diff --git a/internal/runner/thin/warm.go b/internal/runner/thin/warm.go
index 6a43f4fb..006d67c1 100644
--- a/internal/runner/thin/warm.go
+++ b/internal/runner/thin/warm.go
@@ -27,7 +27,21 @@ const warmLimit = time.Minute
// WarmAssistants asks the Assistant worker of each person who used it
// within warmWithin to start its harness, if it is not up already.
-func (e *Engine) WarmAssistants() {
+func (e *Engine) WarmAssistants() { e.warmAssistants("") }
+
+// WarmAssistant does the same for one person, when the instance says
+// they opened Base (its warm command, protocol 24), so the harness is up
+// before they type: only an Assistant they used within warmWithin, and
+// the glance only while a glance slot is free (warmGlance).
+func (e *Engine) WarmAssistant(person string) {
+ if person != "" {
+ e.warmAssistants(person)
+ }
+}
+
+// warmAssistants warms every recent user's Assistant, or when only is
+// set that one person's.
+func (e *Engine) warmAssistants(only string) {
if e == nil {
return
}
@@ -45,6 +59,9 @@ func (e *Engine) WarmAssistants() {
e.mu.Lock()
defer e.mu.Unlock()
for _, p := range persons {
+ if only != "" && p != only {
+ continue
+ }
w := e.worker(workerKey{p, wire.LaneAssistant})
select {
case w.warm <- struct{}{}:
@@ -76,6 +93,14 @@ func (e *Engine) warmOne(k workerKey, w *worker) {
if !ok {
return
}
+ if u, ok := w.coord.(interface{ Up() bool }); ok && u.Up() {
+ // Up already (a turn ran, or a sync or Base's opening warmed
+ // it): only the glance may still need warming.
+ if k.Lane == wire.LaneAssistant {
+ e.warmGlance(k.Person, w, b)
+ }
+ return
+ }
start := time.Now()
err = h.Warm(ctx)
e.log("runner warm", err)
diff --git a/internal/runner/thin/warm_test.go b/internal/runner/thin/warm_test.go
index a9e211fe..7b76b5b5 100644
--- a/internal/runner/thin/warm_test.go
+++ b/internal/runner/thin/warm_test.go
@@ -2,7 +2,9 @@ package thin
import (
"context"
+ "encoding/json"
"slices"
+ "strconv"
"sync"
"testing"
"time"
@@ -10,6 +12,7 @@ import (
"amadan.net/oficina/equipo/internal/runner"
"amadan.net/oficina/equipo/internal/runner/connect"
"amadan.net/oficina/equipo/internal/wire"
+ "github.com/coder/websocket"
)
// warmCoordinator records its warm-ups and turns.
@@ -238,3 +241,183 @@ func TestAssistantWarmNeedsConnectionAndLease(t *testing.T) {
})
}
}
+
+// Opening Base (the instance's warm command, protocol 24) warms that
+// one person's Assistant under the same rule as a sync: only an
+// Assistant they used lately. A person who only talks to the
+// Coordinator, whose Assistant was last used long ago, or who is
+// unknown here warms nothing.
+func TestAssistantWarmOnOpen(t *testing.T) {
+ ctx, cancel := context.WithCancel(context.Background())
+ defer cancel()
+ state, err := OpenState(ctx, t.TempDir())
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer state.Close()
+ ana, bob, cy := "ana@example.com", "bob@example.com", "cy@example.com"
+ for _, s := range []struct{ person, lane string }{{ana, wire.LaneAssistant}, {bob, wire.LaneCoordinator}, {cy, wire.LaneAssistant}} {
+ if err := state.saveSession(ctx, s.person, s.lane, "claude", "c1#rule", "s-"+s.person, "t0"); err != nil {
+ t.Fatal(err)
+ }
+ }
+ old := time.Now().Add(-30 * 24 * time.Hour).UTC().Format(time.RFC3339Nano)
+ if _, err := state.db.ExecContext(ctx, "UPDATE sessions_lane SET updated_at=? WHERE person=?", old, cy); err != nil {
+ t.Fatal(err)
+ }
+ opens := &warmOpens{}
+ e := &Engine{State: state, Emit: func(wire.DeltaReport) {}, Notify: func() {}, Open: opens.open}
+ if err := e.Start(ctx); err != nil {
+ t.Fatal(err)
+ }
+ defer e.Wait()
+ defer cancel()
+ for _, p := range []string{bob, cy, "zed@example.com"} {
+ e.WarmAssistant(p)
+ }
+ time.Sleep(300 * time.Millisecond)
+ if got := opens.keys(); len(got) != 0 {
+ t.Fatalf("opened %v", got)
+ }
+ e.WarmAssistant(ana)
+ waitWarm(t, "ana's warm-up", func() bool {
+ a := opens.get(ana, wire.LaneAssistant)
+ if len(a) != 1 {
+ return false
+ }
+ w, _ := a[0].counts()
+ return w == 1
+ })
+ if got := opens.keys(); len(got) != 1 {
+ t.Fatalf("opened %v", got)
+ }
+}
+
+// The link warms on the instance's warm command at protocol 24, with
+// the lease confirmed first, and acks it. Below 24 there is no warm
+// command: one that came anyway warms nothing.
+func TestLinkWarmsOnOpen(t *testing.T) {
+ for _, protocol := range []int{wire.ProtocolWarm, wire.ProtocolGlance} {
+ t.Run(strconv.Itoa(protocol), func(t *testing.T) {
+ inst := newFakeInstance(t)
+ coord := &warmCoordinator{}
+ startLink(t, inst.url, coord, func(s *State) {
+ if err := s.saveSession(context.Background(), "owner@example.com", wire.LaneAssistant, "claude", "c1#rule", "s1", "t0"); err != nil {
+ t.Fatal(err)
+ }
+ })
+ c := <-inst.conns
+ read(t, c, wire.FrameHello)
+ write(t, c, []byte(`{"id":"i-welcome","type":"welcome","data":{"generation":3,"runner_id":"RUNNER1","protocol":`+strconv.Itoa(protocol)+`,"role":"primary"}}`))
+ readAny(t, c, wire.FrameSync)
+ write(t, c, []byte(`{"id":"c9","type":"warm","data":{"person":"owner@example.com"}}`))
+ if protocol < wire.ProtocolWarm {
+ ackLeases(c)
+ time.Sleep(500 * time.Millisecond)
+ if w, _ := coord.counts(); w != 0 {
+ t.Fatalf("warmed %d times at %d", w, protocol)
+ }
+ return
+ }
+ ack := readAny(t, c, wire.FrameAck)
+ var a wire.Ack
+ json.Unmarshal(ack.Data, &a)
+ if a.ID != "c9" {
+ t.Fatalf("ack %+v", a)
+ }
+ // The warm-up confirms the lease first.
+ ackLeases(c)
+ waitWarm(t, "the warm-up", func() bool { w, _ := coord.counts(); return w == 1 })
+ })
+ }
+}
+
+// readAny reads frames up to the first of kind, whatever its shape.
+func readAny(t *testing.T, c *websocket.Conn, kind string) wire.Frame {
+ t.Helper()
+ for {
+ ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
+ _, raw, err := c.Read(ctx)
+ cancel()
+ if err != nil {
+ t.Fatalf("waiting for %s: %v", kind, err)
+ }
+ if f, _, err := wire.ParseFrame(raw); err == nil && f.Type == kind {
+ return f
+ }
+ }
+}
+
+// ackLeases confirms every lease the runner asks for from now on, as
+// the instance does for the current connection, and reads past the rest.
+func ackLeases(c *websocket.Conn) {
+ go func() {
+ for {
+ ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
+ _, raw, err := c.Read(ctx)
+ cancel()
+ if err != nil {
+ return
+ }
+ if f, _, err := wire.ParseFrame(raw); err == nil && f.Type == wire.FrameLease {
+ ack, _ := wire.NewFrame("a-"+f.ID, wire.FrameAck, wire.Ack{ID: f.ID})
+ raw, _ := json.Marshal(ack)
+ c.Write(context.Background(), websocket.MessageText, raw)
+ }
+ }
+ }()
+}
+
+// An Assistant process stays up four hours unused, warmed or after a
+// turn, so a person who comes back within an afternoon finds it up; a
+// Coordinator process still closes after Idle.
+func TestAssistantIdleCloseFourHours(t *testing.T) {
+ var o ClaudeOptions
+ o.defaults()
+ if o.WarmIdle != 4*time.Hour || DefaultWarmIdle != 4*time.Hour {
+ t.Fatalf("warm idle %s", o.WarmIdle)
+ }
+ assistant := coordBase{o: o, lane: wire.LaneAssistant}
+ coordinator := coordBase{o: o, lane: wire.LaneCoordinator}
+ if assistant.idleAfterTurn() != 4*time.Hour || coordinator.idleAfterTurn() != DefaultIdle {
+ t.Fatalf("idle after a turn: Assistant %s, Coordinator %s", assistant.idleAfterTurn(), coordinator.idleAfterTurn())
+ }
+}
+
+// upCoordinator is a warmCoordinator that says it is up.
+type upCoordinator struct{ warmCoordinator }
+
+func (c *upCoordinator) Up() bool { return true }
+
+// A harness already up is not warmed again (nor logged as a warm-up):
+// Base opened right after a turn finds it up and only the glance may
+// still need warming.
+func TestAssistantWarmSkipsUpHarness(t *testing.T) {
+ ctx, cancel := context.WithCancel(context.Background())
+ defer cancel()
+ state, err := OpenState(ctx, t.TempDir())
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer state.Close()
+ p := "ana@example.com"
+ if err := state.saveSession(ctx, p, wire.LaneAssistant, "claude", "c1#rule", "s", "t0"); err != nil {
+ t.Fatal(err)
+ }
+ coord := &upCoordinator{}
+ g := &fakeGlancer{}
+ e := &Engine{State: state, Emit: func(wire.DeltaReport) {}, Notify: func() {},
+ Open: func(string, string, runner.AccountBinding) (Coordinator, error) { return coord, nil },
+ Glance: func(string, runner.AccountBinding) (Glancer, error) { return g, nil },
+ SendGlance: func(wire.GlanceReport) {}, Glances: func() bool { return true }}
+ if err := e.Start(ctx); err != nil {
+ t.Fatal(err)
+ }
+ defer e.Wait()
+ defer cancel()
+ e.WarmAssistant(p)
+ waitWarm(t, "the glance", func() bool { _, n := g.seen(); return n == 1 })
+ if w, _ := coord.counts(); w != 0 {
+ t.Fatalf("an up harness warmed %d times", w)
+ }
+}
diff --git a/internal/thintest/assistant_warm_contract_test.go b/internal/thintest/assistant_warm_contract_test.go
new file mode 100644
index 00000000..4a54f81a
--- /dev/null
+++ b/internal/thintest/assistant_warm_contract_test.go
@@ -0,0 +1,91 @@
+package thintest
+
+import (
+ "testing"
+ "time"
+
+ "amadan.net/oficina/equipo/internal/wire"
+)
+
+// warmCommands counts the warm commands the instance wrote for runners.
+func (r *rig) warmCommands() int {
+ r.t.Helper()
+ var n int
+ if err := r.inst.DB.Writer().QueryRow("SELECT count(*) FROM runner_commands WHERE kind = ?", wire.FrameWarm).Scan(&n); err != nil {
+ r.t.Fatal(err)
+ }
+ return n
+}
+
+// TestContractAssistantWarmOnOpen: Base reading the Assistant's
+// snapshot, or opening its stream, asks the person's primary at
+// protocol 24 to warm their Assistant: one warm command {person}, then
+// none for five minutes however often Base reads. A primary below 24 is
+// sent none and none is written for it.
+func TestContractAssistantWarmOnOpen(t *testing.T) {
+ r := newRig(t)
+ runner := r.dialAt(wire.ProtocolWarm)
+ a := r.client.Assistant()
+ if _, err := a.Snapshot(r.ctx); err != nil {
+ t.Fatal(err)
+ }
+ f, body, err := runner.Expect(r.ctx, wire.FrameWarm)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if w, ok := body.(*wire.WarmCommand); !ok || w.Person != Owner {
+ t.Fatalf("warm %+v", body)
+ }
+ runner.Send(r.ctx, "ack-warm", wire.FrameAck, wire.Ack{ID: f.ID})
+
+ // Within the window: more reads and a stream warm nothing; the next
+ // frame the runner sees is the message.
+ if _, err := a.Snapshot(r.ctx); err != nil {
+ t.Fatal(err)
+ }
+ s, err := a.Open(r.ctx, 0)
+ if err != nil {
+ t.Fatal(err)
+ }
+ s.Close()
+ r.assistantTurn(runner, a, "fix my website", "w-1")
+ if n := r.warmCommands(); n != 1 {
+ t.Fatalf("%d warm commands within the window", n)
+ }
+
+ // Five minutes on (the runner still heard from), the stream's
+ // opening warms again.
+ var rev int64
+ r.wait("the runner's revision", func(c *Conversation) bool { rev = c.Runner.Revision; return true })
+ later := time.Now().UTC().Add(warmWindow + time.Second)
+ r.inst.Store.Chat().SetClock(func() time.Time { return later })
+ t.Cleanup(func() { r.inst.Store.Chat().SetClock(func() time.Time { return time.Now().UTC() }) })
+ if err := runner.Send(r.ctx, "h-later", wire.FrameHello, primaryAt(wire.Hello{Generation: runner.Welcome.Generation, Repos: []string{}, Connections: []wire.HeldConnection{}, Versions: map[string]string{"runner": "test"}}, wire.ProtocolWarm)); err != nil {
+ t.Fatal(err)
+ }
+ // Offline by the later clock until this hello: a new revision.
+ r.wait("runner heard later", func(c *Conversation) bool { return c.Runner.Online && c.Runner.Revision > rev })
+ s, err = a.Open(r.ctx, 0)
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer s.Close()
+ if _, body, err := runner.Expect(r.ctx, wire.FrameWarm); err != nil || body.(*wire.WarmCommand).Person != Owner {
+ t.Fatalf("no second warm: %v", err)
+ }
+
+ // A primary at protocol 23 is sent none.
+ old := newRig(t)
+ oldRunner := old.dialAt(wire.ProtocolGlance)
+ oa := old.client.Assistant()
+ if _, err := oa.Snapshot(old.ctx); err != nil {
+ t.Fatal(err)
+ }
+ old.assistantTurn(oldRunner, oa, "fix my website", "o-1")
+ if n := old.warmCommands(); n != 0 {
+ t.Fatalf("%d warm commands for a runner at 23", n)
+ }
+}
+
+// warmWindow is the instance's warmEvery.
+const warmWindow = 5 * time.Minute
diff --git a/internal/wire/assistant_test.go b/internal/wire/assistant_test.go
index 039ec2d9..9bb4591f 100644
--- a/internal/wire/assistant_test.go
+++ b/internal/wire/assistant_test.go
@@ -78,10 +78,10 @@ func TestAssistantCardJSON(t *testing.T) {
}
}
-// A runner that speaks 23 or more is spoken to at 23, the glance
-// protocol; jobs came at 22.
-func TestSpokenIs23(t *testing.T) {
- if wire.Spoken(99) != 23 || wire.ProtocolCurrent != wire.ProtocolGlance || wire.ProtocolGlance != wire.Protocol23 || wire.ProtocolJobs != wire.Protocol22 || wire.ProtocolCopy != wire.Protocol21 || wire.ProtocolUsageRefresh != wire.Protocol20 || wire.ProtocolAssistant != wire.Protocol19 {
+// A runner that speaks 24 or more is spoken to at 24, the warm
+// protocol; glances came at 23 and jobs at 22.
+func TestSpokenIs24(t *testing.T) {
+ if wire.Spoken(99) != 24 || wire.ProtocolCurrent != wire.ProtocolWarm || wire.ProtocolWarm != wire.Protocol24 || wire.ProtocolGlance != wire.Protocol23 || wire.ProtocolJobs != wire.Protocol22 || wire.ProtocolCopy != wire.Protocol21 || wire.ProtocolUsageRefresh != wire.Protocol20 || wire.ProtocolAssistant != wire.Protocol19 {
t.Fatalf("spoken %d, current %d", wire.Spoken(99), wire.ProtocolCurrent)
}
}
diff --git a/internal/wire/frames.go b/internal/wire/frames.go
index 681eed7e..9455a73d 100644
--- a/internal/wire/frames.go
+++ b/internal/wire/frames.go
@@ -41,6 +41,9 @@ const (
// instant first line for a person turn. Like a delta it is sent once
// and never acked.
FrameGlance = "glance"
+ // FrameWarm (instance to runner, protocol 24) asks the person's
+ // primary to warm their Assistant: they opened Base.
+ FrameWarm = "warm"
)
// Close codes on the runner stream.
@@ -64,7 +67,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, FrameModels, FrameBudget, FrameResumeSpend, FrameResearchFile, FrameRelease, FramePriority:
+ 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, FrameModels, FrameBudget, FrameResumeSpend, FrameResearchFile, FrameRelease, FramePriority, FrameWarm:
return true
}
return false
@@ -185,6 +188,8 @@ func (f Frame) Decode() (any, error) {
v = &PriorityCommand{}
case FrameGlance:
v = &GlanceReport{}
+ case FrameWarm:
+ v = &WarmCommand{}
default:
return nil, fmt.Errorf("%w: frame type %q", ErrStrict, f.Type)
}
@@ -225,6 +230,13 @@ type Welcome struct {
Tainted bool `json:"tainted,omitempty"`
}
+// WarmCommand asks the runner to warm Person's Assistant (and its
+// glance) ahead of their first message: they opened Base. The runner
+// warms only an Assistant they used lately, as on sync.
+type WarmCommand struct {
+ Person string `json:"person"`
+}
+
// TailMessage is prior conversation, for a fresh coordinator session only.
type TailMessage struct {
Role string `json:"role"`
diff --git a/internal/wire/glance_test.go b/internal/wire/glance_test.go
index fd76bb6b..71641795 100644
--- a/internal/wire/glance_test.go
+++ b/internal/wire/glance_test.go
@@ -14,7 +14,7 @@ import (
// refuses the frame below it, so an older instance never sees one, and
// the frame is never durable (it is sent once, like a delta).
func TestEncodeGlanceBelow23(t *testing.T) {
- if wire.ProtocolGlance != 23 || wire.ProtocolCurrent != wire.ProtocolGlance {
+ if wire.ProtocolGlance != 23 || wire.ProtocolCurrent < wire.ProtocolGlance {
t.Fatalf("protocols %d %d", wire.ProtocolGlance, wire.ProtocolCurrent)
}
f, err := wire.NewFrame("g1", wire.FrameGlance, wire.GlanceReport{TurnID: "t_1", Attempt: 1, Text: "Looking into Tito"})
diff --git a/internal/wire/mixed_protocol_test.go b/internal/wire/mixed_protocol_test.go
index a30879a3..6f49c177 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.Protocol23 {
+ if wire.ProtocolMetered != wire.Protocol12 || wire.ProtocolResearch != wire.Protocol13 || wire.ProtocolCurrent != wire.Protocol24 {
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/models_test.go b/internal/wire/models_test.go
index 042139cd..73818277 100644
--- a/internal/wire/models_test.go
+++ b/internal/wire/models_test.go
@@ -94,7 +94,7 @@ func modelsFrames(t *testing.T) map[string]wire.Frame {
// protocol is checked because an older step in Encode's chain could
// undo a newer one (S5's bug).
func TestEncodeBelowProtocol18AgainstFrozenSchemas(t *testing.T) {
- if wire.ProtocolModels != wire.Protocol18 || wire.ProtocolCurrent != wire.Protocol23 {
+ if wire.ProtocolModels != wire.Protocol18 || wire.ProtocolCurrent != wire.Protocol24 {
t.Fatalf("models %d, current %d", wire.ProtocolModels, wire.ProtocolCurrent)
}
fs := modelsFrames(t)
diff --git a/internal/wire/opencode_test.go b/internal/wire/opencode_test.go
index 16159bef..83c964ef 100644
--- a/internal/wire/opencode_test.go
+++ b/internal/wire/opencode_test.go
@@ -57,7 +57,7 @@ func providersIn(t *testing.T, raw []byte) (providers, harnesses []string) {
// leave hello and sync, its usage rows leave every report, and a connect
// or a report about one is refused. At 17 nothing changes.
func TestEncodeBelowProtocol17DropsOpenCode(t *testing.T) {
- if wire.ProtocolOpenCode != wire.Protocol17 || wire.ProtocolCurrent != wire.Protocol23 {
+ if wire.ProtocolOpenCode != wire.Protocol17 || wire.ProtocolCurrent != wire.Protocol24 {
t.Fatalf("opencode %d, current %d", wire.ProtocolOpenCode, wire.ProtocolCurrent)
}
budget := &wire.Budget{Day: 1_000_000, Month: 10_000_000, Currency: "USD", Revision: 1}
diff --git a/internal/wire/publish_test.go b/internal/wire/publish_test.go
index 74487278..ce5923b6 100644
--- a/internal/wire/publish_test.go
+++ b/internal/wire/publish_test.go
@@ -17,7 +17,7 @@ import (
// and a hello's sites capability are dropped, so nothing a protocol 15
// peer decodes strictly carries them.
func TestEncodeBelowProtocol16DropsPublish(t *testing.T) {
- if wire.ProtocolPublish != wire.Protocol16 || wire.ProtocolCurrent != wire.Protocol23 {
+ if wire.ProtocolPublish != wire.Protocol16 || wire.ProtocolCurrent != wire.Protocol24 {
t.Fatalf("publish %d, current %d", wire.ProtocolPublish, wire.ProtocolCurrent)
}
publish := wire.DispatchCommand{Person: "p", TaskID: "tk", StepID: "s", Attempt: 1, Specialist: wire.SpecialistPublish, Findings: []wire.Finding{}, CandidateSHA: strings.Repeat("e", 40), Publish: &wire.PublishDispatch{App: "site-sample", Into: "main"}}
diff --git a/internal/wire/runners.go b/internal/wire/runners.go
index 4d74c7d2..b3ffc595 100644
--- a/internal/wire/runners.go
+++ b/internal/wire/runners.go
@@ -49,6 +49,7 @@ const (
Protocol21 = 21
Protocol22 = 22
Protocol23 = 23
+ Protocol24 = 24
// ProtocolSpend is the first protocol with a fix round's Feedback and
// a usage row's Turns; Encode drops both below it.
ProtocolSpend = Protocol3
@@ -164,8 +165,12 @@ const (
// ProtocolGlance adds the glance frame (runner to instance): the
// Assistant's instant first line for a person turn. Below it Encode
// refuses the frame, so it is not sent.
- ProtocolGlance = Protocol23
- ProtocolCurrent = ProtocolGlance
+ ProtocolGlance = Protocol23
+ // ProtocolWarm adds the warm command (instance to runner): the
+ // person opened Base, so their primary warms their Assistant now.
+ // Below it Encode refuses the frame, so it is not sent.
+ ProtocolWarm = Protocol24
+ ProtocolCurrent = ProtocolWarm
)
// Runner roles. A person's first runner is the primary: the coordinator,
@@ -566,7 +571,8 @@ var ErrProtocol = errors.New("wire: frame not in this protocol")
// slice 4 frame and field set: protocol 2 fields are dropped and a
// protocol 2 frame type is refused (ErrProtocol).
//
-// Below ProtocolGlance a glance frame is refused.
+// Below ProtocolGlance a glance frame is refused, and below ProtocolWarm
+// a warm command.
func Encode(f Frame, protocol int) (Frame, error) {
if protocol >= ProtocolCurrent {
return f, nil
@@ -578,7 +584,7 @@ func Encode(f Frame, protocol int) (Frame, error) {
if err != nil {
return Frame{}, err
}
- if protocol < ProtocolGlance && f.Type == FrameGlance {
+ if protocol < ProtocolGlance && f.Type == FrameGlance || protocol < ProtocolWarm && f.Type == FrameWarm {
return Frame{}, fmt.Errorf("%w: %s at protocol %d", ErrProtocol, f.Type, protocol)
}
changed := false
diff --git a/internal/wire/runners_test.go b/internal/wire/runners_test.go
index 32ab8d15..577448ed 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.ProtocolGlance || wire.ProtocolGlance != 23 || wire.ProtocolJobs != 22 || wire.ProtocolCopy != 21 || wire.ProtocolUsageRefresh != 20 || wire.ProtocolAssistant != 19 || wire.ProtocolModels != 18 || wire.ProtocolOpenCode != 17 || wire.ProtocolPublish != 16 || wire.ProtocolReadings != 15 || wire.ProtocolScheduler != 14 || wire.ProtocolResearch != 13 || wire.ProtocolMetered != 12 || wire.ProtocolPreviewHost != 11 || wire.ProtocolExplore != 10 || wire.ProtocolPreview != 9 {
+ if wire.ProtocolCurrent != wire.ProtocolWarm || wire.ProtocolWarm != 24 || wire.ProtocolGlance != 23 || wire.ProtocolJobs != 22 || wire.ProtocolCopy != 21 || wire.ProtocolUsageRefresh != 20 || wire.ProtocolAssistant != 19 || wire.ProtocolModels != 18 || wire.ProtocolOpenCode != 17 || wire.ProtocolPublish != 16 || wire.ProtocolReadings != 15 || 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_test.go b/internal/wire/schedule_test.go
index 6f6f9c64..3fa368b3 100644
--- a/internal/wire/schedule_test.go
+++ b/internal/wire/schedule_test.go
@@ -17,7 +17,7 @@ import (
// 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.Protocol23 {
+ if wire.ProtocolScheduler != wire.Protocol14 || wire.ProtocolCurrent != wire.Protocol24 {
t.Fatalf("scheduler %d, current %d", wire.ProtocolScheduler, wire.ProtocolCurrent)
}
by := time.Date(2026, 11, 20, 17, 0, 0, 0, time.UTC)
diff --git a/internal/wire/usage_test.go b/internal/wire/usage_test.go
index 8c1a0104..2b1df3a4 100644
--- a/internal/wire/usage_test.go
+++ b/internal/wire/usage_test.go
@@ -44,7 +44,7 @@ func headrooms(t *testing.T, raw []byte) []map[string]json.RawMessage {
// decodes strictly against the frozen protocol 14 headroom, and the
// caller's own values are untouched; at 15 nothing changes.
func TestEncodeBelowProtocol15DropsReadingTimes(t *testing.T) {
- if wire.ProtocolReadings != wire.Protocol15 || wire.ProtocolCurrent != wire.Protocol23 {
+ if wire.ProtocolReadings != wire.Protocol15 || wire.ProtocolCurrent != wire.Protocol24 {
t.Fatalf("readings %d, current %d", wire.ProtocolReadings, wire.ProtocolCurrent)
}
at := time.Date(2026, 11, 12, 9, 58, 0, 0, time.UTC)
diff --git a/internal/wire/warm_test.go b/internal/wire/warm_test.go
new file mode 100644
index 00000000..62db6eb1
--- /dev/null
+++ b/internal/wire/warm_test.go
@@ -0,0 +1,41 @@
+package wire_test
+
+import (
+ "encoding/json"
+ "errors"
+ "testing"
+
+ "amadan.net/oficina/equipo/internal/wire"
+)
+
+// Warm (protocol 24) is the instance asking the person's primary to warm
+// their Assistant now that they opened Base. It is a command like any
+// other (durable, acked), and Encode refuses it below 24: an older
+// runner's strict decoder would close the stream on it.
+func TestEncodeWarmBelow24(t *testing.T) {
+ if wire.ProtocolWarm != 24 || wire.ProtocolCurrent != wire.ProtocolWarm || wire.Spoken(99) != 24 {
+ t.Fatalf("protocols %d %d", wire.ProtocolWarm, wire.ProtocolCurrent)
+ }
+ f, err := wire.NewFrame("c1", wire.FrameWarm, wire.WarmCommand{Person: "ana@example.com"})
+ if err != nil {
+ t.Fatal(err)
+ }
+ if !f.Durable() {
+ t.Fatal("a warm command is not durable")
+ }
+ body, err := f.Decode()
+ if w, ok := body.(*wire.WarmCommand); err != nil || !ok || w.Person != "ana@example.com" {
+ t.Fatalf("decode %+v %v", body, err)
+ }
+ if _, err := (wire.Frame{ID: "c2", Type: wire.FrameWarm, Data: json.RawMessage(`{"person":"a","more":1}`)}).Decode(); err == nil {
+ t.Fatal("an unknown warm field decoded")
+ }
+ for _, p := range []int{wire.Protocol1, wire.Protocol2, wire.ProtocolAssistant, wire.ProtocolJobs, wire.ProtocolGlance} {
+ if _, err := wire.Encode(f, p); !errors.Is(err, wire.ErrProtocol) {
+ t.Fatalf("a warm encoded at protocol %d: %v", p, err)
+ }
+ }
+ if got, err := wire.Encode(f, wire.ProtocolWarm); err != nil || string(got.Data) != string(f.Data) {
+ t.Fatalf("at 24 %s %v", got.Data, err)
+ }
+}