Repository navigation
Description
Problem
#3479 made a job defer when its agent is already at its per-agent ceiling at the pre-check. A job that passes the pre-check and then loses the race at the authoritative acquire still waits there by polling, holding its queue worker, unless it is a task import.
With PROPR_AGENT_RUN_ALIAS_LIMITS set, several jobs for the same alias submitted close together all pass checkJobAgentCapacity before any of them holds a slot. The ones over the ceiling then wait in prepareAdmittedAgent:
- Only
processTaskImportJobpassesraceWaitMs: JOB_AGENT_CAPACITY_RACE_WAIT_MS, so only import jobs turn a lost race into a deferral. Issue jobs (processGitHubIssueJob.ts), pull request follow-ups (processPullRequestCommentJob.ts), reviews, goals and merge-conflict runs call it withoutraceWaitMsand keep polling. - The comment on
JOB_AGENT_CAPACITY_RACE_WAIT_MSsays only job types that have done nothing user-visible by then opt in, so this looks deliberate rather than an oversight. By the time an issue job reaches the acquire it has set the processing label, updated the task and created a worktree. - A review or scout waiting this way runs into its own 30-minute timeout (
REVIEW_TIMEOUT_MS,SCOUT_TIMEOUT_MS) and ends withAgentCapacityWaitTimeoutError, whichisAgentCapacityRefusaldoes not treat as deferrable. The review fails although nothing was wrong with it. - While a job waits at the acquire I could not find anything written to the task timeline, so the task looks active with no explanation. I read the code for this; I did not confirm it on a running instance.
The ceiling itself holds. On 4cc4f16 with real Redis and the Docker simulator, eight separate processes launching at once on an alias capped at 2 peaked at exactly 2 running, with 6 waiting and no leaked holders. This issue is only about what the waiting jobs do meanwhile.
Question
Should job types other than import give their worker back after a bounded wait at the acquire?
Options I can see:
- Opt the remaining job types into
raceWaitMsand make the work they have already done safe to re-enter (label, task state, worktree). - Leave them waiting, but record the wait on the task timeline the way the pre-check deferral does, and treat a review's or scout's capacity-wait timeout as a deferral instead of a failure.
- Reduce the race itself, for example by taking the slot at the pre-check rather than at container create.
Option 2 looks like the smallest change. I am raising this as a question because the current scoping reads as intentional.
Suggested acceptance
- Three issue jobs submitted together on an alias capped at 2: at most 2 run at once, and the third is either moved to delayed or shown on its task timeline as waiting for agent capacity.
- A review that waits for capacity longer than its own timeout is retried rather than failed.
- The existing guarantees from Defer jobs whose agent is at its ceiling instead of holding a worker, and charge the actual direct agent #3479 still hold: a capacity wait consumes no failure budget and triggers no provider replacement or fallback.
Activity