dispatch

package
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 14, 2026 License: Apache-2.0 Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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

func Light(t *planv1.Task) bool

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

func MemoryAt(res *planv1.Resources, percentile int) uint64

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

func Overlap(a, b []string) bool

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

func Planned(t *planv1.Task) bool

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 Provider added in v0.1.1

func Provider(t *planv1.Task) string

Provider names the task's agent; none is claude.

func ProviderMemory added in v0.1.1

func ProviderMemory(tasks []*planv1.Task, percentile int) map[string][]uint64

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

func ProviderPeaks(tasks []*planv1.Task) map[string][]uint64

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

func QuestionWorker(t *planv1.Task) bool

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 Resuming

func Resuming(t *planv1.Task) bool

Resuming tells whether the task is one Djinn resumes.

func ScopeText

func ScopeText(scopes []string) string

ScopeText writes write scopes for a person.

func TypicalForecast added in v0.1.1

func TypicalForecast(tasks []*planv1.Task, p machine.Policy) uint64

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 Watcher

func Watcher(t *planv1.Task) bool

Watcher tells whether the task is a watcher: a command, no agent. It takes no slot and writes nothing, so neither the machine nor the write scopes hold it, and it holds no other task.

func WorkerMemory added in v0.1.1

func WorkerMemory(tasks []*planv1.Task, p machine.Policy, at ...time.Time) (engaged, actual uint64)

WorkerMemory returns the engaged memory (sum of peak forecasts or measured peaks for running workers) and actual resident memory of running workers.

Types

type AncestryChecker added in v0.1.1

type AncestryChecker func(projectID, a, b string) bool

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

type BranchResolver func(projectID, branch string) (head string, noCommits bool)

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

func (s *Situation) At(now time.Time) *Situation

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

func (s *Situation) Blocker(t *planv1.Task) (why, failed string)

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

func (s *Situation) Engaged() uint64

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

func (s *Situation) Held(t *planv1.Task) (why, failed string)

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

func (s *Situation) Order() []*planv1.Task

Order is the planned tasks in the strict 5-tier order:

  1. Investigator workers (Enlighten me), followed by answer workers;
  2. Correction workers, followed by review workers;
  3. Resumed work tasks (RESUMING: limits, restarts, preemptions);
  4. Work tasks that unblock others (graph's critical path: most planned and waiting dependents first);
  5. 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

func (s *Situation) Pass() []Decision

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

func (s *Situation) Start(t *planv1.Task)

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

func (s *Situation) WithRunning(isRunning func(taskID string) bool) *Situation

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL