runtimeobs

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2026 License: MIT Imports: 10 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

View Source
const MaxBatchTargets = 100

MaxBatchTargets bounds the targets of one BatchSource read.

Variables

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

Functions

func ValidateSource

func ValidateSource(source Source) error

ValidateSource checks every read operation and its immutable provider identity.

Types

type BatchResult

type BatchResult struct {
	Sample Sample
	Err    error
}

type BatchSource

type BatchSource interface {
	ObserveBatch(context.Context, []Target) (results []BatchResult, err error)
}

BatchSource reads multiple instances under the same ownership rules as Observe. Unsupported returns a typed providercontract.UnsupportedError before reading; only that result permits per-target observation. Unavailable or failed reads must not silently retry through Observe. Successful results preserve target order.

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, so providers with a batch read can sample the whole page in one bounded request.

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, including one batch 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) Run

func (s *Sampler) Run(ctx context.Context) error

Run performs one immediate full keyset sweep and then repeats without overlap. A failed sweep is isolated from execution and retried at the next interval.

type SamplerOptions

type SamplerOptions struct {
	Interval      time.Duration
	PageSize      int
	Concurrency   int
	SourceTimeout time.Duration
	Report        func(SweepResult)
}

type Service

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

func NewService

func NewService(resolver TargetResolver, sources map[string]SourceResolver, options ...ServiceOption) (*Service, error)

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. Running targets of a source that explicitly supports BatchSource share one provider read per MaxBatchTargets; other sources are read per target, exactly as ObserveSession reads them. 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
	// ObservationProviderType is a nonempty, immutable telemetry identity.
	ObservationProviderType() string
	Observe(context.Context, Target) (Sample, error)
}

Source reads one provider-owned Runtime instance. Implementations must verify ownership before returning data and must not renew, restart, or stop compute.

type SourceResolver

type SourceResolver interface {
	providercontract.Declared
	ResolveObservationSource(context.Context) (Source, error)
}

SourceResolver selects one immutable source for a page of provider reads. An unconfigured resolver returns ErrUnavailable. Registration never resolves a source; callers validate each selected source before reading it.

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