Documentation
¶
Overview ¶
Parallel agent work scheduling: runs a single assistant turn's independent work units up to agent.max_concurrency at a time, while serializing on declared dependencies and conflicting write targets. Permission-prompt non-overlap is NOT handled here — each unit's Run authorizes independently and the shared single-slot prompt gate guarantees prompts never overlap, so this package imports no dispatch, permission, or UI collaborators.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Schedule ¶
Schedule runs work for a single assistant turn, executing up to maxConcurrency units concurrently while honoring dependency ordering and serializing units with conflicting write targets in input order. maxConcurrency=1 disables parallelism entirely. It returns the first error encountered: an invalid plan (maxConcurrency < 1, duplicate IDs, an unknown dependency, a self-dependency, or a dependency cycle) is reported before any unit runs, so a bad plan never partially executes; otherwise the first Run error or context cancellation is returned. On the first failure no further units are launched and the derived run context is cancelled; already-running units are awaited (they may finish or observe the cancellation) before Schedule returns.
The scheduler is collaborator-agnostic: it only calls Run. Permission-prompt serialization is provided by the shared gated prompt binding the production authorizer wiring installs, not here, so concurrent Run calls authorize independently without the scheduler locking, queuing, or pre-resolving anything.
Types ¶
type WorkUnit ¶
type WorkUnit interface {
// ID returns this unit's stable identifier, unique within one Schedule call. Other units name it
// in their Deps to order after it.
ID() string
// Deps returns the IDs of units that must complete before this one runs. Every named ID must
// belong to a unit in the same Schedule batch.
Deps() []string
// Targets returns the write target paths or resource keys this unit mutates, used only to
// serialize conflicting writes. Read-only targets must not be listed. Two units with
// equal or path-overlapping targets are run in input order rather than concurrently.
Targets() []string
// Run executes the unit. It should honor ctx cancellation; the scheduler cancels a context
// derived from the caller's once any unit fails so cooperating units can stop early.
Run(ctx context.Context) error
}
WorkUnit is one independently schedulable piece of a single assistant turn. The scheduler orders units by their declared dependencies and conflicting write targets, then invokes Run; it never inspects what Run does. Run owns its own dispatch and authorization — the scheduler adds no prompt locking, batching, or pre-resolution (is the shared prompt gate's job).