Repository navigation
feat(platform): run each agent task in a worker of its own - #4603
Merged
Merged
Conversation
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.
yannickmonney
force-pushed
the
feat/agent-workers
branch
from
October 9, 2026 03:16
d4e461a to
3abb88f
Compare
This was referenced Oct 9, 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.
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.
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.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.task_start_agentand thetask.start_agentstep no longer answeragent_busy/busyTaskId; they addwaitingReason.self_start.task_get.agentRunscarrieswaitingReason.Verification
lint:manualpasses.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:
workerFamilyBaseeverywhere, and the test-only constructors moved to a test helper.waitingRuns.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).