events

package
v1.0.310 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 24, 2026 License: MIT Imports: 16 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package events is the composition root of the PR-8 durable decision-event pipeline. It wires, per MCP capability, a fully isolated stack — encrypted spool (internal/mcp/events/spool), denial lane (…/denial), degraded-state machine (…/state) and export foundation (…/export) — behind a Manager that the runtime uses to durably commit sanitized decision events BEFORE any represented irreversible action, and to route attacker-mintable denials into the isolated denial lane.

PR-8 is DECISION-ONLY and DORMANT: the Manager commits durable evidence and hands back an unforgeable receipt, but it never calls a business MCP server, creates an upstream client, invokes tools/call, materializes a credential, contacts a provider, publishes a CP→DP snapshot, or mutates Management state. An inspected ALLOW still returns execution_state "not_implemented"; the receipt is evidence that a FUTURE execution stage may proceed, not an execution itself.

Capability isolation is load-bearing: Gateway and Management own separate spools, denial aggregators, state machines, reserves, counters and export cursors, so a failure in one capability's durability domain cannot degrade the other (MCP-OPS-005 / MCP-EVENT-002 §4b.2).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CredentialGate

type CredentialGate struct {
	// contains filtered or unexported fields
}

CredentialGate is the PR-8 adapter for the PR-4 broker.PreMaterializationGate contract. It durably commits a critical decision event for a credential materialization BEFORE the broker may touch a provider or cache, and returns DurableConfirmed=true ONLY after that commit is confirmed. A high-risk plan the broker will only materialize when DurableConfirmed is thus gated on a real durable receipt: if the commit fails (queue saturation, fsync/ENOSPC/encryption failure, or a degraded domain), the gate denies and the broker's own ordering guarantees that no credential is minted, rotated, revoked, or fetched.

PR-8 does NOT invoke the broker from the live runtime path; this adapter exists so a future execution slice — and the PR-8 tests — can prove the commit-before- side-effect ordering against the real gate contract.

func (*CredentialGate) Authorize

Authorize implements broker.PreMaterializationGate. It commits a critical credential decision event and reports Permit/DurableConfirmed = the commit outcome. It never returns DurableConfirmed=true without a confirmed durable commit.

type DecisionFacts

type DecisionFacts struct {
	Capability  model.Capability
	Criticality model.Criticality
	ActionClass model.ActionClass

	Identity   model.IdentityEvidence
	Decision   model.DecisionEvidence
	Inspection model.InspectionEvidence
	Credential model.CredentialEvidence
	// Shadow, when non-nil, carries the durable Shadow enforcement prediction. Its
	// presence makes the built event a SchemaVersionV2 Shadow decision event; every
	// other event stays v1 (buildEvent). It is set ONLY by the Shadow evaluator's
	// shadowDecisionFacts, from the SAME ShadowDecision returned to the client.
	Shadow *model.ShadowEvidence

	// Outcome, when non-nil, carries the post-execution / send-intent evidence
	// (attempt identity, reservation binding, activation generation, physical send
	// state). It is set for PhaseSendIntent and PhaseOutcome events.
	Outcome *model.OutcomeEvidence
	// Reconciliation, when non-nil, carries append-only witness-reconciliation
	// evidence. Set only for PhaseReconciliation events.
	Reconciliation *model.ReconciliationEvidence
	// Phase selects the event phase. The zero value is PhaseDecision, so every
	// existing caller is byte-identical; PhaseSendIntent and PhaseOutcome are set
	// explicitly by the execution path.
	Phase model.Phase

	SnapshotHash  string
	CorrelationID string // optional; generated when empty
}

DecisionFacts are the sanitized, already-safe fields the runtime maps from a live policy.Decision / inspection.Summary / identity.ResolvedContext (the mapping helpers live in adapt.go). The manager never receives a policy, token, argument or output object — only these typed facts — so a secret cannot reach the event through this API by construction. The redaction scrubber runs as a BACKSTOP over the encoded event before commit.

type DenialInput

type DenialInput struct {
	Capability model.Capability
	Listener   string
	Source     string
	Reason     string
	Tenant     string
	Principal  string
}

DenialInput is one authentication-failure or authorization-denial observation. Tenant and Principal are set ONLY when verified identity exists (the authenticated-but-unauthorized case); for a pre-authentication failure they are empty and no tenant is ever invented.

type DomainHealth

type DomainHealth struct {
	Capability        model.Capability
	CriticalState     string
	DenialState       string
	Severity          string
	CriticalLoss      uint64
	DenialLoss        uint64
	OrdinaryLoss      uint64
	CommitOK          uint64
	CommitFail        uint64
	DenialAggregates  uint64
	RecoveryAttempts  uint64
	RecoverySuccesses uint64
	Spool             spool.Stats
	Denial            denial.Stats
}

DomainHealth is one capability domain's safe snapshot.

type Health

type Health struct {
	NodeID  string
	Domains map[model.Capability]DomainHealth
}

Health is a safe, typed snapshot of the whole manager. It carries no tenant, subject, token, session, argument or URL — only bounded counts, bytes, ids and state names — so it is safe to surface on a health endpoint.

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager is the composition root. It holds one fully isolated domain per MCP capability and routes every operation by capability, so no shared mutable state couples Gateway and Management.

func NewManager

func NewManager(cfg ManagerConfig) (*Manager, error)

NewManager builds and opens both capability domains, recovering durable state and reconstructing each degraded-state machine. Any per-domain open/recover error is returned; a partially constructed manager is never returned.

func (*Manager) Close

func (m *Manager) Close() error

Close stops accepting work and drains bounded pending state. It flushes any open denial aggregates (best-effort) so their evidence is not lost on a clean stop.

func (*Manager) CommitDecision

func (m *Manager) CommitDecision(f DecisionFacts) (spool.CommitReceipt, error)

CommitDecision constructs a sanitized decision event from facts, runs the redaction backstop, and DURABLY COMMITS it to the correct partition. On success it returns an unforgeable receipt (evidence a future execution stage may proceed) — the runtime still returns execution_state "not_implemented". On a critical commit failure it drives the domain into critical-durability-degraded (fail closed) and returns a classified error; a critical operation whose event cannot commit MUST NOT proceed. An ordinary commit failure applies the low-risk loss policy (recorded, never silent).

func (*Manager) CommitThenAct

func (m *Manager) CommitThenAct(f DecisionFacts, act func(spool.CommitReceipt) error) error

CommitThenAct is the generic irreversible-action harness proving the commit → side-effect ordering: it durably commits the decision event and runs the irreversible callback ONLY on a confirmed commit. The callback receives the bound receipt. If the commit fails (admission, encryption, append, sync, checkpoint, or a degraded domain), the callback is NEVER invoked and the commit error is returned — there is no convenience path that skips the commit.

func (*Manager) FlushDenials

func (m *Manager) FlushDenials(capNS model.Capability) (committed, lost int)

FlushDenials commits the denial aggregates whose window has closed into P-DEN. A failed aggregate commit (or a P-DEN quota rejection) enters denial-lane-degraded, increments the DISTINCT denial-loss counter, and the request stays denied — it NEVER blocks authenticated critical work and NEVER enters critical-durability-degraded. It returns the number of aggregates committed and the number lost.

func (*Manager) FlushDenialsForce added in v1.0.195

func (m *Manager) FlushDenialsForce(capNS model.Capability) (committed, lost int)

FlushDenialsForce is FlushDenials with force=true: it commits every pending denial aggregate INCLUDING the still-open current window. It is intended for a graceful-shutdown drain, where a caller wants the last open window durable (and thus exportable) before the manager closes. Same non-blocking, denial-lane-only contract as FlushDenials.

