# The T3 Code events relay turns a milestone into one wake

> For agents: start with the [agent guide](https://ratstack.sh/llms.txt). Every page is Markdown by default; add `Accept: text/html` for HTML.

New on /news: [Pleat 0.2 moves its typed styles to Effect UI](/news).

Before T3 Code exposed events over [MCP](/lore/mcp-is-another-surface), an outside agent had to keep checking for changes. [T3 Code's MCP Events change](https://github.com/pingdotgg/t3code/pull/40774) lets the relay subscribe instead. `thread.run_settled` reports the end of a turn. `thread.needs_input` reports a question or approval request.

The 0.1.12 nightly notes mark the arrival of MCP Events. The relay was tested on a later 0.1.14 nightly using MCP's stateless transport.

A small relay streams both events and sends a waking [Rat King](/lore/rat-king) message to the agent recorded as the thread's starter. The agent can stop checking thread status. The relay can fall back to polling the event feed if streaming fails. It never polls the thread list.

## Record the work before moving the cursor

The cursor tells the relay where to resume. If it saves the cursor first and crashes before recording the event, it can resume past work it never queued. If it saves both in one SQLite transaction, a restart sees both writes or neither.

This excerpt is from `state.mjs` at `d094599` in `rat-king-infra`, a private repository. It is trimmed to show the [checkpoint](/lore/checkpoints-follow-commits). The prepared insert ignores event IDs already in the journal.

Record event rows before advancing the cursor; lines 1-8; highlighted none.

```javascript
transact(() => {
  for (const {event, recipient, status} of rows) {
    insert.run(event.eventId, JSON.stringify(event), recipient, status, now, now);
    // First-invalid alert omitted.
  }
  if (cursor != null) setCursor.run(name, cursor);
  // Recovery bookkeeping and retention omitted.
});
```

Mail crosses a second boundary. The mailbox can accept a message even if the relay never sees its receipt. `submitMail` in `relay.mjs` saves the signed envelope before sending. Every retry uses the saved envelope.

The mailbox returns the original receipt for an identical envelope. A retry does not add a second waking message.

That is [idempotent delivery](/lore/retry-needs-idempotency) for a registered milestone that reaches the mailbox. It does not mean every T3 event arrives. T3's event history is bounded, and the relay's gap recovery covers registered threads within its recovery window.

## Five failures the review caught

The first cut is `2a5ef17`. The fixes below are in `d094599` in the same repo.

1. **Contaminated journal.** The proof run used the same journal as normal delivery. Its test filter could mark another thread's event ignored. On replay, the journal would keep that decision. `relay.mjs` separates the journals, and `openJournal` refuses a journal marked for the other mode.
2. **Silent drops.** The first cut logged an invalid event and moved the cursor past it. The relay now parks a bounded record of the rejected event. In `state.mjs`, the parked row and first-invalid alert commit with the cursor.
3. **Silent stall.** A malformed route could break the whole batch, and recovery errors looked like transport trouble. `routesFrom` now warns and skips the bad line. The relay exits on recovery failure and alerts an operator after three consecutive failures.
4. **Stale recovery.** A gap could make the relay send a wake for a question already answered. `recoverFrom` now reads only pending requests. The delivery loop checks again before sending a recovered request.
5. **Silent expiry.** A rejected read grant could stop the relay with only a log entry. `mcp.mjs` now recognizes rejection in HTTP errors, JSON-RPC errors, and stream termination messages. The relay tries to confirm a durable alert before parking and retries that alert if admission is unconfirmed.

Normal mail also has a retry limit. After six attempts, `exhaustMail` parks the envelope and queues an operator alert in the same transaction. See [Dead letters need a return path](/lore/dead-letters-need-a-return-path) for why parking is only half the job.

The relay lives outside rat-stack and runs as plain Node scripts. Commit progress with the work it promises. Retry the same external write until you have a receipt or a record to repair.

## Sources

1. [T3 Code nightly v0.1.12-nightly.20261123.5124](https://github.com/pingdotgg/t3code/releases/tag/v0.1.12-nightly.20261123.5124)
   T3 Code. The nightly changelog lists the change that added MCP Events for outside agents. Accessed 2026-11-28.

2. [Outside agents poll and stream milestones as MCP events](https://github.com/pingdotgg/t3code/pull/40774)
   T3 Code. Defines the milestones, push and poll delivery, bounded history, and cursor truncation. Accessed 2026-11-28.

## Lore on this page

- [MCP is another surface](/lore/mcp-is-another-surface)
- [Private catalog](/systems/catalog)

## Linked from

- Agent guide → An Effect stack so pure (aspirational) Kit Langton will blush. → [Read page](https://ratstack.sh/llms.txt)

- Change log → What changed in the files served here, newest first. → [Read page](https://ratstack.sh/log)

- Full agent guide → An Effect stack so pure (aspirational) Kit Langton will blush. → [Read page](https://ratstack.sh/llms-full.txt)

- Rat Stack lore | rat-stack → Short, source-grounded notes on the ideas and decisions behind rat-stack. → [Read page](https://ratstack.sh/lore)

- Source change history (log.md) → The generated change log as Markdown. → [Read page](https://ratstack.sh/log.md)
