Commit Graph

5 Commits

Author SHA1 Message Date
HAL9000 432fd2c9a1 fix(events): add unsubscribe() to EventBus protocol and implementations 2026-06-18 10:38:44 +00:00
HAL9000 3459f821c5 fix(events): add close() method to ReactiveEventBus to complete RxPY subject
Add _closed flag and close() method to ReactiveEventBus to complete the
RxPY Subject, preventing subscriber resource leaks. close() is idempotent
and raises RuntimeError when called on a closed bus.

Also adds:
- emit() guard against post-close calls (RuntimeError)
- __enter__/__exit__ context manager protocol for automatic cleanup
- BDD scenarios in event_bus.feature and TDD tests in
  tdd_reactive_event_bus_close.feature

ISSUES CLOSED: #10378
2026-05-13 12:24:33 +00:00
aditya 7348ca1911 fix(events): update tests for DecisionService.record_decision API change
CI / benchmark-publish (pull_request) Has been skipped
CI / lint (pull_request) Successful in 14s
CI / build (pull_request) Successful in 14s
CI / quality (pull_request) Successful in 16s
CI / security (pull_request) Successful in 30s
CI / typecheck (pull_request) Successful in 47s
CI / unit_tests (pull_request) Successful in 2m13s
CI / docker (pull_request) Successful in 38s
CI / integration_tests (pull_request) Successful in 3m3s
CI / coverage (pull_request) Successful in 3m58s
CI / benchmark-regression (pull_request) Successful in 24m40s
- Update event_bus_steps.py to call record_decision() with individual
  parameters (plan_id, decision_type, question, chosen_option, rationale)
  instead of passing a Decision object, matching the master branch API
- Remove ctx.test_decision construction from DecisionService setup steps
  as it is no longer needed with the new signature
- Update robot/helper_event_bus.py decision_service_emits_event() to use
  the new record_decision() parameter signature
- All 9 Robot Framework event bus tests passing
- Behave scenarios at lines 125 and 131 now passing

Fixes event bus test failures after master merge.
2026-03-03 15:42:53 +00:00
aditya 89bc776381 refactor(events): address PR-509 review comments
- Fix CHANGELOG EventType count from 40 to 38 and add missing domains
  (invariant, context) for accurate documentation
- Document correlation_id field as spec extension for request traceability
  in DomainEvent model
- Add thread safety documentation to ReactiveEventBus and LoggingEventBus
  noting single-threaded design and external sync requirements
- Document _persist_audit deferral in ReactiveEventBus.emit() explaining
  audit logging via handler subscription or LoggingEventBus following
  single-responsibility principle
- Replace bare MagicMock() with create_autospec(Settings, instance=True)
  at 5 locations for type-safe test mocking
- Replace nested bare MagicMock for UnitOfWork with create_autospec at 3
  locations to prevent silent breakage on API changes

All changes maintain backward compatibility. No linter errors.
2026-03-03 15:15:55 +00:00
aditya d17895dae2 feat(events): add EventBus protocol and ReactiveEventBus implementation
- Add EventType StrEnum with 38 typed domain event identifiers across 8
  domains (plan lifecycle, decision, actor, tool, resource, sandbox,
  validation, session, budget)
- Add frozen DomainEvent Pydantic model with event_type, auto-UTC
  timestamp, auto-ULID correlation_id, plan_id, root_plan_id,
  session_id, actor_name, project_name, and details fields
- Add @runtime_checkable EventBus Protocol with emit() and subscribe()
- Add ReactiveEventBus backed by RxPY Subject for in-process reactive
  streaming with synchronous handler dispatch and raw Observable stream
- Add LoggingEventBus using structlog for audit-trail-only environments
- Wire DecisionService to emit DECISION_CREATED on record_decision()
- Wire PlanLifecycleService to emit PLAN_CREATED and PLAN_PHASE_CHANGED
  on use_action() and execute_plan() respectively
- Register ReactiveEventBus as Singleton in DI container and inject into
  DecisionService and PlanLifecycleService providers
- Add Behave BDD unit tests: 27 scenarios, 75 steps, 100% branch coverage
- Add Robot Framework integration tests: 9 smoke cases
- Add ASV performance benchmarks: 5 suites covering emit throughput and
  subscriber fan-out
- Add reference documentation at docs/reference/event_bus.md

ISSUES CLOSED: #473
2026-03-02 11:54:53 +00:00