func (*Manager) Health

func (m *Manager) Health() Health

Health returns a safe snapshot across both capability domains.

func (*Manager) NewCredentialGate

func (m *Manager) NewCredentialGate() *CredentialGate

NewCredentialGate returns a gate backed by the manager.

func (*Manager) ObserveDenial

func (m *Manager) ObserveDenial(in DenialInput)

ObserveDenial feeds one denial into the isolated denial lane BEFORE it can occupy any shared queue. It is O(1), never blocks, and NEVER touches the critical track or the P-CRIT reserve. A dropped observation (cardinality bound) still leaves the triggering request denied by the caller — admission to the aggregate is not admission of the request.

func (*Manager) RecoverProbe

func (m *Manager) RecoverProbe(capNS model.Capability) bool

RecoverProbe runs one bounded recovery-probe tick for a capability's critical track. When the domain is critical-durability-degraded and the non-marker criteria (storage writable, reserve free, pending backlog) hold, it enters recovering, DURABLY COMMITS AND READS BACK a recovery marker (criterion 3 — a confirmed commit, not an enqueue), then finalizes to normal only when all four criteria hold. It returns true when the domain returned to normal this tick. There is no bypass: a failed marker commit/readback leaves the domain degraded.

func (*Manager) Spool

func (m *Manager) Spool(capNS model.Capability) *spool.Spool

Spool exposes the capability spool for the export foundation (read-only reads / export ack). It returns nil for an unknown capability.

func (*Manager) WriteAllowedCritical

func (m *Manager) WriteAllowedCritical(capNS model.Capability) bool

WriteAllowedCritical reports whether the given capability's critical track is normal (not degraded/recovering). The runtime consults this to fail a critical operation closed while its domain is degraded.

type ManagerConfig

type ManagerConfig struct {
	NodeID           string
	DataDir          string
	KEK              *secret.Provider
	GatewayLimits    limits.EventLimits
	ManagementLimits limits.EventLimits
	Backend          spool.Backend
	Clock            func() time.Time
}

ManagerConfig constructs a Manager. DataDir is the durable root; each capability gets an isolated subdirectory (DataDir/gateway, DataDir/management) so the two spools never alias. KEK is the mandatory encryption provider (a nil KEK fails closed). Backend and Clock are test seams (nil ⇒ real OS backend / time.Now).

Directories

Path Synopsis
Package denial implements the attacker-mintable denial lane (MCP-EVENT-007): pre-queue admission control and attacker-rate-independent coalescing for authentication-failure and authorization-denial events, so N equivalent denials in one bucket/window cost O(1) durable records.
Package denial implements the attacker-mintable denial lane (MCP-EVENT-007): pre-queue admission control and attacker-rate-independent coalescing for authentication-failure and authorization-denial events, so N equivalent denials in one bucket/window cost O(1) durable records.
Package export is the additive, tenant-separated export foundation for the PR-8 event pipeline (MCP-EVENT-006 / MCP-PRIVACY-002).
Package export is the additive, tenant-separated export foundation for the PR-8 event pipeline (MCP-EVENT-006 / MCP-PRIVACY-002).
Package model defines the immutable, versioned decision-event envelope that the PR-8 durable event pipeline persists.
Package model defines the immutable, versioned decision-event envelope that the PR-8 durable event pipeline persists.
Package spool implements the mandatory local encrypted, bounded, durable spool for the PR-8 decision-event pipeline.
Package spool implements the mandatory local encrypted, bounded, durable spool for the PR-8 decision-event pipeline.
Package state implements the normative, scoped, restart-persistent, bounded durability degraded-state machine (MCP-OPS-005 / EVENT-MODEL.md §4b.5-4b.7).
Package state implements the normative, scoped, restart-persistent, bounded durability degraded-state machine (MCP-OPS-005 / EVENT-MODEL.md §4b.5-4b.7).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL