Skip to content

Route hosted channel messages through the event queues #8148

Open

Description

@senamakel

Parent: #8147

Summary

Route hosted channel messages (Telegram/Discord/Slack over the backend socket) through the tinyeventqueues pipeline instead of the event bus, so none are lost and each one is gated, coalesced and triaged before it costs an agent turn.

Problem

platform/socket/event_handlers.rs (the *:message arm, ~L263) publishes ChannelInboundMessage on the event bus. The bus buffers 256 signals and a lagging subscriber silently skips. ChannelInboundSubscriber (channels/bus/subscriber.rs, ~L142) then blocks up to 180 s per message, so hosted messages are serialized behind each other and can be dropped under load. Every message also costs a full agent turn — channel traffic is never triaged.

Solution

  • In the socket handler, hand the message to inbound::route (as Composio triggers and webhooks do since feat(inbound): queue Composio triggers and agent webhooks through tinyeventqueues #8136); keep the bus publish only as the direct path when the queues do not take the event.
  • Envelope: source = channel:<platform>, conversation_key/thread_key from channel + thread_ts, addressed_to_agent from mention/DM/reply-to-agent, dedupe_key from the platform message id.
  • Deliver starts or steers the turn the subscriber runs today; retire the 180 s blocking wait.
  • Unaddressed group chatter lands as context (ambient buffer for the next real turn), not as a turn of its own.

Acceptance criteria

  • No loss under burst — regression test: 300 hosted messages published faster than turns complete are all delivered (or recorded as context/dropped-with-reason); the bus path loses some.
  • No 180 s serialization — the blocking subscriber is gone; conversations proceed independently, one turn in flight per conversation.
  • Redelivery deduped — the same platform message id twice produces one turn.
  • Fallback intact — with [components] eventqueues = false the current bus path still works.
  • Diff coverage ≥ 80% — the implementing PR meets the changed-lines coverage gate (Vitest + cargo-llvm-cov, enforced by .github/workflows/ci-fast.yml).

Related

Part of #8147. Builds on #8136 (inbound domain, tinyeventqueues v0.1.2) and tinyhumansai/tinyeventqueues#6.

Audit findings (2026-10-20)

  • platform/socket/event_handlers.rs:263-318 is the only publisher of ChannelInboundMessage (L310). It drops messages whose channel or message is empty, and ignores raw_data, so no platform message id reaches the core and nothing can dedupe today.
  • channels/bus/subscriber.rs (283 LOC, registered at core/runtime/subscribers.rs:307-313) runs a full web_chat::start_chat turn per message with a 180 s pump (L107-162).
  • The tinybus subscriber loop awaits handle() inline (vendor/tinybus crates/tinybus/src/events/subscriber.rs:149-185), so every hosted message waits behind the previous turn.
  • SIGNAL_BUFFER = 256 (tinybus/src/connection.rs:133); on lag the loop logs "subscriber lagged, skipped events" and carries on (subscriber.rs:153-159). That is silent loss.
  • The relay path (channel_relay_inbound, channels/providers/relay/store.rs:29,90) already dedupes on message_id durably; reuse that id convention.

Agent brief

Depends on: senamakel#514 · Blocks: #8152, senamakel#515 · Parallel with: #8149, #8150, #8151

Research first

  • Which field of the socket payload (raw_data) carries the platform message id for each hosted provider; ask the backend (backend/ channel socket emitters) if it is missing. The id is the event_id.
  • Whether the backend needs to send a message id at all. If so, file it in tinyhumansai/backend first.

Files to consider

  • Read: crates/openhuman-core/src/platform/socket/event_handlers.rs:263-318, channels/bus/subscriber.rs:40-283, inbound/events.rs (envelope pattern), integrations/composio/bus/trigger_subscriber.rs:223-324 (routing pattern to copy)
  • Change: platform/socket/event_handlers.rs, inbound/events.rs (a channel envelope), channels/bus/subscriber.rs (kept as the direct path only), the channel: handler in inbound/deliver/
  • Tests: platform/socket/event_handlers_tests.rs, channels/bus/subscriber_tests.rs, inbound/*_tests.rs

Workflow: implementing-an-epic step.

Subagents: tdd-implementer (Sonnet), then code-reviewer.

Gates: cargo check --manifest-path Cargo.toml · pnpm rust:clippy · cargo test -p openhuman channels::bus inbound platform::socket · pnpm rust:layout

Activity

  1. added
    subtask
    feature
    rust-core
    channels
    on Oct 20, 2026
  2. M3gA-Mind commented on Nov 16, 2026

    @M3gA-Mind
    Collaborator

    Re-checked on current main: not done yet. Hosted *:message events still publish ChannelInboundMessage on the bus, and the subscriber still runs one turn per message. Only Composio triggers and webhooks use inbound::route.
    One update for whoever picks this up: the socket handling moved (#8487). The entry is now openhuman-tinyhumans/src/socket/port.rs:330 → platform/socket/event_sink.rs, not platform/socket/event_handlers.rs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    channelsfeaturerust-coresubtask

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions