Skip to content

feat(mediation): implement RFC-011 runtime events#89

Merged
beonde merged 2 commits into
mainfrom
feat/rfc-011-events
May 27, 2026
Merged

feat(mediation): implement RFC-011 runtime events#89
beonde merged 2 commits into
mainfrom
feat/rfc-011-events

Conversation

@beonde
Copy link
Copy Markdown
Member

@beonde beonde commented May 27, 2026

Summary

Implements Phase 0.5 of the verification locality plan: RFC-011 Runtime Events.

Changes

New Files

  • pkg/mediation/events.go — RFC-011 event types and envelope format
  • pkg/mediation/emitter.go — async event emission with sink abstraction
  • pkg/mediation/aggregator.go — server-side event collection interface
  • pkg/mediation/events_test.go — event type and emitter tests
  • pkg/mediation/aggregator_test.go — aggregator tests

Updated Files

  • pkg/mediation/doc.go — expanded documentation for event system

Event Types (RFC-011 §5)

Implements all 6 event categories (~25 event types):

  • Identity: identity.verified, identity.invalid, identity.expired
  • Authority: authority.granted, authority.denied, authority.delegated
  • Tool: tool.requested, tool.permitted, tool.denied, tool.executed
  • Resource: resource.filesystem.*, resource.network.*, resource.shell.*
  • Trust: trust.signature.*, trust.revocation.checked

Event Emission Architecture

  • AsyncEmitter — non-blocking emitter with goroutine-based processing
  • EventSink interface — abstraction for event delivery
  • Built-in sinks: ChannelSink, JSONSink, BatchSink, HTTPSink
  • MemoryAggregator — in-memory aggregation for testing and server use

Verification Locality Compliance

Per RFC-011 §4.2 and §7.3, event emission:

  • MUST NOT block the mediation path
  • Uses async channel-based delivery
  • Drops events on channel overflow (never blocks)
  • Provides batch flushing for throughput

Testing

  • All mediation package tests pass
  • Event JSON serialization matches RFC-011 §6.1 envelope format
  • Aggregator capacity limits and query filtering tested

Related

- Add events.go with RFC-011 event types and envelope format
- Add emitter.go with async EventEmitter and sink abstractions
- Add aggregator.go with server-side collection interface
- Support all RFC-011 event categories: Identity, Authority, Tool, Resource, Trust
- Non-blocking event emission (verification locality invariant)
- Comprehensive test coverage for events, emitter, and aggregator
Copilot AI review requested due to automatic review settings May 27, 2026 15:22
@codecov
Copy link
Copy Markdown

codecov Bot commented May 27, 2026

Codecov Report

❌ Patch coverage is 54.25331% with 242 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pkg/mediation/emitter.go 48.84% 146 Missing and 9 partials ⚠️
pkg/mediation/aggregator.go 52.71% 82 Missing and 5 partials ⚠️

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds RFC-011 runtime event emission infrastructure to the pkg/mediation package: typed event constants, an envelope structure, an async non-blocking emitter, several built-in sinks (channel, JSON, batch, HTTP) and an in-memory aggregator for collecting events. The new code complements the existing mediation hook framework introduced in PR #88 but does not yet wire emitter usage into the hooks themselves.

Changes:

  • New Event/EventType envelope and payload types covering identity/authority/runtime/tool/resource/trust categories (RFC-011 §5–§6).
  • New AsyncEmitter with channel-buffered delivery and EventSink implementations (ChannelSink, JSONSink, BatchSink, HTTPSink).
  • New EventAggregator interface and MemoryAggregator with query/subscribe/stats, plus unit tests for events, emitter and aggregator behavior.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
pkg/mediation/events.go Defines event type constants, Event envelope, payload structs, and helpers (HashForEvent, ClassifyPath, ClassifyCommand).
pkg/mediation/emitter.go Implements AsyncEmitter, sink interface, and built-in ChannelSink/JSONSink/BatchSink.
pkg/mediation/aggregator.go Implements EventAggregator interface, MemoryAggregator, query/filter logic, and HTTPSink.
pkg/mediation/events_test.go Tests for event types, envelope, async emitter, channel/JSON/batch sinks.
pkg/mediation/aggregator_test.go Tests for aggregator ingest/query/subscribe/stats and time-range queries.
pkg/mediation/doc.go Expands package docs to describe the new event taxonomy, sinks, and aggregator.

Comment thread pkg/mediation/emitter.go
Comment thread pkg/mediation/aggregator.go
Comment thread pkg/mediation/aggregator.go Outdated
Comment thread pkg/mediation/aggregator.go
Comment thread pkg/mediation/aggregator.go
Comment thread pkg/mediation/aggregator.go
Comment thread pkg/mediation/emitter.go
Addresses Copilot review comments:
- emitter.go: Fix nil pointer panic in EmitIdentityVerified
- emitter.go: Document synchronous fallback caveat for RFC-011 compliance
- emitter.go: Handle sink.Close() error (gosec G104)
- aggregator.go: Return io.EOF instead of nil in nopCloser.Read
- aggregator.go: Store FlushInterval and use it in flushAsync
- aggregator.go: Check response status code in sendBatchSync
- aggregator.go: Fix SubjectDID filter to exclude events without field
- aggregator.go: Document OrganizationID filter is not yet implemented
@beonde beonde merged commit a461aba into main May 27, 2026
5 checks passed
@beonde beonde deleted the feat/rfc-011-events branch May 27, 2026 15:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants