Concepts
Batching & Alarms
Dual-batch prevents blocking. 500ms window collects msgs. 5s heartbeat rotations. 30s stuck -> auto-recovery.
TL;DR: pendingBatch collects (non-blocking). 500ms alarm -> activeBatch processes. 5s heartbeats. 30s no-beat -> recover.
Table of Contents
Dual-Batch
Timings
| Event | Delay | Purpose |
|---|---|---|
| queueMessage | T+0ms | Webhook returns 200 |
| onBatchAlarm | 500ms | Batch msgs -> 1 LLM |
| Heartbeat | 5s loop | Liveness + UX |
| Stuck Check | 30s | Auto-recovery |
Webhook <6ms exit! DO independent.
Stuck Recovery
New msg checks: now - lastHeartbeat > 30s -> Clear stuck -> Process new.
Code Snippet
From architecture.md
Quiz: Why dual-batch?
A: pending never blocks new msgs ✅
Related: Architecture -> | DOs ->
Deploy: bun run deploy:telegram -> Spam msgs -> See batching!