worker

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Package worker implements the private same-executable parent/child transport.

Protocol types, frame codecs, and connection state machines are not public API. They exist only between a host process and a worker re-exec of the same binary.

Index

Constants

This section is empty.

Variables

View Source
var ErrProtocol = errors.New("worker protocol violation")

ErrProtocol lets the authoritative root dispatcher report an impossible child ID or re-bind mismatch.

Functions

func IsWorker

func IsWorker() bool

IsWorker reports whether the current process carries the private worker marker.

func Serve

func Serve() int

Serve serves exactly one request from os.Stdin and os.Stdout and returns process status 0/1.

Types

type Dispatch

type Dispatch func(context.Context, authz.Subject, string, map[string]any, int) (any, error)

Dispatch invokes one authoritative parent capability operation.

remainingIntermediateBytes is the unused native-result value-body budget for this execution. handleNative passes min(MaxValueBytes, remainingIntermediate); the dispatcher uses that as the ConvertOutput node and materialization limit. Exact encoded-byte debit stays in writeNativeResult.

type Limits

type Limits struct {
	// MaxSourceBytes bounds submitted source length.
	MaxSourceBytes int

	// MaxExecutionSteps bounds interpreter work.
	MaxExecutionSteps uint64

	// MaxExecutionTime bounds elapsed execution time including queue wait.
	MaxExecutionTime time.Duration

	// MaxNativeCalls bounds attempted native invocations.
	MaxNativeCalls uint64

	// MaxValueDepth bounds recursive converted-value nesting.
	MaxValueDepth int

	// MaxValueBytes bounds type-preserving encoded value size.
	MaxValueBytes int

	// MaxIntermediateValueBytes bounds cumulative successful native-result
	// value-body bytes for one Execute call. It is independent of MaxValueBytes
	// and is never projected to the child.
	MaxIntermediateValueBytes int

	// MaxConcurrentExecutions bounds live worker children.
	MaxConcurrentExecutions int
}

Limits is the parent-owned immutable worker budget set.

type Runner

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

Runner owns immutable manifest, budgets, caps, dispatch, and live-child permits.

func NewRunner

func NewRunner(bindings []execution.CapabilityBinding, limits Limits, dispatch Dispatch) (*Runner, error)

NewRunner constructs an immutable runner after validating budgets, manifest, and frame caps.

func (*Runner) Execute

func (r *Runner) Execute(ctx context.Context, subject authz.Subject, source string) (any, error)

Execute runs source in a fresh worker and returns the decoded final value.

func (*Runner) Probe

func (r *Runner) Probe() error

Probe runs one five-second same-executable handshake and returns a worker-level error.

Jump to

Keyboard shortcuts

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