session

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2026 License: AGPL-3.0 Imports: 16 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 session holds a sync session's durable state and the cycle that drives it.

Everything lives under ~/.agyn/sync/sessions/<id>/. Nothing persistent is added to the engineer's directory: the platform does not write there, and the identity of the local root is tracked by inode rather than by a marker file.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultRoot

func DefaultRoot() (string, error)

DefaultRoot is ~/.agyn/sync.

func NameFor

func NameFor(localRoot, sandbox string, taken func(string) bool) string

NameFor labels a session for its local directory and its sandbox. The label takes a discriminator on collision; identity is the triple, not the name.

func Overlaps

func Overlaps(a, b string) bool

Overlaps reports whether two roots nest. Two engines writing one subtree cannot be reconciled, so a session that would overlap an existing one is refused at creation.

func RootInode

func RootInode(string) (uint64, error)

Types

type Conflict

type Conflict struct {
	Path         string `json:"path"`
	LocalChange  string `json:"local_change"`
	RemoteChange string `json:"remote_change"`
}

Conflict is a path both sides changed, quarantined rather than resolved.

type Connection

type Connection struct {
	Client      *client.Client
	Diagnostics func() string
	Close       func() error
}

Connection is one attached endpoint session. The runner owns its lifetime and drops it on any failure, because watch state is never trusted across a disconnect.

type Cycle

type Cycle struct {
	State    *State
	Store    *Store
	Endpoint *client.Client
}

Cycle is one pass: identity, scan, guard, reconcile, stage, transition, supply, commit.

func (*Cycle) Run

func (c *Cycle) Run() (*Outcome, error)

Run executes one cycle. A returned *Halt is a durable state, not a transient failure: the caller records it and stops rather than retrying.

type Halt

type Halt struct {
	Reason HaltReason
	Detail string
}

Halt is a durable stop. Nothing has been applied, and it is safe to remain in indefinitely — which is what makes it acceptable for a background process that may never be attended to.

func (*Halt) Error

func (h *Halt) Error() string

type HaltReason

type HaltReason string

HaltReason names why a session stopped, because the recovery differs by cause and the engineer is asserting something different in each case.

const (
	HaltRootReplaced   HaltReason = "root-replaced"
	HaltContentLoss    HaltReason = "content-loss"
	HaltSandboxGone    HaltReason = "sandbox-terminated"
	HaltVersionGap     HaltReason = "version-gap"
	HaltAuthentication HaltReason = "authentication-required"
)

type Outcome

type Outcome struct {
	AppliedLocal  int
	AppliedRemote int
	Conflicts     []Conflict
}

Outcome reports what a completed cycle did.

type Runner

type Runner struct {
	State *State
	Store *Store

	// Dial attaches a fresh endpoint session. Every reconnect performs a full
	// rescan, so nothing is carried across.
	Dial func(context.Context) (*Connection, error)
	// Sandbox reports the sandbox's current state, which is what distinguishes
	// a pause from a halt when the stream breaks.
	Sandbox func(context.Context) (SandboxState, error)

	// Interval is how often a connected session cycles.
	Interval time.Duration
	// Log receives one line per state change. Never per cycle: a quiet session
	// should be quiet.
	Log func(format string, args ...any)
	// contains filtered or unexported fields
}

Runner drives one session: connect, cycle, classify any failure, reconnect.

func (*Runner) Run

func (r *Runner) Run(ctx context.Context) error

Run drives the session until the context is cancelled or it halts. A halt is durable and safe to remain in indefinitely, so Run returns rather than retrying.

type SandboxState

type SandboxState string

SandboxState is what the runner needs to know about the sandbox between cycles, without depending on the Gateway client directly.

const (
	SandboxRunning    SandboxState = "running"
	SandboxStopped    SandboxState = "stopped"
	SandboxTerminated SandboxState = "terminated"
)

type State

type State struct {
	ID   string `json:"id"`
	Name string `json:"name"`

	// Identity is the (local root, sandbox, remote root) triple. The name is
	// only a label.
	LocalRoot  string `json:"local_root"`
	SandboxID  string `json:"sandbox_id"`
	Sandbox    string `json:"sandbox"`
	RemoteRoot string `json:"remote_root"`

	// LocalRootInode identifies the local directory itself. Recorded at
	// creation and re-checked before every cycle: an unmounted drive, a
	// directory deleted and recreated, and a mountpoint that never mounted each
	// present a different inode, and each would otherwise scan as an empty tree
	// and propagate as "everything was deleted".
	//
	// The device number is deliberately absent. st_dev is assigned at mount
	// time rather than being a property of the filesystem, so it changes across
	// remounts on btrfs subvolumes, device-mapper, overlayfs, external drives,
	// and most macOS non-boot volumes — and sessions are expected to survive
	// reboots.
	LocalRootInode uint64 `json:"local_root_inode"`

	Status     Status    `json:"status"`
	StatusNote string    `json:"status_note,omitempty"`
	LastSync   time.Time `json:"last_sync,omitempty"`

	Conflicts []Conflict `json:"conflicts,omitempty"`
}

State is what survives a daemon restart.

type Status

type Status string
const (
	StatusIdle    Status = "idle"
	StatusSyncing Status = "syncing"
	// StatusPaused is a sandbox that stopped. Automatic resumption never
	// restarts it — a background file change must not start billable compute.
	StatusPaused Status = "paused"
	// StatusHalted is durable and safe to remain in indefinitely, which is what
	// makes it acceptable for a background process nobody may be watching.
	StatusHalted Status = "halted"
)

type Store

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

Store is the on-disk home of every session.

func NewStore

func NewStore(root string) *Store

func (*Store) Dir

func (s *Store) Dir(id string) string

func (*Store) List

func (s *Store) List() ([]*State, error)

List returns every persisted session, in name order.

func (*Store) Load

func (s *Store) Load(id string) (*State, error)

func (*Store) LoadAncestor

func (s *Store) LoadAncestor(id string) *core.Entry

LoadAncestor returns the reconciliation base. A missing or unrecognized base is not an error: it means the next cycle re-derives from both sides in the conflict-preserving mode, which is the safe answer.

func (*Store) Remove

func (s *Store) Remove(id string) error

func (*Store) Root

func (s *Store) Root() string

func (*Store) Save

func (s *Store) Save(state *State) error

Save writes through a temporary and renames, so a crash mid-write cannot leave a session unreadable.

func (*Store) SaveAncestor

func (s *Store) SaveAncestor(id string, ancestor *core.Entry) error

SaveAncestor records the agreed state. It is called only after a complete cycle: an interruption at any earlier point recomputes on the next pass rather than recording a state that is not true on disk.

func (*Store) TrashDir

func (s *Store) TrashDir(id string) string

Jump to

Keyboard shortcuts

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