shellliveness

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2026 License: MIT Imports: 6 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 shellliveness decides, from tmux evidence alone, whether a Sidecar shell's tmux session is gone.

Both Workspaces surfaces — the project plugin and the global browser — must reach the same answer, so the rule lives here rather than in either of them. Each surface already watches tmux for its own reasons (the plugin polls the pane it is rendering, the global browser takes one `list-panes -a` per refresh cycle); this package turns what they already saw into a verdict and confirms it with one bounded probe. Nothing here runs on a timer, and nothing here belongs on the startup path.

The asymmetry is deliberate. Leaving a dead row on screen for another poll is a cosmetic defect; deleting a live user's shell entry because tmux hiccuped is data loss. So every ambiguous signal — a missing binary, a socket we could not reach, a server that is not running — resolves to Unknown, and Unknown never closes anything.

Index

Constants

View Source
const DefaultConfirmations = 1

DefaultConfirmations is how many consecutive Gone probes close a shell.

One is correct here because a probe is never the only evidence: the caller has already observed the session missing from a listing or failing to capture, and the probe is the independent second opinion taken fresh from tmux. Two positives from two different observations beats two positives from the same one.

View Source
const DefaultProbeInterval = 15 * time.Second

DefaultProbeInterval throttles repeat probes for one session. The first probe after a suspicion is immediate — that is the one that closes a shell the user just exited. The interval only governs the stuck case, where tmux keeps answering Unknown: a shell that keeps failing must not spawn a tmux process per poll, because on a machine running an endpoint security agent every spawn is expensive.

View Source
const ProbeTimeout = 2 * time.Second

ProbeTimeout bounds one probe. It is generous relative to a `list-sessions` against a healthy server and short enough that a wedged one cannot pin a poll chain for long.

Variables

This section is empty.

Functions

func SuspectsDeath

func SuspectsDeath(message string) bool

SuspectsDeath reports whether a failed tmux interaction is worth probing. It is intentionally cheap and text-based: the caller already has the error in hand, and a probe only follows a positive answer here.

func SuspectsDeathErr

func SuspectsDeathErr(err error) bool

SuspectsDeathErr is SuspectsDeath over an error value.

tmux's actual message is almost never in the error string: a failed exec.Cmd.Output() wraps to "exit status 1" and hides "can't find session" in ExitError.Stderr. Callers that only matched err.Error() were therefore matching nothing at all, which is why an exited shell used to linger.

Types

type ProbeFunc

type ProbeFunc func(session string) Verdict

ProbeFunc answers "is this tmux session running?" for one session name.

type Tracker

type Tracker struct {

	// Confirmations and ProbeInterval default to the constants above when zero.
	Confirmations int
	ProbeInterval time.Duration
	// contains filtered or unexported fields
}

Tracker remembers, per tmux session, what a surface has observed. It holds no tmux handles and starts no goroutines, so constructing one costs nothing and it is safe to build during plugin construction.

func NewTracker

func NewTracker() *Tracker

NewTracker returns an empty tracker with default policy.

func (*Tracker) Confirm

func (t *Tracker) Confirm(name string, verdict Verdict, incarnation uint64) bool

Confirm folds one probe verdict in and reports whether the shell should now be closed. Alive and Unknown both clear the count, so a session that flickers out of reach is never condemned by accumulation.

func (*Tracker) Forget

func (t *Tracker) Forget(name string)

Forget drops all state for a session, for use when a shell is closed by any other route so a later reuse of the name starts clean.

func (*Tracker) Incarnation

func (t *Tracker) Incarnation(name string) uint64

Incarnation identifies the current life of a tmux name. A caller reads it when it starts confirming a death and hands it back to Confirm, which is what makes a verdict that was overtaken by a resurrection unusable rather than merely late (td-6a4100).

func (*Tracker) Observe

func (t *Tracker) Observe(name string)

Observe records positive evidence that the session is running — a listing that included it, a capture that succeeded, or a creation that just made it. It clears any accumulated suspicion: a session that answered is not dying. A surface must call it before a probe of that session can ever close a shell.

func (*Tracker) SeenAlive

func (t *Tracker) SeenAlive(name string) bool

SeenAlive reports whether this tracker ever observed the session running.

It is the gate that separates "a shell died while Sidecar watched" from "a manifest entry that was already cold when Sidecar started". The second is what survives a reboot and what the offline-shell recreate path exists for, and auto-close must not eat it.

func (*Tracker) ShouldProbe

func (t *Tracker) ShouldProbe(name string, now time.Time) bool

ShouldProbe reports whether a probe for this session is due: the tracker must have seen the session alive, and no probe may have run inside the throttle window. It records the attempt.

The liveness half of that gate is the whole safety property, so it lives here rather than in each surface. The project plugin used to substitute "this row has an Agent", which reads as liveness but is not: the nested sibling projection synthesises an Agent for rows whose tmux server this instance cannot even see. One gate, one meaning, both surfaces.

type Verdict

type Verdict int

Verdict is what the evidence supports, not what is true.

const (
	// Unknown means the evidence cannot distinguish a dead session from an
	// unreachable tmux. It is the safe default and must never close a shell.
	Unknown Verdict = iota
	// Alive means tmux positively listed the session.
	Alive
	// Gone means tmux answered, and its answer did not include the session.
	Gone
)

func ProbeSession

func ProbeSession(session string) Verdict

ProbeSession asks tmux for its full session list and compares names exactly.

`has-session -t name` is the obvious call and the wrong one: tmux target resolution falls back to prefix and pattern matching, so it answers about a session the caller did not name. A listing compared with == cannot do that. A listing also fails honestly — if tmux cannot answer at all, including when no server is running, the verdict is Unknown and no shell is closed.

func (Verdict) String

func (v Verdict) String() string

Jump to

Keyboard shortcuts

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