cloudflare-cost-guard
Louis Cai’s open-source rules and TypeScript base class for keeping Durable Object alarms and Worker schedulers from runaway loops.
- Products
- Durable ObjectsWorkers
- Source
- Community resourceGitHub repository
- Author
- Louis Cai (@louis__cai)
Key points
- The README lists five anti-patterns: setAlarm in the constructor, rescheduling at every return without an exit condition, immediate retry on exceptions, alarm polling under 60 seconds, and one cron fanning out to many objects.
- Its four gates are: delete the alarm and return when idle, with explicit stop criteria and a minimum interval; daily and lifetime invocation ceilings with a tripped state that needs a human reset; exponential backoff with a consecutive-error ceiling; and tests that no alarm remains when idle and that the breaker trips.
- The repository ships a SafeAlarmDurableObject base class and a SKILL.md for coding agents. The README states that budget notifications do not suspend Workers, and that each setAlarm() on SQLite-backed Durable Objects is billed as a row written.
Original sources
Undated
Original post
Open original sourceThe author announces the library in a reply to @vikingmute and sums it up in three rules: exit when idle without renewing, trip a code-level breaker when daily calls exceed a limit, and stop completely after consecutive errors.
Read on 𝕏Louis
@louis__cai · Original 𝕏 post
睡醒欠一万刀太真实了。 AI 根本不知道钱贵,写后台定时器特别喜欢在末尾顺手续订,或者报错后秒级重试。加上 Cloudflare 没有断网级的消费硬顶,直接变成印钞机。 顺手把防爆规则和 TypeScript 安全基类抽成了一个开源库: https://t.co/KXVaSERwHd…
More to read
D1
mcwangcn reports past D1 write charges of “over a thousand dollars.”
@mcwangcn says D1 writes previously cost over a thousand dollars and separately mentions Workers CPU charges without giving an amount.
Author experienceDurable Objects
Durable Object alarm rules for agents.md
Viking (@vikingmute) shares the AI-generated Durable Object alarm rules he keeps in agents.md and suggests having another model review changes.
Community resourceWorkers +1
Cloudflare cost playbook
A community playbook for Cloudflare cost retrospectives, cost models, and code review.