Output routing
Kheish separates internal output persistence from external delivery.Local output
Every daemon-produced answer is first recorded locally in the daemon’s own output stream and session records. This ensures the output exists even if an external delivery fails.Rich retained outputs
When a run creates daemon-owned media, the visible reply still needs one final persisted output step. Current pattern:- call one generator such as
generate_audio,generate_image, oredit_image - keep the returned daemon asset ids
- call
emit_outputto publish the visible answer and attach those assets
emit_output includes asset parts or sets include_artifacts_inline = true.
Reply targets
Output routing is driven by reply targets. A run can inherit or override reply targets from:- the explicit request
- the session defaults
- connector-derived routing
- an explicit output override
- the run snapshot
- the session defaults
Generic output plugins
External delivery is handled through a generic output plugin model. Output plugins receive normalized response envelopes and can deliver them to one or more external systems.Queued delivery
Connector-backed output delivery is not purely synchronous. Kheish uses a persisted delivery queue with retries, so transient failures do not silently discard outbound responses. The delivery store keeps pending records, completed delivery audit records, and a dead-letter log. Operator API and CLI views are redacted and can be inspected with:deliveries listdeliveries dead-letterdeliveries get <delivery_id>deliveries replay <delivery_id>deliveries resolve <delivery_id>deliveries replay-bulkdeliveries reset-backpressure
runs get <run_id> also includes the redacted delivery state associated with that run. Dead-letter replay creates a new pending delivery and records replayed_from_delivery_id; the original dead-letter entry remains immutable audit history.
resolve marks a dead-letter as operator-handled without redelivery. replay-bulk supports dry-run, filters, limits, and resolved-DLQ handling. reset-backpressure removes persisted per-target backpressure by redacted target digest or plugin, then wakes the worker.
On restart, uncommitted .settled-* tombstones are restored to pending unless a completed or dead-letter audit entry was already committed. This avoids losing a delivery in the crash window between pending removal and terminal ledger append.
Status keeps both historical and actionable DLQ counts:
dead_lettered: total persisted DLQ historyunresolved_dead_lettered: DLQ entries without a completed replay
unresolved_dead_lettered, so a successfully replayed delivery remains in audit history without keeping the daemon unhealthy forever.
Retry timing is controlled by:
KHEISH_DELIVERY_INITIAL_RETRY_MSKHEISH_DELIVERY_MAX_RETRY_MSKHEISH_DELIVERY_MAX_RETRY_AFTER_MSKHEISH_DELIVERY_MAX_ATTEMPTS
Retry-After delay, the delivery queue honors it but caps it with KHEISH_DELIVERY_MAX_RETRY_AFTER_MS so one hostile or malformed target cannot sleep the queue indefinitely.
HTTP and External connector outputs treat 429 as retryable even when the target omits Retry-After; the queue falls back to its normal retry policy.
Delivery is at-least-once. A crash after the downstream target commits but before the local completed ledger is written can replay the same delivery. HTTP and External connectors send Idempotency-Key: kheish:<delivery_id>; other plugins document their own duplicate-suppression limits.
Queue metrics are available at:
GET /v1/runtime/deliveries/metrics
completed.jsonl, dead-letter.jsonl, and resolved-dead-letter.jsonl.
Current output surfaces
Today, the daemon can keep output local and route it through queued plugins for:- HTTP
- Slack
- Telegram
- External connectors
