Skip to content

The agent that grows with you

docs(gateway): document the intake vs delivery transport matrix

teknium119ca2e505a6a
diff --git a/gateway/AGENTS.md b/gateway/AGENTS.md
index 33433f342af..0bb5baa37a8 100644
--- a/gateway/AGENTS.md
+++ b/gateway/AGENTS.md
@@ -149,6 +149,21 @@ gateway under the backend, and do NOT "fix" update locks by widening the tree-ki
next to the identity; extend the object. `transport_profile` ≠ `runtime_profile` is normal
(shared bot → routed satellite). A source copy goes through `session_identity.replace_source`
so the identity travels with it (`_apply_topic_recovery` does).
+- **Intake vs delivery adapter.** `authz_mixin.py::_intake_adapter_for(source)` is the bot that
+ RECEIVED the event (live transport ref → relay socket → identity's `transport_profile`); it gates
+ intake policy (ignored channels, relay fronting, re-dispatch of a still-live event) and fails
+ closed to `None` for a source with no live provenance. `_delivery_adapter_for(source)` is the bot
+ that ANSWERS — the receiving bot whenever known, else the unique owner of `(platform,
+ runtime_profile)` via `_adapters_for_profile`. Never read `self.adapters[platform]` for a source;
+ never add a third resolver. The matrix (`tests/gateway/test_multiplex_transport_matrix.py`):
+
+ | Topology | runtime | intake | delivery |
+ |---|---|---|---|
+ | per-credential bot, no route | owner | owner adapter | owner adapter |
+ | shared credential → satellite (`profile_routes`) | routed | receiving adapter | receiving adapter (`_is_shared_bot_satellite` after restart) |
+ | shared bot → profile that owns its own bot | routed | receiving adapter | receiving adapter (conversation continuity; #70625's "routed bot" reading was not adopted) |
+ | secondary-owned bot → `default` (`bot_profile`) | default (`agent:main`) | receiving adapter | receiving adapter |
+ | restored / hand-built, no live provenance | stored `source.profile` | **`None`** | unique owner of `(platform, runtime)`; a disconnected secondary → `None`, never the default bot |
- **Token locks.** An adapter that connects with a unique credential (bot token, API key) calls
`acquire_scoped_lock()` from `gateway.status` in `connect()`/`start()` and `release_scoped_lock()`
in `disconnect()`/`stop()`, so two profiles cannot share one credential. Canonical:
diff --git a/website/docs/developer-guide/multiplexing-gateway.md b/website/docs/developer-guide/multiplexing-gateway.md
index d061cf10d2c..dea5122e7db 100644
--- a/website/docs/developer-guide/multiplexing-gateway.md
+++ b/website/docs/developer-guide/multiplexing-gateway.md
@@ -192,6 +192,36 @@ one WARNING at the first seam it reaches, never keyed into `agent:main`. Copy a
source with `session_identity.replace_source`, not `dataclasses.replace`, or the
copy loses its transport and identity.
+## Intake vs delivery: which bot acts on an event
+
+Two runner seams answer the two questions a multiplexed gateway keeps
+conflating (`gateway/authz_mixin.py`):
+
+- `_intake_adapter_for(source)` — the bot that **received** the event. Live
+ provenance only: the transport ref `build_source` pinned, the process-level
+ relay adapter for relay-delivered events, or the adapter currently
+ registered for the identity's `transport_profile` after a reconnect. It
+ gates intake policy (Slack ignored channels, relay fronting, re-dispatch of
+ a queued live event) and returns `None` for a source with no live
+ provenance — nothing may re-admit a restored row on a guessed bot.
+- `_delivery_adapter_for(source)` — the bot that **answers**: sends, edits,
+ typing, progress, pickers, pending-message slots. The receiving bot whenever
+ it is known; otherwise the unique owner of `(platform, runtime_profile)` —
+ a secondary's own adapter, the primary for a shared-bot satellite, and
+ `None` for a secondary whose bot is disconnected (it never borrows the
+ default bot).
+
+| Topology | Runtime (`runtime_profile`, key namespace, home) | Intake | Delivery |
+| --- | --- | --- | --- |
+| Per-credential bot, no route | The bot's own profile | Owner adapter | Owner adapter |
+| Shared credential → satellite via `profile_routes` | Routed profile | Receiving (shared) adapter | Receiving adapter; after a restart the satellite still drains through the primary |
+| Shared bot → a profile that owns its own bot | Routed profile | Receiving adapter | Receiving adapter — the conversation stays with the bot the user wrote to |
+| Secondary-owned bot → `default` (`bot_profile: <secondary>`) | `default` (`agent:main`, default home) | Receiving (secondary) adapter | Receiving adapter |
+| Restored / synthetic source, no live provenance | Stored `source.profile` | **None** (fail closed) | Unique owner of `(platform, runtime)`, else `None` |
+
+Outside multiplexing there is one adapter per platform, so both seams return
+it. `tests/gateway/test_multiplex_transport_matrix.py` asserts every row.
+
## Control plane
Desktop plugins reach the gateway only through the ws JSON-RPC door, so