runtimeobs

package
v0.0.12-rc.2 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2026 License: MIT Imports: 8 Imported by: 0 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 runtimeobs resolves durable Session identity to provider-owned Runtime observations. It is telemetry only and never owns Runtime lifecycle decisions.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnavailable = errors.New("Runtime observation unavailable")
	ErrNotRunning  = errors.New("Runtime is not running")
)

Functions

This section is empty.

Types

type CollectionSource

type CollectionSource string
const (
	CollectionSourceOnRead   CollectionSource = "on_read"
	CollectionSourcePeriodic CollectionSource = "periodic"
)

type ExportOptions

type ExportOptions struct {
	QueueCapacity int
	Timeout       time.Duration
}

type ExportRecord

type ExportRecord struct {
	TenantID      string
	SessionID     string
	EnvironmentID string
	AllocationID  string

	Mode             Mode
	ProviderType     string
	Status           Status
	Reason           string
	CollectionSource CollectionSource

	ResolvedAt     time.Time
	SourceDuration time.Duration
	Sample         *Sample
	TokenUsage     *TokenUsage
}

ExportRecord is the provider-neutral, sanitized history handoff produced after Runtime identity and a current observation result have been validated. It intentionally excludes provider receipts, native identifiers, and raw provider errors.

type Exporter

type Exporter interface {
	Export(context.Context, ExportRecord) error
}

Exporter persists or forwards sanitized Runtime observation records. Core invokes exporters only through a bounded asynchronous dispatcher, so an exporter outage cannot fail or block the current-observation request path.

type HistoryObserver

type HistoryObserver interface {
	ObserveSessionsForHistory(context.Context, []SessionIdentity, OwnershipChecker, PageOptions) ([]Observation, []error)
}

HistoryObserver reads one listed page with bounded concurrency.

type Instance

type Instance struct {
	AllocationID         string
	ProviderKey          string
	DeviceID             string
	ConnectionGeneration string
	AllocationState      string
	AllocationCreatedAt  time.Time
	ComputePhase         string
	// ProviderState is the provider-owned, persisted compute receipt. It is
	// internal-only and lets an observation source verify the exact current
	// incarnation without accepting provider identifiers from the caller.
	ProviderState json.RawMessage
}

Instance is one provider-owned Runtime incarnation. AllocationID is present for managed compute. DeviceID and ConnectionGeneration are reserved for a future authenticated self-hosted telemetry source.

type Mode

type Mode string
const (
	ModeNone       Mode = "none"
	ModeSelfHosted Mode = "self_hosted"
	ModeManaged    Mode = "openai_hosted"
)

type Observation

type Observation struct {
	Target         Target
	Status         Status
	Sample         *Sample
	Reason         string
	ProviderType   string
	ResolvedAt     time.Time
	SourceDuration time.Duration
}

type OwnershipChecker

type OwnershipChecker interface {
	CheckOwnership(context.Context) error
}

type PageOptions

type PageOptions struct {
	// Concurrency bounds identity resolution and per-target provider reads.
	Concurrency int
	// SourceTimeout bounds each provider read.
	SourceTimeout time.Duration
}

PageOptions bounds one page of current reads.

type Sample

type Sample struct {
	ObservedAt time.Time
	StartedAt  *time.Time

	CPUUsageSecondsTotal *float64
	CPUCapacityCores     *float64
	// CPUUtilizationRatio is a provider-reported share of CPUCapacityCores, for
	// providers such as E2B that report a current rate instead of cumulative time.
	// Newer fields are omitted when absent: node frames carry Sample, and an
	// older Core decodes them with unknown fields disallowed.
	CPUUtilizationRatio *float64 `json:",omitempty"`
	MemoryUsageBytes    *uint64
	MemoryLimitBytes    *uint64
	// Disk values are current usage and capacity of the Runtime's disk, when
	// the provider reports them (E2B). They are not part of the /v1 projection.
	DiskUsageBytes *uint64 `json:",omitempty"`
	DiskLimitBytes *uint64 `json:",omitempty"`
}

Sample contains provider-neutral cumulative counters and current gauges. Pointer fields distinguish an observed zero from an unavailable measurement.

type Sampler

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

func NewSampler

func NewSampler(lister SessionLister, observer HistoryObserver, owner OwnershipChecker, options SamplerOptions) (*Sampler, error)

func (*Sampler) Sweep added in v0.0.10

