Concepts
Batching Strategies
Optimize window, trim history, cap maxMsgs. Reduce LLM calls 55%.
TL;DR: Set windowMs:500. Trim history to 10 msgs. Cap maxMessages:10. Recover stuck via heartbeats.
Table of Contents
Config Table
Tune batch-types.ts defaults.
| Config | Default | Fast UX | Max Savings | Impact |
|---|---|---|---|---|
| windowMs | 500 | 100 | 1000 | Latency vs batch size |
| maxWindowMs | 5000 | 2000 | 10000 | Max collection time |
| maxMessages | 10 | 5 | 20 | Prevent overload |
Test impacts: bun test --filter batch.
Trim History
Keep recent messages. Use history.ts.
Call before LLM: trimHistory(state.messages, 10).
Window Tuning
Short window: Fast replies, less batching.
Long window: More savings, higher latency.
Imperative: Start with 500ms. Measure batch sizes in logs.
From batch-types.ts:
Decision Tree
Integrates batching-alarms.md.
Stuck Quiz
Q: Recover stuck batch when?
A: Heartbeat >30s stale ✅
B: Always retry
C: Manual only
Related
Run bun run deploy:telegram. Send rapid msgs. Check logs for batch sizes!