activesessions

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: MIT Imports: 28 Imported by: 1 module, 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

Index

Constants

View Source
const (
	SessionNotOwned                = "SESSION_NOT_OWNED"
	MaxConcurrentSessions          = "MAX_CONCURRENT_SESSIONS"
	SessionCoordinationUnavailable = "SESSION_COORDINATION_UNAVAILABLE"
)

Machine readable refusal reasons, capacity and ownership calling for different operator action

View Source
const NoLockTimeout time.Duration = -1

Waits on a registry lock with no deadline

View Source
const PerSessionExclusiveSubmit = true

Exclusive per session submit the gateway advertises, held by the atomic acquisition check

Variables

This section is empty.

Functions

func ActiveSessionLimitMessage

func ActiveSessionLimitMessage(activeCount int, maxSessions *big.Int, entries []*pyjson.Object) string

Capacity refusal text naming the surfaces that hold the slots

func CoerceMaxConcurrentSessions

func CoerceMaxConcurrentSessions(value any, key string) *big.Int

Positive integer session cap of a config value, nil when disabled or invalid with a warning logged

func FileLock

func FileLock(path string, timeout time.Duration) (func(), error)

Holds the exclusive lock on path as a with block does and returns its release

func FormatAge

func FormatAge(seconds float64) string

Lease age in whole minutes, hours past sixty minutes

func FormatRefusalStderr

func FormatRefusalStderr(message *Refusal) string

Refusal text prefixed with its reason line so the contract survives a subprocess boundary

func LivenessGuard

func LivenessGuard(ctx context.Context, sessionID, registryHome string, ownLiveLeaseIDs map[string]bool, body func(active bool) error) error

Runs body holding the registry lock with whether the session is leased, so no claim lands between check and write

func MarkReleaseQueued

func MarkReleaseQueued(lease any)

Retires a lease from this process view of the registry now, its file write coming later

func OwnStartTime

func OwnStartTime() (float64, bool)

Creation time of this process, false when the platform cannot read it

func PidLiveness

func PidLiveness(pid, processStart any) (alive, known bool)

Whether the pid is still the process that started then, known false when liveness cannot be decided

func PruneDead

func PruneDead(entries []*pyjson.Object, strict bool) ([]*pyjson.Object, error)

Rows whose owner is alive, strict mode requiring every owner to be provably alive

func ReadEntries

func ReadEntries(path string, strict bool) ([]*pyjson.Object, error)

Registry rows of path, strict mode raising on a corrupt or malformed registry

func RegistrySnapshot

func RegistrySnapshot(ctx context.Context, registryHome string, strict bool) ([]*pyjson.Object, error)

Live leases of the registry, dead ones written out under a second lock, strict requiring provable owners

func ReleaseActiveSession

func ReleaseActiveSession(lease *Lease) error

Drops the lease from the registry it was acquired against, an unreadable untracked registry preserved

func ReleaseOrphanedLeases

func ReleaseOrphanedLeases(liveLeaseIDs map[string]bool) (int, error)

Drops the registry entries of this process no live session owns across the root and every profile home

func ResolveMaxConcurrentSessions

func ResolveMaxConcurrentSessions(config any) *big.Int

Top level max_concurrent_sessions of a config with the gateway section as the fallback

func SessionAlreadyOwnedMessage

func SessionAlreadyOwnedMessage(sessionID string, entry *pyjson.Object) string

Refusal text for a session another live process holds, the plain sentence first and details second

func SessionOwnerDetails

func SessionOwnerDetails(sessionID string, entry *pyjson.Object) string

Details line every owner refusal message carries, the surface and age of the holding lease

func SummarizeHolders

func SummarizeHolders(entries []*pyjson.Object) string

Compact holders phrase like tui x4, cli with the age of the oldest lease

func TransferActiveSession

func TransferActiveSession(lease *Lease, sessionID string, metadata map[string]any) (bool, error)

Moves a lease to a new session id without dropping its slot, false when it cannot be moved

func TryAcquire

func TryAcquire(ctx context.Context, sessionID, surface string, cfg any, metadata map[string]any, registryHome string, trackLiveness bool) (*Lease, *Refusal, error)

Acquires an active session slot, refusing a second live owner of the session or a full configured cap

Types

type Lease

type Lease struct {
	LeaseID       string
	Surface       string
	Enabled       bool
	StatePath     string
	LockPath      string
	TrackLiveness bool
	// contains filtered or unexported fields
}

Active session slot recorded in a registry until it is released

func (*Lease) IsEnabled

func (l *Lease) IsEnabled() bool

Whether the lease holds a real registry slot

func (*Lease) Release

func (l *Lease) Release() error

Drops the lease from its registry once, a disabled lease never touching the file

func (*Lease) Released

func (l *Lease) Released() bool

True once the registry drop of the lease has landed

func (*Lease) SessionID

func (l *Lease) SessionID() string

Session the lease currently holds

func (*Lease) TracksLiveness

func (l *Lease) TracksLiveness() bool

Whether the lease records its owner process for cross process liveness checks

type LockUnavailableError

type LockUnavailableError struct {
	Path string
	Err  error
}

Registry lock that could not be taken, the cause wrapped

func (*LockUnavailableError) Error

func (e *LockUnavailableError) Error() string

Message naming the lock file

func (*LockUnavailableError) Unwrap

func (e *LockUnavailableError) Unwrap() error

Cause of the lock failure

type Refusal

type Refusal struct {
	Message      string
	Reason       string
	LedgerStatus string
}

Refusal of an acquisition, the message for people and the reason as the contract

func NewRefusal

func NewRefusal(message, reason string) *Refusal

Refusal carrying a message for people and a machine readable reason

func (*Refusal) PyDeepcopy

func (r *Refusal) PyDeepcopy() any

Refusal rebuilt from its message and reason with its ledger status, as a payload copy needs

func (*Refusal) PyStr

func (r *Refusal) PyStr() string

Message the refusal encodes as wherever a string is expected

func (*Refusal) String

func (r *Refusal) String() string

Message of the refusal

type RegistryError

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

RegistryError reports an unreadable registry or an owner whose liveness cannot be proven

func (*RegistryError) Error

func (e *RegistryError) Error() string

Message of the registry failure

Jump to

Keyboard shortcuts

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