Skip to content

feat(observability): emit EventBus events from HTTP write paths#52

Open
barrygfox wants to merge 1 commit into
qualixar:mainfrom
barrygfox:fix/http-eventbus-emissions
Open

feat(observability): emit EventBus events from HTTP write paths#52
barrygfox wants to merge 1 commit into
qualixar:mainfrom
barrygfox:fix/http-eventbus-emissions

Conversation

@barrygfox

@barrygfox barrygfox commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Description

Wires the EventBus into the six HTTP write-path chokepoints that were previously silent. This is a pure observability improvement — it does not change any write behaviour, recall semantics, data model, or API contract.

Why proposed

Only MCP tool handlers emit EventBus events. Every HTTP fast path — /observe, /remember (sync and async), AutoCapture decisions, and the pending materializer drain — was silent. As a result, the dashboard health pane showed events_last_24h: 0, and the event stream stayed empty regardless of daemon traffic, making it impossible to distinguish a healthy, busy daemon from a stuck one.

Changes

infra/event_bus.py — four new event types registered (3 lines):

Type When
memory.observed /observe accepted content into the debounce buffer
memory.captured AutoCapture matched a buffered observation
memory.dropped AutoCapture rejected a buffered observation
memory.queued /remember accepted content into pending.db (async path)

memory.stored already exists and is reused for the sync /remember and materializer paths.

server/unified_daemon.py — one new helper, six callsites:

  • _emit_event(): mirrors mcp.shared.emit_event but tags source_protocol="http" so the dashboard can distinguish HTTP traffic from MCP tool calls. Best-effort — never raises, logs at DEBUG on failure.
  • Wired into ObserveBuffer.enqueue, ObserveBuffer._flush (both capture and drop branches), POST /remember sync path, POST /remember async path, and materializer drain (source_agent="materializer").

tests/test_server/test_http_eventbus_emissions.py — 10 new tests:

  • New event types present in VALID_EVENT_TYPES
  • _emit_event never raises on bus error
  • _emit_event tags source_protocol="http"
  • ObserveBuffer.enqueue emits memory.observed
  • Duplicate content does not emit a second memory.observed
  • _flush emits memory.captured on AutoCapture match
  • _flush emits memory.dropped on AutoCapture miss

What does not change

  • No write path is altered
  • No API response shape is changed
  • No new dependencies
  • Existing tests unaffected (388 pass on main after this change)

Before this change only MCP tool handlers emitted EventBus events. The
HTTP fast paths — /observe, /remember (sync + async), the AutoCapture
pipeline, and the pending materializer drain — were completely silent.
This left the dashboard health-pane event stream and events_last_24h
counter structurally empty regardless of how much traffic the daemon
served.

This change is purely observational. It does not alter any write
behaviour, recall semantics, data model, or API contract.

Changes:
- infra/event_bus.py: register four new event types (memory.observed,
  memory.captured, memory.dropped, memory.queued). memory.stored already
  existed.
- server/unified_daemon.py: add _emit_event() helper (source_protocol=
  "http", best-effort, never raises) and wire it into six callsites:
    ObserveBuffer.enqueue      → memory.observed
    ObserveBuffer._flush match → memory.captured
    ObserveBuffer._flush miss  → memory.dropped
    POST /remember (async)     → memory.queued
    POST /remember?wait=true   → memory.stored
    materializer drain         → memory.stored (source_agent=materializer)
- tests/test_server/test_http_eventbus_emissions.py: 10 new tests
  covering event type registration, never-raises guarantee, http protocol
  tagging, enqueue emission, duplicate suppression, and flush
  captured/dropped paths.
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.

1 participant