Documentation
¶
Overview ¶
Package lock provides agent identity locking to prevent multiple agents from claiming the same worker identity.
Lock files are stored at <worker>/.runtime/agent.lock and contain: - PID of the owning process - Timestamp when lock was acquired - Session ID (tmux session name)
Stale locks (where the PID is dead) are automatically cleaned up.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrLocked = errors.New("worker is locked by another agent") ErrNotLocked = errors.New("worker is not locked") ErrInvalidLock = errors.New("invalid lock file") )
Common errors
Functions ¶
func CleanStaleLocks ¶
CleanStaleLocks removes all stale locks in a directory tree. Returns the number of stale locks cleaned. A lock is only truly stale if BOTH the PID is dead AND the tmux session doesn't exist. This prevents killing active workers whose spawning process has exited (which is normal - the agent runs as a child in tmux).
func DetectCollisions ¶
DetectCollisions finds workers with multiple agents claiming the same identity. This detects the case where multiple processes think they own the same worker by comparing tmux sessions with lock files. Returns a list of collision descriptions.
Types ¶
type Lock ¶
type Lock struct {
// contains filtered or unexported fields
}
Lock represents an agent identity lock for a worker directory.
func (*Lock) Acquire ¶
Acquire attempts to acquire the lock for this worker. Returns ErrLocked if another live process holds the lock. Automatically cleans up stale locks.
func (*Lock) Check ¶
Check checks if the worker is locked by another agent. Returns nil if unlocked or locked by us. Returns ErrLocked if locked by another live process. Automatically cleans up stale locks.
func (*Lock) ForceRelease ¶
ForceRelease removes the lock regardless of who holds it. Use with caution - only for doctor --fix scenarios.