Documentation
¶
Overview ¶
Package state persists the Assist/Delivery operating mode (PRD §7) in .orchestrator/state.json, machine-local and gitignored. A missing file means Assist; a file that cannot be read, parsed, or recognized is an error so callers fail closed (PRD §15).
Index ¶
- Constants
- func CheckConsistent(st *State, owner *lockfile.Owner) error
- func CompleteDelivery(repoRoot string) error
- func Save(repoRoot string, st *State) error
- type AbortResult
- type Attempt
- type Block
- type BlockResolution
- type Decision
- type Issue
- type Mode
- type Phase
- type PlanRef
- type Run
- type State
Constants ¶
const ( BlockOperational = "operational" BlockHuman = "human-decision" BlockWrong = "wrong-criterion" BlockArchitect = "return-to-architect" BlockSecret = "secret" )
const Path = ".orchestrator/state.json"
Path is the repo-relative location of the state file.
const SchemaVersion = 6
SchemaVersion is the state-file schema this build reads and writes. v3 adds the PR B per-issue lifecycle fields (Issue.Decision, DependsOn, Wave, LastReviewVerdict) and Run.StoppedReason. Before v5, Load rejected every earlier schema with the `orch abort` remediation. v4 preserves OpenCode's model-specific variant or explicit no-variant marker in every persisted Selection. Before v4, state carried only model+effort; after v4, Claude/Codex keep that shape and OpenCode uses the native one. Before v5 approvals bound only submitted plans and config revision strings. v5 records the effective-contract version and execution fingerprint. v4 is still readable for inspection; the run engine refuses to execute it under the new approval semantics. No active run is migrated. v6 records block causes and issue-local resolution history. v4/v5 remain inspectable but cannot execute with this engine; no active run is migrated.
Variables ¶
This section is empty.
Functions ¶
func CheckConsistent ¶
CheckConsistent verifies the invariant that delivery mode and the Delivery lock exist together and describe the same run. st and owner come from Load and lockfile.Inspect.
func CompleteDelivery ¶
CompleteDelivery returns a finished Delivery run to Assist and releases the lock (PRD §7 auto-return). Unlike Abort it is not a repair path: it requires a consistent delivery state owned by a matching lock and fails closed otherwise, so a caller cannot complete over a broken or already-assist state. Ordering matches EnterDelivery/Abort — state first, lock second — so a crash between the two leaves an orphaned lock that denies new runs (fail closed) until `orch abort` clears it.
func Save ¶
Save persists st under repoRoot: it stamps UpdatedAt, validates (the same check Load applies on read), then writes atomically. It is the incremental-persistence primitive the run engine calls after every Delivery sub-step (PRD §23), so a crash leaves the state file matching the last completed step.
Types ¶
type AbortResult ¶
type AbortResult struct {
// PriorRun is the delivery run the state file recorded, if any.
PriorRun *Run
// LockOwner is the readable owner of a released lock, if any.
LockOwner *lockfile.Owner
// LockCleared reports that a lock file (readable or not) was removed.
LockCleared bool
// StateReset reports that an unreadable or inconsistent state file
// was overwritten with assist.
StateReset bool
}
AbortResult describes what Abort found and did.
func Abort ¶
func Abort(repoRoot string) (*AbortResult, error)
Abort returns the repository to Assist and releases the Delivery lock (PRD §15). It is the explicit human recovery path, so it also clears corrupt state files and orphaned or unreadable locks, and it is idempotent. It never touches branches or worktrees. Ordering matters for crash safety: state first, lock second — see EnterDelivery.
type Attempt ¶
type Attempt struct {
Role manifest.Role `json:"role"`
Selection manifest.Selection `json:"selection"`
Failed bool `json:"failed"`
Reason string `json:"reason,omitempty"`
}
Attempt mirrors routing.Attempt in persistable form, so an issue's escalation history (routing.History) survives an orch restart (PR B; this package imports manifest, not routing, to stay off the routing policy dependency edge).
type Block ¶ added in v0.11.0
type Block struct {
ID int `json:"id"`
Cause string `json:"cause"`
Reason string `json:"reason"`
Resolution *BlockResolution `json:"resolution,omitempty"`
}
Block retains each block's identity, cause and original reason, including after resolution. IDs are one-based positions within this issue's history.
type BlockResolution ¶ added in v0.11.0
type Decision ¶
type Decision struct {
Role manifest.Role `json:"role"`
Executor manifest.Selection `json:"executor"`
Reviewer manifest.Selection `json:"reviewer"`
ReviewerDowngraded bool `json:"reviewer_downgraded"`
Rationale string `json:"rationale"`
}
Decision mirrors routing.Decision in persistable form: the current routing chosen for an issue, set at activation and updated by escalate. Like Attempt it keeps this package off the routing policy dependency edge — state imports manifest, never routing, and the run engine converts between the two.
type Issue ¶
type Issue struct {
PlanID string `json:"plan_id"`
Title string `json:"title"`
Phase Phase `json:"phase"`
Number int `json:"number,omitempty"`
URL string `json:"url,omitempty"`
// Branch is the feature branch name. Worktree is the worktree
// directory as a repo-relative slash path.
Branch string `json:"branch,omitempty"`
Worktree string `json:"worktree,omitempty"`
// DependsOn (plan ids) and Wave are copied from the plan at
// EnterDelivery so dispatch can enforce dependencies — every
// DependsOn issue merged or cleaned — without re-taking the plan.
DependsOn []string `json:"depends_on,omitempty"`
Wave int `json:"wave,omitempty"`
// Objective, AcceptanceCriteria, RequiredTests, and TestsCIDoesNotRun
// are the approved plan text, copied at EnterDelivery so dispatch
// hands the executor a transcription of what a human approved rather
// than a recollection of it. Before v6, `orch resume` repopulated them
// from the issue body's audit record. Now that record is checked against
// state: edited GitHub text cannot amend the approved work.
//
// They are optional in the persisted file rather than required by
// validateIssues because a run activated by a build older than the
// schema-2 audit record carries none — and resume cannot repair that
// run. Its issue bodies still hold the older record manifest.Parse
// refuses, so resume takes its failure path and blocks the issue
// instead of repopulating anything. The remediation there is abort,
// never resume (internal/run/dispatch.go, checkApprovedWork).
//
// TestsCIDoesNotRun is optional for a second reason of its own, which
// does not extend to the three fields above it: an empty list is the
// honest reading of a plan that declared nothing, not a gap in a
// record, so checkApprovedWork does not require it and no phase
// treats its absence as damage.
Objective string `json:"objective,omitempty"`
AcceptanceCriteria []string `json:"acceptance_criteria,omitempty"`
RequiredTests []string `json:"required_tests,omitempty"`
TestsCIDoesNotRun []string `json:"tests_ci_does_not_run,omitempty"`
// Decision is the current routing for the issue, set at activation
// and updated by escalate. Required from the dispatched phase onward.
Decision *Decision `json:"decision,omitempty"`
// PR B lifecycle fields.
PRNumber int `json:"pr_number,omitempty"`
PRURL string `json:"pr_url,omitempty"`
ApprovedHeadOID string `json:"approved_head_oid,omitempty"`
ReviewCycles int `json:"review_cycles,omitempty"`
// LastReviewVerdict is "", "approve", or "request-changes": the gate
// merge-report checks without parsing bodies.
LastReviewVerdict string `json:"last_review_verdict,omitempty"`
BlockedReason string `json:"blocked_reason,omitempty"`
Attempts []Attempt `json:"attempts,omitempty"`
Blocks []Block `json:"blocks,omitempty"`
}
Issue is one plan issue's persisted Delivery state.
func (Issue) DecisionPending ¶ added in v0.11.0
DecisionPending fails closed for old blocks without structured provenance. Observations can discharge operational blocks, never a decision.
type Phase ¶
type Phase string
Phase is one issue's position in the Delivery lifecycle (PRD §12). The set is closed. Activation (PR A) writes Planned, IssueCreated, and WorktreeReady; the per-issue lifecycle verbs (PR B) drive the rest. PhaseCleaned is terminal.
const ( // PhasePlanned is an issue's state immediately after EnterDelivery, // before its GitHub issue exists. PhasePlanned Phase = "planned" // PhaseIssueCreated marks a created GitHub issue, before its // branch/worktree exist. PhaseIssueCreated Phase = "issue-created" // PhaseWorktreeReady marks a created branch and worktree, ready for // dispatch. PhaseWorktreeReady Phase = "worktree-ready" // PhaseDispatched marks an issue handed to an executor (branch // fast-forwarded, status in-progress). PhaseDispatched Phase = "dispatched" // PhasePROpen marks an opened pull request awaiting review. PhasePROpen Phase = "pr-open" // PhaseInReview marks an issue in a review cycle. PhaseInReview Phase = "in-review" // PhaseAwaitingMerge marks an approved PR pinned to its head OID, // waiting at the human merge gate. PhaseAwaitingMerge Phase = "awaiting-merge" // PhaseMerged marks a merged PR with its issue closed. PhaseMerged Phase = "merged" // PhaseCleaned is terminal: remote branch, worktree, and local // branch removed. PhaseCleaned Phase = "cleaned" // PhaseAbandoned marks an issue closed without merging; its branch // and worktree are preserved until cleanup. PhaseAbandoned Phase = "abandoned" // PhaseBlocked marks an issue awaiting recovery. Before v6, resume // could clear every block; decisions now require an explicit resolution // or fresh plan approval. Operational recovery still uses `orch resume`. PhaseBlocked Phase = "blocked" )
type PlanRef ¶
type PlanRef struct {
Title string `json:"title"`
Digest string `json:"digest"`
ApprovedBy string `json:"approved_by"`
ApprovedAt time.Time `json:"approved_at"`
ConfigRevision string `json:"config_revision"`
ContractVersion int `json:"contract_version,omitempty"`
ExecutionDigest string `json:"execution_digest,omitempty"`
}
PlanRef records the approved plan an active Delivery run was entered from (PRD §8). The engine cannot verify a human; this is the adapter's assertion, kept for the audit trail.
type Run ¶
type Run struct {
ID string `json:"id"`
Host string `json:"host"` // "claude", "codex", or "opencode"
StartedAt time.Time `json:"started_at"`
Plan PlanRef `json:"plan"`
Issues []Issue `json:"issues"`
// StoppedReason is non-empty when a secret block stopped the whole
// run (PRD §16): every mutating verb but block itself then fails
// closed until `orch abort` or `orch resume` (with its explicit
// resume-stopped-run statement).
StoppedReason string `json:"stopped_reason,omitempty"`
}
Run describes the active Delivery run.
type State ¶
type State struct {
SchemaVersion int `json:"schema_version"`
Mode Mode `json:"mode"`
Run *Run `json:"run,omitempty"` // non-nil iff Mode is delivery
UpdatedAt time.Time `json:"updated_at"`
}
State is the persisted operating state.
func EnterDelivery ¶
EnterDelivery acquires the cross-host Delivery lock and records a new delivery run over plan and issues. Ordering matters for crash safety: lock first, state second — a crash between the two leaves an orphaned lock, which denies every new run (fail closed) until `orch abort` clears it. The reverse order could leave delivery state without a lock, letting a second host acquire.
issues must all be at PhasePlanned and in the order the run engine wants them processed (wave order); plan.Digest must be non-empty (EnterDelivery does not recompute it — the caller has already validated the plan and its approval).