Duyetbot Agent
Concepts

DO Limits & Alarms

Cloudflare DO quotas, alarms, heartbeats. Scale reliably with monitoring.

TL;DR: Track quotas daily. Schedule alarms wisely. Rotate heartbeats. Recover stuck batches automatically.

Table of Contents

Quotas Table

Monitor Cloudflare DO limits. Stay under free tier.

From PLAN.md.

MetricFree TierPaid TierImpact
Requests/day100,00010M+Messages/invocations
Alarms/day1,000UnlimitedBatch triggers
CPU Time/day50,000ms10MmsProcessing budget
Burst CPU30s30sSingle execution limit

Batch messages. Use patterns. Avoid quota exhaustion.

Alarm Usage

Alarms trigger onBatchAlarm(). Collects pending messages.

Tune window for efficiency.

From packages/cloudflare-agent/src/batch-types.ts:

// packages/cloudflare-agent/src/batch-types.ts
const DEFAULT_BATCH_CONFIG = {
  windowMs: 500,    // Fast collection
  maxWindowMs: 5000, // Max wait
  maxMessages: 10,
};
 
// Set alarm
this.ctx.storage.setAlarm(Date.now() + config.windowMs);

Test: bun run test --filter batch.

Heartbeat Mechanism

Edit thinking message every 5s. Proves DO alive.

Detect stuck: now - lastHeartbeat > 30_000ms.

From PLAN.md:

"Thinking 🧠" -> "Still thinking... ⏳" -> "Almost there... 🔄"

Auto-recovery: Clear activeBatch. Promote pendingBatch.

Scaling Flow

+---------------------+
| New Messages        |
+----------+----------+
           |
           v
+------------------------+
| pendingBatch           |
| Non-blocking           |
+----------+-------------+
           |
           v
    +------------------+
    | Alarm 500ms?     |
    +----------+-------+
               |
               v
+------------------------+
| activeBatch            |
| Process LLM            |
+----------+-------------+
           |
           v
+------------------------+
| Heartbeat              |
| 5s Edits               |
+----------+-------------+
           |
           v
+------------------------+
| Response Ready         |
+------------------------+

+---------------------+
| New Msg             |
+----------+----------+
           |
           v
    +------------------+
    | Stuck?           |
    | 30s no beat?     |
    +---+----------+---+
        | Yes      | No
        v          |
    +------------------+
    | Clear active     |
    | Recover          |
    +------------------+

Quiz: Free tier alarms/day?

A: 1,000 ✅
B: 10,000
C: Unlimited

Related:

Run wrangler tail. Watch alarms and heartbeats live!

On this page