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 ¶
- func DefaultRoot() (string, error)
- func NameFor(localRoot, sandbox string, taken func(string) bool) string
- func Overlaps(a, b string) bool
- func RootInode(string) (uint64, error)
- type Conflict
- type Connection
- type Cycle
- type Halt
- type HaltReason
- type Outcome
- type Runner
- type SandboxState
- type State
- type Status
- type Store
- func (s *Store) Dir(id string) string
- func (s *Store) List() ([]*State, error)
- func (s *Store) Load(id string) (*State, error)
- func (s *Store) LoadAncestor(id string) *core.Entry
- func (s *Store) Remove(id string) error
- func (s *Store) Root() string
- func (s *Store) Save(state *State) error
- func (s *Store) SaveAncestor(id string, ancestor *core.Entry) error
- func (s *Store) TrashDir(id string) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NameFor ¶
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.
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 ¶
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 ¶
Cycle is one pass: identity, scan, guard, reconcile, stage, transition, supply, commit.
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.
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 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.
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 (*Store) LoadAncestor ¶
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) Save ¶
Save writes through a temporary and renames, so a crash mid-write cannot leave a session unreadable.
func (*Store) SaveAncestor ¶
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.