Repository navigation
feat(platform): dispatch, admission and leases for agent fleets - #4987
Merged
Merged
Conversation
A provider that answers "the selected model is at capacity" is overloaded
for every run on that model. Each refused run used to fail on its own,
retry a minute later, spend one of its three automatic retries and one of
its task's three automated starts an hour, and the next start launched
into the same refusal: a saturated model emptied the fleet and left its
cards In progress with failed runs.
Now the refusal opens an (organization, provider, model) hold (migration
0205): every run on the model parks at its worker claim with the reason
model_capacity ("Waiting for model capacity") until the hold runs out —
1, 2, 4, 8, then 15 minutes — then one run probes and the rest follow once
it has worked two minutes or any run on the model settles. The refused
run's retry is free for the retry budget and the hourly circuit; after
twelve hours at capacity the run ends with its own failure class. The
task-agent watchdog also re-arms a retry whose job was lost, which left a
run reading "retry pending" forever.
The spawner judged CPU pressure from one reading at the moment someone asked, so a host bouncing around the threshold flapped between admitting and pacing, and nothing outside a session create could ask whether the host had room for more work. A sampler now reads the load, the CPUs online and the CPU, memory and I/O pressure every five seconds and keeps two minutes of readings; a verdict judges the newest reading with the newest one at least ten seconds before it, and a pressed host stays pressed until both fall below the recover share of its thresholds. SANDBOX_ADMISSION_PRESET picks the thresholds (default: CPU pressure alone, as before; conservative: load, CPU, memory and I/O, holding where the host cannot be read), each overridable. GET /v1/admission answers admit or hold with the reason, a retry-after and the evidence, so the platform asks before it starts more work. Heavy phases (installs, builds, full test suites) take a lease bound to their session: granted only under the conservative thresholds, below SANDBOX_HEAVY_LEASES_MAX, with the disk and memory every other lease announced counted; released with the session or at expiry. Capacity reports the leases, and /v1/workspaces/usage measures workspaces for reclaim by size.
Tale's own fleet ran its dispatch as six automations and an LLM manager. On 2026-10-14 the manager's model answered "at capacity" for hours: its task's hourly circuit closed, the fleet sat empty with 170 tasks ready, and failed cards stayed In progress until the manager repaired them. A project now carries a dispatch (migration 0206, managed resource `project-dispatch`): a pool of agents, the runs it may hold, the runs each agent may hold, the columns and labels it takes work from, whether unassigned work goes to the pool, and its admission (preset, start spacing, recheck delays). A pass is a job, one per project at a time: asked for when a run of the project ends, when a held model answers again, when the dispatch is saved, at the time a held pass named, and by a minute scan. It counts every live run of the pool whoever started it, leaves agents whose model is at capacity idle, ranks ready work by column, priority, board order and age, asks the sandbox host before each start (GET /v1/admission) and starts through the same admission as an automation or a manager agent, as `dispatch:<project>`. Standing roles are data on the dispatch: a role starts its agent on its task at each occurrence of its schedule, the occurrence's row claimed in the transaction that starts the run, so an occurrence decided twice starts once and one that finds its role working is coalesced into it. Every pass is recorded; GET /api/app/tasks/dispatch/by-project/:id reads back each agent's runs, why it is idle, the holds and the last passes. The API contract moves to 3.45.0. checkFleetDispatch replays the outage on real Postgres: refusals injected the way the turn host reports them, a stand-in host under pressure, passes and occurrences decided twice, and the manager's task failing on capacity without closing its circuit.
A chat in a project starts with the project's instructions; a task agent's turn never did. Tale's fleet therefore told every agent, in every brief, to read the project instructions back with task_get before deciding anything, because a resumed conversation keeps working from the copy it remembers. Every turn — a start, a retry, a steered restart — now reads the project's instructions when it starts and hands them over between the organization's Custom instructions and the agent's own. The run records the SHA-256 of the project's instructions, the agent's and the task's description its turn was handed, with the execution that read them (migration 0209); the run readback and the run's ledger entry carry the record. A turn whose task or project cannot be read does not start and fails as a start failure, retried like one. The run ledger entry of a run a dispatch pass started also keeps the sandbox host's verdict the pass admitted it on.
A loop inside the platform cannot prove its own availability during an
outage: when Tale's fleet stopped, nothing outside noticed for hours.
The backend's metrics gain
tale_backend_dispatch_last_pass_timestamp_seconds{project}: when each
switched-on dispatch last completed a pass, whatever the pass found. A
dispatch passes at least once a minute, so its age is the heartbeat an
external alert watches. A dispatch switched off drops out; a read that
fails reports zero for every project the last good read knew, so a
failing scrape never keeps a healthy sample. The observability guides
add the alert rule and a dashboard row.
Tale's fleet held its optional CI-producing work while the hosted
runners' queue was full, by rules an agent applied in its head. A
dispatch may now declare gates (migration 0210): signals from outside
that hold the ready work they govern — the tasks with one of a gate's
labels, or all ready work when it names none. Something outside reports
a state, or a value the gate judges with hysteresis: at or above holdAt
it holds, and once held it opens only below recoverBelow. A gate nobody
reports on within its stale window opens, or holds when it says so; a
gate with start spacing lets one start of its work through, then waits.
Standing roles are never held. A report that opens a gate asks for a
pass at once.
External systems report through the REST door, which also reads the
dispatch: POST /api/v1/projects/{id}/dispatch/gates/{key} (project edit
access; DISPATCH_GATE_UNKNOWN, DISPATCH_GATE_VALUE_UNJUDGED) and
GET /api/v1/projects/{id}/dispatch, described by a shared readback
schema. Administrators report from the app. A dispatch whose label
filters or gates name a label the project lacks is refused, naming it.
The readback shows each gate and a `gated` idle reason; every start a
pass makes keeps the host readings it was admitted on.
A new guide, Keep agents busy with dispatch (EN/DE/FR), covers what a project's dispatch takes and who works on it, how a pass starts work and what it checks first, standing roles on a schedule, gates that hold work behind a signal from outside, and how to read why an agent is idle. The API reference gains the dispatch section (read the dispatch, report on a gate, with a CI-queue example); the manager-agent section of the task automation guide points at dispatch, and its waiting-runs section gets an anchor every locale shares. The glossary adds the dispatch gate (Schranke, barrière).
The fleet dispatch lane gains a gate scenario: a full CI queue (23, hold at 20) leaves the task labelled ci waiting while unlabelled work starts, 14 keeps the gate held (hysteresis), 9 opens it and asks for exactly one pass, and the held task starts on the next pass. A report nobody repeats for the stale window reads open and stale in the readback.
Reference rows for the dispatch rules (TASK-R41–R48), the instruction snapshot (TASK-R49), the dispatch heartbeat (TASK-R50) and gates (TASK-R51), with the unit, component and real-Postgres specs that hold them.
A gate's start spacing is now decided before the plan, by a pure gateCandidates: while its spacing runs none of its tasks takes part, otherwise only its best-ranked one, so a spaced task at the top of the queue no longer takes the place of work no gate holds for the whole spacing. A task whose last run failed with an automatic retry armed is not ready work: the retry starts it after the wait its failure called for, and dispatch no longer starts it early. The guide and the schema say plainly that a standing role starts on its schedule even when the pool is full, its run counting toward the pool when its agent is in it.
What pressed Tale's fleet host hardest came after admission, inside
sessions already running: installs, image builds, whole-workspace checks.
A project agent's task run now has host_lease_acquire and
host_lease_release (baseline on every runtime with Tale's MCP channel):
before a heavy phase the agent asks the spawner for a lease, waits and
asks again when refused for pressure, limit, disk, memory or stale
readings, and runs without one where the host cannot be judged
(Kubernetes, Incus, a remote Docker daemon, an older spawner) — never
waiting for ever. A run holds one lease at a time and touches only its
own, on its own session.
Every lease of a run ends with the run: the terminal transition queues
sandbox.release_run_leases in the ending transaction (idempotent, 404
counts as released), and the sandbox watchdog sweeps what a failed
release left (migration 0207). Owners and admins read the active leases
with their run and task; /capacity carries leases {active, max}. The
turn's instructions gain one paragraph on heavy phases where the tools
exist. Rules SBX-R28–SBX-R33; checkHeavyPhaseLeases proves the run-end
release on real Postgres.
The domain-spec guard holds a rule's heading to one sentence of at most 80 characters; it had 82.
A deployment that keeps its Tale configuration in a repository can now declare a project's dispatch as the managed resource `project-dispatch` — its pool, limits, columns, labels, admission, standing roles and declared gates — and the tale CLI plans, applies and reads it back like the other managed kinds: one per project, hashed as the platform stores it, applied after the agents and tasks it names, `enabled: false` applied as declared. Gate state stays runtime: a declaration or readback that carries it is refused, so a report on a gate never shows as drift. A stored dispatch this version cannot read (one a newer version wrote) is no longer read back as none: managed configuration refuses it with CONFIG_UNREADABLE instead of planning a create that would overwrite it, and a save is refused the same way (TASK-R52). The pass and the readback still start nothing on it. The CLI README and the install guides list the new kind.
The platform refuses a dispatch whose label filters or gates name a label the project lacks; TASK-R48 and the DISPATCH_INVALID sentence now say so. The dispatch guide links the CLI section that declares project-dispatch.
A dispatch a newer version stored in a shape this one cannot read used to read back as not set up, inviting a set-up that the save then refuses (CONFIG_UNREADABLE). The readback now answers configured with unreadable: true and no document; no pass acts on it. The fleet dispatch lane proves both on real Postgres (TASK-R52).
…dispatch Main gained #4985, which kept a model-capacity refusal out of a task's hourly automated-start circuit and held fresh automated starts for a 60-second provider floor. This branch handles the same outage with model capacity holds (TASK-R40): a fresh start is admitted and parks at its worker claim until the model's hold ends, so the floor, its startAfterMs plumbing and its admission refusal are dropped; the exclusion from the circuit, the guides' wording and the stale-metadata test are kept, and the floor tests are replaced by one that admits a fresh start after a refusal.
Knip found twelve exports nothing imports: the dispatch actor id, the role schedule reader, the lease bounds, the pressure assessment's windows and recover share, and the workspace-usage batch size. Each is used only inside its module.
Tale's fleet manager spent four nodes per intake source — read the
position, run the importer, save the position, post a receipt comment —
times three sources, plus a transform for the occurrence label. Two new
built-in automations make intake one step whose run record is the
receipt: issues-intake takes {projectId, sources: [...]} (GitHub and
GlitchTip) and runs issues-intake-source once per source; each reads its
position, imports one batch through the importer's cursor input, saves
the position with the read's revision and answers batch, resumed,
restarted, saved, conflict, drained and the importer's counts. A source
whose import fails saves nothing and is retried at the next occurrence,
without stopping the others; a position that cannot be read or saved
fails the run. Positions are keyed like the hand-built chain, so a
running pass carries over.
The importers are unchanged: an organization keeps the copies it has,
and the intake reaches them only through the cursor input they always
took. The validator leaves a composite schema to the run when the value
is a template. Rules AUTO-R57–AUTO-R62; the authoring reference and the
built-in and trigger guides recommend the native step.
Per-organization seeding is operator-triggered: only tale migrate (POST /api/control/provision) and organization creation run it, as the control service says. The provisioning spec and the CLI guide claimed every deploy runs it, so a new built-in — such as the issue intake — seemed to reach existing organizations on its own. They now say to run tale migrate after deploying a release whose new built-ins existing organizations need.
The REST door's dispatch readback is described from the shared schema, which gained unreadable; the published OpenAPI document is regenerated to match. The role schedule reader is formatted after it stopped being exported.
The workspace sweep deleted only owner-gone workspaces and ones unused for the organization's window, never on size or pressure — and Tale's own 200 GiB sandbox volume reached 97% with seven standing workspaces of 20 to 26 GB. The hourly sweep now also asks the spawner how much each of the organization's workspaces holds (GET /v1/workspaces/usage) and, while the workspaces' disk is short or critical, retires the organization's largest idle workspaces until the projected free space is back above the floor with a margin; with a size cap it retires idle workspaces above it. Idle means no compute, no run waiting for it and unused for reclaimMinIdleHours; a pinned workspace, one under a legal hold, a running session and a missing or stale measurement are never reclaimed, and every deletion goes through the existing retire path with its lock, re-check and spawner refusal, audited as disk_pressure or over_size. The sandbox_workspaces policy gains reclaimOnDiskPressure (on), maxWorkspaceGiB (none) and reclaimMinIdleHours (24) — a file without them reads the defaults — in the settings page, the MCP settings kind and the guides; setting or tightening the cap is planned as irreversible. Rules SBX-R34–SBX-R39.
The issues-intake and issues-intake-source packs made one kind of ingestion — issues from GitHub and GlitchTip into tasks — a pair of workflow graphs of its own, beside the mail sync and the cloud document sync, each with its own idea of a position, a receipt and a failure. Ingestion belongs in one general contract instead: a source adapter, a position the platform keeps, an idempotent upsert into a target and a receipt, which the templates then use. That work follows separately; the fleet can schedule the importers it already runs until then. The validator change that came with the packs stays: a value that is a template is left to the run where a schema offers alternatives, and a literal is still judged. This reverts the packs, their rules (AUTO-R57–AUTO-R62), tests and guide sections from commit 3e56b72.
A docs-screenshot entry for the sandbox workspace settings with the size cap and disk-pressure reclaim switches the reclaim change added.
A project tab, Dispatch, for every reader of the project: a summary of the dispatch's state, the warning when its pool can hold more runs than the organization has agent workers, models at capacity, and tables for its agents (with why each idle one is idle), standing roles, gates and recent passes. Project administrators edit it in a dialog that names the version it started from — a stale save offers the current one, issues the platform finds show under their fields — run a pass now, and hold or open a gate. A dispatch saved by a newer version reads as such and offers no editor. The task timeline names a run dispatch started, with its standing-role occurrence, and a status change dispatch made names Dispatch as its actor. EN/DE/FR (de-CH where ß or quotes differ), manual boxes PROJ-F67–F70, PROJ-B20–B23 and PROJ-A9, a docs-screenshot entry (not yet captured), and component tests for the readback states, the editor, the actions and the timeline. The editor's configuration read always refetches when it opens, so a cached read can no longer leave it on its skeleton.
yannickmonney
marked this pull request as ready for review
October 14, 2026 17:09
yannickmonney
added this pull request to the merge queue
Oct 14, 2026
github-merge-queue
Bot
removed this pull request from the merge queue due to failed status checks
Oct 14, 2026
yannickmonney
added this pull request to the merge queue
Oct 14, 2026
This was referenced Oct 15, 2026
5 tasks done
This was referenced Oct 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #4945.
On 2026-10-14 Tale's own development fleet — an LLM manager agent dispatching twenty workers through six automations — emptied: the manager's model answered "Selected model is at capacity" for hours, the manager task's hourly start circuit closed, ~170 ready tasks sat idle, and failed cards stayed In progress until the manager "repaired" them. #4945 had already collected why: the fleet's admission, dispatch and recheck rules were prose an agent executed in its head. This PR builds them into the platform so any project gets them without a policy text.
What changes
A model at capacity waits instead of failing (migration 0205, TASK-R40, TASK-R12). A provider's capacity refusal holds the model for the organization (1, 2, 4, 8, then 15 minutes); every run on it parks as "Waiting for model capacity" and takes no worker; one probe goes first when the hold ends; the refused run's retry spends no attempt and no hourly automated start; a run that settles clears the hold. Supersedes #4985's 60-second admission floor: a fresh start is admitted and waits at its worker claim, so a card is never In progress without a live run.
Native dispatch per project (migration 0206, TASK-R41–R48, R52). A pool of agents, how many runs it and each agent hold, the columns and labels ready work comes from, whether unassigned work goes to the pool, rebalance, and the host admission preset with start spacing and recheck delays. Passes run as jobs — on run end, when a model answers again, on save, when a gate opens, at the time a held pass named, and every minute — count every live run of the pool whoever started it, rank by column/priority/board order/age, ask the sandbox host before each start and start through the same admission as any automated start, as
dispatch:<project>. Standing roles are data: an occurrence is claimed in the transaction that starts its run (decided once, coalesced into a live run, only the latest missed one runs). Managed resourceproject-dispatch(MCP settings + CLI), readback of each agent's runs or why it is idle, the agent-worker warning, recent passes.Gates (migration 0210, TASK-R51). Signals from outside that hold the ready work they govern (e.g. a full CI runner queue): state or value with hysteresis, stale handling, start spacing.
POST /api/v1/projects/{id}/dispatch/gates/{key},GET /api/v1/projects/{id}/dispatch.Host admission and heavy-phase leases in the spawner. A pressure sampler (load per CPU, CPU/memory/I/O PSI) with hysteresis and presets (
default= today's CPU rule,conservative= the fleet's thresholds),GET /v1/admission, and heavy-phase leases (count, predicted disk growth, memory, expiry, released with the session). Platform side:host_lease_acquire/host_lease_releaseagent tools, leases released when a run ends.Instruction snapshot (migration 0209, TASK-R49). Every task turn opens with the project's current instructions; the run records SHA-256 digests of the project's, agent's and task's texts it was handed (readback + ledger). No more
task_getpreamble.Reclaim by size and disk pressure in the workspace sweep, governed by the
sandbox_workspacespolicy, audited.Heartbeat:
tale_backend_dispatch_last_pass_timestamp_seconds{project}with an alert rule in the observability guides (TASK-R50).CLI:
project-dispatchis a managed resource thetaleCLI plans, applies and reads back; a dispatch a newer version stored is never overwritten (TASK-R52).UI: a project Dispatch tab (status, why each agent is idle, standing roles, gates, recent passes, editor with stale-save handling, hold/open gates, run a pass now); the task timeline names runs dispatch started. Docs: a new guide (EN/DE/FR), API reference, env reference, observability. API contract 3.45.0.
Ingestion is deliberately not here: issue-specific intake packs were built and then dropped in favour of a general sync contract, which comes with the template-catalog work in a separate PR.
Proof
checkModelCapacityRetryandcheckFleetDispatchreplay the outage — capacity refusals injected the way the turn host reports them, a stand-in host under pressure, passes and occurrences decided twice, the manager's task failing on capacity without closing its circuit, a gate held by a CI value with hysteresis, a dispatch a newer version stored — 99/99 checks locally before the gate and unreadable scenarios were added;checkHeavyPhaseLeasescovers run-end lease release. The laptop's Docker became unavailable afterwards, so CI's Backend integration is the proof for the later scenarios.Follow-ups
project-dispatchresource once a Tale release with this PR is deployed (draft PR in tale-project/ops).