# Signals ingress External producers send signal groups to the loopback HTTP ingress with `POST /signals`, and a YUI-hosted MCP server sends them as an MCP notification. This page is the contract for both: the routes, the envelope fields, the two delivery classes, and the validation that accepts or refuses a request. A backend author or agent reads it to build a producer the client accepts, and to know when the client turns a group into a turn. The [producer guide](../guide/signals-producer.md) walks through writing a producer. ```mermaid flowchart TD P["Producer"] -->|"POST /signals"| M["Bare route: main"] P -->|"POST /presets/{id}/signals"| W["Bound pet window pet-id"] M --> G{"Wire shape valid?"} W --> G G -->|"no"| E["HTTP 400, 403, 404, 405, 421 or 503"] G -->|"yes"| A["HTTP 200: batch emitted to the target window"] A --> V{"Envelope valid?"} V -->|"no, signals on"| X["Group dropped, one warning"] V -->|"urgent"| N{"User present and pipeline idle?"} N -->|"yes"| T["Turn"] N -->|"no"| U["Urgent buffer"] V -->|"batched"| B["Batch buffer, five-minute interval"] U --> T B --> T ``` ```mermaid sequenceDiagram participant P as Producer participant I as Ingress participant C as Client participant B as Buffer participant K as Backend P->>I: POST a signals array and an envelope I->>I: Check Host and Origin I->>C: Emit the batch to the target window I-->>P: 200, the wire shape was accepted C->>C: Validate the envelope alt the envelope is invalid C->>C: Drop the group and log one warning else urgent C->>K: Fire at once when present and idle C->>B: Otherwise hold in the urgent buffer B->>K: One urgent catch-up turn on the present or idle edge else batched C->>B: Hold in the batch buffer, five-minute interval B->>K: One turn at the boundary, or on a drain at a free slot end K-->>C: Reply ``` ## The request The ingress refuses a request whose `Host` is missing or not `127.0.0.1`, `localhost` or `::1` with 421, and a request whose `Origin` names another host with 403. The request body contains a `signals` array and a delivery envelope: ```json { "signals": [{ "kind": "workflow", "status": "complete" }], "envelope": { "source": "n8n", "event_type": "workflow_done", "delivery": "batched", "event_id": "run-8812", "occurred_at": 1787449000000 } } ``` Signal items are arbitrary opaque JSON values. The client transports and renders them without interpreting their meaning. ## Routes One listener on one port serves every window, and the path chooses the recipient. | Path | Recipient | |---|---| | `/threads/` | The Thread store, no window; see [Threads](./threads.md) | | `/signals` | `main`: the main window's character, whichever preset is active | | `/avatar/state`, `/avatar/perch-targets`, `/avatar/command`, `/relations` | `main` | | `/presets//signals` | `pet-`: the pet window bound to preset ``, and no other window | | `/presets//avatar/state`, `/presets//avatar/perch-targets`, `/presets//avatar/command`, `/presets//relations` | `pet-`; that window answers the request | | any other path under `/presets/`, including a route name outside the routes above | none: HTTP 404 | | an unknown path under `/avatar/` | none: HTTP 404 | | any other unknown bare path | none: HTTP 400 | | a preset id that exists while its pet window is closed | none: HTTP 503 | ### Preset ids `` is one path segment of ASCII letters, digits, `_` and `-`; the prefix itself, an id with no route after it, an empty id, and an id with any other byte all receive 404. The listener is loopback-only and carries no authentication, so a local caller can tell which preset ids exist by the 404 and 503 replies; the ids are opaque keys, not secrets. ## Envelope fields | Field | Valid value | |---|---| | `source` | Non-empty string identifying the producer | | `event_type` | Non-empty string identifying the producer-defined event type | | `delivery` | Exactly `"urgent"` or `"batched"` | | `event_id` | Non-empty opaque string | | `label` | Optional string: the producer's one-line origin | | `occurred_at` | Finite epoch-millisecond number in the inclusive range `-8.64e15` through `8.64e15`, representable as an ISO-8601 date | There is no fallback timestamp. ### The event_id field A group replaces a buffered group with the same `event_id` and the same sending plugin in the same buffer, at its position; a group without a plugin matches only another without one. A group with the same `event_id` from the same plugin waiting in the other buffer is removed; a group with the same `event_id` from another plugin, or from none, stays. A restored group is dropped when either buffer already holds its same-id group. A delivered group is not compared. ### The label field The `label` is the producer's one-line origin, for example `devbox · tmux yui:2 · YUI (main)`. Over 120 code points it is cut to 119 code points plus `…` and the request is accepted; a non-string label makes the envelope invalid. The label is not rendered in `client_context`. The client shows the label after `source`, as the source line of the group on the speech bubble and in History. When the label is absent, the client shows `event_type` instead. The bubble keeps the line to its own width and cuts the rest with an ellipsis, so the distinguishing words go first. ## Delivery `delivery` names one of two delivery classes, `urgent` and `batched`; dropping is a producer-side rule, so a producer that wants a signal dropped does not send it. ### Urgent An `urgent` group means the user should hear it without delay. It fires at once while the user is present and the pipeline is idle, and the proactive gap does not hold it. Otherwise it waits in its own buffer. On the away-to-present or busy-to-idle edge, the buffered urgent groups fire together as one urgent catch-up turn. Urgent groups never share a catch-up turn with `batched` groups. The drains below carry batched groups only, so a buffered urgent group keeps waiting for its own edge. ### Batched A `batched` group always waits in the batch buffer, where the first group starts a five-minute delivery interval. At the interval boundary, all pending batched groups that may leave fire together when the user is present and the pipeline is idle. If those conditions are not met, the groups remain buffered without another timer, and leave on the next drain. ::: tip A batched group that misses its deadline starts no second timer. It leaves on the next drain of the batch buffer. ::: ### Disabled signals The External signals switch gates the groups of the HTTP routes and of Thread updates. A group a plugin's server sent is ungated: it arrives, buffers and leaves the same way whether the switch is on or off. While signals are disabled, the client drops every gated group that arrives, and every gated group stays out of catch-ups, timer firings, drains and restored turns. The next OS idle tick removes the gated groups already buffered. A group a Thread reaction holds survives that removal, and leaves when its reaction fires or releases it while signals are enabled. ### Drains The batch buffer has no catch-up of its own: the dispatcher drains it, in arrival order. At every free slot (no call in flight, no speech owed, do-not-disturb off), the drained groups ride the turn that slot starts, beside the self-started lines that waited for it. With no line waiting, they go out alone as one `signals.catchup` turn, with room under the hourly cap, and only on the edge into a free slot: - the pipeline goes from busy to idle - a do-not-disturb or proactive-gap hold ends - the user returns to present Inside a free stretch, a batched group waits for a turn to ride or for its batch timer. A user message drains the buffer too, and the groups ride the user's turn, do-not-disturb included. Two client-fired candidates also drain the buffer when they arise: a `proactive.tap_bored` turn and the `time_milestone.first_activity` turn. Each takes every pending batched group that no Thread reaction holds; a candidate that has to wait puts them back. #### Held and gated groups An urgent catch-up, a timer firing and a drain carry only the groups that may leave: none that a Thread reaction holds, and no gated group while signals are disabled. Each removes only the groups it carried. With the Thread reactions switch on, a Thread reaction holds every Thread turn group. The held groups stay out of every timer firing and drain. When a reaction finishes, every held, buffered group leaves together as one `signals.batch` turn; a turn the bus refuses leaves them held for the next reaction. The five-group cap of the batch buffer can still push a held group out, and the switch going off releases every held group to normal delivery ([Threads](./threads.md#withdrawn-groups-and-reactions)). ### Groups that go back Groups go back to the front of their buffers, and the next urgent edge or drain delivers them, when: - a candidate that carries groups has to wait - a `signals.*` turn cannot go out now - the user's message cancels the turn that carries them - do-not-disturb turns on while the turn waits for the turn lock - a guardrail debounce or a degraded backend drops the turn - the bus refuses the push - the call fails in transport or at the backend ### Buffer and rate limits Each buffer retains at most five groups and drops its oldest group on overflow. Urgent turns are capped by their own hourly rate limit, `rate_limit.urgent_max` (default 120), and they do not count toward the tier-2 cap. ## From a plugin A YUI-hosted MCP server sends a signal group as the notification `notifications/io.github.yw0nam.yui/signals`. Its `params` is the `POST /signals` body, a `signals` array and an `envelope`, and the MCP host applies the same checks: `signals` is an array, the envelope is present and not null, and each item is at most 16 KiB. The host stamps the payload with server time and the plugin's id, then emits it to `main` the way the bare route does. It works with any ingress port and with the ingress off. The 64 KiB body limit is HTTP-only. A refused notification whose `params` is absent, `null`, or an object is one `signals refused: ` line in the plugin log; scalar or array `params` are refused while the frame is decoded and leave no line. A notification sent before the handshake completes, or after the plugin is turned off, is dropped without a line. External signals does not gate the group ([Disabled signals](#disabled-signals)). ## Relations `GET /relations` and `GET /presets//relations` return the character's relation store: the relation the backend has rated toward the user and toward each other preset (`docs/reference/client-tools.md` § `rate_relation`). `PUT` on the same path replaces the whole store. An external engine that keeps its own relationship record writes the store this way. ```json { "user": { "value": 5, "updated_at": 1787449000000, "log": [{ "at": 1787449000000, "delta": 2, "why": "asked how my day was before the bug" }] }, "aaaa0001": { "value": -6, "updated_at": 1787430000000, "log": [], "note": "trusts the work, doubts the promises" } } ``` ### Store shape One key per target: `user`, or another preset's id. | Field | Valid value | |---|---| | `value` | Integer from -20 to 20 | | `updated_at` | The epoch milliseconds of the last change | | `log` | The last changes, newest first, at most 20, each `{at, delta, why}` with `delta` an integer from -40 to 40 other than 0 and `why` a string of at most 80 characters | | `note` | Optional: an external engine's own summary of the relation, at most 200 characters | A value the user sets by hand in the settings window logs one change with the full jump and the `why` `set by the user`. The client never writes the `note`, and it renders the note on the `relation:` line after the attitude. ### Writes A `PUT` body that is not an object, has a key that is neither `user` nor an existing preset id, or breaks any range receives HTTP 400 and leaves the store unchanged; a valid body answers 200 with the stored body. A key for the window's own preset id is accepted, stored, and never rendered, and any other method receives 405. The window renders the relation on its next turn, and its preset row shows it at once. The daily cap applies to the tool only. A `PUT` stores exactly what it sends. ## Preset switch The bare routes belong to `main`: a group that arrives on `/signals` after the user switches presets becomes a turn of the newly active preset's backend, whichever backend the producer had in mind. A route under `/presets//` belongs to that preset's window: its group becomes a turn of that preset's backend, which stays bound to `` across a switch of the active preset. Each pet window holds its own buffers, so a switch, which reloads `main`, drops every group still buffered there and leaves a bound window's buffers untouched. ## Validation The HTTP ingress requires `POST /signals`, valid JSON, a `signals` array, and an `envelope`. ### Refusals A request with another method on `/signals` or `/presets//signals` receives HTTP 405, and invalid JSON, a missing `signals` array, or an absent or null `envelope` receives HTTP 400. A request under `/presets/` whose id no preset has, or whose path after the id is none of the routes above, receives HTTP 404. An unknown path under `/avatar/` receives HTTP 404; any other unknown bare path receives HTTP 400. A request for a preset id that exists while its pet window is not open receives HTTP 503; it is never passed to `main`. Threads accept only PUT on `/threads/`; a wrong method receives 405. Invalid or missing Thread ids, any other path under `/threads`, and any preset-prefixed Threads path receive 404. Field validation receives 400; the [Threads reference](./threads.md) defines the fields. ### What 200 means HTTP 200 means the ingress accepted the wire shape and attempted to emit the batch to its target window. It does not confirm receipt or delivery. The envelope is forwarded unchanged and stamped with server time. ::: warning A 200 answers the wire shape only. The batch can still lose a group after it: an invalid envelope is dropped as a whole, and one warning records the item count. ::: ### Dropped envelopes A group whose envelope is not an object or fails the field rules is dropped as a whole and one warning is logged with the item count. While signals are disabled, the source drops incoming gated batches before envelope validation and logs no envelope warning; a plugin's batch is validated as usual. ### Size limits A request with any signal item whose JSON serialization exceeds 16 KiB receives HTTP 400; no item of that request is delivered. A request body over 64 KiB receives HTTP 400. ### Connection limits These limits apply to every ingress route. - Request headers must finish within 5 seconds, or the connection closes. - The entire body must arrive within 10 seconds. An unreadable, stalled, or oversized body receives HTTP 400. - Host and Origin checks run before body reads and before `100 Continue`. At most 64 connections are open at once. Additional connections close before parsing. Each connection serves one request; keep-alive is disabled.