Documentation
¶
Overview ¶
Package terminalwork implements the pure-domain durable terminal-work item state machine and store command shapes (requirements 8.1–8.9, design D9).
Work rows are independently idempotent actions with stable source keys, claim leases, and injectable-clock retry schedules. Domain code has no SQL, HTTP, or filesystem I/O. The application processor lives in the app subpackage; durable stores live under internal/infra/terminalwork/workstore.
Index ¶
- Constants
- Variables
- func HasSelectiveBound(q ListQuery) bool
- func SameIntentReplay(a, b WorkRecord) bool
- func ValidateListQuery(q ListQuery) error
- type AppendIntentOutcome
- type BoundVersions
- type BoundedError
- type ClaimDueCommand
- type ClaimLease
- type Clock
- type CompleteCommand
- type LifecycleCorrelation
- type ListPage
- type ListQuery
- type PromotePendingCommand
- type QuarantineCommand
- type RenewClaimCommand
- type RetrySchedule
- type RuntimeIdentityClass
- type ScheduleRetryCommand
- type SourceKey
- type WorkItem
- func (w *WorkItem) Claim(ownerID string, ttl time.Duration, clock Clock) error
- func (w *WorkItem) Complete() error
- func (w *WorkItem) MarkPending() error
- func (w *WorkItem) Quarantine(err BoundedError) error
- func (w *WorkItem) RenewClaim(ownerID string, ttl time.Duration, clock Clock) error
- func (w *WorkItem) Retry(schedule RetrySchedule, clock Clock, err BoundedError) error
- type WorkRecord
Constants ¶
const MaxQueryLimit = 500
MaxQueryLimit is the hard upper bound for ListQuery.Limit.
Variables ¶
var ( ErrQueryTooBroad = errors.New("terminalwork: query too broad") ErrQueryLimitExceeded = errors.New("terminalwork: query limit exceeded") )
Functions ¶
func HasSelectiveBound ¶
HasSelectiveBound reports whether q includes at least one selective filter.
func SameIntentReplay ¶
func SameIntentReplay(a, b WorkRecord) bool
SameIntentReplay reports whether a and b describe the same durable intent payload for idempotent AppendIntent replay (requirements 8.5, design D6).
func ValidateListQuery ¶
ValidateListQuery rejects unsupported or too-broad operator filters.
Types ¶
type AppendIntentOutcome ¶
type AppendIntentOutcome struct {
// Inserted is true only when this call definitively created the Intent row.
Inserted bool
// Replay is true only when an existing exact SameIntentReplay was confirmed.
Replay bool
}
AppendIntentOutcome is the definitive result of a production AppendIntent attempt. Inserted and Replay are mutually exclusive; neither is set when the call returns an ambiguous transport/store error.
func (AppendIntentOutcome) Definitive ¶
func (o AppendIntentOutcome) Definitive() bool
Definitive reports whether the outcome classifies the append unambiguously.
type BoundVersions ¶
type BoundVersions struct {
GenerationID string // executable-policy generation (persisted generation_id)
RuntimeInstanceID string // opaque process/manager incarnation
RuntimeGenerationID string // request-plane runtime configuration generation
ProviderID string
RatingID string
}
BoundVersions records generation/provider/rating versions bound at admit.
Identity rules (task 3.6):
- GenerationID is the executable-policy / snapshotgen generation identity. The historical field name is retained for persisted rows, storage codecs, and SameIntentReplay determinism. Prefer ExecutableGenerationID().
- RuntimeInstanceID is the opaque runtimehost.Manager process incarnation.
- RuntimeGenerationID is the runtimehost request-plane generation identity (GenerationMeta.ID). Together with RuntimeInstanceID it forms durable runtime identity; numeric IDs alone are not restart-safe.
- These identities must never be conflated with each other or with model registry/catalog generations.
func (BoundVersions) ExecutableGenerationID ¶
func (v BoundVersions) ExecutableGenerationID() string
ExecutableGenerationID returns the executable-policy generation identity.
func (BoundVersions) HasRuntimeGeneration ¶
func (v BoundVersions) HasRuntimeGeneration() bool
HasRuntimeGeneration reports whether an exact runtime configuration identity was bound (both instance and generation non-empty).
func (BoundVersions) RuntimeIdentity ¶
func (v BoundVersions) RuntimeIdentity() RuntimeIdentityClass
RuntimeIdentity returns the runtime identity classification for this row.
type BoundedError ¶
BoundedError is a content-safe work error classification.
type ClaimDueCommand ¶
type ClaimDueCommand struct {
OwnerID string
TTL time.Duration
Limit int
Now time.Time
ProviderID string
Kind sdk.WorkKind
}
ClaimDueCommand selects and claims a bounded batch of due work.
type ClaimLease ¶
ClaimLease coordinates workers, not users.
type CompleteCommand ¶
CompleteCommand marks claimed work completed for the expected owner.
type LifecycleCorrelation ¶
LifecycleCorrelation ties work to safe request/attempt identities.
type ListPage ¶
type ListPage struct {
Records []WorkRecord
Cursor string
}
ListPage is one bounded page of work records.
type ListQuery ¶
type ListQuery struct {
WorkID string
SourceKey SourceKey
State sdk.WorkState
States []sdk.WorkState
ProviderID string
Kind sdk.WorkKind
RequestID string
AttemptID string
DueBefore time.Time
UpdatedAfter time.Time
UpdatedBefore time.Time
Limit int
Cursor string
}
ListQuery is a bounded operator filter for terminal-work rows (requirement 8.9, 12.6–12.7).
type PromotePendingCommand ¶
PromotePendingCommand moves intent rows to pending claim eligibility.
type QuarantineCommand ¶
type QuarantineCommand struct {
WorkID string
Err BoundedError
Now time.Time
}
QuarantineCommand permanently parks malformed or non-retryable work.
type RenewClaimCommand ¶
RenewClaimCommand extends a held claim lease for the same owner.
type RetrySchedule ¶
RetrySchedule computes deterministic backoff without jitter in the domain.
type RuntimeIdentityClass ¶
type RuntimeIdentityClass uint8
RuntimeIdentityClass classifies BoundVersions runtime identity material.
const ( // RuntimeIdentityLegacy is both runtime instance and generation empty — // process-registry compatible rows from before task 3.6. RuntimeIdentityLegacy RuntimeIdentityClass = iota // RuntimeIdentityExact is both runtime instance and generation non-empty. RuntimeIdentityExact // RuntimeIdentityMalformed is only one of instance/generation populated. // It never falls back to legacy process-registry resolution. RuntimeIdentityMalformed )
type ScheduleRetryCommand ¶
type ScheduleRetryCommand struct {
WorkID string
ExpectedOwnerID string
Schedule RetrySchedule
Err BoundedError
Now time.Time
}
ScheduleRetryCommand schedules a non-permanent retry for claimed work.
type SourceKey ¶
SourceKey is a stable versioned work identity key (requirement 8.2).
type WorkItem ¶
type WorkItem struct {
SourceKey SourceKey
WorkID string
Kind sdk.WorkKind
State sdk.WorkState
ProviderID string
Lifecycle LifecycleCorrelation
Versions BoundVersions
Attempts int
NextRetryAt time.Time
Lease ClaimLease
Error BoundedError
}
WorkItem is one independently idempotent terminal action.
func NewIntent ¶
func NewIntent(source SourceKey, workID string, kind sdk.WorkKind, providerID string, life LifecycleCorrelation, ver BoundVersions) (*WorkItem, error)
NewIntent records durable intent first (design D9).
func (*WorkItem) MarkPending ¶
MarkPending promotes intent to pending.
func (*WorkItem) Quarantine ¶
func (w *WorkItem) Quarantine(err BoundedError) error
Quarantine permanently parks malformed or non-retryable work.
func (*WorkItem) RenewClaim ¶
RenewClaim extends a held claim lease for the same owner.
func (*WorkItem) Retry ¶
func (w *WorkItem) Retry(schedule RetrySchedule, clock Clock, err BoundedError) error
Retry schedules a retry using the clock and schedule.
type WorkRecord ¶
type WorkRecord struct {
WorkID string
SourceKey SourceKey
PayloadVersion int
Kind sdk.WorkKind
State sdk.WorkState
ProviderID string
Lifecycle LifecycleCorrelation
Versions BoundVersions
Payload []byte
FactID string
LeaseSetID string
Attempts int
NextRetryAt time.Time
Lease ClaimLease
Error BoundedError
CreatedAt time.Time
UpdatedAt time.Time
}
WorkRecord is the persisted terminal-work row (requirements 8.1–8.2, design D14).
func (*WorkRecord) ApplyWorkItem ¶
func (r *WorkRecord) ApplyWorkItem(w *WorkItem, now time.Time)
ApplyWorkItem copies domain transition results back into the record.
func (WorkRecord) ToWorkItem ¶
func (r WorkRecord) ToWorkItem() *WorkItem
ToWorkItem projects persisted state into the domain item for transitions.
func (WorkRecord) Validate ¶
func (r WorkRecord) Validate() error
Validate rejects malformed persisted records before store I/O.