queue

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: MIT Imports: 6 Imported by: ? 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 queue holds the Redis-backed run queue, the per-run control channel (cancel) and the per-run steer list.

Index

Constants

View Source
const (
	// Stream is the run queue.
	Stream = "work:runs"
	// Group is the consumer group of runtimes.
	Group = "runtime"
	// MaxSteers is the cap of pending steer messages per run.
	MaxSteers = 20
)

Variables

View Source
var (
	// ErrTooManySteers is returned when MaxSteers are already pending.
	ErrTooManySteers = errors.New("too many pending steer messages")
	// ErrSteersClosed is returned once the run stopped accepting steers (final step or finished).
	ErrSteersClosed = errors.New("the run no longer accepts messages")
)

Functions

func SteerMessages

func SteerMessages(threadID, runID string, steers []Steer) []*store.Message

SteerMessages turns steers that will not reach the model of this run into thread messages, so the next run sees them.

Types

type Bus

type Bus interface {
	PublishCancel(ctx context.Context, runID string) error
	// SubscribeCancel calls fn when a cancel is published; the returned func unsubscribes.
	SubscribeCancel(ctx context.Context, runID string, fn func()) (func(), error)
	// PushSteer fails with ErrSteersClosed after FinalizeSteers.
	PushSteer(ctx context.Context, runID string, s Steer) error
	DrainSteers(ctx context.Context, runID string) ([]Steer, error)
	// FinalizeSteers atomically stops accepting steers and returns the pending ones.
	FinalizeSteers(ctx context.Context, runID string) ([]Steer, error)
	// ReopenSteers accepts steers again (the run continues after all).
	ReopenSteers(ctx context.Context, runID string) error
	// CloseSteers stops accepting steers and returns the pending ones without
	// removing them: AckSteers removes them once they are stored elsewhere.
	CloseSteers(ctx context.Context, runID string) ([]Steer, error)
	// AckSteers removes the first n pending steers (stored by the caller).
	AckSteers(ctx context.Context, runID string, n int) error
	// SteerRuns lists the runs that may still hold pending steers (the
	// sweeper stores those of finished runs).
	SteerRuns(ctx context.Context) ([]string, error)
}

Bus carries per-run control signals and steers.

type Memory

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

Memory is an in-process run queue and control bus: it implements Queue, the runtime's RunQueue and Bus without Redis, for a host that runs the agent in its own process (TUI, desktop app, tests).

func NewMemory

func NewMemory() *Memory

NewMemory returns an empty in-memory queue and bus.

func (*Memory) Ack

func (q *Memory) Ack(context.Context, string) error

func (*Memory) AckSteers

func (q *Memory) AckSteers(_ context.Context, runID string, n int) error

func (*Memory) CloseSteers

func (q *Memory) CloseSteers(_ context.Context, runID string) ([]Steer, error)

func (*Memory) DrainSteers

func (q *Memory) DrainSteers(_ context.Context, runID string) ([]Steer, error)

func (*Memory) Enqueue

func (q *Memory) Enqueue(_ context.Context, runID string) error

func (*Memory) EnsureGroup

func (q *Memory) EnsureGroup(context.Context) error

EnsureGroup is a no-op.

func (*Memory) FinalizeSteers

func (q *Memory) FinalizeSteers(_ context.Context, runID string) ([]Steer, error)

func (*Memory) PruneConsumers

func (q *Memory) PruneConsumers(context.Context, string, time.Duration) (int, error)

func (*Memory) PublishCancel

func (q *Memory) PublishCancel(_ context.Context, runID string) error

func (*Memory) PushSteer

func (q *Memory) PushSteer(_ context.Context, runID string, s Steer) error

func (*Memory) Read

func (q *Memory) Read(ctx context.Context, _ string, count int, block time.Duration) ([]Message, error)

Read waits up to block for queued runs and hands out at most count of them. Delivery is at most once: a process that dies loses its queue anyway.

func (*Memory) Reclaim

func (q *Memory) Reclaim(context.Context, string, time.Duration) ([]Message, error)

Reclaim returns nothing: entries are not kept after Read.

func (*Memory) ReopenSteers

func (q *Memory) ReopenSteers(_ context.Context, runID string) error

func (*Memory) SteerRuns

func (q *Memory) SteerRuns(context.Context) ([]string, error)

func (*Memory) SubscribeCancel

func (q *Memory) SubscribeCancel(_ context.Context, runID string, fn func()) (func(), error)

type Message

type Message struct {
	StreamID string
	RunID    string
}

Message is a queue entry.

type MessageAppender

type MessageAppender interface {
	AppendMessages(ctx context.Context, msgs ...*store.Message) error
}

MessageAppender stores thread messages (store.Store).

type Queue

type Queue interface {
	Enqueue(ctx context.Context, runID string) error
}

Queue enqueues runs.

type Steer

type Steer struct {
	ID   string `json:"id"`
	Text string `json:"text"`
	// Author is who sent the steer, with AuthorKind and OnBehalfOf as on store.Message.
	Author     string `json:"author,omitempty"`
	AuthorKind string `json:"authorKind,omitempty"`
	OnBehalfOf string `json:"onBehalfOf,omitempty"`
}

Steer is a user message injected into a running run.

func KeepSteers

func KeepSteers(ctx context.Context, bus Bus, st MessageAppender, threadID, runID string, deadline time.Time) ([]Steer, error)

KeepSteers closes a run's steer list and stores its pending steers in the thread (delivered=false), retrying transient Redis/Postgres errors until deadline. It returns the steers that are stored (only those may be announced as kept); on error the steers stay pending in Redis, listed by SteerRuns, so the sweeper stores them later: an accepted steer is never lost.

Jump to

Keyboard shortcuts

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