Documentation
¶
Overview ¶
Package limiter owns the designated protected VirtualKey admission SPI. The designated surfaces are Dimension and its LLM/MCP/Agent constants, Policy, Clock, LimiterRequest, LimiterDecision, LimiterBackend, LimiterProvider, Config, ModuleID, MemoryBackendType, Factory, NewMemoryBackend and the MemoryBackend Admit/Retire/Health/Close methods, ErrLimiterUnavailable and ErrLimiterRetired. Their exported fields and method signatures are protected beginning with v0.7.0 after published-tag consumer acceptance. Selection and its accessors are Community assembly implementation surfaces.
Policies and globally unique generations are committed before admission. One call atomically consumes one token or denies without consumption; errors can be ambiguous and are never retried by the gateway. Cancellation and bounded deadlines are mandatory. Retire permanently fences generations, even when a late operation arrives; Admit returns ErrLimiterRetired (possibly wrapped), which never triggers fail-open. Generation-scoped quota storage survives replacement of prepared backend connection handles on unrelated extension mutations. A switch of backend authority/config resets generations; no token transfer is promised. Prepare initializes handles, Health diagnoses, Close stops and drains once under the extension manager's common five-second lifecycle budget.
Index ¶
- Constants
- Variables
- func Factory(runtime bool) *extension.Factory
- type Clock
- type Config
- type Dimension
- type LimiterBackend
- type LimiterDecision
- type LimiterProvider
- type LimiterRequest
- type MemoryBackend
- type Policy
- type Selection
- func (s *Selection) Backend() LimiterBackend
- func (s *Selection) Budget() time.Duration
- func (s *Selection) Close(context.Context) error
- func (s *Selection) Configuration() Config
- func (s *Selection) Health(ctx context.Context) error
- func (s *Selection) Identity() string
- func (s *Selection) StateResetComparedTo(ctx context.Context, previous extension.Resource) (bool, error)
- func (s *Selection) String() string
Constants ¶
const MemoryBackendType = "memory"
const ModuleID = "online.agentguide.community.limiter"
Variables ¶
var ErrLimiterRetired = errors.New("limiter_retired")
Functions ¶
Types ¶
type Config ¶
type Config struct {
BackendModuleID string `json:"backend_module_id"`
BackendType string `json:"backend_type"`
TimeoutMS int `json:"timeout_ms"`
FailureMode string `json:"failure_mode"`
}
Config is the Community-owned selection envelope (schema 1). No policy bypass is implicit: failure_mode defaults to closed.
type LimiterBackend ¶
type LimiterBackend interface {
Admit(context.Context, LimiterRequest) (LimiterDecision, error)
Retire(context.Context, string) error
Health(context.Context) error
Close(context.Context) error
}
LimiterBackend is the candidate protected domain SPI. All methods honor context; diagnostics are replaced by bounded gateway codes. Retire fences a generation permanently, including late operations. Admit on a retired generation must return ErrLimiterRetired (possibly wrapped); it never fails open. Generation-scoped storage survives replacement of a module's prepared connection/resource handles. Close stops admissions, cancels/drains work, and runs once per owned handle. Backend factories initialize connections before extension publication.
type LimiterDecision ¶
LimiterDecision reports one atomic consume-or-deny operation. A failure may have consumed a token; the caller must never retry it automatically.
type LimiterProvider ¶
type LimiterProvider interface {
LimiterBackend(string) (LimiterBackend, error)
}
LimiterProvider is implemented by a linked extension's prepared resource. Selection resolves this interface only during preparation, never per request.
type LimiterRequest ¶
type LimiterRequest struct {
Generation string
VirtualKeyID string
Dimension Dimension
Limit Policy
}
LimiterRequest is an immutable policy snapshot. Generation is an opaque, globally unique policy identity, never a bearer key. An unchanged policy keeps its generation across extension refreshes. Backends must preserve its state.
type MemoryBackend ¶
type MemoryBackend struct {
// contains filtered or unexported fields
}
MemoryBackend is the Community process-local reference backend. Its lifetime is one gateway; it is not a distributed quota authority.
func NewMemoryBackend ¶
func NewMemoryBackend(clock Clock) *MemoryBackend
func (*MemoryBackend) Admit ¶
func (b *MemoryBackend) Admit(ctx context.Context, r LimiterRequest) (LimiterDecision, error)
type Selection ¶
type Selection struct {
// contains filtered or unexported fields
}
func DefaultSelection ¶
func DefaultSelection() *Selection
func (*Selection) Backend ¶
func (s *Selection) Backend() LimiterBackend
func (*Selection) Configuration ¶
Selection is Community runtime wiring, not an extension implementation API. It provides an immutable prepared backend selection to the VirtualKey owner.
func (*Selection) StateResetComparedTo ¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package contracttest provides reusable protected limiter conformance suites.
|
Package contracttest provides reusable protected limiter conformance suites. |