Skip to content

feat(pluginmgr): add GRPCBroker reverse channel and streaming delivery#335

Merged
pocky merged 1 commit into
mainfrom
feature/F092-grpcbroker-and-grpc-streaming-for-plugin
May 8, 2026
Merged

feat(pluginmgr): add GRPCBroker reverse channel and streaming delivery#335
pocky merged 1 commit into
mainfrom
feature/F092-grpcbroker-and-grpc-streaming-for-plugin

Conversation

@pocky
Copy link
Copy Markdown
Contributor

@pocky pocky commented May 8, 2026

Summary

  • Completes the bidirectional plugin event system (F092) by activating GRPCBroker to let plugins emit events back to the host at runtime via HostClient, not just as return values from HandleEvent
  • Introduces persistent client-side gRPC streaming (StreamEvents RPC) for host-to-plugin event delivery, replacing per-event unary RPCs with a single long-lived connection and automatic fallback to unary when streaming is unavailable
  • Promotes hostEventServiceID to an exported constant (HostEventServiceID) shared between host and SDK, eliminating duplicate declarations and the risk of service ID drift
  • Extends integration test coverage with 259 lines of broker integration tests (emit/deny/stream/fallback/goroutine-leak/benchmark) to validate the full bidirectional event lifecycle

Changes

Plugin SDK

  • pkg/plugin/sdk/host_client.go: Export HostEventServiceID constant (was unexported duplicate); switch to errors.New for static error strings; use exported constant in broker.Dial call
  • pkg/plugin/sdk/host_client_test.go: Update assertions to reference exported HostEventServiceID constant

Plugin Manager — Core

  • internal/infrastructure/pluginmgr/grpc_event.go: Move domainEventToStreamMessage conversion helper here from stream_manager.go so proto↔domain conversions are co-located in the gRPC adapter file
  • internal/infrastructure/pluginmgr/stream_manager.go: Remove domainEventToStreamMessage (relocated to grpc_event.go)
  • internal/infrastructure/pluginmgr/rpc_manager.go: Replace local hostEventServiceID constant with sdk.HostEventServiceID to use the single exported source of truth

Plugin Manager — Tests

  • internal/infrastructure/pluginmgr/broker_integration_test.go: New file — integration tests covering emit-and-receive, emit denied by manifest, 100-event streaming with sequence numbers, transparent fallback to unary, goroutine leak verification across 50 cycles, F090 backward compatibility, and unary/stream delivery benchmarks
  • internal/infrastructure/pluginmgr/grpc_event_test.go: Add unit tests for domainEventToStreamMessage (all fields, zero sequence number)
  • internal/infrastructure/pluginmgr/rpc_manager_test.go: Add tests for startBrokerHostService nil-broker/nil-bus no-ops, manifestLookup thread-safety, and stream-manager fallback path; fix wireEventSubscriptions test to use NewStreamManager instead of zero-value struct literal
  • internal/infrastructure/pluginmgr/stream_manager_test.go: Replace single lastMessage field with messages slice in mock to support multi-event tests without message clobbering; add dequeue semantics to getLastMessage

Infrastructure — Notify

  • internal/infrastructure/notify/webhook_test.go: Replace external httpbin.org URL in concurrent webhook test with local httptest.Server to eliminate network dependency in unit tests

Documentation

  • docs/development/plugin-event-architecture.md: Add F092 architecture sections covering GRPCBroker, HostEventService, StreamManager, EventDeliverer seam, fallback handling, and updated ASCII architecture diagram
  • docs/user-guide/plugin-events.md: Document HostClient.Emit() as second emission method, add SetHostClient wiring guide, streaming delivery section with automatic fallback description
  • README.md: Update Plugin System feature bullet with GRPCBroker reverse channel and persistent streaming delivery descriptions
  • CLAUDE.md: Replace two outdated pitfalls/conventions with new rules for gRPC/concurrency coverage requirements and staged-file verification

Test plan

  • Run make test-race — verify no data races in stream managers, EventBus delivery goroutines, and broker integration paths
  • Run make test-unit — confirm all pluginmgr and sdk unit tests pass including new domainEventToStreamMessage and HostEventServiceID tests
  • Run go test ./internal/infrastructure/pluginmgr/ -run TestBrokerIntegration -v — verify emit/deny/stream/fallback/goroutine-leak integration scenarios all pass
  • Run go test ./internal/infrastructure/pluginmgr/ -bench BenchmarkEventDelivery -benchmem — confirm stream delivery throughput exceeds unary baseline

Closes #334


Generated with awf commit workflow

@pocky pocky force-pushed the feature/F092-grpcbroker-and-grpc-streaming-for-plugin branch from afb2df2 to 22e5333 Compare May 8, 2026 15:51
@pocky pocky marked this pull request as ready for review May 8, 2026 16:11
@pocky pocky merged commit 7c342b1 into main May 8, 2026
5 checks passed
@pocky pocky deleted the feature/F092-grpcbroker-and-grpc-streaming-for-plugin branch May 8, 2026 16:11
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.

F092: GRPCBroker and gRPC Streaming for Plugin Event System

1 participant