ADR 0019doc/{zh,en}/adr/0019-connection-health.md

ADR 0019: A Transport Reports Its Connection's Health

Status: accepted, 2026-11-29, by the owner's approval of the twin fallback design (option A); built with it.

Status: accepted, 2026-11-29, by the owner's approval of the twin fallback design (option A); built with it.

Context

The Feishu digital twin answers /dt from the owner's account over the web client's protocol. When that session stops working, through risk control, a protocol change or an expired login, /dt silently reaches nobody in the chats the bot is not in. The owner asked to be told, once, through a connection that still works, and once again when the twin is back.

A Transport cannot send: sending belongs to the Delivery stage, and one plugin instance calling another's API would bypass presentation, receipts and retries. The Host already sends notices to admins (NotifyAdmins, used for a rejected configuration). What is missing is a way for a Transport to say that its connection is up or down.

Decision

  1. A new optional contract, plugin.HealthReporter, on the TransportHost: ReportHealth(ctx, Health{State, Key, Params, Reason}), with State up or down, Key and Params a message of the reporting plugin's own locale files, and Reason an optional shorter message key of the same files (with the same parameters): why it is down, as orquelo status shows it.
  2. The Transport decides when it is down. The Host times nothing; each Transport applies its own policy (the twin: at once for a needed login, after fallback_after, default 5 minutes, of reconnecting).
  3. The Host tells the admins of the other connections, once a change. It keeps each connection's last state in memory. On a change to down, and on a change back to up, it renders the plugin's message in each admin's connection locale and queues it as a Host notice to their direct chat, presented and delivered as any notice. The reporting connection's own admins are skipped: it is the one that cannot deliver. A repeated state, and a first up (a connection starting), tell nobody; the admins' notices of a change are queued in one transaction, and when that fails the change is not taken, so the next report of the same state sends them all, once (Feishu #287, 2026-11-30).
  4. The state does not outlive the Host. A Host that starts with a connection down is told once more. For orquelo status (2026-11-30, the owner), the running Host writes each reporting connection's state, its reason rendered in the Host's locale, and since when to health.json in its state directory on every change, including a new reason while it stays down (the since is kept; Feishu #288), and drops a connection a reload removed, so one added back is new (Feishu #289), and orquelo serve removes the file when it starts, so the record needs no expiry of its own (AGENTS.md section 11). orquelo status prints a line per reporting connection only while a Host runs, such as twin: down since 09:55 (login required: /login feishu.cn): the time in the local zone, its month and day when not today. A connection that never reported, such as the bot, the console and the HTTP API today, prints none.

Consequences

  • ◆New public contract: plugin.HealthReporter and plugin.Health (pkg/plugin/health.go); the Host renders a plugin's message by key through its instance (registry.Instance.Message), so it holds no channel text of its own.
  • ◆Only in-process (builtin) Transports can report for now; the process protocol gets a host.report_health callback when an external Transport needs it.
  • ◆The log records connection.health on every change, connection.health_record_failed when the record cannot be written or cleared, and admin.notice_failed as for any admin notice.
  • ◆internal/host/connhealth holds the record's format, which the Host writes and the CLI reads.
  • ◆Any channel can use it; the Host has no Feishu branch.
  • ◆Amended 2026-12-04 (Feishu #357): the Host also watches the parts every instance reports (plugin.StatusReporter, such as an MCP bundle's servers) once a minute; one unavailable for 5 minutes on end is down, and the admins are told once and once again when it works, in the Host's own words (host.instance_down, host.instance_up), recorded in the same health.json as instance/part and shown by orquelo status (instance health). No plugin contract is added.