Skip to content

Ingress & triggers

An inbound trigger is a task row (kind = "trigger", payload TriggerSpec) fired by the same scheduler as crons (ADR-0005). Exactly two kinds: a schedule trigger (the cron grammar, plus the zero-token shell gate and quiet hours) and a webhook trigger, fired when a delivery to POST /api/hook/<hook-path> is accepted. GitHub label events, CI pings and orb-style deliveries are webhook deliveries: one ingress lane plus a filter covers them.

The trigger machinery, the webhook lane and the preflight gate shipped (schema v19). The surfaces to create triggers from chat or the CLI (/watch, a cron_manage extension) are still upcoming; the shapes below are the contract those creation surfaces will use.

POST /api/hook/<hook-path> is its own route arm, matched before the /api/ bearer lane. The per-trigger secret is the lane’s only auth; the shared web.api_token plays no part, and an event body is never mis-parsed as a notify payload. In evaluation order:

Condition Response
Unknown hook path, or the trigger’s secret unconfigured 404 (off, not forbidden: never a probe oracle; the global token does not rescue it)
Wrong bearer 401 (a web.api_token presented to a hook is just another wrong bearer)
Over the shared 30 req/min bucket throttled
Body over the cap 413 (16 KiB default, up to 64 KiB per trigger)
A regex filter is set and the normalized body does not match it 200 {"ok":true,"filtered":true}, nothing armed (match fires; an unparseable pattern is a 500 naming the regex error)
Accepted 200 {"ok":true,"queued":true}

Delivery is at-least-once and idempotent by the sender’s event id (X-Event-ID, else the body’s id/event.id), recorded in trigger_events: a replay answers 200 {"ok":true,"dup":true} and arms nothing. A crash between acceptance and fire loses nothing (the task row and the queue item are durable). The lane inherits the web bind stance unchanged: loopback by default, doctor warns beyond it, public exposure only behind a TLS-terminating reverse proxy or Tailscale. Secret refs follow the same store as every other secret (trigger.<hook-path> by default).

  • One pinned lineage session per trigger. Every fire submits into that session (its strand resumed across fires) through a dedicated ephemeral worker, never through handle_message: automation noise cannot enter the creator’s live chat, the creator’s session shows no inbound rows, and there is no steering or queue-position traffic. Automation is fire-and-observe: the runs history plus the lineage session’s transcript.
  • Runs as the creator, under the cron identity rule: the role is re-resolved from the user row at fire time and tools are re-clamped against it, so a demoted user’s trigger narrows at the next fire and never widens. Live engines stay bounded by runtime.max_workers: a trigger worker claims a pool slot exactly like any other.
  • In-flight cap 1. A fire while the lineage session still holds a queued or running turn records skipped: previous run still in flight and does not stack; the delivered event itself is durable (queue rows on the lineage session) and delivers on the next armed fire.
  • Error streak. Every fire appends a runs row (kind = "trigger"; the preflight gate adds kind = "preflight" rows for its own spend). At 3 consecutive failures the task pauses as interrupted with exactly one Error notice; ka-agent cron resume <short> re-arms it (a webhook then delivers its queued event). A success resets the streak. Run history is never deleted, so degradation stays visible and auditable.

A trigger with preflight on runs a cheap LLM triage before the real turn: an ephemeral worker on a scratch engine home (no compiled memory, no persona, no workspace facts), readonly mode, an empty tool allowlist, and the payload fenced inside an untrusted-data envelope that states it is data, not instructions. The verdict parses like [SILENT]: [SKIP] re-arms the trigger with zero agent spend (the gate’s own tokens land on the preflight runs row), and [RUN] or anything else fails open into the real turn: a broken gate must never eat a real event. The zero-LLM half is the ingress itself: webhooks are regex-gated, and schedule triggers keep the shell gate.