Documentation
¶
Overview ¶
Package task is the runtime layer's task handles (plan 02 §5), mirroring shepherd2/runtime/handles.py: a synchronous facade over the trace store. No scheduler, no goroutine management beyond the one StartTask spawns — callers wrap in goroutines if they want concurrency.
Python is strictly synchronous; the Go addition is StartTask, which runs the body in a goroutine and hands back a live Run whose Wait blocks until the terminal frontier exists. StartTaskSync is the faithful port — it runs the body inline, exactly like Python's @task start, and its record trace is ID-identical to the reference for the same fixture (pinned by TestStartTaskSyncMatchesPythonVector).
Error-shape divergence, recorded rather than hidden: Python formats a task failure as "{ExceptionType}: {message}" because exceptions carry types. Go's TaskFunc returns (map, error); a failed run records err.Error() as the failure text, and a panic records "panic: <value>". The record shapes are identical — only the error text's provenance differs.
Index ¶
- type ChildHandle
- func (h *ChildHandle) Cutoff(ctx context.Context) (trace.Frontier, error)
- func (h *ChildHandle) ExecutionID() string
- func (h *ChildHandle) FrontierID() string
- func (h *ChildHandle) Relation() trace.ExecutionRelation
- func (h *ChildHandle) RelationID() string
- func (h *ChildHandle) Snapshot(ctx context.Context) (*trace.Execution, error)
- func (h *ChildHandle) Wait(ctx context.Context) (*trace.Execution, error)
- type Registry
- type Run
- type TaskControl
- func (c *TaskControl) Abandon(ctx context.Context, handle *ChildHandle) (trace.ExecutionRelation, error)
- func (c *TaskControl) Adopt(ctx context.Context, executionID, frontierID, relationID string) (*ChildHandle, error)
- func (c *TaskControl) AwaitTerminal(ctx context.Context, handle *ChildHandle) (*trace.Execution, error)
- func (c *TaskControl) CausalTail() string
- func (c *TaskControl) Publish(ctx context.Context, kind string, data map[string]any) (trace.Record, error)
- func (c *TaskControl) ReadExecution(ctx context.Context, executionID string) (*trace.Execution, error)
- func (c *TaskControl) Spawn(ctx context.Context, taskRef string, inputs map[string]any, reg *Registry) (*ChildHandle, error)
- type TaskFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ChildHandle ¶
type ChildHandle struct {
// contains filtered or unexported fields
}
ChildHandle is the live handle for a child execution related to a parent. A child handle only exists once the child is terminal — Spawn runs the child synchronously, and Adopt validates the frontier before recording the relation — so Wait never waits: it reads the retained cutoff once, exactly like Python's handle, whose cutoff property would raise on a missing frontier.
func (*ChildHandle) ExecutionID ¶
func (h *ChildHandle) ExecutionID() string
func (*ChildHandle) FrontierID ¶
func (h *ChildHandle) FrontierID() string
func (*ChildHandle) Relation ¶
func (h *ChildHandle) Relation() trace.ExecutionRelation
func (*ChildHandle) RelationID ¶
func (h *ChildHandle) RelationID() string
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry maps task refs to bodies. The task ref is the caller's string — Python derives it from the class's module and qualname; Go has no equivalent, so the registry key IS the task ref, recorded in the created fact verbatim.
The map is mutex-guarded because StartTask runs lookups on task goroutines; registering while a task is in flight would otherwise be a fatal concurrent map access.
func NewRegistry ¶
func NewRegistry() *Registry
type Run ¶
type Run struct {
// contains filtered or unexported fields
}
Run is the live handle for one root execution. For a StartTask run it carries the body's completion channel, so a failed body surfaces through Wait instead of polling forever for a frontier that will never exist.
func StartTask ¶
func StartTask(ctx context.Context, store *trace.SQLiteTraceStore, reg *Registry, taskRef, runID string, inputs map[string]any) (*Run, error)
StartTask runs a task in a goroutine and returns immediately with a live Run; Wait blocks until the body has recorded its terminal frontier, and a failed body surfaces through Wait as an error rather than a hang. This is the Go-idiom addition documented in the file header.
func StartTaskSync ¶
func StartTaskSync(ctx context.Context, store *trace.SQLiteTraceStore, reg *Registry, taskRef, runID string, inputs map[string]any) (*Run, error)
StartTaskSync runs a task synchronously — the faithful port of Python's @task start. An empty runID generates one ("run:<32 hex>", the shape of Python's uuid4().hex). The returned Run is terminal by the time it exists.
func (*Run) ExecutionID ¶
func (*Run) FrontierID ¶
func (*Run) Snapshot ¶
Snapshot returns the CURRENT projected execution — pending, running or terminal — without waiting for anything: it folds the owner prefix as it stands. Unlike Wait it never blocks on the frontier.
type TaskControl ¶
type TaskControl struct {
// contains filtered or unexported fields
}
TaskControl is the parent-owned control surface available while a task body runs.
func (*TaskControl) Abandon ¶
func (c *TaskControl) Abandon(ctx context.Context, handle *ChildHandle) (trace.ExecutionRelation, error)
Abandon records that a related child is no longer effective for this parent, keyed by the child handle's relation id so the latest-wins fold drops it from effective history. The child's terminal cutoff is read once, without polling: Python's abandon reads handle.cutoff as a property, which raises on a missing frontier — a child without a terminal cutoff cannot be abandoned, it can only be left alone.
func (*TaskControl) Adopt ¶
func (c *TaskControl) Adopt(ctx context.Context, executionID, frontierID, relationID string) (*ChildHandle, error)
Adopt records a parent-owned adopted relation to an existing execution. The frontier must exist and target the named execution — a dangling relation would make the parent's effective history unresolvable, so both are checked before anything is appended. An empty relationID derives one from the adopt intent.
func (*TaskControl) AwaitTerminal ¶
func (c *TaskControl) AwaitTerminal(ctx context.Context, handle *ChildHandle) (*trace.Execution, error)
AwaitTerminal observes a child's terminal cutoff and returns the projected execution. It also advances this control's causal tail to the child's terminal frontier record, matching the reference.
func (*TaskControl) CausalTail ¶
func (c *TaskControl) CausalTail() string
CausalTail returns the latest parent-visible fact for subsequent appends.
func (*TaskControl) Publish ¶
func (c *TaskControl) Publish(ctx context.Context, kind string, data map[string]any) (trace.Record, error)
Publish appends a parent-owned fact into the current execution trace and advances the causal tail to it. Python returns the Fact; Go returns the retained trace.Record. A nil data map publishes {}, never JSON null — Python's dict(data or {}) normalizes the same way.
func (*TaskControl) ReadExecution ¶
func (c *TaskControl) ReadExecution(ctx context.Context, executionID string) (*trace.Execution, error)
ReadExecution reads a known child execution from its retained frontier.
func (*TaskControl) Spawn ¶
func (c *TaskControl) Spawn(ctx context.Context, taskRef string, inputs map[string]any, reg *Registry) (*ChildHandle, error)
Spawn runs a child task synchronously and returns its handle, recording a spawned relation on this execution's owner path. The child's run id is "<parent run id>:child:<n>".
The relation is recorded before the child runs — the cross-language contract, since the child's create batch is caused-by the relation fact. A child that cannot run records its own failure and still publishes a terminal frontier, so the relation's child_frontier_id resolves unless the store itself failed mid-spawn.
type TaskFunc ¶
type TaskFunc func(control *TaskControl) (map[string]any, error)
TaskFunc is one programmatic task body. It returns the run's outputs; a nil map means no outputs. Python's _coerce_outputs has a {"result": x} fallback for non-dict returns — Go's signature makes that case unexpressible, so nil is the only empty form.