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 Light(t *planv1.Task) bool
- func MemoryAt(res *planv1.Resources, percentile int) uint64
- 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 TypicalForecast(tasks []*planv1.Task, p machine.Policy) uint64
- 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 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) WithAncestry(branchHead BranchResolver, isAncestor AncestryChecker) *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. This matches Djinn's machine idle threshold (DefaultIdleThreshold = 3 * time.Minute).
Variables ¶
This section is empty.
Functions ¶
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 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 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 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.
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 a slot alone: the machine is not under pressure and its memory holds it. An investigator pauses
// a work task for it (the harness's preemptForSlot): it takes that task's slot, never one more.
Slot bool
}
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.
Gates int
// 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 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 5-tier order:
- Investigator workers (Enlighten me), followed by answer workers;
- Correction workers, followed by review workers;
- Resumed work tasks (RESUMING: limits, restarts, preemptions);
- Work tasks that unblock others (graph's critical path: most planned and waiting dependents first);
- Other work tasks.
Within each level and sub-level, ties are broken by the wish's rank, then 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, the first wish of the rank first, then the oldest: each task it starts counts as writing and takes a slot for the ones after it.
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) 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) 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. |