func (s *Sampler) Sweep(ctx context.Context) (result SweepResult)

Sweep performs one full keyset sweep. A failed sweep is isolated from execution; the caller repeats sweeps without overlap.

type SamplerOptions

type SamplerOptions struct {
	PageSize      int
	Concurrency   int
	SourceTimeout time.Duration
}

type Service

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

func NewService

func NewService(resolver TargetResolver, source func(context.Context) (Source, string, error), options ...ServiceOption) (*Service, error)

NewService reads managed Runtimes through source, which returns the Sandbox Provider of the deployment's current selection and its registered kind, or ErrUnavailable while none is selected.

func (*Service) Close

func (s *Service) Close(ctx context.Context) error

Close drains pending history handoffs within ctx. Current-observation callers may keep using a Service without an exporter; Close is then a no-op.

func (*Service) ObserveSession

func (s *Service) ObserveSession(ctx context.Context, tenantID, sessionID string) (Observation, error)

func (*Service) ObserveSessionForHistory

func (s *Service) ObserveSessionForHistory(ctx context.Context, tenantID, sessionID string, owner OwnershipChecker, sourceTimeout time.Duration) (Observation, error)

ObserveSessionForHistory performs the same provider-neutral current read, but marks its export as deployment-periodic so coverage queries can distinguish it from user-triggered API reads. It has no lifecycle side effects.

func (*Service) ObserveSessions

func (s *Service) ObserveSessions(ctx context.Context, sessions []SessionIdentity, options PageOptions) ([]Observation, []error)

ObserveSessions observes one page of Sessions, reading each running target exactly as ObserveSession reads it. Results and errors are aligned with sessions.

func (*Service) ObserveSessionsForHistory

func (s *Service) ObserveSessionsForHistory(ctx context.Context, sessions []SessionIdentity, owner OwnershipChecker, options PageOptions) ([]Observation, []error)

ObserveSessionsForHistory is the periodic-collection form of ObserveSessions.

type ServiceOption

type ServiceOption func(*serviceOptions) error

func WithExporter

func WithExporter(exporter Exporter, options ExportOptions) ServiceOption

WithExporter enables best-effort history export. Queue saturation drops the newest handoff; it never changes the Runtime observation result.

type SessionIdentity

type SessionIdentity struct {
	TenantID, SessionID string
}

type SessionLister

type SessionLister interface {
	ListRuntimeObservationSessions(context.Context, string, int) (SessionPage, error)
}

type SessionPage

type SessionPage struct {
	Sessions   []SessionIdentity
	NextCursor string
}

type Source

type Source interface {
	providercontract.Declared
	Observe(context.Context, Target) (Sample, error)
}

Source is the observation half of a Sandbox Provider, which services/core/internal/sandbox/sandbox_provider.go defines.

type Status

type Status string
const (
	StatusObserved    Status = "observed"
	StatusUnsupported Status = "unsupported"
	StatusUnavailable Status = "unavailable"
)

type SweepResult

type SweepResult struct {
	StartedAt, CompletedAt   time.Time
	Listed, Observed, Failed int
	Complete                 bool
}

SweepResult is deliberately low-cardinality. It reports collection coverage without exposing tenant, Session, allocation, provider-native, or error text.

type Target

type Target struct {
	TenantID, SessionID, EnvironmentID string
	Mode                               Mode
	Instance                           Instance
	// TokenUsage is the latest measured Core Session usage: every recorded
	// root Turn snapshot, active Turns included. Unlike public Session usage it
	// is not withheld until every Turn ends. It is Session-scoped and
	// deliberately independent of the provider Runtime.
	TokenUsage *TokenUsage
}

Target binds telemetry to durable Core identity. A Session is not itself a process or sandbox, so callers must retain the complete binding.

type TargetResolver

type TargetResolver interface {
	Resolve(context.Context, string, string) (Target, error)
}

type TokenUsage

type TokenUsage struct {
	InputTokens  uint64
	OutputTokens uint64
}

TokenUsage contains cumulative measured Session counters. Missing native measurements remain nil at the Target level and are never treated as zero.

Directories

Path Synopsis
Package otlpexporter sends sanitized Runtime observation records to an operator-configured OTLP/HTTP metrics endpoint.
Package otlpexporter sends sanitized Runtime observation records to an operator-configured OTLP/HTTP metrics endpoint.

Jump to

Keyboard shortcuts

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