supervisor

package
v0.49.1 Latest Latest
Warning

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

Go to latest
Published: May 15, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package supervisor spawns and tracks per-thread `codex app-server` subprocesses inside the codex-app-gateway pod.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChildHandle

type ChildHandle struct {
	WSURL     string // ws://127.0.0.1:PORT
	HTTPURL   string // http://127.0.0.1:PORT  (for /readyz, /healthz)
	CodexHome string
	// contains filtered or unexported fields
}

ChildHandle is what spawnCodexAppServer returns.

func (*ChildHandle) Done

func (h *ChildHandle) Done() <-chan struct{}

Done returns a channel closed after the subprocess exits. Useful for callers that want to be notified of unexpected termination.

func (*ChildHandle) IsAlive

func (h *ChildHandle) IsAlive() bool

IsAlive reports whether the subprocess is still running. Cheap; suitable for calling on every EnsureSubprocess hit.

func (*ChildHandle) Stop

func (h *ChildHandle) Stop(ctx context.Context) error

Stop sends SIGTERM, waits up to 10s, then SIGKILLs.

type ConfigBuilder

type ConfigBuilder func() (codexhome.ConfigInput, error)

ConfigBuilder produces a fresh ConfigInput at spawn time. Allowed to hit the network; errors propagate.

type IdleReaper

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

IdleReaper periodically scans the Supervisor and shuts down entries idle for longer than idleAfter.

func NewIdleReaper

func NewIdleReaper(sup *Supervisor, interval, idleAfter time.Duration, logger *slog.Logger) *IdleReaper

func (*IdleReaper) Run

func (r *IdleReaper) Run(ctx context.Context)

Run blocks until ctx is done, ticking every interval and shutting down idle entries.

type Key

type Key struct {
	WorkspaceID string
	ThreadID    string
}

Key identifies one (workspace, thread) subprocess slot.

type Supervisor

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

Supervisor owns the in-memory (workspace, thread) → subprocess map.

func NewSupervisor

func NewSupervisor(cfg SupervisorConfig) *Supervisor

func (*Supervisor) EnsureSubprocess

func (s *Supervisor) EnsureSubprocess(ctx context.Context, key Key, build ConfigBuilder) (*ChildHandle, error)

EnsureSubprocess returns a live ChildHandle for key, spawning one if necessary. Concurrent EnsureSubprocess calls for the same key see the same handle (one-spawn-per-key invariant; loser of the race discards their spawn). If a cached entry's subprocess has crashed, it is evicted and a fresh subprocess is spawned.

func (*Supervisor) Shutdown

func (s *Supervisor) Shutdown(ctx context.Context, key Key) error

Shutdown terminates the subprocess for key, uploads its CODEX_HOME to S3, and drops the in-memory entry. Safe on missing keys.

func (*Supervisor) ShutdownAll

func (s *Supervisor) ShutdownAll(ctx context.Context)

ShutdownAll shuts down every active subprocess.

func (*Supervisor) Touch

func (s *Supervisor) Touch(key Key)

Touch bumps the last-active timestamp for a key. Callers must invoke it on every proxied frame (see proxy.RunProxy's onFrame callback) so the IdleReaper sees fresh activity for the duration of an active session, not just at connect/disconnect.

type SupervisorConfig

type SupervisorConfig struct {
	CodexBin string
	HomeMgr  *codexhome.Manager
	Store    codexhome.ObjectStore
	ExtraEnv []string     // forwarded to every spawned subprocess
	Logger   *slog.Logger // defaults to slog.Default() if nil
}

SupervisorConfig holds the static dependencies.

Jump to

Keyboard shortcuts

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