loop

package
v0.1.22 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MarkAttachmentReady added in v0.1.18

func MarkAttachmentReady(ctx context.Context)

func RunControlLoop

func RunControlLoop(ctx context.Context, config bridgeconfig.Config) error

func RunControlLoopWithCodec added in v0.1.18

func RunControlLoopWithCodec(ctx context.Context, config bridgeconfig.Config, codec ControlCodec) error

func ShouldHandle

func ShouldHandle(config bridgeconfig.Config, event protocol.Event) bool

func WithAttachmentReady added in v0.1.18

func WithAttachmentReady(ctx context.Context, ready func()) context.Context

Types

type AsyncControlCodec added in v0.1.18

type AsyncControlCodec interface {
	StartControlAsync(context.Context, *MoltnetClient, bridgeconfig.Config) error
	ControlAccepted(bridgeconfig.Config, protocol.Event, ControlAcceptance) error
	// WaitControlAsync blocks until everything StartControlAsync spawned has
	// returned. RunControlLoopWithCodec cancels the context it handed to
	// StartControlAsync before calling this, so the wait is bounded by that
	// cancellation rather than by the work itself.
	//
	// Without it the loop cancelled the follower and returned immediately, so
	// RunControlLoopWithCodec returning did not mean the codec had stopped: a
	// follower could still be publishing a reply and writing its durable
	// receipt store after its caller believed shutdown was complete. A caller
	// then has no safe point to tear down the receipt store's directory, and
	// the goroutine outlives the loop that owns it.
	WaitControlAsync()
}

AsyncControlCodec persists accepted work before the inbound attachment ACK and follows its terminal result independently. Moltnet remains transport; the runtime remains responsible for execution policy and scheduling.

type ControlAcceptance added in v0.1.18

type ControlAcceptance struct {
	ID            string
	AgentID       string
	DeliveryID    string
	RequestDigest string
	AcceptedAt    time.Time
}

ControlAcceptance is runtime-neutral durable acceptance metadata. A codec may use it to start asynchronous terminal-receipt delivery after the attachment has already accepted the inbound event.

type ControlCodec added in v0.1.18

type ControlCodec interface {
	EncodeRequest(context.Context, bridgeconfig.Config, ControlDelivery) (*http.Request, error)
	DecodeResponse(bridgeconfig.Config, ControlDelivery, *http.Response) (ControlResult, error)
}

ControlCodec owns a runtime's request and response wire contracts. A nil request with no error intentionally skips a delivery, which lets runtimes without a bootstrap wire event opt out without branching in the loop.

type ControlDeferredError added in v0.1.19

type ControlDeferredError struct {
	Reason     string
	RetryAfter time.Duration
}

ControlDeferredError means the runtime has not accepted ownership yet, but may accept the same delivery later. It is backpressure, not a failed wake: leave the attachment cursor unchanged, then retry after a bounded delay. Runtime codecs validate the wire reason before constructing this error.

func (*ControlDeferredError) Error added in v0.1.19

func (e *ControlDeferredError) Error() string

type ControlDelivery added in v0.1.18

type ControlDelivery struct {
	Target        protocol.Target
	EventID       string
	From          string
	Message       string
	TransportText string
	OccurredAt    time.Time
}

ControlDelivery is the runtime-neutral wake material produced by the Moltnet stream. Runtime adapters own its wire encoding.

type ControlPublicationObserver added in v0.1.18

type ControlPublicationObserver interface {
	ControlResultPublished(ControlDelivery)
}

ControlPublicationObserver is an optional codec hook called only after a requested Moltnet publication succeeds.

type ControlResult added in v0.1.18

type ControlResult struct {
	Text        string
	Publish     bool
	PublishOnce bool
	Acceptance  *ControlAcceptance
}

ControlResult tells the shared loop whether a decoded runtime result should be published back to the inbound Moltnet conversation.

type DurableAcceptanceCodec added in v0.1.18

type DurableAcceptanceCodec interface {
	RequiresDurableAcceptance() bool
}

DurableAcceptanceCodec marks codecs whose successful response is the sole attachment ACK boundary. Failed acceptance must remain unacknowledged and replayable; it cannot be converted into a skipped delivery.

type MoltnetClient

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

func NewMoltnetClient

func NewMoltnetClient(config bridgeconfig.Config) *MoltnetClient

func (*MoltnetClient) ReportWakeFailed added in v0.1.14

func (c *MoltnetClient) ReportWakeFailed(
	ctx context.Context,
	requestPayload protocol.ReportWakeFailedRequest,
) error

ReportWakeFailed posts a terminal (permanent or retry-budget-exhausted) control-delivery wake failure to POST /v1/agents/wake-failed, so the server records agent.wake.failed for an event the bridge already ACKed and skipped, without tearing down the attachment socket to do so. See internal/bridge/loop/control_delivery.go's reportWakeFailure, the sole caller.

func (*MoltnetClient) SendMessage

func (c *MoltnetClient) SendMessage(
	ctx context.Context,
	requestPayload protocol.SendMessageRequest,
) (protocol.MessageAccepted, error)

func (*MoltnetClient) StreamEvents

func (c *MoltnetClient) StreamEvents(
	ctx context.Context,
	config bridgeconfig.Config,
	handle func(event protocol.Event) error,
) error

func (*MoltnetClient) StreamEventsReady

func (c *MoltnetClient) StreamEventsReady(
	ctx context.Context,
	config bridgeconfig.Config,
	onReady func(),
	handle func(event protocol.Event) error,
) error

Jump to

Keyboard shortcuts

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