Skip to content

The warm pool boots or creates one device per queued request, and the boot cap defaults from the CPU #774

Closed

Description

@V3RON

Part of #771.

Scope

A worker starts a boot or a creation for every queued virtual request, not only for the queue head, up to warmPool.maxConcurrentBoots in flight at once counting the head's own, and that cap defaults from the CPU instead of 1. A request queued behind the head is granted the device the pool started for it the moment it is ready. A keep boot the RAM budget would refuse is no longer tried silently on every pass. Explicit targets fill after the queue's devices, within the same cap, and wait only behind a request the pass could not serve.

In short

Today five agents asking for one kind at once pay five boots one after the other: only the head of the queue plans, and the pool boots a shut-down device for the head only, never creating one. After this PR the pool looks at every waiting request, oldest first, and matches each to at most one device, each device to at most one waiter: an idle ready device that serves it, else a device on its way that serves it. A waiter left without one gets a shut-down device that serves it booted, or, when it is behind the head, a device of its resolved spec created, under an ownerless boot claim, so it is granted that device as soon as it is ready. The head's own creation stays leasing's. These boots and creations run beside the pass, and the boot cap counts them together with the head's own work in flight. A request being queued triggers a pass at once. warmPool.maxConcurrentBoots defaults to max(1, floor(cpuCount / 4)), counted over the host's CPUs, so a 12-CPU Mac runs 3 at once.

flowchart LR
  Q[waiting requests, oldest first] --> S{served by a ready device,\none on its way, or an earlier waiter's?}
  S -- yes --> N[nothing]
  S -- no --> B{shut-down device fits?}
  B -- yes --> BO["boot it (today: head only; now: every waiter) *"]
  B -- no --> H{head of the queue?}
  H -- yes --> L[leasing creates it, as today]
  H -- no --> C["pool creates its spec, ownerless boot claim (new) *"]
  BO & C --> CAP["at most maxConcurrentBoots at once, default max(1, cpu/4) (new) *"]
Loading
  • on its way: a device in provisioning, or shut down under an ownerless boot claim, that serves the request; the planner waits for it instead of starting another (ADR 0017 §6).
  • boot cap: warmPool.maxConcurrentBoots, the most boots and creations in flight at once: the pool's own, for waiters and targets, plus each waiting request whose own boot or creation leasing is running.

User's session, five agents on a 12-CPU worker with one ready iPhone 16, fake timings:

$ for a in a1 a2 a3 a4 a5; do simlock lease --platform ios --device "iPhone 16" --os 18.4 --agent-id $a --detach & done
# today: a1 warm; a2 creates (60 s); a3 waits, then creates (60 s); a4, a5 the same: about 4 minutes until a5
# after: a1 warm; a2 creates (leasing's own, 1 of the cap of 3); the pool creates for a3 and a4 at once; a5 once one of the three is ready: about 2 minutes until a5

What the pass proposes for one waiting request:

Waiting request Today After
head, not in flight, a shut-down device fits boot it boot it (beside the pass)
head, not in flight, nothing fits nothing (leasing creates) nothing (leasing creates)
head in flight nothing nothing
behind the head, a ready idle device fits and no earlier waiter takes it nothing nothing (granted when it reaches the head)
behind the head, a device on its way serves it and no earlier waiter took it nothing nothing
two waiters, one device on its way that serves both nothing the second gets a boot or a creation
behind the head, a shut-down device fits nothing boot it
behind the head, nothing fits nothing create its resolved spec
the first waiter no ready idle device takes, nothing fits nothing nothing: it is the head, leasing creates for it (decided in delivery, pending the maintainer)
any, boot cap reached (in-flight waiters counted) head: boot it; others: nothing nothing, no target short
any, a device an operator reset shut down fits head: boot it boot it: a request asks for it
any, RAM budget or device limit refuses the boot or creation boot proposed, declined silently in the act nothing proposed

simlock config prints warmPool.maxConcurrentBoots as 3 on a 12-CPU host with no file value; today 1.

If this goes wrong, a user would notice two devices created for one request, a request stuck waiting on a device the pool never finished, or more boots at once than the machine can take.

Technical spec

Facts

Commit 97bc8eaf.

# Fact Source
F1 WaitingDemand carries inFlight, platform, requirement, mode, classOf; no spec src/core/domain.ts:135-141
F2 waitingDemand() lists every pending waiter with a resolved waiter.spec, inFlight when processing, requirement from the waiter or exactRequirement(spec) src/leasing/lease-acquisition-coordinator.ts:635-652
F3 The policy boots only for the head (position === 0 && !demand.inFlight), a shut-down device from bootable in registry order, never creates; every unserved waiter holds one slot back from idle boots src/core/warm-pool/policy.ts:292-313
F4 boots() never asks admit.boot; the converger's #boot returns false with no log when tryReserveBoot refuses src/core/warm-pool/policy.ts:292-326; src/core/warm-pool/converger.ts:561-574
F5 A target is not short, and gets no boot, while a non-in-flight waiter sits on its platform; the cap is plan.started < maxConcurrentBoots, counting the pool's flights and keep boots only; the head's boot ignores the cap and resetDevices src/core/warm-pool/policy.ts:516-531, :488-495, :292-301
F5a A keep boot (no target) is awaited inline by #act; only a target's boot or creation is launched beside the pass; inFlight lists the pool's flights only; the view exposes isClaimed(deviceId) with no claim kind or owner src/core/warm-pool/converger.ts:493-512, :480; src/core/warm-pool/policy.ts:95
F5b The triggers are daemon.started, device.reclaimed, device.quarantine-recovered, lease.granted, lease.released, device.shutdown, device.deleted, cleanup.executed, capacity.changed; lease.queued is emitted when a request is queued src/core/warm-pool/converger.ts:685-695; src/leasing/lease-acquisition-coordinator.ts:1203
F5c claims.claim(deviceId) answers a claim's kind and owner; the planner reads it for the on-its-way test src/leasing/acquisition-planner.ts:168-171
F6 The planner waits on a device in provisioning or shutdown under an ownerless boot claim that serves the request, unless noWait src/leasing/acquisition-planner.ts:131-139, :168-171
F7 Only the virtual queue head is driven; physical waiters all are src/leasing/lease-acquisition-coordinator.ts:1243-1252
F8 A target creation: tryReserveProvisioning under the lock, provisioner.provision(spec, { claim: { kind: "boot" }, reservation }), the claim released once ready, kick(); a throw logs warm pool creation of a device failed and #failed(target) src/core/warm-pool/converger.ts:596-623
F9 A provision proposal is launched as a flight keyed by proposal.target; a flight's end triggers a pass when an attempt was made src/core/warm-pool/converger.ts:503-507, :518-539
F10 The provisioner: claimProvision under the lock, then driver.provision outside it, then registerDevice; the device is invisible to the planner in between src/core/device-provisioner.ts:66, :79, :93
F11 defaultWarmPoolConfig.maxConcurrentBoots is 1, a static object; config.ts spreads it at :894-895; defaultConfig takes systemStats at :866; capacity defaults read systemStats.cpuCount() src/core/warm-pool/config.ts:41-46; src/core/config.ts:866, :894-895; src/core/capacity/strategies/resource/index.ts:139-147
F12 SystemStats.cpuCount() is availableParallelism(); FakeSystemStats takes { cpuCount, totalRamBytes } src/ports/system-stats.ts:9-10, :22-26
F13 config.get's schema types warmPool.maxConcurrentBoots as z.number(); 3 passes src/contract/schemas.ts:1011-1014
F14 serves() uses mayBeGranted, specMode, fits(requirement, spec, classOf) src/core/warm-pool/policy.ts:233-239
F15 The fast e2e lane counts makeReady calls on the fake driver and has a "while the warm pool boots a released device" group e2e/warm-pool-reserve.test.ts:28-30, :107
F16 Docs: maxConcurrentBoots default 1 (docs/CONFIGURATION.md:22); the class lease order names "a device the warm pool is already booting" (docs/CLI.md:594-604); the manual's state table row "Target boots and creations at once | 1" and its step 4 "not while a request is queued on its platform" src/core/warm-pool/AGENTS.md ("How it works" 4, "State and timers")
F16a Every place that states "a target waiting behind a queued request is not short": docs/EVENTS.md:35, docs/internal/EVENTS.md:73, docs/CLI.md:1523, docs/CONFIGURATION.md:21, src/core/warm-pool/AGENTS.md:61 rg -n -i "behind a queued request" docs src
F16b ADR 0017 §4: "while a request is waiting for capacity on a platform, the pool makes no boot or provision for a target on that platform"; ADR 0038 narrows it (its Supersedes line) docs/internal/adr/0017-*.md §4; PR #772
F16c e2e/warm-targets.test.ts "keeps two ready one boot after the other" asserts provisioned, ready, provisioned, ready with no maxConcurrentBoots in its config; FAKE_LANE_BASE_CONFIG sets none, and the e2e daemon reads the host's CPUs e2e/warm-targets.test.ts:70-90; e2e/helpers/env.ts:90-97; src/ports/system-stats.ts:9-10
F17 RetrySchedule keys failures by sameSpec with no attempt limit src/core/warm-pool/retry.ts:24-43
F18 Never-leased ready devices no target keeps are shut down after idle.shutdownAfterMs src/core/warm-pool/policy.ts:403-430

Modules touched

Searches: WaitingDemand, waitingDemand, maxConcurrentBoots, defaultWarmPoolConfig, waiting-request, inFlight over src/, e2e/, docs/.

  • src/core/domain.ts: WaitingDemand.spec: VirtualSpec.
  • src/leasing/lease-acquisition-coordinator.ts: waitingDemand() adds spec: waiter.spec.
  • src/core/warm-pool/policy.ts: WarmPolicyView.onItsWay: readonly { spec: VirtualSpec; deviceId?: string }[] (every provisioning or shutdown device under an ownerless boot claim, with its id, plus one entry without an id per creation flight of a spec beyond that spec's provisioning devices under an ownerless boot claim, so a pool creation counts once and a pool boot of a shut-down device, which keeps its device shutdown under the claim, never hides a creation); boots() per waiter in queue order, one device per waiter (F3); admit.boot for every boot proposal; a provision proposal with reason waiting-request for a waiter behind the head; the head's boot under the cap and allowed a reset device; started counts each in-flight waiter and a queued head no device serves whose own creation admit.create and its platform's room would allow, never one the budget blocks; fillTarget keeps a target waiting only behind a waiter the pass could not serve.
  • src/core/warm-pool/converger.ts: #view() builds onItsWay from claims.claim (F5c, the claims option gains it); every waiting-request boot and creation is launched beside the pass (#launch, keyed by the waiter's spec) and so counted in inFlight (F5a); lease.queued joins TRIGGERS (F5b).
  • src/core/warm-pool/config.ts: defaultWarmPoolConfig(systemStats); src/core/config.ts:894 passes systemStats.
  • Tests: src/core/warm-pool/policy.test.ts, converger.test.ts, src/leasing/lease-acquisition-coordinator.test.ts, src/core/config.test.ts, e2e/warm-pool-reserve.test.ts; e2e/warm-targets.test.ts pins warmPool.maxConcurrentBoots: 1 in its config (F16c).
  • Docs: docs/CONFIGURATION.md:22, docs/CLI.md:594-604, src/core/warm-pool/AGENTS.md (steps 1 and 4, the state table), docs/internal/flows/device-selection.md:84, and the five places of F16a.
flowchart LR
  L["leasing waitingDemand *"] --> D["core domain WaitingDemand *"]
  P["warm-pool policy *"] --> D
  C["warm-pool converger *"] --> P
  C --> PR[core DeviceProvisioner]
  C --> CAP[core capacity]
  CF["core config *"] --> WC["warm-pool config *"]
  CF --> SS[ports SystemStats]
Loading

Surface and extension points

None added. defaultWarmPoolConfig becomes a function of SystemStats, exported from src/core/warm-pool/index.ts as before.

Contract and event changes

No wire shape changes: config.get keeps maxConcurrentBoots a number (F13). No payload changes: device.provisioned is emitted by the provisioner as for a target's creation. warm-pool.target-missed's condition changes in words only: a target behind a waiter the pass gave a device is now short when the budget stops it, and both catalog rows (F16a) say "waiting behind a queued request the pass could not serve" instead. Searched src/contract for maxConcurrentBoots, WaitingDemand: one schema line, no type.

Other code on the same state

Searched tryClaim(.*"boot", tryReserveProvisioning, tryReserveBoot, queue.head, #drive( over src/: 6 files.

  • The planner (F6, F7): for the head it may boot or provision its own device under an owner claim while the pool proposes a boot of a shut-down device for the same head; both take the claim under the lock, the second sees it (today's behaviour, converger.test.ts "does not boot a device that was claimed between the proposal and the action"). For a creation the pool makes for the next waiter, the planner sees it once registered (F10) and waits (F6); in the window between claimProvision and registerDevice a head granted exactly then may provision its own: one extra device, idle and never leased, shut down by F18 and deleted by the idle delete. Accepted in ADR 0038 Consequences.
  • Leasing's eviction for the head: evicts an idle running device, never a provisioning one (not a running state) or a claimed one.
  • The reaper and F18: a waiter cancelled or timed out after the pool created for it leaves a never-leased ready device; F18 shuts it down after idle.shutdownAfterMs.
  • Nuke: the pool acts on nothing while maintenanceActive (converger.ts:283-291); a creation already running finishes.
  • The retry schedule (F17): one schedule per spec, shared on purpose. A failed creation for a waiter holds its spec back a minute for the pool's next creation of that spec, a configured target of it included (it is the same kind failing); the request plans itself when it reaches the head. A waiter's in-flight creation counts in a target of that spec's pending and booting, as a target's own does: one device of the kind is on its way either way.

Failure modes

Call Outcome What happens Limit, counted from
provisioner.provision for a waiter ok device ready, claim released, kick(); the waiter is granted it when it reaches the head the driver's boot deadline, from makeReady
throws logged warm pool creation of a device failed, #failed(spec), kick(); the waiter plans itself at the head —
reservation refused in the gate nothing started, no kick (F8) —
lifecycle.bootWarm for a waiter ok / throws / declined beside the pass, as a target's boot: a throw logs and holds the spec back; declined asks for no pass (F9) the driver's boot deadline
admit.boot / admit.create refuses refused no proposal; the waiter holds its slot as today (F3) —

State written: none new. A restart mid-creation leaves a provisioning device, as a target's creation does today. Two callers at once: the planner for the head and the pool for a waiter behind it, see Other code.

Rules in play

  • ADR 0038 §6, "the pool serves the whole queue, not only its head" and "the head's creation stays leasing's own": the policy creates for position ≥ 1 only.
  • ADR 0038 §7, "defaults to max(1, floor(cpuCount / 4))".
  • ADR 0017 §6, "a device that serves the request and is either under a boot claim or in provisioning is a reason to wait": the pool's creation carries the ownerless claim (F8).
  • ADR 0017 §4, "It never bypasses the queue": queue work is proposed first and bounded by the same budget. Its "makes no boot or provision for a target on that platform" while a request waits is narrowed by ADR 0038 §6 (F16b): a target waits only behind a waiter the pass could not serve.
  • ADR 0017 §3, the pool "reacts to committed facts on the bus": lease.queued is one more.
  • Architecture rule 16 (policy stays pure): the new rule lives in policy.ts; the converger only acts.
  • Testing rule 10: every "every waiter" and "in order" claim lists its cases below.

Tests

Seams: evaluate(view) in src/core/warm-pool/policy.test.ts; WarmPool with the fake lifecycle and provisioner in converger.test.ts; LeaseAcquisitionCoordinator in src/leasing/lease-acquisition-coordinator.test.ts; loadConfig in src/core/config.test.ts; the CLI over a fake driver in e2e/warm-pool-reserve.test.ts.

  • evaluate proposes, for waiters behind the head and in queue order, one creation of each waiter's spec, up to maxConcurrentBoots counting the pool's flights, each in-flight waiter, and a queued head that no device serves and whose own creation the budget would admit (admit.create ok and room on its platform: it is about to start it), and nothing for the head (cases: in-flight head, three waiters, cap 3 → two creations; queued unserved admitted head, three waiters, cap 3 → two creations; queued head refused by its platform's running limit, cap 1, an iOS waiter → the iOS waiter gets its creation; cap reached → no proposal and no target short; head queued and not in flight → a boot of a shut-down device only, never a creation; head queued at the cap → nothing).
  • evaluate matches each device to one waiter in queue order and proposes nothing for a waiter an idle ready device or an onItsWay entry serves (cases: one ready device and two waiters it serves → nothing for the second: the head is the first waiter no ready idle device takes, so the second is the head and leasing creates for it (decided in delivery, pending the maintainer); one onItsWay entry and two waiters → the second gets a creation; a slim ready device and a full waiter → a creation).
  • evaluate boots a shut-down device that serves a waiter behind the head before creating one, and may boot one an operator reset shut down, for the head too (extends "boots a device only for the head of the queue, not for a request behind it", which this replaces).
  • evaluate proposes no boot that admit.boot refuses for ram-budget, for a waiter or a recently released device, and holds the waiter's slot (replaces the silent decline of F4; case: refused → no proposal, the slot stays held).
  • evaluate fills a target after the queue's devices within one cap, and keeps a target waiting, not short, only behind a waiter the pass could not serve (extends "targets" group).
  • WarmPool runs a waiting-request creation under an ownerless boot claim and a provisioning reservation, releases the claim once ready, kicks, and on a throw logs once and holds the spec back a minute (extends "with a target and no device, makes one creation under an ownerless boot claim ...").
  • WarmPool runs waiting-request boots beside the pass, three at once under cap 3, and counts them in the next pass's inFlight (extends "runs two creations at once with maxConcurrentBoots 2 and not a third").
  • WarmPool builds onItsWay with one entry per on-its-way device and one per creation flight not yet registered, never two for one creation and never one short (cases: a creation flight before and after registerDevice; a boot of a shut-down device and an unregistered creation of the same spec at once → two entries).
  • WarmPool runs a pass on lease.queued (extends "runs a pass on each trigger event and on the tick, and none once disposed").
  • LeaseAcquisitionCoordinator grants a request queued behind an in-flight head the device the pool created for it, with no provision of its own, and waitingDemand() lists each waiter's resolved spec (extends "grants a request queued while a new device was booting a second new device once the first is granted, with no release").
  • loadConfig defaults warmPool.maxConcurrentBoots to max(1, floor(cpuCount / 4)) and a file value wins (cases: 2 CPUs → 1, 8 → 2, 12 → 3, file 5 → 5).
  • e2e: five detached leases of one kind on a worker with one ready device and maxConcurrentBoots 3 start three makeReady calls at once, not four, then the fourth once one is ready, and every lease is granted, with no device left idle and never leased after a tick (extends e2e/warm-pool-reserve.test.ts).
  • e2e: e2e/warm-targets.test.ts "keeps two ready one boot after the other" still passes on a host of any CPU count, its config pinning the cap to 1 (F16c).

Done when

  • pnpm test:changed passes.
  • pnpm test:e2e e2e/warm-pool-reserve.test.ts e2e/warm-targets.test.ts passes.
  • rg -n -i "behind a queued request" docs src finds only the new wording (F16a).
  • rg -n "cpuCount" src/core/warm-pool/config.ts shows the default derived there, and docs/CONFIGURATION.md states the formula.

Out of scope

  • Learned kinds, displacement and the stored record (the next task).
  • The origin field in status (the last task).
  • A creation for the queue head: leasing's own, as today.

Depends on

Written by an agent.

Activity

  1. added
    task:draft
    on Oct 20, 2026
  2. added
    task:ready
    and removed
    task:draft
    on Oct 20, 2026
  3. self-assigned this
    on Oct 20, 2026
  4. 44 remaining items

  5. added
    task:ready
    and removed
    task:blocked
    on Oct 21, 2026
  6. added 2 commits that reference this issue on Oct 21, 2026
    4215b63
    e5ae89b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    task:ready

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions