carlos / platform Public

console: a fleet run is picked only within its grant's window; the gate journals a refused service (rootfs plan 6, branch review R1)

P1: the run door refuses a run past its grant's pickupBy (404, at the
lookup and the claim), and the pickup is provision.RunPickBefore, which
refuses a queued run past its pickup deadline (the record's or the
grant's) inside the mutation. No store request added. Witnesses: a box
attached in time whose pickup lands past the window picks nothing and the
run expires as normal; an expired token replayed at the door gets 404.

P2: the interactive door is registered through cliRouteJournaled, so a
service credential the role gate refuses gets journalUnplaced's line
(once per caller per minute) beside the same 403; tested through the
registered route.

Census: relayPickup and registerCLIRoutes re-pinned; the overlay
re-proposed with its claims carried over (seal c86929d0 unchanged).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by claude agent, operated by paul@keymail.dev 45736122ed78e7727477df56fff47ae5ba6354a1 parent 3e60617
8 files changed, +163 −22
  • internal/console/apiinteractive_refused_test.go +13 −2
  • internal/console/apirunsbox.go +29 −12
  • internal/console/apirunsbox_test.go +61 −0
  • internal/console/authcli.go +28 −1
  • internal/console/svcroutes_test.go +6 −4
  • internal/provision/rootfs_apps_6_census_test.go +9 −2
  • internal/provision/run.go +16 −0
  • internal/provision/testdata/plan14-root-reads-rootfs-apps-6.tsv +1 −1

CI cancelled โ€” superseded by a newer push — run details

Intent

Human

<task-notification> <task-id>bn5hbkxn6</task-id> <tool-use-id>toolu_011Uo7ivNyQcJn4HsFqYa2v1</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/ba9fa944-a429-4788-9b3c-f2b2f42617f3/tasks/bn5hbkxn6.output</output-file> <status>completed</status> <summary>Background command "Run Astra whole-branch review of Plan 6" completed (exit code 0)</summary> </task-notification>

Human

<task-notification> <task-id>bwnzf3883</task-id> <tool-use-id>toolu_01TkZS55QgThZGogS79uESn2</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/ba9fa944-a429-4788-9b3c-f2b2f42617f3/tasks/bwnzf3883.output</output-file> <status>completed</status> <summary>Background command "Wait for CI on the Plan 6 branch" completed (exit code 0)</summary> </task-notification>

diff --git a/internal/console/apiinteractive_refused_test.go b/internal/console/apiinteractive_refused_test.go
index 710f362d5..39098195f 100644
--- a/internal/console/apiinteractive_refused_test.go
+++ b/internal/console/apiinteractive_refused_test.go
@@ -241,6 +241,9 @@ func TestUnplacedCallersWriteNoRefusedRow(t *testing.T) {
t.Cleanup(func() { log.SetOutput(prev) })
stranger := cliToken(t, fx.consoleFixture, "mallory@keymail.dev", "code-ix-unplaced-stranger")
svc := serviceToken(t, fx.st, fx.acctID, "ci-admin", "shop", "admin")
+ // Another credential for the handler's own 404 below, so its line is
+ // not the gate's line rate-limited away.
+ svc2 := serviceToken(t, fx.st, fx.acctID, "ci-other", "shop", "admin")
fx.srv.cli.instances = newRateLimiter(1, cliRateWindow)
fx.srv.cli.instances.allow(hashToken(fx.alice), time.Now())
for _, c := range []struct {
@@ -250,6 +253,7 @@ func TestUnplacedCallersWriteNoRefusedRow(t *testing.T) {
{"no credential", "", http.StatusUnauthorized},
{"a bad credential", "not-a-token", http.StatusUnauthorized},
{"a service credential", svc, http.StatusForbidden},
+ {"a service credential again", svc, http.StatusForbidden},
{"a stranger", stranger, http.StatusNotFound},
{"a stranger again", stranger, http.StatusNotFound},
{"throttled", fx.alice, http.StatusTooManyRequests},
@@ -260,7 +264,11 @@ func TestUnplacedCallersWriteNoRefusedRow(t *testing.T) {
}
}
// A principal that is not a person, past the mux: the handler's 404.
- svcP, ok := fx.st.CLIPrincipal(svc, time.Now())
+ gateP, ok := fx.st.CLIPrincipal(svc, time.Now())
+ if !ok || gateP.Kind != PrincipalService {
+ t.Fatalf("the service credential resolves to %+v", gateP)
+ }
+ svcP, ok := fx.st.CLIPrincipal(svc2, time.Now())
if !ok || svcP.Kind != PrincipalService {
t.Fatalf("the service credential resolves to %+v", svcP)
}
@@ -288,7 +296,10 @@ func TestUnplacedCallersWriteNoRefusedRow(t *testing.T) {
where := fx.acct + "/shop/" + ixHost
for _, want := range []string{
"console: api interactive: refused mallory@keymail.dev on " + where + ": 404",
- "console: api interactive: refused service ci-admin (credential " + svcP.CredentialID + ") on " + where + ": 404",
+ // Through the registered route: the gate's 403, journaled once
+ // for two tries (R1 P2).
+ "console: api interactive: refused service ci-admin (credential " + gateP.CredentialID + ") on " + where + ": 403",
+ "console: api interactive: refused service ci-other (credential " + svcP.CredentialID + ") on " + where + ": 404",
"console: api interactive: throttled alice@keymail.dev on " + where + ": 429",
} {
if n := strings.Count(logs.String(), want); n != 1 {
diff --git a/internal/console/apirunsbox.go b/internal/console/apirunsbox.go
index 540752b6d..a48f82f59 100644
--- a/internal/console/apirunsbox.go
+++ b/internal/console/apirunsbox.go
@@ -69,7 +69,9 @@ type runRelayHub struct {
// door's openRegistry; openWait, alive and lostAfter replace
// interactive.OpenWait, KeepaliveEvery and KeepaliveLost; grace
// replaces runRelayGrace; afterHello runs once a hello passed its
- // checks, before the pickup.
+ // checks, before the pickup; now replaces time.Now for the grant's
+ // pickup window (the door's claim and the pickup's own check).
+ now func() time.Time
boxRegistry func() (consoleRegistry, error)
openWait time.Duration
alive time.Duration
@@ -90,6 +92,13 @@ type runRelay struct {
func newRunRelayHub() *runRelayHub { return &runRelayHub{byID: map[string]*runRelay{}} }
+func (h *runRelayHub) clock() time.Time {
+ if h.now != nil {
+ return h.now()
+ }
+ return time.Now()
+}
+
func (h *runRelayHub) add(rel *runRelay) {
h.mu.Lock()
h.byID[rel.id] = rel
@@ -109,12 +118,14 @@ func (h *runRelayHub) lookup(id string) *runRelay {
return h.byID[id]
}
-// claim takes an unattached run for a box: false for any other id.
-func (h *runRelayHub) claim(id string) bool {
+// claim takes an unattached run for a box within its grant's pickup window
+// (R1 P1): false for any other id, and for one whose window has passed by
+// now.
+func (h *runRelayHub) claim(id string, now time.Time) bool {
h.mu.Lock()
defer h.mu.Unlock()
rel, ok := h.byID[id]
- if !ok || rel.attached {
+ if !ok || rel.attached || now.After(rel.pickupBy) {
return false
}
rel.attached = true
@@ -195,8 +206,9 @@ func (s *Server) putRunGrant(ctx context.Context, req runs.Request, wire []byte)
// handleBoxRun is the run door. Before the upgrade, in order: a host-claim
// console (409 RFS-6-C35); an id that is not a run id, not a fleet run this
-// console is waiting on, a wrong run token, or a box without its fleet's
-// identity (404, all the same); a run a box already took (409). Then the
+// console is waiting on, a run past its grant's pickup window (an expired
+// token replayed gets nothing), a wrong run token, or a box without its
+// fleet's identity (404, all the same); a run a box already took (409). Then the
// WebSocket, at RunMaxFrame, carried by relayRun until the run ends.
func (s *Server) handleBoxRun(w http.ResponseWriter, r *http.Request) {
if s.cfg.HostClaim {
@@ -210,7 +222,8 @@ func (s *Server) handleBoxRun(w http.ResponseWriter, r *http.Request) {
return
}
rel := h.lookup(id)
- if rel == nil || !interactive.TokenMatches(r.Header.Get(interactive.HeaderToken), rel.tokenHash) {
+ now := h.clock()
+ if rel == nil || now.After(rel.pickupBy) || !interactive.TokenMatches(r.Header.Get(interactive.HeaderToken), rel.tokenHash) {
http.NotFound(w, r)
return
}
@@ -222,8 +235,8 @@ func (s *Server) handleBoxRun(w http.ResponseWriter, r *http.Request) {
return
}
_, label, _ := strings.Cut(name, "/")
- if !h.claim(id) {
- if h.lookup(id) == nil {
+ if !h.claim(id, now) {
+ if rel := h.lookup(id); rel == nil || now.After(rel.pickupBy) {
http.NotFound(w, r)
return
}
@@ -376,7 +389,10 @@ func receiveRunHello(ws *websocket.Conn, id string, wait time.Duration) (interac
// run's timeout, then, as one write step, RunPick under the hello's box and
// agent boot, and on an error the record read back with pickedAnyway's rule
// (a CAS that landed can answer an error). why is RunNotPickedCutover when
-// the draining gate refused the step.
+// the draining gate refused the step. The pick refuses a run past its
+// pickup deadline, the record's or the grant's, inside the mutation (R1
+// P1): a box that attached in time but whose pickup lands late picks
+// nothing, and the run expires as any queued run does.
func (s *Server) relayPickup(ctx context.Context, rel *runRelay, hello interactive.RunHello) (time.Time, string, error) {
rctx, cancel := runWriteCtx(ctx)
defer cancel()
@@ -387,9 +403,10 @@ func (s *Server) relayPickup(ctx context.Context, rel *runRelay, hello interacti
if err := runs.CheckTimeout(req.Timeout()); err != nil {
return time.Time{}, "", err
}
- deadline := time.Now().UTC().Add(req.Timeout())
+ h := s.runRelays
+ deadline := h.clock().UTC().Add(req.Timeout())
err = s.lifetimesStep(rctx, true, func(sctx context.Context) error {
- _, err := provision.SetRecordRun(sctx, s.cfg.Releases, rel.acct, rel.app, rel.host, provision.RunPick(rel.id, hello.Box, hello.Boot, deadline))
+ _, err := provision.SetRecordRun(sctx, s.cfg.Releases, rel.acct, rel.app, rel.host, provision.RunPickBefore(rel.id, hello.Box, hello.Boot, deadline, rel.pickupBy, h.clock))
if err == nil {
return nil
}
diff --git a/internal/console/apirunsbox_test.go b/internal/console/apirunsbox_test.go
index 211e8e421..e85d8763d 100644
--- a/internal/console/apirunsbox_test.go
+++ b/internal/console/apirunsbox_test.go
@@ -26,6 +26,7 @@ import (
"sort"
"strings"
"sync"
+ "sync/atomic"
"testing"
"time"
@@ -837,3 +838,63 @@ func TestCutoverWitnessControlsAreTagged(t *testing.T) {
func nodeText(src []byte, n ast.Node) string {
return string(src[n.Pos()-1 : n.End()-1])
}
+
+// shiftedRelayClock puts the run hub on a clock shift ahead of real time,
+// which the test moves (R1 P1).
+func shiftedRelayClock(fx *interactiveFx) *atomic.Int64 {
+ var shift atomic.Int64
+ fx.srv.runRelays.now = func() time.Time { return time.Now().Add(time.Duration(shift.Load())) }
+ return &shift
+}
+
+// R1 P1: the console picks a fleet run only within the grant's pickup
+// window. A box that attached in time but whose pickup lands past the
+// window picks nothing: the run stays queued, and expires as any queued
+// run does.
+func TestRunRelayPickupPastTheWindowIsRefused(t *testing.T) {
+ fx, b1 := runFleetFx(t, "code-rb-late")
+ shift := shiftedRelayClock(fx)
+ id := postFleetRun(t, fx, okMeta())
+ g := runGrant(t, fx, id)
+ ws, err := runBoxDial(t, fx, id, fleetHeader(g.Token, "home/b1", b1))
+ if err != nil {
+ t.Fatalf("a dial within the window: %v", err)
+ }
+ // Attached at about 0 s; the pickup comes 61 s after admission.
+ fx.srv.runRelays.afterHello = func(string) { shift.Store(int64(runs.PickupWindow + time.Second)) }
+ _, before := ixRecord(t, fx, ixHost)
+ runHello(t, ws, interactive.RunHello{Schema: 1, Run: id, Box: "box-a", Boot: "b00t"})
+ if p := runPicked(t, ws); p.State != interactive.RunStateNotPicked {
+ t.Fatalf("a pickup past the window: %+v, want not picked", p)
+ }
+ fx.srv.runRelays.relays.Wait()
+ if _, after := ixRecord(t, fx, ixHost); !bytes.Equal(before, after) {
+ t.Fatalf("the record changed:\n%s\n%s", before, after)
+ }
+ if res := runResultOf(t, fx, id); res != nil {
+ t.Fatalf("a result %+v", res)
+ }
+ r := runState(t, fx, provision.RunQueued)
+ fx.srv.runSweep(context.Background(), r.Deadline.Add(time.Second))
+ runState(t, fx, provision.RunExpired)
+ if res := runResultOf(t, fx, id); res == nil || res.Refused != runs.RefusedExpired {
+ t.Fatalf("result %+v, want refused expired", res)
+ }
+}
+
+// R1 P1: a run's token replayed past its grant's pickup window gets the
+// door's 404 and no upgrade, before any sweep has pruned the run.
+func TestRunDoorRefusesATokenPastItsWindow(t *testing.T) {
+ fx, b1 := runFleetFx(t, "code-rb-replay")
+ shift := shiftedRelayClock(fx)
+ id := postFleetRun(t, fx, okMeta())
+ g := runGrant(t, fx, id)
+ shift.Store(int64(runs.PickupWindow + time.Second))
+ if fx.srv.runRelays.lookup(id) == nil {
+ t.Fatal("the run's relay was pruned: the door's own check is not what is tested")
+ }
+ runBoxRefused(t, fx, "an expired token", id, fleetHeader(g.Token, "home/b1", b1))
+ if r := runState(t, fx, provision.RunQueued); r.Box != "" {
+ t.Fatalf("run %+v, want queued and never picked", r)
+ }
+}
diff --git a/internal/console/authcli.go b/internal/console/authcli.go
index 21e868d87..29567122a 100644
--- a/internal/console/authcli.go
+++ b/internal/console/authcli.go
@@ -452,10 +452,32 @@ func (s *Server) cliRoute(pattern string, allow svcrole.Set, h http.HandlerFunc)
s.registerRoute(pattern, s.cliGate(allow, h))
}
+// cliRouteJournaled is cliRoute whose role gate, when it refuses a service
+// credential, also calls refused with the request, the principal and the
+// status, before the same refusal: the interactive session door's journal
+// line for a caller the gate stops before the door (rootfs apps Plan 6,
+// branch review R1 P2).
+func (s *Server) cliRouteJournaled(pattern string, allow svcrole.Set, h http.HandlerFunc, refused func(*http.Request, Principal, int)) {
+ if allow.Permits(svcrole.Team) {
+ panic("console: cliRouteJournaled " + pattern + " admits the team role; a team door is registered through cliScopedRoute")
+ }
+ if s.cliRoles == nil {
+ s.cliRoles = map[string]svcrole.Set{}
+ }
+ s.cliRoles[pattern] = allow
+ s.registerRoute(pattern, s.cliGateRefused(allow, h, refused))
+}
+
// cliGate is the handler cliRoute and cliScopedRoute register: the bearer
// resolved once, the role gate, and the principal handed down on the
// request context.
func (s *Server) cliGate(allow svcrole.Set, h http.HandlerFunc) http.HandlerFunc {
+ return s.cliGateRefused(allow, h, nil)
+}
+
+// cliGateRefused is cliGate with refused, when not nil, told of each
+// service credential the role gate refuses.
+func (s *Server) cliGateRefused(allow svcrole.Set, h http.HandlerFunc, refused func(*http.Request, Principal, int)) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
if s.cliBodyWrap != nil && r.Body != nil {
r.Body = s.cliBodyWrap(r)
@@ -473,6 +495,9 @@ func (s *Server) cliGate(allow svcrole.Set, h http.HandlerFunc) http.HandlerFunc
s.noteSeen(p.Address, now)
}
if p.Kind == PrincipalService && !allow.Permits(p.Role) {
+ if refused != nil {
+ refused(r, p, http.StatusForbidden)
+ }
if allow.Empty() {
// A closed door has no role that would work, so naming the
// caller's role and an empty list ("needs one of []") would
@@ -796,7 +821,9 @@ func (s *Server) registerCLIRoutes() {
// session is a live shell into production data, so no credential reaches
// it, the run role included; the handler answers anything but a person
// with the byte-identical 404.
- s.cliRoute("GET /api/cli/apps/{account}/{app}/instances/{host}/interactive", svcrole.Set{}, s.handleAPIInteractive)
+ // A service credential the gate refuses gets the door's journal line
+ // (journalUnplaced, once per caller per minute) beside its 403.
+ s.cliRouteJournaled("GET /api/cli/apps/{account}/{app}/instances/{host}/interactive", svcrole.Set{}, s.handleAPIInteractive, s.journalUnplaced)
// `carlos instances retry <host>` (apiretry.go): the operate family's, as
// restart is. The {host} wildcard and the 404 are the instance family's.
s.cliScopedRoute("POST /api/cli/apps/{account}/{app}/instances/{host}/retry", svcrole.Allow(svcrole.Operate), scopeHost, s.handleAPIInstanceRetry)
diff --git a/internal/console/svcroutes_test.go b/internal/console/svcroutes_test.go
index f7e9d8f57..0b5375ff3 100644
--- a/internal/console/svcroutes_test.go
+++ b/internal/console/svcroutes_test.go
@@ -824,7 +824,7 @@ func scanCLISource(t *testing.T) *cliSource {
// variable rather than a literal, and it is the mechanism these
// tests are asserting ABOUT โ€” reading it as a door would be
// reading the lock as a way in. It is the only exemption.
- if fd.Name != nil && (fd.Name.Name == "cliRoute" || fd.Name.Name == "cliScopedRoute" || fd.Name.Name == "registerRoute") {
+ if fd.Name != nil && (fd.Name.Name == "cliRoute" || fd.Name.Name == "cliScopedRoute" || fd.Name.Name == "cliRouteJournaled" || fd.Name.Name == "registerRoute") {
continue
}
src.inspect(t, fd.Body)
@@ -845,12 +845,14 @@ func (src *cliSource) inspect(t *testing.T, body *ast.BlockStmt) {
return true
}
switch sel.Sel.Name {
- case "cliRoute", "cliScopedRoute":
+ case "cliRoute", "cliScopedRoute", "cliRouteJournaled":
// cliScopedRoute (teamdoors.go) is the team role's registration:
// the same gate with a scope target between the Set and the
- // handler. Both are gated doors to this scan.
+ // handler. cliRouteJournaled is cliRoute with a hook told of
+ // each service credential the gate refuses (the interactive
+ // door's journal line). All are gated doors to this scan.
want := 3
- if sel.Sel.Name == "cliScopedRoute" {
+ if sel.Sel.Name != "cliRoute" {
want = 4
}
if len(call.Args) != want {
diff --git a/internal/provision/rootfs_apps_6_census_test.go b/internal/provision/rootfs_apps_6_census_test.go
index f3247b66e..b638e21be 100644
--- a/internal/provision/rootfs_apps_6_census_test.go
+++ b/internal/provision/rootfs_apps_6_census_test.go
@@ -108,11 +108,18 @@ package provision
// devbox dispatch and usage line), Server.registerCLIRoutes (main's fleet
// box drain route) and NewServer (main's fleet alert, alert link and
// Protection routes).
+// - Branch review R1: Server.relayPickup's one SetRecordRun is now
+// RunPickBefore (RunPick that refuses a queued run past its pickup
+// deadline, the record's or the grant's, inside the mutation), and the
+// hub's clock seam; same class, re-pinned. Server.registerCLIRoutes
+// registers the interactive door through cliRouteJournaled, the same
+// zero role set with the gate's service refusal journaled (P2); the
+// same record literals, nothing written; re-pinned.
func rootfsApps6WriteCensusInventory() []censusEntry {
entries := append([]censusEntry(nil), managedFleets1bWriteCensusInventory()...)
replacements := []censusEntry{
{"internal/provision/reconcile.go", "Reconcile", "key-site", "key:ParseRecordKey,key:RecordKey,lit:instances", "9df6bc87e3680b4340c9edcc3fa1156b6b6d4964ea81e75bea26e408b6ed7be9"},
- {"internal/console/authcli.go", "Server.registerCLIRoutes", "key-site", "lit:instances,lit:sidecars", "2b3558d594a04b02faa119af48bec340e9b78bb011d320ae9b553ffb4b200645"},
+ {"internal/console/authcli.go", "Server.registerCLIRoutes", "key-site", "lit:instances,lit:sidecars", "5f4d79750935a15f58e0328d1894857913ab9d08412183be27bdd5d63e7b4bfd"},
{"internal/console/server.go", "NewServer", "key-site", "lit:instances", "4ba01dc8aac6752e12f7971276520e76cf3aaacad90662148ba64aa72761f10b"},
{"internal/instanceexec/exit.go", "parseExitArgs", "key-site", "lit:instances", "be3a7828e292b4977c42f21d8283fc9d185505ced9ffdf2543267a88bc8033a9"},
{"internal/console/apiinstanceimport.go", "Server.handleAPIImportAbort", "record-writer", "key:SetRecordSeed", "2f8ff7416ac0508b33bb9791ae314c144e6d26bdc7773e859b1f04c7d9b3d2d0"},
@@ -162,7 +169,7 @@ func rootfsApps6WriteCensusInventory() []censusEntry {
{"internal/host/runrelay.go", "bucketRunSink.Pickup", "record-writer", "key:SetRecordRun", "4a6697ba281c55c20f24d5d98b93c97d98f707aaa036fd1c38f121e32f92b775"},
{"internal/host/runrelay.go", "bucketRunSink.Finish", "record-writer", "key:SetRecordRun", "f2b4f7d8552f1fb674fda3ba5581e7bad73381df9f66bc63b640d6aa2a166929"},
{"internal/runs/chunker.go", "StorePut", "nonrecord", "sel:Put", "f0f32756f9a7620ff2c6022606663918de07f7d914f3b41568c1e076cbbd3805"},
- {"internal/console/apirunsbox.go", "Server.relayPickup", "record-writer", "key:SetRecordRun", "97ef0383c3dabb5b843112140b6b6f31e4d6eb2a69c5f2fe696e996e7f070a2a"},
+ {"internal/console/apirunsbox.go", "Server.relayPickup", "record-writer", "key:SetRecordRun", "d06ff8cfee5c391e13559bb504b72d6f4748c4758a2b19fce220f4846b51c628"},
{"internal/console/apirunsbox.go", "Server.relayFinish", "record-writer", "key:SetRecordRun", "111f2d0b82df1a5a43db9de4db42460f0f2da68bc7bb1bf4e654ba978733d241"},
{"internal/console/apirunsbox.go", "Server.putRunGrant", "nonrecord", "sel:Put", "dfe2af1b1ddc08230e1ec91de8714a6e0f18d61b21225934dfbf8ffb1f197e28"},
{"internal/console/apirunsbox.go", "Server.relayChunk", "nonrecord", "sel:Put", "88ae3066378d390befb706ac5fd2911827f56a731154b2040f3b5e72ea17c856"},
diff --git a/internal/provision/run.go b/internal/provision/run.go
index d9af76a67..4890704f4 100644
--- a/internal/provision/run.go
+++ b/internal/provision/run.go
@@ -245,6 +245,22 @@ func RunPick(id, box, boot string, deadline time.Time) func(*Record) error {
}
}
+// RunPickBefore is RunPick that refuses, with ErrRunConflict, a queued run
+// whose pickup deadline has passed: the record's own (set at admission) or
+// by, a grant's pickup deadline, when not zero. now is read inside the
+// mutation, so a retried CAS asks again (rootfs apps Plan 6 Task 16, R1 P1:
+// the console's run relay picks only within the signed pickup window).
+func RunPickBefore(id, box, boot string, deadline, by time.Time, now func() time.Time) func(*Record) error {
+ pick := RunPick(id, box, boot, deadline)
+ return func(rec *Record) error {
+ t := now()
+ if r := rec.ActiveRun; r != nil && r.ID == id && r.State == RunQueued && (t.After(r.Deadline) || (!by.IsZero() && t.After(by))) {
+ return fmt.Errorf("%w: run %s is past its pickup deadline", ErrRunConflict, id)
+ }
+ return pick(rec)
+ }
+}
+
// RunCancelTransition cancels: queued becomes cancelled, which is terminal,
// so no box ever launches it; picked becomes cancel, and the owning box
// stops the unit (run spec ยง5.7). cancel stays cancel.
diff --git a/internal/provision/testdata/plan14-root-reads-rootfs-apps-6.tsv b/internal/provision/testdata/plan14-root-reads-rootfs-apps-6.tsv
index ee075a0c9..484d87aad 100644
--- a/internal/provision/testdata/plan14-root-reads-rootfs-apps-6.tsv
+++ b/internal/provision/testdata/plan14-root-reads-rootfs-apps-6.tsv
@@ -153,5 +153,5 @@ internal/host/runs.go runsWorker.pickup legacy accepted-legacy accepted-legacy;r
@coverage internal/instanceexec 65f6db1c6bf469f1d19615ec989f54c20de3b73c3c03ae2d677cffbcc60470fd
@coverage internal/interactive 4b2657ae42617d7d25d1391e24c435a38c670f3b57d7790cab511675b44d3b17
@coverage internal/layout 1527c3b31d87743798002b1ebefcd2cb0dc422a8642f72a3ff8dbefbd2c84d9b
-@coverage internal/provision 06442bc72306330dc917139c3114be22ab8af2bef3c9febe632431353530c508
+@coverage internal/provision 44b314ad9b45e002558b44bf8da721b113acb8f625a444ce3e75e46bf1f16c8c
@coverage internal/runs 1141462afdd515b66a1df867fd4b783d876533e9bdccc0b32a4c852567470148