Suggesting assignments#
This guide shows how to let Planning Engine pick who works on a task. It covers filling open positions, fixing assignments that no longer fit, moving work off overloaded people, and reading and committing the proposal.
How auto-assignment works#
project.suggestAssignments(slots, options) takes a list of slots and returns a proposal. The call is synchronous and never changes the project. You decide what to commit.
A slot is one position on one task: "task C needs one person, and dev1 or dev2 can do it". It's a plain object with the task, the list of eligible resources (allowed) and, when someone already fills it, the assignment that does. The engine doesn't know about skills. If you model skills, project.slots(pool, requirements) builds the slots for you (see Skills and requirements).
Every slot is in one of three states, judged from its current resource:
| State | Meaning | targets value |
What the call does |
|---|---|---|---|
| empty | no assignment | "empty" |
fills it with the cheapest eligible resource |
| broken | held by a resource outside allowed |
"broken" |
moves it to the cheapest eligible resource |
| valid | held by a resource in allowed |
"valid" |
moves it only if another resource is strictly cheaper |
The targets option says which states to act on. The default is ["empty"]: fill open positions and leave the rest alone.
The call is greedy. It visits slots one at a time and tries every eligible resource on a working copy of the project. Each try is scheduled and scored the same way evaluate scores a candidate: finish delay plus overload plus a heavy penalty for conflicts. The cheapest resource wins, and later slots build on the earlier picks.
The result has two main parts. changes is a SchedulingChanges object you can pass straight to apply. steps logs every decision with the cost before and after, so a UI can explain each pick.
suggestAssignments never removes an assignment. It can add one (fill) or change the resource of one (repair, rebalance). A slot it can't fix is reported, and you decide what to do with it.
The proposal is built on the solved baseline, so the project must be solved and clean. Failures are thrown synchronously:
| Failure | Error |
|---|---|
Project not solved yet, or edited with apply since the last solve |
ProjectError, code: "no-baseline" |
baselineId doesn't name the current baseline |
ProjectError, code: "stale-baseline" |
| Bad slot (see Slots) | InputError, path like "slots[1].allowed[0]" |
Bad option value: unknown targets value, duplicate target, passes below 1, negative penalty, unknown id in fixed |
InputError, kind: "validation" |
| Unknown option key | InputError, kind: "parse" |
See Handling errors for the error classes.
Slots#
A Slot is { id, task, allowed, value?, assignment? }. The order of allowed is the tie-break: when two resources cost the same, the earlier one wins. A new assignment gets value units, 1 by default.
The slot id becomes the id of the assignment that fills it. On the next run, pass that id back in assignment, so the slot counts as filled and isn't filled twice.
const = ;
const = new;
;
// Task C needs one person: dev1 or dev2.
const = ;
const = ;
This prints sC on C: dev2. dev1 is already double-booked on A and B, so putting C on dev1 adds two more days of overload. dev2 is free.
To describe a filled slot, set assignment. The assignment must be active and on the slot's task:
const = ;
The call checks every slot before it does any work. It throws an InputError on a duplicate slot id, an unknown or summary task, an unknown resource in allowed, a value that isn't a finite number above 0, or an assignment that isn't active or is on another task. The error path points at the slot field, for example slots[0].allowed[0]. The full list is on the Slot reference.
If you model skills, don't build slots by hand. project.slots(pool, requirements) builds them from a pool of workers and task requirements, and binds existing assignments to their slots:
const = new;
;
const = ;
const = ;
// One slot "qa#1" on C, with dev1 as the only eligible resource.
const = ;
const = ;
; // 1 step(s)
Options#
Pass only the options you need; every field is optional.
| Option | Default | Use it to |
|---|---|---|
targets |
["empty"] |
choose which slot states to act on; [] only reports broken slots |
fixed |
[] |
keep listed assignments where they are |
newResourcePenalty |
0 |
trade balance against headcount (see How picks are made) |
passes |
1 |
rebalance valid slots more than once |
level |
false |
score each candidate after leveling |
clearFirst |
false |
score against a copy with stored leveling delays cleared |
baselineId |
none | throw stale-baseline if the project changed |
All options are on the suggestAssignments reference.
Rebalancing filled slots#
Add "valid" to targets to move work off overloaded people. Rebalancing runs after filling and repairing, so it also sees the slots that were just filled.
const = new;
;
const = ;
const = ;
The call fills sC with dev2, then moves aB from dev1 to dev3. dev2 isn't a good pick for B anymore, because it now works on C. The proposal holds one add (sC) and one update (aB to dev3).
A valid slot moves only on strict improvement: on a tie, the current resource stays. With newResourcePenalty at 0, a valid slot is skipped when its current resource isn't overloaded during the task. One pass is often enough. When a later move makes an earlier pick worse, raise passes. The loop stops early after a pass that moves nothing.
Keeping people in place#
List assignment ids in fixed to keep them out of every pass, whatever the load:
const = new;
;
const = ;
const = ;
const = result.. ?? ;
; // 1 add(s), 0 update(s)
sC is still filled with dev2, but aB stays on dev1. A fixed resource still counts as being on its task, and a fixed slot that is broken is still listed in invalid. An id in fixed must name an active assignment, otherwise the call throws an InputError at fixed[i]. The id doesn't have to be bound to a slot.
Repairing broken slots#
A slot breaks when its resource drops out of allowed, for example after a requirement or a skill grade changed. Run with targets: [] first to only check, then with "broken" to fix:
const = new;
;
// B now needs dev2 or dev3, but dev1 holds it.
const = ;
const = ;
; // broken: [ 'sB' ]
const = ;
A repair always moves the slot. It takes the cheapest eligible resource, even if keeping the current one would cost less. A broken slot is visited once, with no retry. If no eligible resource can take it, it keeps its assignment and stays in invalid.
Scoring after leveling#
By default each candidate is only scheduled, so overload shows up as cost. With level, each candidate is also leveled with those leveling options and scored on the leveled plan, where overload turns into delay. The score then tells you how much later the project would finish with each pick.
const = new;
;
const = ;
const = ;
const = result..?..;
sC goes to dev2. The leveled finish is two days later than the accepted plan, because leveling still has to separate A and B on dev1.
Leveled metrics have the same fields as Metrics plus converged, rounds and windows.
Each pick builds on the scheduled copy, not the leveled one, so leveling delays don't add up across picks. Every candidate runs a full level, so keep leveled scoring for small sets of slots.
If the project holds delays from an earlier level run, those delays can hide overload, and the rebalance skip rule then sees nothing to fix. Set clearFirst: true to score against a copy with the delays and pauses cleared. changes then carries a tasks.update for each cleared task, so committing it reproduces the cleared state.
How picks are made#
Slots are visited in a fixed order, set once from the accepted plan: task start, then task order in the data, then the order of the slots you passed. Picks that move dates don't change the order. The order matters, because the result is greedy: an early slot takes the best resource, and later slots work around it.
The call runs in passes:
- Pass 0 fills empty slots and repairs broken ones, if those states are targeted.
- Passes 1 to
passesrebalance every valid slot, if"valid"is targeted.
For each slot the call tries every resource in allowed, except duplicates and resources already on the task (a task never gets the same person twice). It schedules each try on a copy of the working state and computes its cost:
cost = evaluate cost against the accepted plan
+ newResourcePenalty ร (people in use now โ people in use in the accepted plan)
The evaluate cost is finish delay plus overload plus 1000 per conflict or cycle; see Evaluating alternatives. It's always measured against the accepted plan, never against the previous pick.
"People in use" counts the resources that have at least one active assignment, out of those in any slot's allowed plus the current holders of filled slots. Once someone is brought in, later slots can use them for free. Moving someone's last assignment away lowers the cost.
newResourcePenalty is the one lever between balance and headcount. At 0 the call spreads work to idle people. A large value keeps work on the people who are already busy, as long as their extra overload costs less than the penalty:
const = new;
;
const = ;
penalty 0: 3 in use, cost 0
penalty 0.5: 3 in use, cost 1
penalty 5: 1 in use, cost 4
At 0.5, two new people cost 1, and removing four days of overload is worth more. At 5, one new person would cost more than the two extra days of overload on dev1, so C goes to dev1 and nobody else is brought in. With a penalty above 0, valid slots aren't skipped when their holder isn't overloaded: freeing a person is a gain on its own.
A candidate that can't be applied or scheduled is dropped. An empty slot with no candidate left goes to unfilled.
Reading the proposal#
The result has everything a UI needs to show and explain the proposal:
changes- the net edit: one add per filled slot, one update per moved assignment (even after several passes), and theclearFirstclears. ItsbaselineIdis set.steps- every decision that changed the working state, in order.unfilled- targeted empty slots left empty.invalid- slots whose resource is outsideallowedat the end, whatevertargetswas.baselineandproposed- cost and people in use before and after.proposedalso carries the scheduledMetricsand, withlevel, the leveled ones.
A step has no kind field. Read the kind from fromResource and pass:
const = new;
;
const = ;
const = ;
;
cost 2 -> 0
sC on C: fill to dev2, cost 2 -> 2
sB on B: rebalance from dev1 (pass 1) to dev3, cost 2 -> 0
The step costs form a chain: the first before is baseline.cost, and each before is the previous step's after. The baseline costs 2 because dev1 is already overloaded for two days. Filling C doesn't make that worse, and moving B to dev3 removes it.
proposed.scheduled is the full Metrics of the final state, with finish, overload per resource, conflicts and cycles. Its finish dates follow the project's date setting, like every other result date. See the suggestAssignments reference for every result field.
Committing#
Pass result.changes to apply, then reschedule. If you scored with level, run level with the same options instead of solve(null).
const = new;
;
const = ;
const = ;
const = ;
;
// Next run: sC is now the id of the assignment on C.
const = ;
; // 0 step(s): nothing left to improve
changes.baselineId names the plan the proposal was built on. If the project changed in between, apply throws a ProjectError with code: "stale-baseline" instead of committing an outdated proposal. A rejected operation sets needsResync; see Recovering from rejected changes.
The new assignment takes the slot id, so the slot keeps its binding after the commit. On the next run, pass that id in assignment, as above. project.slots() binds slots this way for you. A slot id that is already the id of another assignment makes the call throw an InputError at slots[i].id. Without that check, every add for the slot would be rejected as a duplicate id, and the slot would stay unfilled without a reason.
You can also commit part of a proposal. changes is a plain SchedulingChanges object, so drop the adds or updates the user declines before you call apply.
The committed plan matches proposed when config.gap_behavior is "compress". With the default "preserve", it can differ slightly. The call reschedules after each pick, while the commit reschedules once, and preserved dates depend on the path taken. Treat proposed as an estimate in that mode. See SchedulingConfig.
suggestAssignments runs one schedule (and one level, with level) per slot and candidate, all on the calling thread, and blocks the event loop until it returns. On large projects, run it in a Worker; see Running in a worker.