Skip to main content

EventBus

Messaging is part of ISH's context and coordination layer: it lets agents exchange events and targeted messages. It differs from shared working state. EventBus delivers notifications inside a running application; ContextStore holds named values agents can read or update; SqliteMailbox queues messages that must survive a process restart. A notification can point an agent to shared context, but the context record remains in ContextStore and is not copied or synchronized by the event system.

from ish import EventBus

bus = EventBus()
subscription = bus.subscribe("build.*")
bus.publish_sync("build.api", {"status": "complete"}, source="builder")
page = bus.poll(subscription)
print(page)

Event delivery​

Routing​

Topic matching​

  • A subscription matches events using the configured topic grammar. A subscriber receives an event once even if multiple patterns match.
  • Subscriptions are local to the process. Reconnecting clients can read retained history or their unread inbox when those features are enabled.
  • Selectable TopicGrammar:
    • Fnmatch (default): Uses permissions::fnmatch_simple supporting glob * and ? across the full topic string.
    • Mqtt: Splits topic and pattern on . segments (mqtt_match), treating + or * as a single-segment wildcard and # or ** as a trailing multi-segment wildcard (# / ** only match at the final segment of the pattern). Each subscriber has a bounded in-memory queue. If it falls behind, the poll result reports missed events so the consumer can catch up or reload state.

Event IDs, unread cursors​

  • Events include an identifier, topic, source, JSON payload, and timestamp. If no source is supplied, the runtime labels it system.
  • Messages sent to an agent inbox can be read as unread messages or filtered by timestamp. Reading unread messages advances that recipient's inbox cursor.

Targeted inbox messages​

Publishing to inbox.<recipient> (send_to in Python) makes the message retrievable from that process's inbox through poll_inbox / inbox. This is not restart-safe; use SqliteMailbox when queued delivery must survive a process exit:

import asyncio
from ish import EventBus

async def main() -> None:
bus = EventBus()
await bus.send_to("worker", {"task": "lint"}, sender="coordinator")
unread = bus.poll_inbox("worker", unread_only=True)
print(unread)

asyncio.run(main())

Host callbacks​

Register process-local subscribers when handling events inline. Rust owns callback registration order, topic matching, and deduplication; each SDK keeps only the user callback reference and invokes the callbacks returned by Rust. Unsubscribe hooks detach the Rust registration and release the host reference. Callback failures are recorded in the bounded Rust diagnostics buffer, with the stable handler label handler across SDKs:

from ish import EventBus

bus = EventBus()
unsubscribe = bus.subscribe("build.*", lambda ev: print("Event:", ev.topic, ev.payload))
bus.publish_sync("build.ui", {"ok": True}, source="ci")
unsubscribe()

Bounded mailbox behavior​

Use a bounded mailbox when producers need explicit queue and payload limits or must coordinate backpressure across tenants:

FlowControlQuota FieldDefault ValueEnforcement Scope
max_queue_messages1000Maximum queued entries inside one mailbox instance
max_queue_bytes10 * 1024 * 1024 (10 MiB)Maximum sum of payload sizes inside one mailbox instance
max_message_bytes1024 * 1024 (1 MiB)Per-message payload byte cap (returns BackpressureError::MessageTooLarge)
max_tenant_backlog_bytes50 * 1024 * 1024 (50 MiB)Aggregate backlog across all mailboxes sharing a tenant_id via TenantQuotaLease

Unlike generic drop-oldest queues, BoundedMailbox differentiates overflow behavior by MessageClass:

MessageClassTelemetry Tag (static_telemetry_tags)Overflow Behavior (EventOverflowPolicy)
BestEffortTelemetry"telemetry"On DropOldest: pops oldest message and calls record_delivery_gap. On DropNewest: assigns monotonic sequence, calls record_delivery_gap, and returns Ok(seq). On Reject / Block: returns BackpressureError::QueueFull. Adjacent drops on the same topic coalesce into one DeliveryGapEvent (first_missing_sequence, last_missing_sequence, gap_count).
OrdinaryNotifications"notification"Never silently dropped. Any queue or byte overflow returns BackpressureError::QueueFull.
WorkflowStateTransitions"workflow"Never silently dropped. Any queue or byte overflow returns BackpressureError::WorkflowTransitionRejected.
DurableMailboxMessages"mailbox"Rejected upfront on in-memory BoundedMailbox (before assigning a sequence) with BackpressureError::DurablePersistenceRequired. Route these through SqliteMailbox (DurableMailbox).

Durable mailbox leases​

SqliteMailbox stores messages and delivery claims in SQLite. A worker claims a message for a limited period and acknowledges it after processing:

  • Message enqueue validates configured size and backlog limits before accepting a message.
  • If a worker stops responding, its lease expires and another worker can claim the message.
  • An expired worker cannot acknowledge a message after another worker has claimed it.

Agent tools​

In Python, bus.get_tools(agent_name=...) returns tools for publishing events and sending inbox messages (plus an inbox-checking tool when agent_name is provided). Event payloads across all SDKs must be finite JSON values, and EventBus host callbacks are process-local rather than a durable delivery guarantee.