Skip to content

Comments

feat(bridge): generic event envelope dispatch#138

Merged
benvinegar merged 1 commit intomainfrom
feat/generic-event-bridge
Feb 23, 2026
Merged

feat(bridge): generic event envelope dispatch#138
benvinegar merged 1 commit intomainfrom
feat/generic-event-bridge

Conversation

@baudbot-agent
Copy link
Collaborator

Summary

Client-side support for modem-dev/baudbot-services#56.

Refactors processPulledMessage() in broker-bridge.mjs to support a generic envelope format alongside the legacy raw Slack event_callback format. This enables the broker to deliver events from multiple sources (Slack, dashboard, system) through a single inbox.

Changes

slack-bridge/broker-bridge.mjs

  • isGenericEnvelope() — detects the new structured envelope format (source, type, payload, broker_timestamp)
  • handleSlackPayload() — extracted from processPulledMessage(), handles Slack event_callback events
  • handleDashboardEvent() — stub handler for dashboard events (env updates, config changes)
  • handleSystemEvent() — stub handler for system events
  • processPulledMessage() — now dispatches by envelope format:
    • Generic envelopes route by source field (slack → handleSlackPayload, dashboard → handleDashboardEvent, system → handleSystemEvent)
    • Unknown sources are logged + acked to avoid blocking the queue
    • Legacy raw Slack payloads still work (backwards compat during rollout)

test/broker-bridge.integration.test.mjs

  • 3 new integration tests covering generic envelope dispatch:
    • source=slack → forwards to agent via Slack handler
    • source=dashboard → logs + acks
    • Unknown source → warns + acks
  • Fixed test env inheritance (cleanEnv() helper) to prevent false failures when host broker token is expired

Backwards Compatibility

Critical: the broker will be deployed before all agents update, so old-format messages (raw Slack event_callback) continue to work via the legacy path.

Testing

✓ 130 tests passing (6 test files)
✓ Lint clean on changed files

Refactor processPulledMessage() in broker-bridge.mjs to support a generic
envelope format alongside the legacy raw Slack event_callback format.

Changes:
- Add isGenericEnvelope() detection function for structured envelopes
  with source, type, payload, and broker_timestamp fields
- Extract existing Slack handling into standalone handleSlackPayload()
- Add stub handlers for dashboard and system event sources
- Dispatch generic envelopes by source (slack, dashboard, system)
- Unknown sources are acked to avoid blocking the queue
- Legacy raw Slack payloads continue to work (backwards compat)

Tests:
- Add 3 integration tests: generic slack dispatch, dashboard dispatch,
  unknown source ack
- Fix test env inheritance (cleanEnv helper) to prevent false failures
  when host broker token is expired

Refs: modem-dev/baudbot-services#56
@greptile-apps
Copy link

greptile-apps bot commented Feb 23, 2026

Greptile Summary

Refactors the broker bridge message processor to support a generic multi-source envelope format while maintaining backwards compatibility with legacy Slack payloads.

Key changes:

  • Introduced isGenericEnvelope() to detect structured envelopes with source, type, payload, and broker_timestamp fields
  • Extracted Slack event handling logic into dedicated handleSlackPayload() function
  • Added routing switch in processPulledMessage() that dispatches by envelope source field (slack/dashboard/system)
  • Stub handlers for dashboard and system events log and ack messages
  • Unknown sources are logged with warning and acked to prevent queue blocking
  • Legacy raw Slack event_callback payloads continue to work through fallback path

Testing:

  • 3 new integration tests validate generic envelope dispatch for all source types
  • Fixed test environment inheritance issue with cleanEnv() helper
  • All 130 tests passing

The implementation is production-ready and follows the deployment strategy where the broker will be updated first, requiring backwards compatibility for agents still sending legacy format messages.

Confidence Score: 5/5

  • Safe to merge - well-architected refactor with comprehensive testing and backwards compatibility
  • Clean separation of concerns with extracted handlers, robust envelope detection, graceful handling of unknown sources to prevent queue blocking, comprehensive integration tests covering all paths, and critical backwards compatibility for rollout safety
  • No files require special attention

Important Files Changed

Filename Overview
slack-bridge/broker-bridge.mjs Added generic envelope dispatch system with isGenericEnvelope() detection, extracted handleSlackPayload() from processPulledMessage(), and added stub handlers for dashboard and system events with backwards compatibility for legacy Slack payloads
test/broker-bridge.integration.test.mjs Added 3 integration tests for generic envelope dispatch (slack source, dashboard source, unknown source) and introduced cleanEnv() helper to prevent test failures from stale host broker tokens

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Broker pulls encrypted message] --> B[Verify signature]
    B --> C[Decrypt envelope]
    C --> D{isGenericEnvelope?}
    D -->|Yes| E{Check source field}
    D -->|No| F[Legacy path: handleSlackPayload]
    E -->|slack| G[handleSlackPayload with payload.payload]
    E -->|dashboard| H[handleDashboardEvent - stub]
    E -->|system| I[handleSystemEvent - stub]
    E -->|unknown| J[Log warning + ack]
    F --> K[Process Slack event]
    G --> K
    H --> L[Return true - ack]
    I --> L
    J --> L
    K --> L
Loading

Last reviewed commit: c21a62a

@benvinegar benvinegar merged commit b541f9a into main Feb 23, 2026
10 checks passed
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