dispatch

package
v0.0.10 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 12, 2026 License: MIT Imports: 19 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package dispatch wires inbound WebSocket frames to the agent layer. It owns one Turn per active RunID and a per-Turn output goroutine that forwards the agent's events to the transport.

Concurrency: Handle is safe for one goroutine (typically the read loop). Each session runs its own goroutine. Internal state is mutex-protected.

Index

Constants

This section is empty.

Variables

View Source
var ErrRouterBusy = errors.New("dispatch: router has unsettled work")
View Source
var ErrRouterClosed = errors.New("dispatch: router closed")
View Source
var ErrRouterQuiesced = errors.New("dispatch: router quiesced")

ErrRouterQuiesced also wraps failed quiesce attempts that have fenced admission.

Functions

This section is empty.

Types

type Config

type Config struct {
	Registry           *agent.Registry
	Sender             Sender
	Log                *slog.Logger
	IdleTimeout        time.Duration
	PreparationTimeout time.Duration
	LocalWorkspace     *localworkspace.Binding
}

Config is the constructor input. Registry and Sender are required; Log is optional (defaults to slog.Default()).

type Router

type Router struct {
	// contains filtered or unexported fields
}

Router maps inbound Envelopes to agent sessions.

func New

func New(cfg Config) (*Router, error)

New returns a Router ready to Handle inbound frames.

func (*Router) ActiveRuns

func (r *Router) ActiveRuns() int

ActiveRuns returns the in-flight run count. Wired into the heartbeat payload supplier.

func (*Router) Handle

func (r *Router) Handle(ctx context.Context, env proto.Envelope) error

Handle dispatches one inbound Envelope. Errors are returned for programmer-visible problems (bad shape, registry miss); transient session-level failures are logged and swallowed.

Adopts env.Trace into ctx so every downstream log under it inherits the same trace_id, making a single grep cover both sides.

func (*Router) Quiesce

func (r *Router) Quiesce(ctx context.Context, request proto.EnvironmentSuspendPayload) error

Quiesce serializes against admission, then drains every admitted output and receipt while retaining settled idle Executors for suspension. Busy rejection leaves admission open; a drain timeout keeps it closed until the caller shuts the connection down.

func (*Router) Resume

func (r *Router) Resume(request proto.EnvironmentSuspendPayload, sender Sender) error

Resume opens admission only after the caller authenticated a new connection and Core confirmed the exact suspension identity on that connection.

func (*Router) Shutdown

func (r *Router) Shutdown(ctx context.Context) error

Shutdown stops admission and waits for owned cleanup. A later call retries only failed cleanup; caller timeouts never abandon or duplicate in-flight work.

type Sender

type Sender interface {
	Send(ctx context.Context, env proto.Envelope) error
}

Sender is the subset of transport.Conn the dispatcher needs. Tests supply a fake; production wires this to *transport.Conn.Send.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL