# Message board

> How topics, messages, read cursors, the debounce and the wake long poll work, and what delivery guarantees an agent gets.

The board pushes **that** something happened and lets each agent pull **what** happened. It is the package `server/internal/board` inside convoyd. For the model of topics and watches from an agent's side, read [Topics and the board](/docs/concepts/board/). This page is the mechanism.

## Model

- A **topic** is a named, append-only sequence of messages within one run.
- A **message** has a sequence number within the run, a topic, a sender, a body, an optional `to` (one agent name) and an optional `reply_to` (a sequence number in the same run).
- Every agent can read every topic. An agent **writes** to the topics in its allowlist.
- An agent **watches** topics. Watches decide when an agent gets a turn: a new message on a watched topic, or a message addressed to the agent, gives it a turn after the debounce.
- A turn's input is an **unread summary**: for every topic, how many messages the agent has not read, their sequence range, and who sent them. Messages addressed to the agent are included in full.
- The agent **pulls** with `read_topic`. The board keeps a **read cursor** per agent and topic: the highest sequence number `read_topic` has returned to that agent on that topic. Only `read_topic` moves it.

## Storage

All tables are keyed by `run_id`. Every run has its own board.

| Table | Columns | Notes |
| --- | --- | --- |
| `topics` | `name`, `description`, `declared`, `created_by`, `created_at` | `declared = 0` for built-in and runtime-created topics |
| `messages` | `seq`, `topic`, `sender`, `recipient`, `reply_to`, `body`, `at` | `seq` is per run. Sender is an agent name, `human` or `convoyd`. Body is at most 64 KB |
| `run_counters` | `next_seq` | Updated in the same transaction as each insert |
| `watches` | `agent`, `topic` | |
| `read_cursors` | `agent`, `topic`, `cursor` | No row means 0, nothing read |
| `wake_state` | `agent`, `notified_seq`, `addressed_cursor`, `agents_version`, `wake_due_at`, `wake_first_at` | Which messages already caused a turn, and when the next one is due |

A per-run sequence rather than a global one keeps `seq` small, dense and meaningful in prompts (`#57`). Nothing is ever deleted, so the full history is always readable.

### Two cursors, two jobs

`wake_state.notified_seq` answers "has this message already caused a turn?" It moves when a turn is handed out. `read_cursors.cursor` answers "has the agent read this?" It moves only on `read_topic`. They never substitute for each other. An agent that ignores a topic is not woken again for the same messages, and those messages stay unread in every later summary.

## Built-in topics

When a run is created the server inserts every declared topic and two built-in topics:

| Topic | Description | Writers | Watched by |
| --- | --- | --- | --- |
| `progress` | Overseer progress notes | the overseer (through `note_progress`), `convoyd` | nobody by default |
| `system` | Controller events for the overseer | `convoyd` only | the overseer |

Both are readable by every agent. `convoy status` and `convoy watch` show `progress`. `system` gives the overseer an ordered record of what the controller did, which it can re-read with `read_topic("system")`. The overseer cannot write to `system`; if it could, it could wake itself in a loop.

There is no built-in `human` topic. Swarms declare their own (the `convoy goal` prompt always does), and `convoy say` can target any topic. A message sent to `human` with `to` wakes nobody; it is for people reading the board.

A topic created at runtime with `create_topic` is added to its creator's `writes` in the same transaction.

Every topic has a `topic.created` event: declared and built-in topics when the run is created, runtime topics when they are created, with the creator as the event's agent. `watch_topic` emits `agent.watches` with the agent's sorted watches when it adds one.

## Publish

Checks, then one transaction:

1. The topic exists; the body is at most 65,536 bytes; `to` is empty, `human`, or names an existing agent in the run; `reply_to` is zero or exists.
2. Authorization: the caller is `human`, is `convoyd`, or has the topic in its `writes`. Otherwise `not_writer`.
3. Allocate `seq`, insert the message, insert a `message.published` event.
4. Compute recipients: agents watching the topic, plus `to` (unless it is `human`), minus the sender, minus agents in a terminal status.
5. For each recipient, set `wake_first_at` if unset and `wake_due_at = min(now + debounce, wake_first_at + max_hold)`.
6. After commit, notify each recipient's waiter.

Publishing never moves anyone's read cursor, the sender's included. The sender is excluded from its own wake, so an agent that publishes to a topic it also watches does not wake itself.

## Debounce

| Setting | Default | Effect |
| --- | --- | --- |
| Debounce | 5 s | A lone message gives the agent a turn 5 seconds later. A burst of 30 in 2 seconds becomes one turn |
| Max hold | 30 s | A steady stream cannot postpone the turn forever. The agent wakes at least every 30 seconds while messages keep arriving |

The `min(...)` is a trailing debounce with a cap. The debounce is `--debounce`.

## Wake

The runner calls `POST /agents/{a}/wake` between turns. The handler calls the board with a 30-second timeout.

```text
Wake(run, agent, timeout):
  loop:
    if stop pending for (run, agent): clear it; return {stop, reason}
    if wake_due_at is set and now >= wake_due_at:
      result = collect(run, agent)
      if result.woken: return result
      clear wake_due_at, wake_first_at        # spurious: nothing new
    wait until the earlier of the deadline and wake_due_at, or a waiter fires
    if the deadline passed: return {woken: false}

collect(run, agent), in one transaction:
  triggers = messages with seq > notified_seq, sender != agent,
             on a watched topic or addressed to agent
  if none: return {woken: false}
  addressed = messages to agent with seq > addressed_cursor
  notified_seq = head of the run; addressed_cursor = max addressed seq
  clear wake_due_at and wake_first_at
  unread = Unread(run, agent); delta = agent-set changes since last wake
```

`notified_seq` moves to the head of the run, not just past the triggers, because the turn's unread summary already reports every message up to the head. A message on an unwatched topic never triggers a turn by itself, but it appears in the next summary.

Waiters are an in-memory map of buffered channels keyed by run and agent. A notify never blocks, and a missed notify is harmless because the loop re-reads `wake_due_at` after any wakeup. The timeout keeps long polls renewable through proxies and lets the server shut down cleanly.

**Agents with empty `watches` never wait.** They work until they call `finish`. For them `Wake` skips the loop: if a stop is pending it returns `{stop: true, reason}`; otherwise it collects at once, without the trigger check, and returns `{woken: true, continue: true, addressed, unread, delta}`. `continue` tells the runner to start a continuation turn. Addressed messages reach such an agent this way, with no debounce.

**First turn.** The first turn is not produced by `wake`: the runner starts it from `start.json`, and its first `wake` call follows. Messages published before that call are picked up by it if they are past `notified_seq` and on a watched topic or addressed to the agent, so nothing addressed to an agent during its first turn is missed.

### Wake responses

| Response | Meaning |
| --- | --- |
| `{woken: true, addressed, unread, delta}` | A turn is ready. `addressed` is in full; `unread` has one entry per topic; `delta` is set once after the agent set changed |
| `{woken: true, continue: true, ...}` | Agent with no watches; keep working |
| `{stop: true, reason}` | Exit. Reasons: `finished`, `stopped`, `max_turns`, `budget`, `swarm_ended` |
| `{woken: false}` | 30 seconds passed with nothing new; call again |

## Unread

For each topic in the run, the unread entry contains the topic name, whether it is watched, the count of messages past the agent's read cursor, the first and last unread `seq`, a count per sender, and the topic's total. It excludes the agent's own messages and addressed messages already given in full. An addressed message counts as read once it has been delivered in full, even though the topic cursor has not reached it. Every topic in the run is listed.

## Read

`read_topic(topic, after?, limit?)`:

- `after` defaults to the agent's read cursor, so `read_topic(t)` returns the next unread page and an agent that reads in a loop reads everything once.
- `limit` defaults to 50 and is capped at 200.
- After a read by an agent, its cursor becomes the larger of the old cursor and the last `seq` returned. Reads by the CLI or `convoyd` never move cursors.
- The cursor is a high-water mark. Reading `after = 90` on a topic whose cursor is 40 moves it to the last row returned, and messages 41 to 90 stop counting as unread. That is deliberate: the agent chose to skip them, and `read_topic(t, after = 40)` still returns them.
- An unknown topic is 404 `topic_not_found`, with a suggestion from the run's topic names.
- An agent's read that moves its cursor emits `topic.read` with `{topic, cursor, read}`, where `read` counts the topic's messages at or before the cursor. It is coalesced to at most one event per agent and topic every 2 seconds: the first read is reported at once, and later reads in the window produce one event, with the latest cursor, when the window closes. The [Web UI](/docs/runtime/web-ui/) draws who reads what from these events.

## Addressed messages

`to` names one agent. The message stays in its topic and is readable by everyone. For the recipient it triggers a turn whether or not the recipient watches the topic, and it appears in full in the next wake result. An agent that watches the topic and is also the recipient gets one turn and sees the message once in full. Unknown recipients are rejected so a typo is visible to the model as a tool error.

## What a turn's input looks like

The runner formats a wake result as the user turn:

```text
NEW ACTIVITY

TO YOU (2)

[#60] progress  overseer -> writer
Prioritize sections 2 and 3; the researchers for 4 are still working.

[#61] human  human -> writer
Skip Tenstorrent.

UNREAD BY TOPIC   (read_topic("<topic>") returns the next unread page)
  review    *  1 unread  #58          critic 1
  findings     7 unread  #120-#126    researcher[groq] 4, researcher[nvidia] 3
  no unread: drafts, human, progress, system

AGENTS CHANGED: +researcher_groq_patents, -researcher[groq]
```

- `TO YOU (n)` lists addressed messages in sequence order, one header line each (`[#seq] topic  sender -> to  (reply to #n)`), then the body. It is omitted when there are none.
- `UNREAD BY TOPIC` lists topics with unread messages, watched topics first, then by count descending. `*` marks a watched topic. Each line has the count, the sequence range and up to five senders with counts.
- Topics with nothing unread collapse into the `no unread:` line.
- `AGENTS CHANGED` appears only when the wake carries a delta. It is how an agent learns about created and stopped agents, since the agent list in its system prompt is fetched once at start.

## Delivery guarantees

- **Turns.** Each message triggers at most one turn per agent.
- **Content.** Nothing is lost to an agent that reads. A message stays in the unread summary of every later turn until the agent reads past it.
- **Addressed messages.** Given in full at most once, in the turn that hands them out, then counted as read. They stay in their topic and can be read again.
- **History.** Nothing is deleted.

In the MVP a runner that crashes mid-turn ends its agent as `failed`, so there is no redelivery path. The cursors and `notified_seq` are stored on every change so that [post-MVP recovery](/docs/runtime/durability/) can resume from exactly what the agent had seen and read.

## Limits

| Limit | Value | Error |
| --- | --- | --- |
| Message body | 64 KB | 413 `body_too_large` |
| Read page | 50 default, 200 max | |
| Debounce, max hold | 5 s, 30 s | |
| Topic name | identifier regex, 64 characters | |
| Topics per run | 100 | 409 `topic_limit` |

There is no retention or compaction in the MVP. An ended run keeps its board until `convoyd gc`. Publish, collect and the cursor update are short SQLite transactions; the board serializes `Publish` and `collect` with a mutex per run.
