processes

package
v0.62.3 Latest Latest
Warning

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

Go to latest
Published: May 20, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const MaxBufferBytes = 1 << 20 // 1 MiB

MaxBufferBytes is the per-session cap on accumulated stdout+stderr. Anything beyond this is truncated from the head of the ring; the session records how many bytes were lost so the SDK can warn.

Variables

This section is empty.

Functions

This section is empty.

Types

type Chunk

type Chunk struct {
	Stream string `json:"stream"` // "stdout" or "stderr"
	Data   []byte `json:"-"`
	Seq    int    `json:"seq"`
}

Chunk is one stdout or stderr segment delivered to the SDK. Seq is monotonically increasing per-session starting at 1; the SDK passes the highest Seq it has seen as the `since` query param to get only newer chunks.

type Manager

type Manager struct {
	IdleTimeout time.Duration
	// contains filtered or unexported fields
}

Manager owns the in-process session table. Call Run() at startup to spawn the background goroutine that calls Sweep() every minute; sessions inactive for IdleTimeout are dropped (the SDK polling stops returning their output and the session ID goes 404).

func NewManager

func NewManager(idleTimeout time.Duration) *Manager

func (*Manager) Forget

func (m *Manager) Forget(id string)

func (*Manager) Get

func (m *Manager) Get(id string) (*Session, bool)

func (*Manager) Register

func (m *Manager) Register(s *Session)

func (*Manager) Run

func (m *Manager) Run()

Run starts a goroutine that calls Sweep every minute until Stop().

func (*Manager) Stop

func (m *Manager) Stop()

func (*Manager) Sweep

func (m *Manager) Sweep()

Sweep removes sessions whose lastActivity is older than IdleTimeout. Call from a background goroutine via Run() or invoke directly in tests.

type Session

type Session struct {
	ID          string
	WorkspaceID string
	// contains filtered or unexported fields
}

Session is one long-running process spawned via tools.UnifiedExec / exec_command. The SDK polls Output, writes stdin, and terminates via the corresponding /api/sdk/processes/{sid}/* endpoints.

func (*Session) Append

func (s *Session) Append(stream string, data []byte)

Append adds a chunk and updates lastActivity. Old chunks are dropped from the head when the total exceeds MaxBufferBytes; the dropped bytes are accumulated into lostBytes so the SDK can warn.

func (*Session) LastActivity

func (s *Session) LastActivity() time.Time

LastActivity is the time of the most recent Append / SetExit.

func (*Session) LostBytes

func (s *Session) LostBytes() int

LostBytes is the total bytes dropped from the head of the ring after the buffer hit MaxBufferBytes. Reset to 0 on a fresh session.

func (*Session) OutputSince

func (s *Session) OutputSince(since int) (chunks []Chunk, exit *int, alive bool)

OutputSince returns every chunk whose Seq > since, plus the current exit code (nil if still running) and an alive flag.

func (*Session) SetExit

func (s *Session) SetExit(code int)

SetExit records the process exit code (or signal) and refreshes lastActivity so the session lives one more idle-timeout window for final output polling.

Jump to

Keyboard shortcuts

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