Documentation
¶
Overview ¶
Package graph answers the static questions about a tasks.json DAG: is it valid, what order do the tasks go in, and what does it look like.
Everything here is a pure function of the tasks and, where routing matters, of a set of route keys. No I/O, no database, no clock — which is what lets `orch validate` run on a project that has never been dispatched.
Two of the three have a Python counterpart and are held to it:
- Validate ports `preflight.validate_graph`, message for message. The text is user-visible and `scripts/parity.sh` diffs it, so even the quoting style is copied.
- FindCycles ports `preflight.find_cycles`, including how it canonicalises a cycle so the same loop is not reported twice from different entry points.
DOT has no counterpart: Python emits a self-contained HTML page with inline SVG and no DOT anywhere. Go replaces that (see docs/brainstorm/ go-migration-notes.md), so its tests are its own.
Index ¶
- Constants
- func CriticalPath(tasks []model.Task) map[string]bool
- func DOT(tasks []model.Task) string
- func DisplayOrder(tasks []model.Task) []model.Task
- func DownstreamImpact(tasks []model.Task) map[string]int
- func FindCycles(tasks []model.Task) [][]string
- func HasErrors(problems []Problem) bool
- func Parallelizable(tasks []model.Task) []model.Task
- func Ready(tasks []model.Task) []model.Task
- func TopoOrder(tasks []model.Task) ([]string, error)
- type Orphan
- type PhaseRow
- type Problem
- type Projection
- type Severity
- type Summary
Constants ¶
const ( KindSchemaTasks = "schema.tasks" KindDepMissing = "dep.missing" KindDepCycle = "dep.cycle" KindRouteUnresolved = "route.unresolved" )
The kinds Validate can emit. Callers filter on these, so they are constants rather than literals scattered through the file.
const ProjectionTrustDays = 30
ProjectionTrustDays is where a projection stops being worth trusting: beyond a month, a pace measured over one week is extrapolating further than it can see.
Variables ¶
This section is empty.
Functions ¶
func CriticalPath ¶
CriticalPath returns the ids on the longest weighted path through the DAG.
Weight is `estimate_hours`, falling back to 1 when it is zero or absent so an un-estimated project still produces a path rather than collapsing to nothing. Direction follows `dependencies`: a task's time accumulates after its upstream finishes.
Kahn's order plus a DP, so it is O(V+E) and silent on cycles — a cycle stops draining the queue and whatever was computed before the stall is returned. That is Python's behaviour, and `FindCycles` is the function whose job is to complain about it.
Why the traversal order is reproduced exactly ¶
The DP result does not depend on the order ready nodes come off the queue — a node is only processed once every dependency has been. The FINAL PICK does: `max(dist, key=…)` returns the first key with the maximal value in dict insertion order, and insertion order comes from the pop order. So the stack pops from the end like Python's `list.pop()`, and the winner is found by scanning the ids in the order they entered `dist`. Two paths of equal length are not a hypothetical — they are what an un-estimated project of parallel branches is made of.
func DOT ¶
DOT renders the DAG as Graphviz DOT.
**This replaces Python's `orch graph`, it does not port it.** `graph.py` writes a self-contained HTML page with inline SVG; there is no DOT anywhere in the Python tree. The visual DAG lives in the dashboard now (GraphPage + /api/graph), so the CLI's job is the machine-readable form: pipeable into `dot`, greppable, and diffable in review. The change is recorded in docs/brainstorm/go-migration-notes.md as a visible contract change for anyone scripting `orch graph --out plan.html`.
The output is deterministic — phases in ascending order, tasks by id within a phase, edges in the order their dependencies are declared. Determinism is not a nicety here: it is what lets the output be a golden file and what keeps a re-render out of a diff.
Tasks are grouped into a subgraph per phase so `dot` lays them out in columns, which is the one thing the HTML version did that was actually worth keeping.
func DisplayOrder ¶
DisplayOrder returns tasks sorted by (phase, id) — the order `orch tasks` and `orch status` print, ported from `TaskQueue.all()` (FR-Q-2).
It is NOT a dependency order. A task can appear before something it depends on if the phases say so. That is fine for a listing, where the reader wants the same rows in the same places every time, and wrong for a scheduler.
func DownstreamImpact ¶
DownstreamImpact answers "unblock this and how many tasks become reachable".
Two rules make the number useful rather than merely large:
- Only NOT-DONE descendants count. A finished task no longer waits on anything, so it must not keep inflating the score of everything upstream of it once the chain has drained.
- Traversal still passes THROUGH done tasks, so pending work sitting below a completed intermediate node is still reached.
O(V+E) per task on one shared reverse adjacency.
func FindCycles ¶
FindCycles returns every dependency cycle as a path of task ids, closed — `A -> C -> B -> A`. Ported from `preflight.find_cycles`, including the details that decide WHICH path is reported, because `orch validate`'s output is diffed between the two binaries.
Three-colour DFS: white unvisited, grey on the stack, black done. A back edge to a grey node closes a cycle, and the path is reconstructed from the parent chain so the message names the actual edges rather than just asserting a cycle exists.
Self-loops are excluded: `validateDependencies` already reports them as `dep.cycle` with a clearer message, and including them here would report the same mistake twice.
The DFS is iterative. Python's comment says "to avoid stack overflow on very deep graphs"; Go's stacks grow, so the reason here is different and smaller — an iterative port is easier to check line-by-line against the original than a recursive rewrite would be, and this function's whole value is being the same as the original.
func HasErrors ¶
HasErrors reports whether any problem is fatal. `orch validate` exits non-zero on this, and warnings alone must not fail a build.
func Parallelizable ¶
Parallelizable returns the tasks whose dependencies no longer hold them back: backlog or todo, with every dependency already done. It is Python's analytics figure (the dashboard's `parallelizable`), not what a run dispatches — that is Ready.
A dependency that names a task nobody defined counts as NOT done. That is Python's `by_id.get(dep_id)` returning None, and it is the safe reading — a task whose dependency does not exist has an unmet dependency, whatever the reason. `OrphanDependencies` is how the operator finds out why.
Sorted by (phase, id), which is also how Python returns it.
func Ready ¶
Ready is what `orch run` would dispatch right now: Parallelizable narrowed to todo. A backlog task must be promoted first — engine.TaskQueue.Ready skips it — so calling it ready promised a dispatch that never came (#235). This is the notion every "ready" surface (orch explain, orch_context, orch_list_tasks{ready}) publishes.
func TopoOrder ¶
TopoOrder returns the task ids in dependency order: every task appears after everything it depends on.
**New in Go.** Python has no topological sort — `TaskQueue.all()` sorts by (phase, id) for display, and `TaskQueue.ready()` picks whatever has its dependencies satisfied right now. So this has no Python counterpart to be held to, and its tests are its own. It exists because the scheduler needs it, and because `orch graph` should be able to print a plan in the order it will actually happen.
Ties are broken by (phase, id), the same rule DisplayOrder uses, so the output is deterministic: the same tasks.json always produces the same order, which is what makes it diffable in a parity harness at all.
Returns an error when the graph cannot be ordered — a cycle, or a dependency on a task that does not exist. Both are already reported by Validate with a better message; the error here exists so a caller that skipped validation cannot silently receive a truncated order.
Types ¶
type Orphan ¶
Orphan is one dependency pointing at a task nobody defined.
func OrphanDependencies ¶
OrphanDependencies lists dependencies on ids that do not exist.
A healthy tasks.json has none; anything here is a typo, a deleted task, or a half-finished import. Reported in tasks order, then dependency order, so two runs on the same file produce the same list.
type PhaseRow ¶
PhaseRow is one phase's tally.
func PhaseCounts ¶
PhaseCounts tallies per phase, ordered by phase number.
Only phases that have at least one task appear — a project whose phases run 1, 2, 5 gets three rows, not five. Python's `defaultdict` has the same effect, and inventing empty rows for the gap would be inventing phases.
type Problem ¶
type Problem struct {
// TaskID and Remediation are pointers so that "not applicable" crosses the
// wire as `null` rather than as `""` or as an absent key.
//
// Python's `ValidationError.as_json` writes every key every time, with
// `None` where there is nothing to say: a task with no id has
// `"task_id": null`, and a problem with no fix to suggest has
// `"remediation": null`. `orch validate --json` output is diffed between
// the two binaries by scripts/parity.sh, so an omitted key and an empty
// string are both failures — and they are also different to a consumer,
// which can tell "no task" from "a task whose id is the empty string".
TaskID *string `json:"task_id"`
Field string `json:"field"`
Kind string `json:"kind"`
Message string `json:"message"`
Remediation *string `json:"remediation"`
Severity Severity `json:"severity"`
}
Problem is one finding, mirroring `preflight.ValidationError`.
`Kind` is the machine-stable tag callers filter on; `Message` is the human string. Both cross the wire in `orch validate --json`, so both are part of the compatibility contract rather than internal detail.
func Validate ¶
Validate runs every static check and returns the problems in the same order Python's `validate_graph` does: schema, then dependencies, then cycles, then routes.
`routes` is the set of keys from model_router.yaml. Pass nil to skip route checking entirely — that is how Python's `router_keys=None` behaves, and it is what `orch validate` does before the router has been loaded.
Deliberately NOT included, matching Python: `files.writable` and `preset.sanity`. Both do I/O, and a caller who wants them composes them explicitly rather than having a "static validation" call touch the disk.
type Projection ¶
type Projection struct {
// Days is the projection in days, to one decimal.
Days float64
// Date is the calendar day it lands on, YYYY-MM-DD (UTC).
Date string
// Confidence is "high" within ProjectionTrustDays, "low" beyond.
Confidence string
}
Projection is when the remaining work finishes at the measured pace.
func ProjectCompletion ¶
func ProjectCompletion(remainingTasks, doneInWindow, windowDays int, now time.Time) *Projection
ProjectCompletion projects a finish date from velocity: tasks finished in the last windowDays, applied to the tasks that remain. It is the one projection every surface shows (Sprint page, stakeholder summary, published snapshot, PDF), so they cannot quote different finishes for the same state.
nil means no projection — nothing left, or no pace measured yet — which a caller must show as "unknown", never as "done today".
type Severity ¶
type Severity string
Severity mirrors the Python field. Every static validator currently emits "error"; the field exists because `validate_files_writable` and `validate_preset_sanity` emit warnings, and they will land here later.
type Summary ¶
type Summary struct {
Total int
Done int
InProgress int
Blocked int
Backlog int
PercentDone float64
EstimateHoursTotal float64
}
Summary is the header bar: how many of each, how far along, how much work.
`Backlog` is backlog + todo deliberately, matching Python's comment: the operator asking "how much is left" does not care about the split, and two adjacent numbers that always move together read as one number badly.
func Summarize ¶
Summarize counts a project in one pass.
The `else` branch is why `Backlog` can exceed backlog+todo: any status that is not done / in-progress / blocked lands there, including one this build has never heard of. Python does the same, and the alternative — dropping unknown statuses — makes the numbers stop adding up to `Total`, which is the one property a header bar must have.