Engineering note
Why a roster fails, and how the scheduler explains it
Constraint solving is the easy part of shift scheduling. The hard part is telling a clinic manager which constraint is short, by how much, and what would change it.
Hisashi Aoki · 26 November 2026 · 6 min read
Most scheduling tools treat “cannot generate” as an error state. A clinic manager experiences it as a dead end: the month is not done, the deadline is tomorrow, and the system offers a retry button. The useful output is not a different error message — it is a specific answer: which constraint is short, by how much, and what would change it.
The model is the interesting part
A monthly roster is a constraint satisfaction problem with domain rules that do not generalise well. memeShift models it explicitly:
- Night blocks. A night shift reserves the next day as post-night (明け) and the day after as rest. These are not two independent assignments.
- Headcount per shift type, with daily overrides for a specific date.
- Consecutive-day limits that differ per staff member.
- Compatibility rules — pairings that must happen together or must never happen (must_together / must_separate).
- Preferences — requested days off and fixed shifts — applied before general assignment.
Generation is therefore not a round-robin with a random seed. It is a pipeline: constraint checking, assignment, off-day distribution, pattern rotation, then fairness balancing.
Why “infeasible” is a useless answer
A solver can prove infeasibility without telling anyone which decision caused it. In practice the cause is usually one of four things: not enough night-capable staff on a date, a consecutive-day limit that blocks the only available person, preferences concentrated on the same days, or a compatibility rule that removes the remaining candidates.
memeShift computes that attribution per date and shift type and returns a structured explanation instead of a boolean:
- required versus assigned headcount;
- the constraint family that produced the shortfall;
- a suggested action, including which screen to open.
That last part matters more than it sounds. “Night capability is short on the 12th” is information. “Open the staff screen and add night capability for Staff D” is a task.
Fairness has to be measured across the year
A monthly roster can look balanced and still be unfair. Night shifts cluster around the same people; weekends drift to whoever accepts them; early and late shifts split into two groups that never swap.
The statistics service aggregates the year, not the month: night counts, night → post-night frequency, average consecutive days, early/late imbalance, holiday counts, preference achievement rate, and safety indicators such as short intervals between shifts. Those same numbers drive the dashboard and the generator’s balancing pass, so the thing being optimised and the thing being reported are the same thing.
Repair, not regeneration
Regenerating a published roster destroys work people have already planned around. The repair path is bounded and explicit: local conflicts are resolved while fixed cells stay fixed, and a break-route search proposes the smallest relaxations that would unlock progress — release a fixed shift, move a preference, relax a constraint — ranked by candidate gain against penalty.
Applying a route is a confirmed action. The UI shows the route before it changes a single cell, because a scheduler who cannot predict the tool will not trust it.
Determinism is a feature
The same month always produces the same roster from the same inputs. That is not an implementation detail: it makes screenshots reproducible, tests stable, and disagreements debuggable. It is also why the public demo can run entirely in the browser on seeded synthetic data, with no backend and no real staff records anywhere.
What I would do differently
I would model constraint violations as first-class rows rather than derived objects. Today the explanation is computed, which is fast and easy to reason about; storing violations as records would make partial repairs auditable by default and would let the UI show the history of what was relaxed, when, and by whom. That is a schema decision, and it is much cheaper to make before the first facility than after the fifth.
The result
A scheduler that returns a reason instead of a failure, measures fairness over the year, and repairs locally with a visible route. The engine has no framework dependency, so the same code runs as a library, a CLI, or inside the API — and the public demo is the same UI with a deterministic data adapter.
Work with me
I build healthcare and operations software end to end — MVP in 2–6 weeks, production system plus CI/CD in 10–14 weeks, or fractional engineering at 20–30 hours a week.