Documentation
¶
Overview ¶
Package dispatch decides which planned task starts now: the scheduler's rules, in plain Go, apart from the store and the workers. A pass reads a Situation (the tasks, the wishes, the projects, the machine) and gives a Decision for each planned task: start it, let it wait with its reason, or fail it. The harness acts on the decisions; the dispatch bench (internal/dispatch/bench) feeds it cases written by hand.
Index ¶
- Constants
- func CanonicalModel(raw string) string
- func ChangesNoCode(t *planv1.Task) bool
- func Feedback(t *planv1.Task) bool
- func Ifrit(t *planv1.Task) bool
- func Investigation(t *planv1.Task) bool
- func InvestigationCap(slots int) int
- func Light(t *planv1.Task) bool
- func LimitModel(text string) string
- func MemoryAt(res *planv1.Resources, percentile int) uint64
- func Mockup(t *planv1.Task) bool
- func Overlap(a, b []string) bool
- func Planned(t *planv1.Task) bool
- func Provider(t *planv1.Task) string
- func ProviderMemory(tasks []*planv1.Task, percentile int) map[string][]uint64
- func ProviderPeaks(tasks []*planv1.Task) map[string][]uint64
- func QuestionWorker(t *planv1.Task) bool
- func Resuming(t *planv1.Task) bool
- func ScopeText(scopes []string) string
- func ServedFirst(t *planv1.Task) bool
- func TypicalForecast(tasks []*planv1.Task, p machine.Policy) uint64
- func TypicalPeak(tasks []*planv1.Task, p machine.Policy) uint64
- func Urgent(t *planv1.Task) bool
- func UrgentOf(tasks []*planv1.Task, wishID, except string, feedback bool) *planv1.Task
- func Watcher(t *planv1.Task) bool
- func WorkerMemory(tasks []*planv1.Task, p machine.Policy, at ...time.Time) (engaged, actual uint64)
- type AncestryChecker
- type BranchResolver
- type Decision
- type Machine
- type Network
- type Situation
- func (s *Situation) At(now time.Time) *Situation
- func (s *Situation) Blocker(t *planv1.Task) (why, failed string)
- func (s *Situation) Engaged() uint64
- func (s *Situation) Held(t *planv1.Task) (why, failed string)
- func (s *Situation) Order() []*planv1.Task
- func (s *Situation) Pass() []Decision
- func (s *Situation) Start(t *planv1.Task)
- func (s *Situation) WithAccounts(f func(t *planv1.Task) (why string, moves bool)) *Situation
- func (s *Situation) WithAncestry(branchHead BranchResolver, isAncestor AncestryChecker) *Situation
- func (s *Situation) WithLanes(lane func(wish *planv1.Wish, t *planv1.Task) string) *Situation
- func (s *Situation) WithNetwork(n *Network) *Situation
- func (s *Situation) WithQuestions(code func(id string) string) *Situation
- func (s *Situation) WithRunning(isRunning func(taskID string) bool) *Situation
Constants ¶
const WorkerPeakWarmup = 3 * time.Minute
WorkerPeakWarmup is the delay before a running worker's own measured p95 memory replaces the provider forecast in engaged memory calculations.
Rationale: Agents (such as Claude Code or Antigravity) take 1 to 2 minutes during startup to authenticate, inspect repository status, and spin up language servers. By 3 minutes, resident memory stabilizes into representative peaks.
Variables ¶
This section is empty.
Functions ¶
func CanonicalModel ¶ added in v0.2.0
CanonicalModel returns the canonical model identifier when raw names a recognized agent model (from `agy models`, the pricing table, or a provider's model family), and "" when raw is empty, a URL, or not a model name (such as "standard-paygo").
func ChangesNoCode ¶ added in v0.2.0
ChangesNoCode tells whether the task's work never reaches its project's code: an investigation or a mockup, whose commits Djinn never merges. The other workers' state holds none of them: neither its wish's red push checks, nor a merge in conflict or its repair (pushHeld), nor the merge freeze while a branch is repaired (it merges nothing), nor a write scope; and its work never holds a task that depends on it once done.
func Feedback ¶ added in v0.2.0
Feedback tells whether the task is urgent for the developer's quick feedback (Task.feedback): a mockup or a change they asked to see, after the wish's urgent repair.
func Ifrit ¶ added in v0.2.0
Ifrit tells whether the task is an ifrit (TASK_KIND_IFRIT): a worker that stays lit while the developer is there. The developer waits for it: it starts beyond the slots, as a task started by hand does, and only the machine's pressure or its memory hold it.
func Investigation ¶ added in v0.2.0
Investigation tells whether the task is an investigation (TASK_KIND_INVESTIGATION): a short study or audit that ends in a tilasm and a question, its commits never merged. It works in a worktree of its own, so it takes a slot like any worker; it is served first, as an investigator is (ServedFirst), at most InvestigationCap of them at once.
func InvestigationCap ¶ added in v0.2.0
InvestigationCap is how many investigations and mockups run at once on a machine of slots: one on a machine of three slots or fewer, two above, so that they never take more than a third of the work's slots, and never starve it.
func Light ¶
Light tells whether the task writes nothing in its project's folder: a watcher, or a question worker. Only a watcher takes no slot.
func LimitModel ¶ added in v0.2.0
LimitModel returns the model name a limit message or wait reason proves exhausted, or "" when the message names no model. It never reads a model from a URL.
func MemoryAt ¶ added in v0.1.1
MemoryAt is a worker's memory at percentile of its series: the 50th, 60th, 70th, 80th or 95th, the first of them at or above percentile; the 95th when that one was never recorded (a worker measured before Djinn kept it), then the peak.
func Mockup ¶ added in v0.2.0
Mockup tells whether the task is a mockup task (TASK_KIND_MOCKUP): framed like an investigation, it puts a tilasm's next version, then revises the question it iterates on (Task.question).
func Overlap ¶
Overlap tells whether two sets of write scopes share a path: one names the other, or a folder holding it. No scope is the whole folder. Case is ignored, as on macOS and Windows.
func Planned ¶
Planned tells whether Djinn starts the task by itself, once it is ready: a task planned on this machine, or one whose worker Djinn resumes (cut short by a restart, or by its provider's usage limit). An azima never is: no worker runs it.
func ProviderMemory ¶ added in v0.1.1
ProviderMemory returns the memory of finished workers at percentile of their series (MemoryAt), by provider, the latest first.
func ProviderPeaks ¶ added in v0.1.1
ProviderPeaks returns the measured p95 memories (falling back to peak memories if p95 is unset) of finished workers, by provider, the latest first: the worker memory guardrail's baseline, never tied to the notch.
func QuestionWorker ¶
QuestionWorker tells whether Djinn started the task on a question (Task.role): it reads and runs djinn's commands, no build nor gate, so it holds no write scope; an agent all the same, it takes a slot like any worker (W577: the load bar's count is every agent that runs), and waits while the machine is under pressure or its memory would not hold it. On a full machine, an investigator takes the slot of a work task it pauses (Decision.Slot).
func ServedFirst ¶ added in v0.2.0
ServedFirst tells whether the task is served before the planned work, and may take, on a full machine, the slot of a work task it pauses (Decision.Slot): an investigator (Enlighten me), an investigation or a mockup. None is held by the paused workers that resume first, nor preempted itself.
func TypicalForecast ¶ added in v0.1.1
TypicalForecast returns the measured forecast per worker of the providers in use (or all measured providers), at the notch's percentile (machine.Policy.Percentile), or p.WorkerForecast() when none is measured.
func TypicalPeak ¶ added in v0.4.0
TypicalPeak returns the highest typical peak memory of a worker of the providers in use (or all measured providers), at the notch's percentile (machine.Policy.Percentile), without the margin: what machine.Policy.Slots takes as a peak. 0 when none is measured.
func Urgent ¶ added in v0.2.0
Urgent tells whether the lead marked the task urgent (Task.urgent) and it is still to run or runs: planned, waiting, running or paused. While planned it goes before every other planned task, takes a slot whatever the machine, as djinn task start does, and its integration branch's red push checks do not hold it. A watcher or an azima never is: neither takes a slot. It is of one of two classes: a repair, which unblocks the wish and goes first, or a task for the developer's quick feedback (Feedback). At most one task of a wish is urgent of each class at a time (UrgentOf).
func UrgentOf ¶ added in v0.2.0
UrgentOf is the urgent task of the wish among tasks (Urgent) of the class feedback says (Feedback, or a repair), other than the task except; nil when none is.
Types ¶
type AncestryChecker ¶ added in v0.1.1
AncestryChecker tells whether commit a is an ancestor of commit b in projectID: git merge-base --is-ancestor a b.
type BranchResolver ¶ added in v0.1.1
BranchResolver resolves the head SHA of branch in projectID, and tells whether the branch has no commit beyond the point it started from (noCommits).
type Decision ¶
type Decision struct {
Task *planv1.Task
// Why it waits.
Why string
// Why it never will start: it fails.
Failed string
// It waits for a dependency's work to be committed into the wish's integration branch: the integration commits
// that work at once.
Commit bool
// It waits for the machine alone: no slot free, the machine under pressure, or its memory short. Forced
// (djinn task start), it may start. A task that waits for one going first before it does not.
Machine bool
// It waits for room on the machine: Machine, or a task the memory holds goes before it (Task.room_wait). Neither
// its wish, a dependency, a push hold, a usage limit nor a write scope holds it.
Room bool
// It waits for a slot alone: the machine is not under pressure and its memory holds it. An investigator, an
// investigation, a merge or a repair pauses a work task for it (the harness's preemptForSlot): it takes that task's
// slot, never one more.
Slot bool
// What holds it while it waits (Task.hold): unspecified when it starts or fails.
Hold planv1.TaskHold
}
Decision is what a pass decides for one planned task. Why and Failed both empty: it starts now.
type Machine ¶
type Machine struct {
// Slots is the most workers that run at once, and Rule how it was decided.
Slots int
Rule string
// Pressure says why the machine is under pressure, "" when it is not: no worker starts then.
Pressure string
// Running is the number of workers that run now.
Running int
// Gates is the number of gates held outside the running workers: each takes a slot. Merges is how many of them
// Djinn holds to merge a task's work, settle a merge or check a push.
Gates, Merges int
// Keep keeps one slot free for the gates of merges and pushes, when the machine has more than one (Q26): a new
// worker never takes it, so a merge or a push never waits behind workers on a full machine. A merge's gate held
// outside the workers takes that slot. djinn up keeps it once its gates are served.
Keep bool
// Resuming is the number of workers paused by the load bar or for an investigator, which resume before any new
// task (Q123): each keeps its slot from a new work task. An investigator goes before them.
Resuming int
// Available is the memory available to new programs, in bytes; 0 when unknown, and then the memory holds no
// worker back. Policy weighs it against what a worker of the task's provider typically takes
// (machine.Policy.WorkerRoom).
Available uint64
// Total is the machine's total RAM in bytes; 0 when unknown.
Total uint64
Policy machine.Policy
}
Machine is what the machine allows now.
type Network ¶ added in v0.2.0
type Network struct {
// Down says since when the network is down, or that it may be while Djinn probes it: no worker starts then, a
// watcher neither. "" when it is up.
Down string
// OnePerPass: the network is back, and the work the outage stopped resumes one task per pass, so that its workers
// do not all call their providers at once; the tasks after it in the order wait their turn. Spent: the harness
// resumed a paused worker in this pass already, and no task starts besides.
OnePerPass, Spent bool
}
Network is what the network allows now (W285).
type Situation ¶
type Situation struct {
// contains filtered or unexported fields
}
Situation is what a pass knows: every task, every wish, which projects are in Git, and the machine. Its zero value knows nothing and limits nothing; New fills it.
func New ¶
func New(tasks []*planv1.Task, wishes []*planv1.Wish, git map[string]bool, machine *Machine) *Situation
New is the situation of tasks and wishes, all of them as the store lists them (oldest first), the projects in Git being git (a project not in it is not), and machine what the machine allows (nil: nothing limits).
func (*Situation) At ¶
At sets the time the situation is read at, which a usage limit's reset is compared with: the harness's clock.
func (*Situation) Blocker ¶
Blocker says why the task cannot start now (why), or why it never will (failed); both empty when it can start. Its wish must be active (not paused nor granted); then come the dependencies, its provider's usage limit, the write scopes, and the machine; a watcher only waits for its wish and its dependencies, a question worker for the machine's pressure and memory too. A wish the situation does not know does not hold the task.
func (*Situation) Engaged ¶ added in v0.1.1
Engaged is the sum of peak forecasts or measured peaks of the workers running or started in this pass.
func (*Situation) Held ¶ added in v0.1.1
Held is Blocker without the machine: what holds the task whatever the machine allows (its wish, a dependency, a push hold, its provider's usage limit, a write scope). A task forced to start (djinn task start) needs Held empty.
func (*Situation) Order ¶
Order is the planned tasks in the strict tiered order, the urgent tasks before all (Urgent), a repair before a task for feedback:
- Investigator workers (Enlighten me), followed by answer workers, then investigations and mockups;
- Correction workers, followed by review workers;
- Resumed work tasks (RESUMING: limits, restarts, preemptions);
- Work tasks: the first wish of the rank first, then the work of the first azima of its rank (Task.rank, work of no azima after it), then the tasks that unblock others (graph's critical path: most planned and waiting dependents first), then the others.
Within the first tiers and their sub-levels, ties are broken by the wish's rank, then its azimas' rank; then, in every tier, the oldest first, then by task ID. The tasks of a wish that is not active come last; Blocker keeps them waiting.
func (*Situation) Pass ¶
Pass decides for every planned task, in Order: the first wish of the rank first, then its first azima, then the oldest. Each task it starts counts as writing and takes a slot for the ones after it. An urgent task starts whatever the machine (Urgent).
func (*Situation) Start ¶
Start counts the task as started: it takes a slot and memory, and writes in its project unless it is a question worker; a watcher takes nothing.
func (*Situation) WithAccounts ¶ added in v0.4.0
WithAccounts tells the situation the sign-ins of the agents (T33): f says why no sign-in of a task's agent may take its worker now, each paused or held by a limit ("" when one may), and whether the task, waiting for the limit of the account it ran on, moves now to another one free.
func (*Situation) WithAncestry ¶ added in v0.1.1
func (s *Situation) WithAncestry(branchHead BranchResolver, isAncestor AncestryChecker) *Situation
WithAncestry equips the situation with functions to check branch heads and ancestry in Git repositories.
func (*Situation) WithLanes ¶ added in v0.4.0
WithLanes tells the situation the branch each task's work merges into, "" when it cannot tell (W630): under the per-azima strategy, its azima's own branch, else the wish's integration branch. A red push check, or a correction that repairs a branch, then holds only the tasks whose work merges into that branch.
func (*Situation) WithNetwork ¶ added in v0.2.0
WithNetwork tells the situation what the network allows now; nil: nothing holds back.
func (*Situation) WithQuestions ¶ added in v0.2.0
WithQuestions equips the situation with what names a question by its identifier: a task whose dependency waits on a blocking question (Task.wait_question_id) waits "for Q51".
func (*Situation) WithRunning ¶ added in v0.1.1
WithRunning equips the situation with a function to check if a task currently has an active worker run. A task whose status is RUNNING but has no active run (a lost process) is not counted as running.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package bench is the dispatch bench (T07): dispatch situations written as data, each with the decision expected by hand, and what a contender decides for each.
|
Package bench is the dispatch bench (T07): dispatch situations written as data, each with the decision expected by hand, and what a contender decides for each. |