For developers · Orchestrator
Queue order and slot share
On this page
- 1. Which issues may start
- Readiness
- 2. The order inside a repository
- The score
- The release bonus and the due date (#1850)
- Worked example: four issues of one repository
- Worked example: the same issue at other due dates
- 3. Sharing the worker slots between repositories
- Slots and the equal share
- The deadline of a release (#1850)
- The order of starts
- Worked example: ten slots, eight repositories
- Worked example: a release behind its date
- 4. Where to change it and where the app explains it
This page explains, end to end, which issue the autopilot starts next: which issues may start at all, how the issues of one repository are ordered (the score), and how the worker slots are shared between repositories (the fair share). Every number below is the default of the code; the worked examples are checked by tests (named at each example), so this page and the code cannot drift apart silently.
In short: inside a repository the next release goes first, then the highest score. Between repositories every repository with work gets an equal share of the slots; an urgent issue, then a release due soon goes first, then the rotation. A release that cannot make its date at the equal share may take more slots, but every other repository keeps at least one.
1. Which issues may start#
The dispatcher only looks at repositories whose Autopilot is on (state "active"). Of their open issues, one may start when all of this holds:
| Condition | What it means |
|---|---|
| Ready | The read model's readiness is ready: the ready label (or a legacy alias), or a trusted author and a complete description. See Readiness below. |
| Inside the release focus | With a release focus (the default: the next release), only issues of that release and the issues it depends on start (release.md, "Release focus"). When nothing in the focus is ready, the focus steps aside and the rest starts. |
| Dependencies done | Every issue it depends on (Depends on #N / Blocked by #N, also in other watched repositories) is closed. A cycle needs a person (needs-clarification). |
| Nobody else holds it | No lease of a run that has not ended yet, no "Solve with an agent" session on it, no running branch of the same repository changing the same files (the overlap wait, at most 30 minutes), no open part of a split issue. |
| A machine can take it | Some machine fits its os:, host: and tool: labels and has a free slot, memory, disk and agent usage left (dispatcher.md, "Workers per machine"; satellites.md). An issue no machine takes waits with the reason on the board; the next issue may go. |
Readiness#
Readiness is computed from the labels in this order; the first match wins
(read_model::readiness):
| Labels / state | Readiness | Starts? |
|---|---|---|
in-progress | in progress | no |
in-review | in review | no |
needs-human | needs a person | no |
stalled | stalled | no |
| dependency cycle | needs clarification | no |
an open dependency, or blocked | blocked | no |
prd or extern | held | no |
ready, or a trusted author | ready | yes |
| anything else | needs approval | no |
A trusted author's issue without the ready label also needs a complete enough description,
else it reads "needs clarification"; in a repository that only handles new issues, the backlog
from before it was switched on needs the ready label (dispatcher.md,
"Readiness").
2. The order inside a repository#
The issues that may start are ordered in two groups:
- First group: the issues of the next release and boosted issues
(
read_model::goes_first). The next release is- every issue with
release:next, - every open issue of the next release milestone (the open milestone with a version title that is due first, else the lowest version, see release.md), and
- every issue those depend on.
Only with release planning on for the repository; with it off, only boosted issues form the first group.
- every issue with
- Everything else.
Inside each group the score decides, highest first. Ties go to the older issue, then to the lower number. The dispatcher and the app's queue use the same order (#962).
The score#
score = priority weight
+ age_per_hour × full hours since the issue was opened
+ boost (when the boost label is on the issue)
+ release bonus (when the issue is in the next release, see below)| Term | Key | Default | Range | Rule |
|---|---|---|---|---|
| Priority p0 | p0 | 1000 | 0–10000 | priority:p0 (legacy prio:0) |
| Priority p1 | p1 | 300 | 0–10000 | priority:p1; also a bug without a priority label (bug, typ:bug, type:bug, kind/bug, …) |
| Priority p2 | p2 | 100 | 0–10000 | priority:p2; also every other issue without a priority label |
| Priority p3 | p3 | 30 | 0–10000 | priority:p3 and anything lower (p4, p5, …) |
| Age | age_per_hour | 1 | 0–1000 | Per full hour since the issue was opened; nothing waits forever. |
| Boost | boost | 500 | 0–10000 | The issue carries the boost label (boost_label, default boost, compared ignoring case). |
| Release bonus | release_bonus | 200 | 0–10000 | The issue is in the next release; scaled by the release's due date, see below. |
| Window | release_due_days | 14 | 1–365 | Days before the due date at which the bonus starts to grow; also the window of the deadline rule in the slot share. |
| Far share | release_far_percent | 25 | 0–100 | Percent of release_bonus for a release due release_due_days or more away. |
Several priority labels: the best one counts. A priority label always beats what the type implies.
The release bonus and the due date (#1850)#
The release bonus grows as the next release's due date comes closer. With d the whole days from
today (this machine's calendar day) to the due date, B = release_bonus, W = release_due_days
and F = B × release_far_percent / 100 (rounded down):
| Due date | Bonus |
|---|---|
none set (also release:next without milestone) | B (the bonus as before) |
overdue, today or tomorrow (d ≤ 1) | B |
1 < d < W | F + (B − F) × (W − d) / (W − 1), rounded down |
d ≥ W | F |
With the defaults (B = 200, W = 14, F = 50):
| Due in | none | 30 days | 14 days | 13 days | 7 days | 2 days | 1 day | today | overdue |
|---|---|---|---|---|---|---|---|---|---|
| Bonus | 200 | 50 | 50 | 61 | 130 | 188 | 200 | 200 | 200 |
Why this curve: a worker run, its checks and the review take hours, so today and tomorrow are the same urgency and get the full bonus. Two weeks is a common release rhythm; further away the date says little about today's order, but a release still keeps a quarter of its bonus. A straight line in between means every day closer adds the same number of points and a nearer date never scores lower than a later one. A release without a due date keeps the bonus it always had, so repositories that do not set dates see no change.
Inside one repository all issues of the next release share its due date, so the bonus mostly orders them against boosted issues (both are in the first group) and raises the repository's best score, which the slot share uses for repositories that have not started yet.
Worked example: four issues of one repository#
Defaults; the repository's next release v2.0 is due tomorrow. Test:
read_model::tests::docs_queue_order_score_examples.
| Issue | Labels | Opened | Priority | Age | Boost | Release bonus | Score |
|---|---|---|---|---|---|---|---|
| #101 | typ:feature | 72 h | none, feature → p2 = 100 | 72 × 1 = 72 | 0 | not in the release: 0 | 172 |
| #102 | typ:bug | 2 h | none, bug → p1 = 300 | 2 × 1 = 2 | 0 | 0 | 302 |
| #103 | priority:p2, in v2.0 | 30 h | p2 = 100 | 30 × 1 = 30 | 0 | due in 1 day: 200 | 330 |
| #104 | priority:p3, boost | 10 h | p3 = 30 | 10 × 1 = 10 | 500 | 0 | 540 |
Order: the first group (#104 boosted, #103 in the next release) by score, then the rest by score: #104 (540), #103 (330), #102 (302), #101 (172). #103 would go before #102 even with a lower score, because the next release goes first.
Worked example: the same issue at other due dates#
#103 again (p2, 30 hours old), with v2.0 due at other dates. Score = 100 + 30 + bonus:
| v2.0 due | Bonus calculation | Bonus | Score |
|---|---|---|---|
| no date | full bonus | 200 | 330 |
| in 30 days | d ≥ 14: 200 × 25 / 100 | 50 | 180 |
| in 13 days | 50 + 150 × (14 − 13) / 13 = 50 + 11 | 61 | 191 |
| in 7 days | 50 + 150 × (14 − 7) / 13 = 50 + 80 | 130 | 260 |
| in 2 days | 50 + 150 × (14 − 2) / 13 = 50 + 138 | 188 | 318 |
| tomorrow | d ≤ 1: full bonus | 200 | 330 |
| today | full bonus | 200 | 330 |
| 2 days ago | overdue: full bonus | 200 | 330 |
(150 × 7 / 13 = 80.8, rounded down to 80; 150 × 12 / 13 = 138.5, rounded down to 138.)
3. Sharing the worker slots between repositories#
Each push tick (every 5 s) the dispatcher asks the pure planner dispatch::fair::plan which
repository starts next; inside that repository the first issue of the order above that a machine
takes starts. The planner sees per repository: running workers (here and on worker machines),
ready issues, ready priority:p0 issues, the best ready score and, new with #1850, the next
release's deadline.
Slots and the equal share#
- Slots:
dispatch.max_workers, or fewer when the machines' own maximums add up to less (dispatcher.md, "Workers per machine"). Waiting resolver runs take their system slots first; the planner shares the rest. - Active repositories: Autopilot on and ready issues or running workers.
- Equal share:
floor(slots / active), at least 1. Example: 8 slots and 3 active repositories give 2 each; 10 slots and 8 repositories give 1 each.
The deadline of a release (#1850)#
A repository's next release weighs in when it has a due date at most release_due_days (default 14) days away, or is overdue, and has ready issues. Two numbers come from it
(fair::Deadline):
- Pressure = open release issues ÷ days left, where days left = days until due + 1 (today counts). Overdue is the highest pressure. Open means open or being worked on, in this repository; done (merged or closed) issues do not count.
- Need = the slots the release needs to make its date if every slot finishes one issue a day
(
ISSUES_PER_SLOT_DAY= 1): open issues ÷ days left, rounded up; overdue: all open issues. One issue a day is cautious on purpose: run, checks, review and merge, with the questions in between, often take most of a day.
A release whose need is above the equal share is pressed: its repository may hold up to its
need, but never more than slots − (active − 1), so one slot stays for every other active
repository. The extra slots only go to release issues: once the release has no ready issue left,
the repository is back to the equal share.
The order of starts#
For each free slot, the planner picks among the repositories with ready issues:
Without a pressed release:
- repositories below their share before those at or above it (who only get leftover slots);
- inside each of the two: an urgent issue (
priority:p0) first; - then a release due soon: highest pressure first, then the earlier due date;
- then the rotation: a repository that never started first, then the one whose last start is the longest ago (a start moves the repository to the end; kept in memory, reset on restart);
- then the best ready score, then the repository's name.
With at least one pressed release, step 1 has four levels instead of two:
- every repository with no running worker gets its first slot;
- pressed repositories fill up to their need (within the bound above);
- the others fill up to the equal share;
- leftover slots.
Steps 2–5 order each level as before. Without any release due within its window, nothing of this
changes the order of #959 (tested: fair::tests::a_release_not_behind_keeps_the_equal_share and
the earlier fair-share tests, unchanged).
No slot stays free while anything is ready: slots no repository below its share can use go to the others. The global limit and every machine limit always hold.
Worked example: ten slots, eight repositories#
Test: fair::tests::docs_queue_order_slot_example. Ten free slots, eight active repositories
(app, api, cli, docs, lib, ops, site, web), each with 3 or more ready issues, none
running yet:
app: release v2.0 due tomorrow, 6 open issues, all ready. Days left 2, pressure 6 ÷ 2 = 3.000, need ⌈6 ÷ 2⌉ = 3.api: release v0.9 due in 6 days, 4 open issues. Days left 7, pressure 4 ÷ 7 = 0.571, need ⌈4 ÷ 7⌉ = 1.cli: one readypriority:p0issue.- Equal share: ⌊10 ÷ 8⌋ = 1. Bound for a pressed release: 10 − 7 = 3.
appneeds 3 > 1: pressed, limit 3.apineeds 1: not pressed, but due soon.
| Start | Repository | Why |
|---|---|---|
| 1 | cli | first slots; urgent issue first |
| 2 | app | first slots; release due soon, pressure 3.000 |
| 3 | api | first slots; release due soon, pressure 0.571 |
| 4–8 | docs, lib, ops, site, web | first slots; rotation (none started yet, same score: by name) |
| 9 | app | pressed, 1 of 3 |
| 10 | app | pressed, 2 of 3 |
Result: app 3 workers, every other repository 1. Without the due dates the two leftover slots
would have gone by the rotation to cli and api.
Later ticks, one slot freeing at a time:
- A worker of
docsends:docshas none running, so it gets the slot back first. - A worker of
appends:appis below its need of 3, so the slot stays withapp. - Once
apphas no ready release issue left, it is held to the equal share again: a slot freeing atopsgoes back toops.
Worked example: a release behind its date#
Test: fair::tests::docs_queue_order_held_example. Eight slots, four repositories with plenty of
ready issues; app's release v2.0 is overdue with 9 open issues. Share ⌊8 ÷ 4⌋ = 2, need 9 (all,
overdue), bound 8 − 3 = 5. Result: app 5, docs, lib and web 1 each. The three
wait below their equal share for app's release; their ready issues show "Waits for a free slot:
release v2.0 of owner/app is due on (its date) and gets more slots." app itself waits at its
bound with the plain "Waits for a free slot of this repository."
4. Where to change it and where the app explains it#
- Weights: globally in
orchestration.jsonunderscore(all keys of the table above), per repository underrepos[].score; a repository without own weights uses the global ones. In the app: the repository's settings, section "Order", switch "Own weights", one field per weight with its range; a value outside the range is refused and the old value stays. The core refuses an out-of-range value in the file the same way (ScoreWeights::validate). - Slots:
dispatch.max_workersand each machine's own maximum (dispatcher.md). The deadline rule has no switch of its own: setrelease_due_daysto 1 to make it apply only to releases due today, tomorrow or overdue. - Why an issue waits: a ready issue held by the share shows on the board and in the sidebar
as "Waits for a free slot of this repository." (
repo_shareinhost-wait.json); when a pressed release takes the slot, the text names it: "Waits for a free slot: release {version} of {repository} is due on {date} and gets more slots." (in all six languages). A machine reason (offline, full, a missing tool) wins over the share. - Order in the app: the release view sorts by the dispatcher's order (#1716), and the queue beside the sessions lists the issues in the order above.
- Logs:
dispatch.release_pressed(debug) names the pressed repositories of a tick;dispatch.host_waitlogs each wait reason once per change.