reconcile

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package reconcile defines restart-safe assignment recovery decisions.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrClaimLost        = errors.New("SecondBox reconciliation claim is no longer current")
	ErrFenceProofAbsent = errors.New("SecondBox reconciliation cannot advance without fence proof")
)

Functions

This section is empty.

Types

type Action

type Action string
const (
	ActionWait              Action = "wait"
	ActionRetry             Action = "retry"
	ActionFence             Action = "fence"
	ActionAdvanceGeneration Action = "advance_generation"
	ActionFailTerminal      Action = "fail_terminal"
)

type AssignmentState

type AssignmentState struct {
	State            string
	Generation       int64
	FenceProofDigest string
	FailureClass     FailureClass
	RetryCount       int
	RetryLimit       int
	Deadline         time.Time
}

AssignmentState is durable evidence used to compute one reconciliation action.

type AssignmentWorker

type AssignmentWorker struct {
	Store            WorkerStore
	WorkerID         string
	ClaimDuration    time.Duration
	PollInterval     time.Duration
	CommandDeadline  time.Duration
	HeartbeatTimeout time.Duration
	NewCommandID     func(string) string
}

AssignmentWorker reconciles deadline and Runner-loss evidence without process-local ownership.

func (AssignmentWorker) RunOnce

func (worker AssignmentWorker) RunOnce(
	ctx context.Context,
	now time.Time,
) (Decision, bool, error)

RunOnce performs at most one revision-fenced Assignment transition.

type Claim

type Claim struct {
	AssignmentID   string
	SandboxID      string
	InstanceID     string
	RunnerID       string
	WorkerID       string
	FencingToken   []byte
	Correlation    *runnerv1.Correlation
	Revision       int64
	State          AssignmentState
	ClaimExpiresAt time.Time
}

Claim is one revision-fenced bounded reconciliation work item.

type Decision

type Decision struct {
	Action         Action
	NextGeneration int64
}

Decision is one idempotent action. Runner loss can advance authority only through the current home runner's durable local Workspace receipt.

func DecideAssignment

func DecideAssignment(state AssignmentState, now time.Time) Decision

DecideAssignment classifies bounded retry, deadlines, and terminal failures.

func DecideRunnerLoss

func DecideRunnerLoss(state AssignmentState, now time.Time) Decision

DecideRunnerLoss fences uncertain compute before queuing a local generation advance.

type FailureClass

type FailureClass string
const (
	FailureTransient      FailureClass = "transient"
	FailureCompatibility  FailureClass = "compatibility"
	FailureFencing        FailureClass = "fencing"
	FailureStartupTimeout FailureClass = "startup_timeout"
)

type PostgresStore

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

PostgresStore coordinates restart-safe reconciliation workers.

func NewPostgresStore

func NewPostgresStore(ctx context.Context, databaseURL string) (*PostgresStore, error)

NewPostgresStore connects the reconciler to PostgreSQL authority.

func (*PostgresStore) AdvanceFencedGeneration

func (store *PostgresStore) AdvanceFencedGeneration(
	ctx context.Context,
	assignmentID string,
	expectedRevision int64,
	now time.Time,
) (int64, error)

AdvanceFencedGeneration converts proven Runner loss into the same runner-local generation-advance boundary used by an ordinary stop. It never relocates the Sandbox or advances PostgreSQL ahead of the home runner's durable receipt.

func (*PostgresStore) ApplyDecision

func (store *PostgresStore) ApplyDecision(
	ctx context.Context,
	claim Claim,
	decision Decision,
	fenceCommand *runnerv1.FenceCommand,
	nextReconcileAt time.Time,
	now time.Time,
) error

ApplyDecision commits one idempotent revision-fenced reconciliation transition.

func (*PostgresStore) ClaimNext

func (store *PostgresStore) ClaimNext(
	ctx context.Context,
	workerID string,
	claimExpiresAt time.Time,
	now time.Time,
) (Claim, bool, error)

ClaimNext leases one due assignment using SKIP LOCKED across control-plane replicas.

func (*PostgresStore) Close

func (store *PostgresStore) Close()

func (*PostgresStore) MarkExpiredRunners

func (store *PostgresStore) MarkExpiredRunners(
	ctx context.Context,
	heartbeatCutoff time.Time,
	now time.Time,
) (int64, error)

MarkExpiredRunners makes assignments uncertain without authorizing replacement.

func (*PostgresStore) RequestRunnerDrain

func (store *PostgresStore) RequestRunnerDrain(
	ctx context.Context,
	runnerID string,
	drainCommand *runnerv1.DrainCommand,
	now time.Time,
) error

RequestRunnerDrain records the admission barrier before a Drain command is sent.

type WorkerStore

type WorkerStore interface {
	MarkExpiredRunners(context.Context, time.Time, time.Time) (int64, error)
	ClaimNext(context.Context, string, time.Time, time.Time) (Claim, bool, error)
	ApplyDecision(context.Context, Claim, Decision, *runnerv1.FenceCommand, time.Time, time.Time) error
	AdvanceFencedGeneration(context.Context, string, int64, time.Time) (int64, error)
}

WorkerStore owns durable Assignment claims, commands, and generation advancement.

Jump to

Keyboard shortcuts

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