Documentation
¶
Overview ¶
Package invalidation tracks which published profiles depend on mutable source worktrees and records why a profile no longer describes them.
The state is derived metadata. It never changes CURRENT or a published generation; a successful full rebuild replaces the profile record and clears its stale marker.
Index ¶
- Constants
- Variables
- type Manager
- func (manager *Manager) Invalidate(ctx context.Context, profile string, actual sourceobservation.Manifest) error
- func (manager *Manager) MarkStale(ctx context.Context, worktree topology.WorktreeID, repository string, ...) error
- func (manager *Manager) ProfilesForSource(worktree topology.WorktreeID) []string
- func (manager *Manager) RecordPublished(ctx context.Context, record ProfileRecord) error
- func (manager *Manager) Refresh(ctx context.Context) error
- func (manager *Manager) Snapshot() State
- type ProfileRecord
- type ProfileState
- type Reason
- type SourceChange
- type SourceDependents
- type State
Constants ¶
const ( // CurrentVersion is the on-disk schema version of the invalidation state. CurrentVersion = 1 // StateFileName is the installation-level file containing the reverse index // and the stale diagnostics for every profile. StateFileName = "source-invalidation.json" )
Variables ¶
var ( // ErrStateBusy means another process is updating the installation state. // Callers can retry; no state was changed by the refused operation. ErrStateBusy = errors.New("source invalidation state is busy") // ErrProfileNotTracked means no published source manifest has been recorded // for the requested profile yet. ErrProfileNotTracked = errors.New("profile has no tracked source generation") )
Functions ¶
This section is empty.
Types ¶
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager owns one installation-level invalidation file. Its in-process mutex protects the cached state; the sidecar lock makes read-modify-write safe when separate profile indexers update the same installation concurrently.
func Open ¶
Open loads the installation invalidation state. A missing file means no published profile has been registered yet. The root itself is not created until the first mutating operation.
func (*Manager) Invalidate ¶
func (manager *Manager) Invalidate(ctx context.Context, profile string, actual sourceobservation.Manifest) error
Invalidate compares a profile's newly observed manifest and marks every profile that depends on each changed worktree. A profile-wide configuration change only affects the profile that supplied it.
func (*Manager) MarkStale ¶
func (manager *Manager) MarkStale(ctx context.Context, worktree topology.WorktreeID, repository string, reason Reason, detail string) error
MarkStale marks all profiles depending on the supplied worktree. It is the path for a watcher that knows a source became unavailable before it can make a complete manifest. The detail must preserve the observed failure reason.
func (*Manager) ProfilesForSource ¶
func (manager *Manager) ProfilesForSource(worktree topology.WorktreeID) []string
ProfilesForSource returns the profiles that use worktree in canonical name order. It reads the explicit reverse index, not repository names or paths.
func (*Manager) RecordPublished ¶
func (manager *Manager) RecordPublished(ctx context.Context, record ProfileRecord) error
RecordPublished records a successful generation and clears the stale state that generation accounts for. It does not clear stale markers belonging to other profiles that depend on the same worktree.
A change observed after the pass last verified its sources is not in the generation, and the record of it survives: see unpublishedChanges.
type ProfileRecord ¶
type ProfileRecord struct {
Profile string
Generation string
Manifest sourceobservation.Manifest
}
ProfileRecord is the publication input used to update one profile's state.
type ProfileState ¶
type ProfileState struct {
Profile string `json:"profile"`
Generation string `json:"generation"`
Manifest sourceobservation.Manifest `json:"manifest"`
Stale bool `json:"stale,omitempty"`
Reason string `json:"reason,omitempty"`
Changes []SourceChange `json:"changes,omitempty"`
}
ProfileState is the tracked source record for one profile. Manifest is kept so a daemon can rebuild the reverse index and explain a stale state after a restart without opening the graph database.
type Reason ¶
type Reason string
Reason identifies the first actionable cause of a source change.
const ( ReasonContentChanged Reason = "content_changed" ReasonCommitChanged Reason = "commit_changed" ReasonDirtyChanged Reason = "dirty_changed" ReasonBranchChanged Reason = "branch_changed" ReasonPolicyChanged Reason = "policy_changed" ReasonSourceAdded Reason = "source_added" ReasonSourceRemoved Reason = "source_removed" ReasonProviderChanged Reason = "provider_changed" ReasonObservationChanged Reason = "observation_changed" ReasonProfileConfigurationChange Reason = "profile_configuration_changed" ReasonResolverChanged Reason = "resolver_changed" ReasonAnalyzerChanged Reason = "analyzer_changed" )
type SourceChange ¶
type SourceChange struct {
Worktree topology.WorktreeID `json:"worktree,omitempty"`
Repository string `json:"repository,omitempty"`
Reason Reason `json:"reason"`
Detail string `json:"detail,omitempty"`
Before *topology.SourceObservation `json:"before,omitempty"`
After *topology.SourceObservation `json:"after,omitempty"`
}
SourceChange is one observed reason a profile's published inputs differ. Before and After are absent for profile-wide configuration changes and After is absent when a source became unavailable.
func CompareManifests ¶
func CompareManifests(expected, actual sourceobservation.Manifest) ([]SourceChange, error)
CompareManifests explains every source difference between a published manifest and a newly observed one. The result is sorted by WorktreeID and is suitable for both state persistence and diagnostics.
type SourceDependents ¶
type SourceDependents struct {
Worktree topology.WorktreeID `json:"worktree"`
Profiles []string `json:"profiles"`
}
SourceDependents is the explicit reverse relationship from one mutable worktree to every profile whose effective source set contains it.
type State ¶
type State struct {
Version int `json:"version"`
Profiles []ProfileState `json:"profiles"`
Sources []SourceDependents `json:"sources"`
}
State is the persisted invalidation index. Sources is redundant with the manifests on purpose: it makes the reverse relationship inspectable without decoding every profile record, while validation prevents the two views from diverging.