Documentation
¶
Overview ¶
Package runs is the background-run table a front-end uses for long_running operations: Start reserves the operations registry's working-tree slot under a new run id and runs the operation in a goroutine, and Status / Result / Cancel / List address the run by that id afterwards. The table is front-end-neutral — the MCP server is its first user — and lives only as long as the process that holds it.
Index ¶
- type Collector
- func (*Collector) OnGateComplete(string, types.StepResults, time.Duration)
- func (*Collector) OnGateStart(string, []string)
- func (*Collector) OnPhaseComplete(string, types.StepResults, time.Duration)
- func (*Collector) OnPhaseStart(string, []string)
- func (c *Collector) OnStepComplete(result types.StepResult)
- func (*Collector) OnStepStart(string, string)
- func (c *Collector) Steps() []types.StepResult
- type Registry
- type Snapshot
- type State
- type Table
- func (t *Table) Cancel(id string) error
- func (t *Table) CancelAll()
- func (t *Table) List() []Snapshot
- func (t *Table) Result(id string) (Snapshot, error)
- func (t *Table) Start(ctx context.Context, name string, input any) (string, error)
- func (t *Table) Status(id string) (Snapshot, error)
- func (t *Table) Wait()
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Collector ¶
type Collector struct {
// contains filtered or unexported fields
}
Collector is the ExecutionObserver an operation runs under when a front-end shapes its result afterwards: it records every completed step as reported, a group step with its children still nested on it (the group carries its own status, error and output; the children are its breakdown). The engine serializes observer calls, but a run's steps are read while it is still reporting, so the record is mutex-guarded. The zero value is ready to use.
func (*Collector) OnGateComplete ¶
OnGateComplete is a no-op; its results were already reported step by step.
func (*Collector) OnGateStart ¶
OnGateStart is a no-op; the collector records only completed steps.
func (*Collector) OnPhaseComplete ¶
OnPhaseComplete is a no-op; its results were already reported step by step.
func (*Collector) OnPhaseStart ¶
OnPhaseStart is a no-op; the collector records only completed steps.
func (*Collector) OnStepComplete ¶
func (c *Collector) OnStepComplete(result types.StepResult)
OnStepComplete records result, children included.
func (*Collector) OnStepStart ¶
OnStepStart is a no-op; the collector records only completed steps.
func (*Collector) Steps ¶
func (c *Collector) Steps() []types.StepResult
Steps returns a copy of the recorded steps.
type Registry ¶
type Registry interface {
// Reserve takes the slot for the operation named name on behalf of holder; a held
// slot fails with CodeUnavailable "busy: <holder> is running".
Reserve(name, holder string) (interfaces.Reservation, error)
}
Registry is the slice of the operations registry the table needs: reserving the working-tree slot for one operation on behalf of a holder (the run id).
interface-composition exemption — the consumer-side contract between the run table and execution/ops.Registry, with no core interface to embed.
type Snapshot ¶
type Snapshot struct {
// Started is when Start launched the run.
Started time.Time
// Ended is when the operation returned; zero while running.
Ended time.Time
// Err is the operation's coded error; nil while running or on success.
Err error
// LogPaths is the log paths onDone returned, aligned with the front-end's
// flattened view of Steps; nil while running.
LogPaths []string
// ID is the run id Start returned.
ID string
// Op is the operation's name.
Op string
// State is where the run is in its life.
State State
// Steps is every step the operation has completed so far, in order, a group step
// with its children nested.
Steps []types.StepResult
}
Snapshot is a point-in-time copy of one run.
type State ¶
type State string
State is where a run is in its life.
const ( // StateRunning is a run whose operation has not returned yet. StateRunning State = "running" // StateSucceeded is a run whose operation returned nil. StateSucceeded State = "succeeded" // StateFailed is a run whose operation returned an error other than a cancel // (a timeout included). StateFailed State = "failed" // StateCancelled is a run stopped by Cancel or CancelAll. StateCancelled State = "cancelled" )
type Table ¶
type Table struct {
// contains filtered or unexported fields
}
Table tracks the background runs of one front-end session. Build it with New.
func New ¶
func New( reg Registry, newID func() string, onDone func(Snapshot) ([]string, error), keep int, ) *Table
New builds an empty table that reserves through reg, mints run ids with newID, and calls onDone (when non-nil) once per run as it ends — the front-end's hook to persist the run's step logs. It remembers at most keep finished runs, forgetting the oldest first (keep <= 0 remembers every run); a running run is never forgotten.
func (*Table) Cancel ¶
Cancel cancels run id's context; the run ends cancelled once its operation returns. Cancelling a finished run is a no-op; an unknown id fails with CodeNotFound.
func (*Table) CancelAll ¶
func (t *Table) CancelAll()
CancelAll cancels every run and refuses any later Start: the front-end's shutdown.
func (*Table) Result ¶
Result returns run id's final snapshot. A run still running fails with CodeConflict; an unknown id with CodeNotFound.
func (*Table) Start ¶
Start reserves the slot for the operation named name under a new run id and runs it in the background with input, returning the id at once. The run keeps ctx's values but not its cancellation: it outlives the call that started it and ends on its own, on its operation's timeout, or on Cancel / CancelAll. A reservation failure (unknown, excluded, or busy) is returned as is; a table that is shutting down fails with CodeUnavailable, and a run id the table already holds with CodeInternal.