Documentation
¶
Overview ¶
Package app composes SpareRunner's enrollment, transport, and durable stores into executable controller and agent flows. Domain and transport packages remain independently testable; this package owns process-level wiring.
Index ¶
- Constants
- Variables
- func ClassifyGitHubObservationFailure(failure error) store.GitHubObservationFailureClass
- func InitializeController(ctx context.Context, directory string, hints []string) (code string, err error)
- func JoinAgent(ctx context.Context, options JoinOptions) (string, error)
- func LoadManagementBootstrapProof(directory string, canonicalOrigin string) (string, error)
- func RefreshGitHubRunnerRelease(ctx context.Context, stateStore githubRunnerReleaseStore, ...) (store.GitHubRunnerReleaseState, error)
- func RequireInitializedControllerState(directory string) error
- func ServeAgent(ctx context.Context, options AgentServeOptions) error
- func ServeController(ctx context.Context, state *ControllerState, options ControllerServeOptions) error
- func ValidateAdminListener(listener net.Listener) error
- type AgentBroker
- func (broker *AgentBroker) Close()
- func (broker *AgentBroker) ConnectedCount() int
- func (broker *AgentBroker) DisconnectError(nodeID domain.NodeID) (error, bool)
- func (broker *AgentBroker) GoString() string
- func (broker *AgentBroker) LogValue() slog.Value
- func (broker *AgentBroker) MarshalJSON() ([]byte, error)
- func (broker *AgentBroker) Readiness(nodeID domain.NodeID) (AgentSnapshot, bool, context.Context)
- func (broker *AgentBroker) ReplayPrepare(ctx context.Context, nodeID domain.NodeID, metadata transport.CommandMetadata, ...) (transport.ExecutionUpdate, error)
- func (broker *AgentBroker) SendCancel(ctx context.Context, nodeID domain.NodeID, metadata transport.CommandMetadata) (transport.ExecutionUpdate, error)
- func (broker *AgentBroker) SendPrepare(ctx context.Context, nodeID domain.NodeID, metadata transport.CommandMetadata, ...) (transport.ExecutionUpdate, error)
- func (broker *AgentBroker) SendReconciliationCancel(ctx context.Context, nodeID domain.NodeID, metadata transport.CommandMetadata, ...) (transport.ExecutionUpdate, error)
- func (broker *AgentBroker) SendStart(ctx context.Context, nodeID domain.NodeID, metadata transport.CommandMetadata, ...) (transport.ExecutionUpdate, error)
- func (broker *AgentBroker) Snapshot(nodeID domain.NodeID) (AgentSnapshot, bool)
- func (broker *AgentBroker) String() string
- type AgentBrokerOptions
- type AgentCommandConsumer
- type AgentCommandConsumerFunc
- type AgentCommandRecord
- type AgentCommandRuntime
- func (runtime *AgentCommandRuntime) Accept(ctx context.Context, envelope *transport.Envelope) (*acceptedAgentCommand, error)
- func (runtime *AgentCommandRuntime) AcknowledgeUpdate(ctx context.Context, messageID string) error
- func (runtime *AgentCommandRuntime) PendingUpdates(ctx context.Context) ([]store.PendingExecutionUpdate, error)
- func (runtime *AgentCommandRuntime) Ready(ctx context.Context) bool
- func (runtime *AgentCommandRuntime) RunnerVersion() string
- func (runtime *AgentCommandRuntime) Start(ctx context.Context) error
- func (runtime *AgentCommandRuntime) UpdateReady() <-chan struct{}
- type AgentConsumers
- type AgentDisconnectConsumer
- type AgentDisconnectConsumerFunc
- type AgentDisconnectRecord
- type AgentEligibilityConsumer
- type AgentEligibilityConsumerFunc
- type AgentExecutionUpdateRecord
- type AgentLocalControlOptions
- type AgentOwnerStateConsumer
- type AgentOwnerStateConsumerFunc
- type AgentOwnerStateRecord
- type AgentReadinessConsumer
- type AgentReadinessConsumerFunc
- type AgentServeOptions
- type AgentSnapshot
- type AgentSnapshotConsumer
- type AgentSnapshotConsumerFunc
- type AgentState
- type ControllerFleet
- type ControllerFleetProvider
- type ControllerFleetSession
- type ControllerFleetTarget
- type ControllerRunnerConfig
- type ControllerRunnerCoordinator
- func (coordinator *ControllerRunnerCoordinator) CommitMessage(ctx context.Context, message github.Message) error
- func (coordinator *ControllerRunnerCoordinator) CommitSessionDemand(ctx context.Context, snapshot github.SessionSnapshot) error
- func (coordinator *ControllerRunnerCoordinator) CommitSessionHealthy(ctx context.Context, snapshot github.SessionSnapshot) error
- func (coordinator *ControllerRunnerCoordinator) DriveNext(ctx context.Context) (bool, error)
- func (coordinator *ControllerRunnerCoordinator) PollAndDriveOnce(ctx context.Context) (*github.Message, error)
- func (coordinator *ControllerRunnerCoordinator) PollOnce(ctx context.Context) (*github.Message, error)
- func (coordinator *ControllerRunnerCoordinator) ReconcileJITAttempt(ctx context.Context, claimKey int64) error
- func (coordinator *ControllerRunnerCoordinator) Run(ctx context.Context) error
- type ControllerRunnerLifecycle
- type ControllerServeOptions
- type ControllerState
- func (state *ControllerState) Close() error
- func (state *ControllerState) CreateJoinCode(ctx context.Context, hints []string) (string, error)
- func (state ControllerState) GoString() string
- func (state ControllerState) LogValue() slog.Value
- func (state ControllerState) MarshalJSON() ([]byte, error)
- func (state ControllerState) String() string
- type ExecutionUpdateConsumer
- type ExecutionUpdateConsumerFunc
- type JoinOptions
- type ManagementTargetIntentRecorder
- type ManagementTargetVerifier
Constants ¶
const ( DefaultDiscoveryTimeout = 3 * time.Second DefaultConnectTimeout = 30 * time.Second DefaultReconnectDelay = 5 * time.Second DefaultAgentHeartbeatInterval = time.Second DefaultAgentReadinessTimeout = 500 * time.Millisecond )
const DefaultAgentReadinessLease = 4 * time.Second
const DefaultHTTPReadHeaderTimeout = 10 * time.Second
Variables ¶
var ( ErrAgentOffline = errors.New("agent is offline") ErrAgentDisconnected = errors.New("agent disconnected") ErrAgentSessionReplaced = errors.New("agent session was replaced") ErrAgentProtocol = errors.New("agent protocol violation") ErrAgentBrokerClosed = errors.New("agent broker is closed") ErrAgentCommandConsumerRequired = errors.New("agent command consumer is required") ErrAgentSnapshotConsumerRequired = errors.New("agent snapshot consumer is required") ErrAgentReadinessConsumerRequired = errors.New("agent readiness consumer is required") ErrExecutionUpdateConsumerRequired = errors.New("execution update consumer is required") ErrAgentOwnerStateConsumerRequired = errors.New("agent owner state consumer is required") ErrAgentCommandCommit = errors.New("agent command commit failed") ErrAgentSnapshotCommit = errors.New("agent snapshot commit failed") ErrExecutionUpdateCommit = errors.New("execution update commit failed") ErrAgentDisconnectCommit = errors.New("agent disconnect commit failed") ErrAgentReconciliationStale = errors.New("agent reconciliation snapshot changed") )
var ( // ErrControllerFleetConfig reports an incomplete fleet composition. It is a // programming error at construction time, never a runtime provider state. ErrControllerFleetConfig = errors.New("controller fleet configuration is invalid") // ErrControllerFleetScaleSet reports that the durable runtime binding no // longer names the scale set GitHub reports for this Target. Driving it // anyway could consume another installation's queue, so the Target runs no // coordinator until an operator reprovisions it. ErrControllerFleetScaleSet = errors.New("GitHub scale set does not match the stored runtime binding") )
var ( ErrGitHubRunnerReleaseConfig = errors.New("GitHub runner release observation is not configured") ErrGitHubRunnerReleaseObservation = errors.New("GitHub runner release observation failed") ErrGitHubRunnerReleaseStore = errors.New("GitHub runner release state persistence failed") )
var ( ErrControllerRunnerConfig = errors.New("controller runner coordinator configuration is invalid") ErrGitHubAcquireAmbiguous = errors.New("GitHub job acquisition is ambiguous") ErrGitHubAvailableUnclaimed = errors.New("GitHub available job has no eligible durable slot claim") ErrGitHubPrepareFailed = errors.New("Agent runner preparation failed") ErrGitHubStartAmbiguous = errors.New("Agent runner start is ambiguous") ErrGitHubReconciliationRequired = errors.New("GitHub runner reconciliation is required") ErrGitHubReconciliationPending = errors.New("GitHub runner reconciliation needs another observation") ErrGitHubSessionFailureStore = errors.New("GitHub session failure state could not be persisted") ErrControllerRunnerAdmission = errors.New("controller runner admission is unavailable") // ErrControllerRunnerNoCandidate reports that the Target currently has no // node the coordinator could even evaluate for capacity. It is a normal, // recoverable state (an empty or fully removed fleet), never a fatal one. ErrControllerRunnerNoCandidate = errors.New("controller runner target has no candidate node") )
var ( ErrAlreadyInitialized = errors.New("sparerunner state is already initialized") ErrNotInitialized = errors.New("sparerunner state is not initialized") )
var ErrAgentRuntimeDegraded = errors.New("agent runner runtime is degraded")
Functions ¶
func ClassifyGitHubObservationFailure ¶
func ClassifyGitHubObservationFailure( failure error, ) store.GitHubObservationFailureClass
ClassifyGitHubObservationFailure maps immediate provider errors to the secret-free persistence allowlist shared by session and release observations. Callers must exclude intentional local cancellation before persisting it.
func InitializeController ¶
func InitializeController(ctx context.Context, directory string, hints []string) (code string, err error)
InitializeController publishes a complete state directory atomically. A failed initializer rolls back platform credentials before removing its uniquely-created staging directory; failed credential cleanup preserves the private locators for explicit recovery.
func LoadManagementBootstrapProof ¶
LoadManagementBootstrapProof derives the owner proof used by the local CLI to establish an administrator session. The durable root remains behind the Controller's private credential locator and is never returned to the caller.
func RefreshGitHubRunnerRelease ¶
func RefreshGitHubRunnerRelease( ctx context.Context, stateStore githubRunnerReleaseStore, observer githubRunnerReleaseObserver, ) (store.GitHubRunnerReleaseState, error)
RefreshGitHubRunnerRelease records either one exact successful observation or one allowlisted failure. An intentional caller cancellation is not provider evidence and therefore does not make the last-known release stale.
func RequireInitializedControllerState ¶
RequireInitializedControllerState reports whether a directory is a controller state directory this host may write private material into. Commands that touch credentials directly — rather than through the management API — call it so an uninitialized or hand-made directory produces the actionable "run sprun init" error instead of a platform credential-store failure, which on Windows is how a missing directory ACL surfaces.
func ServeAgent ¶
func ServeAgent(ctx context.Context, options AgentServeOptions) error
func ServeController ¶
func ServeController(ctx context.Context, state *ControllerState, options ControllerServeOptions) error
func ValidateAdminListener ¶
ValidateAdminListener keeps the unauthenticated management surface on loopback. A future LAN management mode must terminate authenticated TLS at this boundary or explicitly trust an authenticated reverse proxy.
Types ¶
type AgentBroker ¶
type AgentBroker struct {
// contains filtered or unexported fields
}
AgentBroker owns one active bidirectional session actor per authenticated node. It never stores command payloads or JIT configuration.
func NewAgentBroker ¶
func NewAgentBroker(epoch domain.ControllerEpoch, consumers AgentConsumers) *AgentBroker
func NewAgentBrokerWithOptions ¶
func NewAgentBrokerWithOptions( epoch domain.ControllerEpoch, consumers AgentConsumers, options AgentBrokerOptions, ) *AgentBroker
func (*AgentBroker) Close ¶
func (broker *AgentBroker) Close()
func (*AgentBroker) ConnectedCount ¶
func (broker *AgentBroker) ConnectedCount() int
func (*AgentBroker) DisconnectError ¶
func (broker *AgentBroker) DisconnectError(nodeID domain.NodeID) (error, bool)
DisconnectError exposes an optional durable disconnect failure without disguising the session as connected. A later successful disconnect or a replacement session activation clears the retained error.
func (*AgentBroker) GoString ¶
func (broker *AgentBroker) GoString() string
func (*AgentBroker) LogValue ¶
func (broker *AgentBroker) LogValue() slog.Value
func (*AgentBroker) MarshalJSON ¶
func (broker *AgentBroker) MarshalJSON() ([]byte, error)
func (*AgentBroker) Readiness ¶
func (broker *AgentBroker) Readiness( nodeID domain.NodeID, ) (AgentSnapshot, bool, context.Context)
Readiness returns one atomic view of the current Agent evidence and a state-incarnation context. The context is canceled whenever readiness changes, its lease expires, or the authenticated session disconnects.
func (*AgentBroker) ReplayPrepare ¶
func (broker *AgentBroker) ReplayPrepare( ctx context.Context, nodeID domain.NodeID, metadata transport.CommandMetadata, disableUpdate bool, snapshotDigest string, ) (transport.ExecutionUpdate, error)
ReplayPrepare replays a previously committed secret-free Prepare identity. A prior Controller epoch is accepted only at this broker boundary; the durable command consumer still requires an exact existing record, so this path cannot introduce new old-epoch authority.
func (*AgentBroker) SendCancel ¶
func (broker *AgentBroker) SendCancel( ctx context.Context, nodeID domain.NodeID, metadata transport.CommandMetadata, ) (transport.ExecutionUpdate, error)
func (*AgentBroker) SendPrepare ¶
func (broker *AgentBroker) SendPrepare( ctx context.Context, nodeID domain.NodeID, metadata transport.CommandMetadata, disableUpdate bool, ) (transport.ExecutionUpdate, error)
SendPrepare asks the Agent to materialize the non-secret runner package and runtime boundary. Admission of the later JIT-bearing start remains the durable coordinator's responsibility; broker memory is not desired state.
func (*AgentBroker) SendReconciliationCancel ¶
func (broker *AgentBroker) SendReconciliationCancel( ctx context.Context, nodeID domain.NodeID, metadata transport.CommandMetadata, snapshotDigest string, ) (transport.ExecutionUpdate, error)
SendReconciliationCancel commits a recovery-only Cancel authority before it reaches the Agent. It is used when desired state is already terminal but a fresh Agent snapshot proves that the exact local runtime still exists.
func (*AgentBroker) SendStart ¶
func (broker *AgentBroker) SendStart( ctx context.Context, nodeID domain.NodeID, metadata transport.CommandMetadata, disableUpdate bool, jitConfig runner.JITConfig, ) (transport.ExecutionUpdate, error)
SendStart writes the secret-bearing payload directly to the active session. The temporary JSON buffer is wiped immediately after the synchronous write; no broker queue, pending record, or callback receives the JIT body.
A disconnect after Write is ambiguous: the Agent may already have committed and started the command. The broker never retries or regenerates JIT material. The coordinator must reconcile the Agent command/outbox snapshot before it creates another JIT configuration for this execution.
func (*AgentBroker) Snapshot ¶
func (broker *AgentBroker) Snapshot(nodeID domain.NodeID) (AgentSnapshot, bool)
func (*AgentBroker) String ¶
func (broker *AgentBroker) String() string
type AgentBrokerOptions ¶
type AgentCommandConsumer ¶
type AgentCommandConsumer interface {
// HandleAgentCommand must exact-deduplicate CommandID and commit before
// returning nil. Different node actors may call it concurrently.
HandleAgentCommand(context.Context, AgentCommandRecord) error
}
type AgentCommandConsumerFunc ¶
type AgentCommandConsumerFunc func(context.Context, AgentCommandRecord) error
func (AgentCommandConsumerFunc) HandleAgentCommand ¶
func (consumer AgentCommandConsumerFunc) HandleAgentCommand(ctx context.Context, command AgentCommandRecord) error
type AgentCommandRecord ¶
type AgentCommandRecord struct {
NodeID domain.NodeID
Kind transport.MessageType
Metadata transport.CommandMetadata
PayloadDigest [sha256.Size]byte
Reconciliation bool
ReplayOnly bool
SnapshotDigest string
}
AgentCommandRecord is the non-secret, durable identity committed before a command reaches the network. PayloadDigest covers kind + NUL + the exact encoded payload; the raw payload and JIT configuration never cross this boundary.
type AgentCommandRuntime ¶
type AgentCommandRuntime struct {
// contains filtered or unexported fields
}
AgentCommandRuntime connects authenticated protocol commands to the durable local runner boundary. Accept persists the replay identity before the caller acknowledges a command; Execute performs the separately replay-safe lifecycle.
func NewAgentCommandRuntime ¶
func NewAgentCommandRuntime(nodeID string, agentStore *store.AgentStore, manager runnerLifecycle, pkg runner.Package) (*AgentCommandRuntime, error)
func (*AgentCommandRuntime) AcknowledgeUpdate ¶
func (runtime *AgentCommandRuntime) AcknowledgeUpdate(ctx context.Context, messageID string) error
func (*AgentCommandRuntime) PendingUpdates ¶
func (runtime *AgentCommandRuntime) PendingUpdates(ctx context.Context) ([]store.PendingExecutionUpdate, error)
func (*AgentCommandRuntime) Ready ¶
func (runtime *AgentCommandRuntime) Ready(ctx context.Context) bool
Ready performs a live, non-secret platform admission probe. The returned error is classification-only and must never be copied into heartbeat payloads.
func (*AgentCommandRuntime) RunnerVersion ¶
func (runtime *AgentCommandRuntime) RunnerVersion() string
RunnerVersion is the exact audited package identity this Agent can materialize. It is safe to publish in the typed snapshot and lets the Controller reject a stale or mixed-version Agent before reserving a slot.
func (*AgentCommandRuntime) Start ¶
func (runtime *AgentCommandRuntime) Start(ctx context.Context) error
Start binds background completion monitoring to the Agent process lifetime, not to any one controller connection. Rebinding would make ownership ambiguous and therefore fails closed.
func (*AgentCommandRuntime) UpdateReady ¶
func (runtime *AgentCommandRuntime) UpdateReady() <-chan struct{}
type AgentConsumers ¶
type AgentConsumers struct {
Commands AgentCommandConsumer
Snapshot AgentSnapshotConsumer
Readiness AgentReadinessConsumer
ExecutionUpdates ExecutionUpdateConsumer
Disconnects AgentDisconnectConsumer
Eligibility AgentEligibilityConsumer
OwnerState AgentOwnerStateConsumer
}
Command, snapshot, readiness, and execution-update consumers are mandatory for a work-bearing production session; Disconnects is optional for brokers without a scheduler projection. A nil mandatory owner fails closed before its corresponding ACK or command write. Consumers are commit boundaries and must not synchronously call this broker's Send methods.
Eligibility is deliberately not mandatory: it is informational display data, not a correctness or security boundary, so its absence degrades a heartbeat ack to carrying no eligible-target list rather than failing the session.
OwnerState is optional in the same sense as Disconnects — a broker without a durable projection has nothing to adopt into — but it is not best-effort: a heartbeat that reports an owner change with no consumer configured fails closed rather than silently dropping the change.
type AgentDisconnectConsumer ¶
type AgentDisconnectConsumer interface {
// HandleAgentDisconnect runs outside the per-node lifecycle lock and must
// honor context cancellation. The broker lifetime owns the context so
// Controller shutdown can interrupt a stalled local projection.
HandleAgentDisconnect(context.Context, AgentDisconnectRecord) error
}
AgentDisconnectConsumer owns the durable readiness revocation and last-known Controller projection transition after the current authenticated session disappears. It is optional because enrollment-only and test brokers do not advertise scheduler capacity.
type AgentDisconnectConsumerFunc ¶
type AgentDisconnectConsumerFunc func(context.Context, AgentDisconnectRecord) error
func (AgentDisconnectConsumerFunc) HandleAgentDisconnect ¶
func (consumer AgentDisconnectConsumerFunc) HandleAgentDisconnect( ctx context.Context, record AgentDisconnectRecord, ) error
type AgentDisconnectRecord ¶
AgentDisconnectRecord binds an offline transition to the exact full Agent journal that activated the disappearing authenticated session. The digest contains no JIT material or credential.
type AgentEligibilityConsumer ¶
type AgentEligibilityConsumer interface {
EligibleTargets(
ctx context.Context,
nodeID domain.NodeID,
os domain.OperatingSystem,
architecture domain.Architecture,
) ([]transport.EligibleTarget, error)
}
AgentEligibilityConsumer reports which configured GitHub Targets currently match a node's platform. It is read-only display data derived from configuration, never a scheduling decision or a capacity guarantee. The node identity is required because each entry also reports whether the controller has durably adopted that Target as excluded for this node.
type AgentEligibilityConsumerFunc ¶
type AgentEligibilityConsumerFunc func( context.Context, domain.NodeID, domain.OperatingSystem, domain.Architecture, ) ([]transport.EligibleTarget, error)
func (AgentEligibilityConsumerFunc) EligibleTargets ¶
func (consumer AgentEligibilityConsumerFunc) EligibleTargets( ctx context.Context, nodeID domain.NodeID, os domain.OperatingSystem, architecture domain.Architecture, ) ([]transport.EligibleTarget, error)
type AgentExecutionUpdateRecord ¶
type AgentExecutionUpdateRecord struct {
MessageID string
Update transport.ExecutionUpdate
PayloadDigest [sha256.Size]byte
}
ExecutionUpdateConsumer is the scheduler/reconciler-owned durable boundary. The envelope message ID participates in exact deduplication. The broker acknowledges an update only after this callback accepts it. Different node actors may call the consumer concurrently.
type AgentLocalControlOptions ¶
type AgentLocalControlOptions struct {
Enabled bool
OwnerUIDs []int
OwnerSIDs []string
Logger *slog.Logger
}
AgentLocalControlOptions configures the same-host endpoint the tray, the launcher, and the CLI use. Authorization is an explicit allowlist of local principals: the service account itself, plus any node-owner desktop account the operator names. The naming is per platform because the two systems have no common principal type — OwnerUIDs on Unix, OwnerSIDs on Windows — and the option that does not apply to the running platform is ignored. An empty allowlist authorizes nobody but the service account.
type AgentOwnerStateConsumer ¶
type AgentOwnerStateConsumer interface {
HandleAgentOwnerState(context.Context, AgentOwnerStateRecord) error
}
AgentOwnerStateConsumer owns the durable adoption of node-owner availability state reported on a heartbeat. It runs under the per-node lifecycle lock before the acknowledgement, so a failed adoption fails the heartbeat instead of leaving the owner's change unrecorded but acknowledged.
type AgentOwnerStateConsumerFunc ¶
type AgentOwnerStateConsumerFunc func(context.Context, AgentOwnerStateRecord) error
func (AgentOwnerStateConsumerFunc) HandleAgentOwnerState ¶
func (consumer AgentOwnerStateConsumerFunc) HandleAgentOwnerState( ctx context.Context, record AgentOwnerStateRecord, ) error
type AgentOwnerStateRecord ¶
type AgentOwnerStateRecord struct {
NodeID domain.NodeID
SnapshotDigest string
AvailabilityIntent domain.AvailabilityIntent
ExcludedTargets []domain.TargetID
// pointer means "no change reported" and preserves the last-known adopted
// value, exactly like an empty AvailabilityIntent; it never resets to false,
// because silently downgrading a reported weakness to "isolated" would be
// the one wrong answer an operator cannot detect.
SharedRunnerIdentity *bool
}
AgentOwnerStateRecord binds one mid-session node-owner availability change to the exact full Agent journal that activated this session. Intent "" and a nil ExcludedTargets each mean "no change reported"; a non-nil ExcludedTargets is the authoritative full set, including an empty one.
type AgentReadinessConsumer ¶
type AgentReadinessConsumer interface {
HandleAgentReadiness(context.Context, domain.NodeID, string, bool) error
}
AgentReadinessConsumer owns the durable readiness-only compare-and-swap. Readiness is lease-backed liveness and must not be persisted by replaying an older full Agent journal snapshot.
type AgentReadinessConsumerFunc ¶
func (AgentReadinessConsumerFunc) HandleAgentReadiness ¶
type AgentServeOptions ¶
type AgentServeOptions struct {
StateDirectory string
// LocalControl serves the node-local availability endpoint for the tray,
// launcher, and CLI. It is disabled by default so an unconfigured owner
// identity never widens the Agent's local surface implicitly.
LocalControl AgentLocalControlOptions
// SharedRunnerIdentity reports that this node's native runner executes jobs
// under the Agent's own uid rather than a dedicated per-runner uid, so the
// isolation between the Agent and the job it runs is absent. It is a static
// process-level fact set once from the serve flag and reported unchanged to
// every observer, so nobody mistakes this weaker mode for the isolated one.
//
// It is observation only. It must never affect capacity or readiness gating:
// admission stays the conjunction of native runner readiness and the owner's
// availability intent, exactly as it is without this option.
ConnectionTimeout time.Duration
ReconnectDelay time.Duration
HeartbeatInterval time.Duration
ReadinessTimeout time.Duration
Logger *slog.Logger
CommandRuntime func(context.Context, *AgentState) (*AgentCommandRuntime, error)
}
type AgentSnapshot ¶
type AgentSnapshot = transport.AgentSnapshot
AgentSnapshot is the authenticated, non-secret journal evidence used to reconcile and activate a node session.
type AgentSnapshotConsumer ¶
type AgentSnapshotConsumer interface {
// HandleAgentSnapshot must durably reconcile the full typed journal before
// returning nil. Different node handshakes may call it concurrently.
HandleAgentSnapshot(context.Context, AgentSnapshot) error
}
AgentSnapshotConsumer owns durable reconciliation of the complete Agent journal snapshot. A session is not acknowledged or activated until it accepts the snapshot.
type AgentSnapshotConsumerFunc ¶
type AgentSnapshotConsumerFunc func(context.Context, AgentSnapshot) error
func (AgentSnapshotConsumerFunc) HandleAgentSnapshot ¶
func (consumer AgentSnapshotConsumerFunc) HandleAgentSnapshot(ctx context.Context, snapshot AgentSnapshot) error
type AgentState ¶
type AgentState struct {
Directory string
Store *store.AgentStore
PrivateKey ed25519.PrivateKey
NodeID string
Endpoint string
CertificateDER []byte
CADER []byte
}
func (*AgentState) Close ¶
func (state *AgentState) Close() error
func (*AgentState) CredentialReady ¶
func (state *AgentState) CredentialReady(ctx context.Context) error
CredentialReady verifies that the exact durable node identity and enrolled configuration remain loadable through the platform credential store. The in-memory TLS key alone is insufficient admission authority because losing durable identity would make the next service restart unreconcilable.
func (AgentState) GoString ¶
func (state AgentState) GoString() string
func (AgentState) LogValue ¶
func (state AgentState) LogValue() slog.Value
func (AgentState) MarshalJSON ¶
func (state AgentState) MarshalJSON() ([]byte, error)
func (AgentState) String ¶
func (state AgentState) String() string
type ControllerFleet ¶
type ControllerFleet struct {
// contains filtered or unexported fields
}
ControllerFleet supervises exactly one runner coordinator per bound Target. A GitHub scale set exposes a single message queue, so two sessions or two pollers over one Target would race and double-consume it; the fleet is the component that makes "one per Target" a structural property.
func NewControllerFleet ¶
func NewControllerFleet( state *ControllerState, provider ControllerFleetProvider, logger *slog.Logger, ) (*ControllerFleet, error)
NewControllerFleet composes the production fleet. A controller without GitHub App authority has no provider and must not be given a fleet at all; that is a normal disconnected state handled by the caller, so it fails closed here.
func (*ControllerFleet) DesiredTargets ¶
func (fleet *ControllerFleet) DesiredTargets( ctx context.Context, ) ([]ControllerFleetTarget, error)
DesiredTargets resolves the coordinator set the current durable state calls for. A Target without a committed runtime binding, without a runner profile, or without provisioning evidence is deliberately absent: fail closed at zero capacity and let the existing github_target_runtime_unverified condition surface it, rather than fabricating a binding.
type ControllerFleetProvider ¶
type ControllerFleetProvider interface {
Open(context.Context, ControllerFleetTarget) (ControllerFleetSession, ControllerRunnerLifecycle, error)
}
ControllerFleetProvider opens the exact GitHub surface for one Target. The production implementation lives below; tests substitute it so fleet supervision can be exercised without a live provider.
func NewGitHubAuthorityFleetProvider ¶
func NewGitHubAuthorityFleetProvider(authority *github.Authority) ControllerFleetProvider
NewGitHubAuthorityFleetProvider returns nil when the controller has no GitHub App authority. A disconnected controller is a normal state, so the caller simply runs no fleet.
type ControllerFleetSession ¶
type ControllerFleetSession interface {
Close(ctx context.Context) error
// contains filtered or unexported methods
}
ControllerFleetSession is the provider surface one Target's coordinator owns for the lifetime of a single attempt.
type ControllerFleetTarget ¶
type ControllerFleetTarget struct {
TargetID domain.TargetID
ScaleSetID github.ScaleSetID
ScaleSetName string
RunnerGroupID int
InstallationID int64
Scope string
ScopeKind domain.TargetScopeKind
RunnerProfileID domain.RunnerProfileID
VersionPolicy domain.RunnerVersionPolicy
}
ControllerFleetTarget is one fully resolved unit of coordination: a Target whose configuration, committed runtime binding, and provisioning evidence all agree. It is comparable on purpose, so a configuration change is detected by value rather than by re-deriving intent.
type ControllerRunnerConfig ¶
type ControllerRunnerConfig struct {
ScaleSetID github.ScaleSetID
TargetID domain.TargetID
// Scope and ScopeKind name the GitHub org/repo this coordinator serves. They
// travel on prepare and start purely so a node owner's desktop surface can
// say which scope a job belongs to; the Agent enforces on TargetID alone.
Scope string
ScopeKind domain.TargetScopeKind
RunnerProfileID domain.RunnerProfileID
VersionPolicy domain.RunnerVersionPolicy
// NodeID pins this coordinator to exactly one node. It is optional: an
// empty value makes every configured node a candidate and the binding is
// resolved per operation instead. The live acceptance rig sets it so its
// evidence stays about one known machine.
NodeID domain.NodeID
ControllerEpoch domain.ControllerEpoch
Reconciler controllerRunnerReconciler
}
type ControllerRunnerCoordinator ¶
type ControllerRunnerCoordinator struct {
// contains filtered or unexported fields
}
func NewControllerRunnerCoordinator ¶
func NewControllerRunnerCoordinator( stateStore controllerRunnerStore, session controllerRunnerMessageSession, agents controllerRunnerAgent, lifecycle ControllerRunnerLifecycle, config ControllerRunnerConfig, logger *slog.Logger, ) (*ControllerRunnerCoordinator, error)
NewControllerRunnerCoordinator creates the production-callable single-slot vertical for exactly one Target. A GitHub scale set exposes one message queue, so exactly one coordinator, session, and poller may exist per Target; the owning node is therefore resolved per operation rather than pinned.
func (*ControllerRunnerCoordinator) CommitMessage ¶
func (*ControllerRunnerCoordinator) CommitSessionDemand ¶
func (coordinator *ControllerRunnerCoordinator) CommitSessionDemand( ctx context.Context, snapshot github.SessionSnapshot, ) error
func (*ControllerRunnerCoordinator) CommitSessionHealthy ¶
func (coordinator *ControllerRunnerCoordinator) CommitSessionHealthy( ctx context.Context, snapshot github.SessionSnapshot, ) error
func (*ControllerRunnerCoordinator) DriveNext ¶
func (coordinator *ControllerRunnerCoordinator) DriveNext(ctx context.Context) (bool, error)
DriveNext advances at most one durable single-slot claim. A pre-existing Pending claim is sufficient after restart; no in-memory PollOnce result is required.
func (*ControllerRunnerCoordinator) PollAndDriveOnce ¶
func (*ControllerRunnerCoordinator) PollOnce ¶
func (coordinator *ControllerRunnerCoordinator) PollOnce(ctx context.Context) (*github.Message, error)
PollOnce commits one GitHub message before acknowledgement. Capacity is read from the same durable single slot used by CommitMessage and is zero whenever its node is draining, quarantined, revoked, missing, or already reserved.
func (*ControllerRunnerCoordinator) ReconcileJITAttempt ¶
func (coordinator *ControllerRunnerCoordinator) ReconcileJITAttempt( ctx context.Context, claimKey int64, ) error
ReconcileJITAttempt is the only path that permits a later JIT attempt. It requires a freshly activated Agent snapshot, then either proves the exact start command was accepted or removes and re-reads the deterministic GitHub runner registration before marking it absent.
func (*ControllerRunnerCoordinator) Run ¶
func (coordinator *ControllerRunnerCoordinator) Run(ctx context.Context) error
Run owns the single-target acceptance loop. A restart drives already-acquired or preparing work and prior-epoch reconciliation before long polling, so it does not consume most of GitHub's runner pickup window. Pending work remains poll-first because commit-before-ack redelivery is its upstream authority.
type ControllerRunnerLifecycle ¶
type ControllerRunnerLifecycle interface {
GenerateJITConfig(context.Context, github.JITRequest) (runner.JITConfig, github.RunnerReference, error)
QueryRunner(context.Context, github.RunnerQuery) (*github.RunnerReference, error)
RemoveRunner(context.Context, github.RunnerReference) error
}
ControllerRunnerLifecycle makes JIT generation testable without exposing the opaque body. The production adapter is NewGitHubClientRunnerLifecycle.
func NewGitHubClientRunnerLifecycle ¶
func NewGitHubClientRunnerLifecycle(client *github.Client) (ControllerRunnerLifecycle, error)
type ControllerServeOptions ¶
type ControllerState ¶
type ControllerState struct {
Directory string
Identity enroll.ControllerIdentity
Store *store.ControllerStore
Service enroll.Service
Sessions *transport.ActiveSessionRegistry
AgentBroker *AgentBroker
Reconciler *reconcile.Controller
TargetVerifier ManagementTargetVerifier
GitHubAuthority *github.Authority
AdminSession [32]byte
Epoch uint64
}
func OpenController ¶
func (*ControllerState) Close ¶
func (state *ControllerState) Close() error
func (*ControllerState) CreateJoinCode ¶
func (ControllerState) GoString ¶
func (state ControllerState) GoString() string
func (ControllerState) LogValue ¶
func (state ControllerState) LogValue() slog.Value
func (ControllerState) MarshalJSON ¶
func (state ControllerState) MarshalJSON() ([]byte, error)
func (ControllerState) String ¶
func (state ControllerState) String() string
type ExecutionUpdateConsumer ¶
type ExecutionUpdateConsumer interface {
// HandleExecutionUpdate must exact-deduplicate (NodeID, MessageID), including
// PayloadDigest, and commit the lifecycle observation before returning nil.
HandleExecutionUpdate(context.Context, AgentExecutionUpdateRecord) error
}
type ExecutionUpdateConsumerFunc ¶
type ExecutionUpdateConsumerFunc func(context.Context, AgentExecutionUpdateRecord) error
func (ExecutionUpdateConsumerFunc) HandleExecutionUpdate ¶
func (consumer ExecutionUpdateConsumerFunc) HandleExecutionUpdate(ctx context.Context, update AgentExecutionUpdateRecord) error
type JoinOptions ¶
type JoinOptions struct {
StateDirectory string
JoinCode string
Controller string
Discoverer transport.Discoverer
DiscoveryTimeout time.Duration
ConnectionTimeout time.Duration
}
func (JoinOptions) GoString ¶
func (options JoinOptions) GoString() string
func (JoinOptions) LogValue ¶
func (options JoinOptions) LogValue() slog.Value
func (JoinOptions) MarshalJSON ¶
func (options JoinOptions) MarshalJSON() ([]byte, error)
func (JoinOptions) String ¶
func (options JoinOptions) String() string
type ManagementTargetVerifier ¶
type ManagementTargetVerifier interface {
VerifyManagementTarget(
context.Context,
config.GitHubTargetConfiguration,
) (store.ManagementGitHubTarget, error)
}
ManagementTargetVerifier is the only path that may turn operator-controlled target fields into private/safe provider authority. A disconnected Controller deliberately leaves this nil and rejects new or identity-changing targets. Implementations return a managementapi.ValidationError for an authoritatively unsafe/public target and another error for unavailable or uncertain authority. Provider creation is fenced by a durable provisioning intent before the configuration CAS; a concurrent CAS failure is therefore observable as an ambiguous intent instead of being reported as a successful local-only write.
Source Files
¶
- agent.go
- agent_availability.go
- agent_broker.go
- agent_local_control.go
- agent_local_control_unix.go
- agent_runner.go
- controller.go
- controller_agent_store.go
- controller_fleet.go
- controller_reconcile_actions.go
- controller_release.go
- controller_runner.go
- enrollment_guard.go
- enrollment_projection.go
- github_authority.go
- github_management.go
- management_api.go
- publish_linux.go
- state.go
- state_sync_other.go
- state_unix.go