Documentation
¶
Overview ¶
Package core provides shared types and contracts used across all GRIP packages.
It defines the fundamental building blocks:
- AdmissionMode: controls behavior when capacity is exhausted (HardReject, SoftAllow, SoftAllowWithSignal)
- DeadlinePolicy: controls when deadlines are enforced (BeforeAdmission, AfterAdmission, Ignore)
- Execution: carries per-request metadata through the pipeline
- ExecutionGuarantees: specifies ordering and delivery semantics
- ShutdownCoordinator: interface for graceful shutdown coordination
Core types are designed to be lightweight value types with no external dependencies, ensuring they can be imported by any GRIP package without creating circular dependencies.
Index ¶
- Variables
- func BreakOrdering(kind FailureKind) bool
- func DeriveExecutionContext(parent context.Context, shutdown <-chan struct{}, deadline time.Time) (context.Context, context.CancelFunc)
- func IsFailure(kind FailureKind) bool
- func IsRetryable(kind FailureKind) bool
- func IsTerminal(kind FailureKind) bool
- type AdmissionController
- type AdmissionMode
- type CancellationSource
- type DeadlinePolicy
- type Execution
- type ExecutionGuarantees
- type Executor
- type FailureKind
- type Interceptor
- type ShutdownCoordinator
Constants ¶
This section is empty.
Variables ¶
var ( // ErrStreamClosed is returned when stream is no longer accepting messages ErrStreamClosed = errors.New("stream: closed") // ErrBackpressure is returned when backpressure rejects the message ErrBackpressure = errors.New("stream: backpressure rejection") // ErrPanicRecovered is returned when a panic was caught ErrPanicRecovered = errors.New("stream: panic recovered") // ErrOrderingClosed is returned when ordering system is closed ErrOrderingClosed = errors.New("stream: ordering closed") // ErrAdmissionRejected is returned when admission rejects execution ErrAdmissionRejected = errors.New("admission: rejected") // ErrAdmissionSignaled is returned when admission signals degradation ErrAdmissionSignaled = errors.New("admission: signaled") // ErrServerShutdown is returned when server is shutting down ErrServerShutdown = errors.New("server: shutdown") // ErrClientCanceled is returned when client cancelled ErrClientCanceled = errors.New("client: canceled") // ErrDeadlineExceeded is returned when deadline exceeded ErrDeadlineExceeded = errors.New("deadline: exceeded") // ErrPartialFailure is returned when partial batch failed ErrPartialFailure = errors.New("execution: partial failure") // ErrInsufficientSuccess is returned when insufficient items succeeded ErrInsufficientSuccess = errors.New("execution: insufficient success") )
Functions ¶
func BreakOrdering ¶
func BreakOrdering(kind FailureKind) bool
BreakOrdering reports whether ordering guarantees are invalidated by this failure (execution cannot safely retry after this).
func DeriveExecutionContext ¶
func DeriveExecutionContext( parent context.Context, shutdown <-chan struct{}, deadline time.Time, ) (context.Context, context.CancelFunc)
DeriveExecutionContext creates the canonical execution context used by all executors.
IMPORTANT CONTRACT: - NO deadline logic here - NO timeout logic here - ONLY cancellation propagation + attribution
Precedence: 1. Server shutdown 2. Parent cancellation (client or parent-deadline)
Deadline attribution is handled OUTSIDE this function.
func IsFailure ¶
func IsFailure(kind FailureKind) bool
IsFailure reports whether kind represents a failure.
func IsRetryable ¶
func IsRetryable(kind FailureKind) bool
IsRetryable reports whether the execution MAY be retried without violating correctness.
func IsTerminal ¶
func IsTerminal(kind FailureKind) bool
IsTerminal reports whether the failure MUST terminate the execution or stream immediately.
Types ¶
type AdmissionController ¶
AdmissionController decides whether an execution may proceed.
Admission happens BEFORE execution begins and may be influenced by backpressure, concurrency limits, or system health.
type AdmissionMode ¶
type AdmissionMode int
AdmissionMode defines what happens when execution capacity is exhausted.
const ( // AdmissionHardReject rejects requests immediately when capacity is full. AdmissionHardReject AdmissionMode = iota // AdmissionSoftAllow allows execution on best-effort basis. AdmissionSoftAllow // AdmissionSoftAllowWithSignal allows execution but surfaces an explicit // admission failure signal to the caller. AdmissionSoftAllowWithSignal )
type CancellationSource ¶
type CancellationSource int32
CancellationSource represents why an execution was cancelled.
const ( SourceUnknown CancellationSource = iota SourceClientCancel SourceServerShutdown SourceDeadlineExceeded SourceAdmissionRejected SourceInternalError )
func CancellationSourceOf ¶
func CancellationSourceOf(ctx context.Context) CancellationSource
CancellationSourceOf returns the reason execution was cancelled.
type DeadlinePolicy ¶
type DeadlinePolicy int
DeadlinePolicy defines when deadlines are enforced.
const ( // DeadlineBeforeAdmission counts queueing time toward deadlines. DeadlineBeforeAdmission DeadlinePolicy = iota // DeadlineAfterAdmission enforces deadlines only after execution begins. DeadlineAfterAdmission // DeadlineIgnoreAfterAdmission ignores the deadlines once admitted. DeadlineIgnoreAfterAdmission )
type Execution ¶
type Execution struct {
Ctx context.Context
Guarantees ExecutionGuarantees
}
Execution represents a single logical unit of work. This may correspond to: - a unary RPC - a streaming message - a batch element
type ExecutionGuarantees ¶
type ExecutionGuarantees struct {
AdmissionMode AdmissionMode
DeadlinePolicy DeadlinePolicy
}
ExecutionGuarantees defines the complete behavioral contract for an execution.
Only fields that are actively enforced by the execution pipeline are included. AdmissionMode controls capacity gating. DeadlinePolicy controls deadline enforcement.
type Executor ¶
Executor is the only component allowed to run user code.
Responsibilities: - Enforce admission guarantees - Enforce cancellation precedence - Enforce deadline semantics - Enforce failure semantics - Ensure no goroutine leaks
Executor must be deterministic and race-safe
type FailureKind ¶
type FailureKind int
const ( // No failures (successful processing) FailureNone FailureKind = iota // User handler returned an error FailureHandlerError // Context cancelled (client cancel, deadline) FailureContextCancelled // Backpressure rejected the message FailureBackpressure // Ordering system closed or violated FailureOrdering // Stream is shutting down FailureShutdown // Internal invariant violated (BUG) // This is NEVER retryable and ALWAYS terminal FailureInternal // Admission rejected FailureAdmission // Panic recovered FailurePanic )
func Classify ¶
func Classify(err error) FailureKind
Classify maps an error to a FailureKind. This is the canonical way to classify errors across all packages.
func (FailureKind) String ¶
func (fk FailureKind) String() string
String returns a human-readable name for the failure kind
type Interceptor ¶
Interceptor allows observing and decorating execution.
IMPORTANT: - Interceptors MUST NOT modify ExecutionGuarantees - Interceptors MUST NOT block indefinitely - Interceptors MUST BE idempotent
Interceptors may: - record metrics - add tracing - log execution
type ShutdownCoordinator ¶
type ShutdownCoordinator interface {
BeginShutdown()
Done() <-chan struct{}
}
ShutdownCoordinator coordinates graceful shutdown.
Guarantees: - Shutdown is idempotent - Shutdown is race-free - Shutdown honors CancellationPrecedence