Arcana::Bus
Central message router for agent-to-agent communication.
Supports direct delivery (send) and topics (publish/subscribe).
A #topic is a shared log: publishing stores a post once, anyone
reads it with topic_log(topic).read(after:), and subscribers get a
short notification of each post. Other topic names fan a full copy
out to each subscriber (the older form). Addresses are resolved
through the directory when available — bare names like "memo"
resolve to "memo:agent" or "memo:service" if unambiguous.
bus = Arcana::Bus.new writer = bus.mailbox("writer:agent") artist = bus.mailbox("artist:agent")
Direct message — bare name resolves if unambiguous
bus.send(Envelope.new(from: "writer:agent", to: "artist", ...))
Instance methods
Default max queue length for newly created mailboxes. nil means
unbounded (the historical default). Set via bin/arcana.cr from
ARCANA_MAILBOX_MAX_QUEUE. Mailboxes created with an explicit
max_queue: via a custom mailbox_factory override this.
Default max queue length for newly created mailboxes. nil means
unbounded (the historical default). Set via bin/arcana.cr from
ARCANA_MAILBOX_MAX_QUEUE. Mailboxes created with an explicit
max_queue: via a custom mailbox_factory override this.
Dispatch based on the envelope's ordering field (auto-resolved). Returns {reply, resolved_ordering}. Reply is nil for async.
Like deliver, but silently drops if the target mailbox doesn't exist.
Topics are registered in the directory, and their listings show each topic's newest post, so the directory asks the bus for that.
Optional event recorder. When set, material bus actions (sends, publishes, subscribe/unsubscribe, prune) emit events. Newly created mailboxes inherit this recorder via their persistence hooks.
Optional event recorder. When set, material bus actions (sends, publishes, subscribe/unsubscribe, prune) emit events. Newly created mailboxes inherit this recorder via their persistence hooks.
Get or create a mailbox for an address. Topics have none: see
topic_log.
Pending message count for an address. Returns 0 if no mailbox.
Prune stale agent listings and inactive mailboxes.
- Agent listings with last_seen older than
listing_ttlare removed. - Mailboxes with last_activity older than
mailbox_ttlare removed. Services are never pruned (they are re-registered from code at startup). Returns {pruned_listings, pruned_mailboxes}.
Publish an envelope to a topic.
For a #topic, the post is stored once in the topic's log and its
number returned; each subscriber gets a short notification (see
notify_subscribers). Raises unless the topic is registered.
For any other topic name, each subscriber gets a full copy, with
to set to its address, and nil is returned. The copy keeps the
bus's verified stamp but not the sender's signature, which covers
to.
Drop a topic's log and subscriptions (when it's unregistered).
Send an envelope and wait for a reply. Creates a temporary reply mailbox, sets reply_to, and blocks until a response arrives or the timeout expires. The reply mailbox is cleaned up automatically.
Resolve ordering: syntactic — service addresses (colon) are sync, agent addresses (no colon) are async.
Set a topic's subscribers as a snapshot recorded them, without the
checks subscribe makes.
Send an envelope to its to address. Raises if no mailbox exists,
or MailboxFull if the recipient's queue is at capacity.
Send, but return false instead of raising when the target mailbox
doesn't exist OR is full. Backpressure and missing-address both
collapse to "message didn't land" — callers who want to distinguish
should use send and catch specific errors.
Send an envelope and register an expectation for a reply on the sender's mailbox. Returns the correlation_id for tracking.
Subscribe an address to a topic. For a #topic, the topic must be
registered and the subscriber must have a mailbox, since that's
where notifications go. cadence is how often to be told:
only "always" (on every post) exists so far.
When true, every successful send fans out a metadata copy to the
sys.message.sent topic. Reactive infrastructure (like AIX's
tmux bridge) subscribes to it and gets push-quality wake
notifications without polling GET /events. Default OFF — enable
via ARCANA_SYSTEM_TOPICS=1 in the daemon, or set directly here.
Fanout cost: one extra Mailbox#deliver per subscriber per send.
When true, every successful send fans out a metadata copy to the
sys.message.sent topic. Reactive infrastructure (like AIX's
tmux bridge) subscribes to it and gets push-quality wake
notifications without polling GET /events. Default OFF — enable
via ARCANA_SYSTEM_TOPICS=1 in the daemon, or set directly here.
Fanout cost: one extra Mailbox#deliver per subscriber per send.
The log of a registered #topic, created on first use. Raises
unless the directory lists address as a topic. Its retention
follows the listing's.
What a topic's directory listing shows: its newest post and how many subscribe. Nil before its log exists.