Skip to content

feat(platform): run each agent task in a worker of its own - #4603

Merged
yannickmonney merged 31 commits into
mainfrom
feat/agent-workers
Oct 9, 2026
Merged

yannickmonney merged 31 commits into
mainfrom
feat/agent-workers

Conversation

@yannickmonney

@yannickmonney yannickmonney commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

What

An agent is a configuration; each of its runs works in a worker, a sandbox of its own. The same agent can work several tasks in parallel, bounded by the organization's limit of agent workers.

  • One sandbox per run [TASK-R24]. Two runs of one agent never share a sandbox, so each keeps its own memory, processes and files. Workers are named Worker 1, Worker 2, … per agent (and per member for member-started runs). Migration 0167 adds the worker claim columns and a one-run-per-worker unique index.
  • A start that finds no worker waits [TASK-R25]. A start that finds no free worker queues at every door: the app, agents, schedules and automations. It says why (org_limit, host, destroy_pending, exec_limit) and starts by itself when room frees. It uses no attempt, gets its full working time from the moment it starts, and waits at most 12 hours. A freed worker goes to the agent with the fewest runs working, then to the longest waiter.
  • A task returns to its worker [TASK-R27]. A task's next run goes back to its worker when that worker is free, continuing the conversation and the files it left. A failed or cancelled run's worker is held for that task for 15 minutes.
  • A waiting run can be withdrawn. It can be cancelled (Stop in the Run row), and reassigning the task cancels it.
  • UI.
    • The Run row, the timeline and the chat tray say why a run waits; admins get a link to the limit.
    • The Sandboxes page lists each agent's workers with their current tasks, and shows the waiting count under the "Agent workers" quota.
  • Contract 3.25.0 (after feat(platform): let agents add, edit and search knowledge entries #4548's 3.23.0 and feat(platform): mention agents and people by name, stored by id #4598's 3.24.0):
    • task_start_agent and the task.start_agent step no longer answer agent_busy/busyTaskId; they add waitingReason.
    • An agent naming itself for another task is refused with self_start.
    • task_get.agentRuns carries waitingReason.
  • Docs and manual. Docs in EN/DE/FR cover project agents, concepts, sandboxes, triggers, task automation, tasks, chat basics and the environment reference. Manual boxes TASK-F81–F83, TASK-B50–B52, SET-F80–F82 and SET-B35–B36 are added.

Verification

  • Typecheck, platform lint and knip are clean, and lint:manual passes.
  • Unit, UI and browser tests for the touched areas pass, as do i18n (platform and @tale/ui), the guards and the docs tests.
  • Real Postgres: 313 of 313 checks pass across 14 lanes, among them checkAgentWorkers, ExecLimitPark, TaskAgentRuns, ScheduledAgentStarts, AutomatedRetryAgentBusy, Watchdogs and SandboxSessions.
  • After the rebase onto 3bc0b32225, the contract spec tests pass (133/133).

Review findings

The lane's adversarial review raised 2 major and 8 minor findings. Each was verified, then fixed with tests:

  • Major: a run that had not claimed a worker counted as holding worker 1. A burst of starts could take a task's own worker or open extra ones. Only claimed runs count now.
  • Major: no contract bump. It is now 3.25.0, with an API-reference paragraph in EN/DE/FR.
  • A wake cleared no leftover claim stamp, so it could hit the one-run-per-worker index. A wake now clears the stamp and names the family's first worker, and the watchdog logs one organization's failed wake and goes on.
  • A fresh start could take the room a wake had just given a waiting run. A woken run keeps its place until its claim: a start that never waited counts it and waits behind it (TASK-R25, new integration case).
  • The parked-reason SQL lives in one place, the worker-family rule uses workerFamilyBase everywhere, and the test-only constructors moved to a test helper.
  • Comments that narrated past behaviour are now in the present tense.
  • SET-B35 no longer expects a run to work while the sandbox service is down.
  • The Sandboxes page no longer crashes when an api of the previous release answers without waitingRuns.
  • The tool guidance, tool and step descriptions and triggers docs now name all four waiting reasons.

Real Postgres after the fixes: 158 of 158 checks pass across 9 lanes (checkAgentWorkers, checkExecLimitPark, checkTaskAgentRuns, checkWatchdogs, checkAutomatedRetryAgentBusy, checkScheduledAgentStarts, checkDelegatedAgentStartTool, checkSandboxSessions, checkSandboxSettingsViews).

Still open: the limits screenshot (settings-sandboxes.webp) still shows "Project agent sessions"; I'll retake it once the machine is less loaded.

Merge order: last of the train, after #4548 (0164) and #4598 (0165/0166).

@yannickmonney
yannickmonney marked this pull request as ready for review October 9, 2026 02:41
Worker 1 of an agent's standing workspace and of each member's workspace
keeps today's id; worker n >= 2 appends -w<n>. projectAgentWorker reads
the family and worker back, so the standing and member inverses, the
legal-hold match, member removal and erasure cover every worker of a
family. The legacy agent flow's pin on session_naming.ts moves to
per-declaration sections; the reused helpers stay byte-identical.
Migration 0167 adds project_agent_runs.session_claimed_at_ms (when the
run took its worker), waiting_reason (why a parked run waits) and a
partial unique index that lets one live, unparked run hold a worker.
A run that meets no room keeps why it waits: the organization's agent
workers, the sandbox host, a pending Destroy or its sandbox's process
limit. A start that raced into a worker already held blames no limit.
Every park gives the run's worker back and names the family's first
worker again; a wake clears the reason. The run card, the run list,
task_get and the chat tray carry the reason while the run is parked.
The release, the idle release and the watchdog's orphan backstop guard a
worker by the live runs that name it, not by every run of its agent, so
a worker's slot frees the moment its own run ends. Wakes take the parked
run of the agent with the fewest runs working first, then the oldest
park, so one agent's burst never starves the others. A turn whose worker
stays up wakes the agent's oldest parked run instead of the runs parked
on that workspace.
The task.agent_turn job claims the worker a run starts in, under the
agent's lock and the organization's admission lock: the task's previous
worker when free, then a worker still up, then a stopped one, then a new
one while a slot is left. A run no worker can take is parked with its
reason instead of refused, and a free worker being destroyed is waited
for. A worker whose run failed or was cancelled is kept for that task for
15 minutes. A run whose starter lost the editor role while it waited
moves into the member's own workers. Waiting no longer uses up a run's
working time: the launch stores a deadline counted from the start. The
agent's workspace guidance now says each worker is its own.
A delegated start, an automation step and the automatic retry of a run they started no longer answer or wait agent_busy: the run takes a worker of its own, or waits for one. The started answer says when it waits (waitingReason), an agent naming itself for another task is refused as self_start, and the busy probe, the busy wait and their recheck chain are gone; a check an earlier image queued simply kicks.
A run that waits for a worker and never launched has done nothing yet: reassigning its task, by a person, an agent or a delegated start of another agent, cancels it instead of refusing TASK_HAS_LIVE_RUN. A delegated start withdraws it only once every check admitted the start; a run that launched, or was woken a moment ago, still holds the task.
The ops indicators read lists every live agent run (running first, then queued oldest first, at most 50 with runsTruncated) with its waiting reason and worker. Run reads carry the worker a run holds. Sandboxes rows name each agent worker and the key and title of the task its op works, and the view counts every run waiting for room by reason.
A worker that stays up after its turn ends (pinned, or still held) is free only for a run of its own workspace family. The agent wake now picks the oldest parked run of that family, so a run parked for a member's workspace is no longer woken by a standing worker's freed exec place, and the run refused an exec place on that worker is woken first.
Nothing outside their modules reads them since the busy-agent retry wait is gone.
A lane in an organization of its own drives the turn job's claim, slot reserve or resume, launch, settle and release on hand-inserted runs: two workers for two tasks, a third run waiting with org_limit and no third workspace, per-worker release and reuse, task affinity, the one-run-per-worker index, member families and a demoted starter, the fair wake across agents, the withdrawal of a waiting run on reassignment, and migration 0167's shape.
The scope switch had no trailing return, which the consistent-return lint rule refuses.
The workspace cleanup lane now holds a departed member's worker 2 going with the member, the agent's own worker 2 and another member's staying, a held member's worker 2 kept on agent deletion and never dated for disuse.
The worker claim spelled out the organization's admission lock instead of calling lockOrgAdmission, a second copy of the lock every reserve, resume and release takes.
The automated-coverage rows and the native start's error row still said a busy agent answers agent_busy and a retry waits for it; both now start a run of their own, and an agent's start of itself on another task answers self_start. The delegated-start lane's header and race comment say the same.
The idle-release lane's queued run named a made-up workspace and relied on the agent-wide guard to protect the agent's workspace. A worker is now guarded by its own runs only: the run names the workspace it will work in, and a run of the same agent in another worker is shown to hold nothing there.
A run parked for room now reads its reason wherever it shows: the task's
Run row and its timeline row read one short state per reason (waiting for
a worker, for room on the host, for a workspace being deleted, for its
sandbox) with the sentence that explains it, and the chat tray reads the
same short state. When every agent worker of the organization is busy, an
Owner or Admin also gets a link to raise the limit in Settings > Sandboxes.
The timeline stops dropping the park: its adapter keeps waitingForCapacity,
the reason and the worker a live run holds. The board's ops read exposes
the live runs and whether the list was cut short, for the board to use.
Each of an agent's workspaces is one of its workers now, so its row says
which: "Worker 2", or "Member worker 2" for one that runs the agent for a
member. Current tasks name each task by its key and title and open it,
instead of printing a task id prefix; a task gone since keeps the prefix.
The limit reads "Agent workers" with what it counts, and under it a manager
sees how many agent runs wait for a free worker: what raising it would
start. The workspaces read keeps that count beside the rows it answers.
An agent is a configuration; each task it works on at the same time runs
in a worker, a running copy of it in a sandbox of its own. The project
agents guide gets a section on running one agent on several tasks: the
Agent workers limit, waiting for a worker and why, how to take a waiting
run back, and which worker a task's next run goes to. Sandboxes names the
limit, the worker rows, task names, the waiting count and each waiting
reason as the app words them; triggers and task automation stop promising
agent_busy and the two-hour retry wait, and say a busy agent is started
and may wait. EN, DE and FR alike; the ops process stays a backend worker.
An agent worker is one running copy of a project agent, working one task in a sandbox of its own. The term stays a loanword in German and French, distinct from the operations process backend-worker; Instanz and instance are avoided because they already name the Tale deployment.
Tasks gain the boxes for one agent working two tasks at once, a third start
waiting for a worker and starting on its own (and being taken back), a
manager starting a busy agent, every waiting reason in its own words, a
task's next run going back to its worker, and a member's own workers.
Settings gain the worker rows with their task names, the Agent workers
limit with its waiting count, Stop task on one worker, Destroy of one worker
while another is free, and a worker giving its quota back when its own run
ends. The chat tray, Destroy and quota boxes quote the new labels, and the
automation register owns the server and component halves.
The Destroy row's wait splits into one sentence per workload, German counts workers toward the limit instead of against it, and French takes a waiting run back with retirer, which cannot be read as resuming it.
Every kick and every wake names its family's first worker until its
claim runs, so counting the name sent a task's next run away from its
own worker and let a burst of starts open new workers beside a stopped
one. The claim now counts a run working in a worker or one that has
claimed it; the provisional name still guards the worker against an
idle release.
A run an older image parked could keep its claim stamp and a worker
number. Woken that way it collided with the run holding that worker now,
and the unique index refused the wake, every tick, for every organization
the watchdog visited after it. A wake now clears the stamp and names the
family's first worker, as a park does; the watchdog logs one
organization's failed wake and goes on. The worker family is read through
workerFamilyBase, never a copy of the suffix rule in SQL.
…25.0

task_start_agent and the automation step task.start_agent stopped
answering agent_busy and busyTaskId and gained waitingReason; an agent
naming itself is refused with self_start; task_get agentRuns carry
waitingReason. An automation branching on agent_busy behaves differently
now, so the change takes its own contract version, documented in the API
reference in EN, DE and FR.
The 0167 header, the waiting-run withdrawal and the retry recheck queue said what the code used to do. They now say what it does: one sandbox per concurrent run, a reassignment withdraws a run that has not launched, and the recheck queue stays registered so a check a previous image queued is still delivered.
Every read of a waiting run now nests parkedRunSql / parkedWaitingReasonSql (agent-runs.ts, alias-aware for the run card's joined read) instead of writing the CASE out again: the run columns, the run card, the run summaries, the board's live runs and the Sandboxes page's waiting count. The board's live runs name their worker through agentRunWorkerNumber, the rule the run card and the run list already use. The worker-number constructors only tests call (standingWorkerSessionId, memberWorkerSessionId) move to session_naming.test-helpers.ts.
…aited

A wake hands the room a worker freed to the waiting run the fair order
picks, but until that run's claim a fresh start could take the room and
park it again, so waiting runs could be overtaken until their 12-hour
deadline. A wake now keeps the run's waiting reason until its claim; a
start that has not waited counts such woken runs against the room and
waits behind them. Woken runs do not count one another, and no read
shows the kept reason.
A browser on the new release that reaches an api of the previous one
while a deploy rolls gets the workspaces without the waiting count, and
the page crashed reading it. The count is optional in the contract and
the page shows none when it is missing.
The box stopped the sandbox service and expected the run to work in
Worker 2 at once, but that worker can only start once the service is
back. It now checks that the run never waits for the workspace being
destroyed, and works in Worker 2 once the service returns.
A started run that waits says why in waitingReason: org_limit, host,
destroy_pending or exec_limit. The agent tool guidance, the tool and
automation step descriptions and the triggers docs in EN, DE and FR named
only the first or the first and third.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant