Documentation
¶
Overview ¶
Package idle is the daemon's suspend detector (DBX-47, section 4.3a). It evaluates activity signals, reports IdleState changes and emits SuspendRequested once the instance has been idle for the grace period (or a ceiling is reached). The gateway executes the suspend.
Index ¶
Constants ¶
const ( DefaultActivityWindow = 2 * time.Minute DefaultCPUThreshold = 5.0 DefaultGracePeriod = 5 * time.Minute DefaultMaxDeferral = 12 * time.Hour DefaultMaxContinuousAwake = 24 * time.Hour )
Policy defaults (IdlePolicy).
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CPUSampler ¶
CPUSampler reports CPU usage since the previous sample, as percent of one core, in total and per process group.
type Detector ¶
type Detector struct {
// SettledOffset settles in-flight entities and returns the log offset through which everything is settled.
SettledOffset func() uint64
// contains filtered or unexported fields
}
Detector is the idle state machine.
func (*Detector) Evaluate ¶
Evaluate runs one evaluation and emits events. It's called on a ticker (and directly by tests).
func (*Detector) Reset ¶
func (d *Detector) Reset()
Reset restarts activity timers (memory restore detected, or a fresh boot).
func (*Detector) SetLeases ¶
SetLeases replaces the leases when generation is newer than the last applied one. Deferrals are clamped to now + maxDeferral; expired leases are dropped.
type Emitter ¶
type Emitter interface {
IdleState(*devboxv1.IdleState)
SuspendRequested(*devboxv1.SuspendRequested)
}
Emitter receives detector events.
type Policy ¶
type Policy struct {
ActivityWindow time.Duration
CPUThresholdPct float64
GracePeriod time.Duration
MaxDeferral time.Duration
MaxContinuousAwake time.Duration
}
Policy is the resolved idle policy.
func PolicyOf ¶
func PolicyOf(p *devboxv1.IdlePolicy) Policy
PolicyOf resolves an IdlePolicy with defaults.
type ProcSampler ¶
type ProcSampler struct {
Root string
// Exclude reports processes that don't count (the daemon, browser helpers); called with pid and pgid.
Exclude func(pid, pgid int) bool
// contains filtered or unexported fields
}
ProcSampler samples /proc/<pid>/stat CPU times for every process outside the daemon.
type Sources ¶
type Sources struct {
// Agent returns agent turn and pending-interaction reasons.
Agent func(now time.Time) []*devboxv1.BusyReason
// TerminalJobs returns PTY foreground jobs.
TerminalJobs func() []TerminalJob
// StreamActivity returns the last byte time of each interactive stream source (terminal, vnc, preview, cdp).
StreamActivity func() map[string]time.Time
// CPU samples process CPU outside the daemon.
CPU CPUSampler
}
Sources provide the signals.
type TerminalJob ¶
type TerminalJob struct {
TerminalID string
Command string
// Pgid is the job's process group (for CPU attribution); 0 when unknown.
Pgid int
}
TerminalJob is a PTY foreground job.