multiplex

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package multiplex is part of the GoFastr harness.

See docs/harness-architecture.md for the architecture this package implements.

Package multiplex implements the multi-client routing layer that sits between transports and the engine. Per hard rule 7, this is where "engine knows about clients, not transports" lives.

Responsibilities:

  • Track all attached clients per session.
  • Total-order SendInput across all transports (mid-turn input rejected with TurnInProgress; rule 9).
  • Track originator for each turn so PermissionRequested events carry the right ClientID.
  • Enforce permission arbitration: agents cannot self-approve (rule 11); at least one human ack required by default.
  • Broadcast events to all attached clients of a session.
  • Route AnswerPermission deliveries to the engine.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnknownSession         = errors.New("multiplex: unknown session")
	ErrNoPendingPermission    = errors.New("multiplex: no pending permission")
	ErrAgentCannotSelfApprove = errors.New("multiplex: agent cannot self-approve permission (rule 11)")
	ErrHumanAnswerRequired    = errors.New("multiplex: a human-class client must answer this prompt")
	ErrAnswerChannelFull      = errors.New("multiplex: permission answer channel full (race)")
	ErrUnhandledCommand       = errors.New("multiplex: command not handled at this layer")
)

Errors. These are wire-format Reason codes for control.Error events.

Functions

This section is empty.

Types

type Mux

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

Mux is the multiplexer. One per harness process; manages multiple EngineRuns simultaneously.

func New

func New() *Mux

New returns an empty Mux.

func (*Mux) Attach

func (m *Mux) Attach(session ids.SessionID, c control.Client) error

Attach registers a client with the mux for one session. The client will receive broadcast events and can issue commands via Dispatch.

func (*Mux) Detach

func (m *Mux) Detach(session ids.SessionID, clientID ids.ClientID)

Detach removes a client. Non-destructive at the engine level — the EngineRun continues, events still flow to other attached clients.

func (*Mux) Dispatch

func (m *Mux) Dispatch(ctx context.Context, c control.Client, cmd control.Command) error

Dispatch is the single entry point for client → engine commands. All transports call this; the mux enforces total ordering, identity rules, and routes the command.

Returns an error event Reason on failure (caller wraps as control.Error and sends to the originating client).

func (*Mux) EngineFor

func (m *Mux) EngineFor(session ids.SessionID) *engine.Engine

EngineFor returns the engine for a session, or nil.

func (*Mux) HasHumanAttached

func (m *Mux) HasHumanAttached(session ids.SessionID) bool

HasHumanAttached reports whether at least one human-class client is currently attached to the session.

func (*Mux) RegisterEngine

func (m *Mux) RegisterEngine(e *engine.Engine)

RegisterEngine binds an EngineRun to the multiplexer. Subsequent Attach calls for the same session can connect clients to it.

func (*Mux) Subscribe

func (m *Mux) Subscribe(session ids.SessionID, callID ids.CallID) <-chan engine.PermissionAnswer

Subscribe implements engine.AnswerRouter — the permission middleware calls Subscribe to wait for answers.

func (*Mux) UnregisterEngine

func (m *Mux) UnregisterEngine(session ids.SessionID)

UnregisterEngine removes a session from the mux. Attached clients receive SessionEnded as the engine shuts down separately.

func (*Mux) Unsubscribe

func (m *Mux) Unsubscribe(session ids.SessionID, callID ids.CallID)

Unsubscribe is called by the middleware when the permission resolves (allowed, denied, or timed out).

type TurnInProgressError

type TurnInProgressError struct {
	OriginatorID ids.ClientID
}

TurnInProgressError matches control.ReasonTurnInProgress on the wire.

func (*TurnInProgressError) Error

func (e *TurnInProgressError) Error() string

Jump to

Keyboard shortcuts

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