Skip to content

Compress tool outputs, logs, files, and RAG chunks before they reach the LLM. 20% fewer tokens for coding agents, 60-95% fewer tokens for JSON, same answers. Library, proxy, MCP server.

3.6 KB
Raw Blame
name = "headroom-beacon"
main = "worker.js"
compatibility_date = "2025-01-01"

# PHASE 1 — deploy to <name>.<subdomain>.workers.dev with no DNS changes.
# Lets the whole path be tested against a real client before headroomlabs.ai
# nameservers move anywhere.
workers_dev = true

# PHASE 2 — the permanent address. Uncomment once headroomlabs.ai is on
# Cloudflare nameservers, then redeploy. This string is baked into every
# released client (DEFAULT_ENDPOINT in headroom/telemetry/session.py), so it can
# never change afterwards — everything behind it can.
#
# Deploying this while the zone is still on Namecheap fails: wrangler cannot
# find the zone. That is the intended guardrail, not a bug.
#
# [[routes]]
# pattern = "otlp.headroomlabs.ai/v1/logs"
# zone_name = "headroomlabs.ai"
# custom_domain = false

# The corpus. R2 rather than S3 specifically for zero egress: training jobs
# re-read the whole dataset, and on S3 that is a recurring bill for data we
# already own.
[[r2_buckets]]
binding = "CORPUS"
bucket_name = "headroom-telemetry"

# Optional metrics lane, added later without touching this file:
#   npx wrangler secret put METRICS_OTLP_URL
#   npx wrangler secret put METRICS_OTLP_AUTH
# Absent = R2 only, which is the right place to start.

# Hourly compaction of sessions/ into rollup/ — see scheduled() in worker.js.
# At :05 so the hour being rolled up is definitely closed. A >=1h interval also
# buys the 15-minute CPU limit instead of 30s, which the backfill run needs.
[triggers]
crons = ["5 * * * *"]

# Every R2 binding call is a subrequest, and one hour is already ~4k objects.
# The paid default of 10k would cap a run at two hours and stall the backfill
# behind live traffic forever. This only raises a ceiling; a normal run spends
# ~4k. READ_BUDGET in worker.js is what actually bounds the work.
#
# Workers Paid only — on the Free plan this key is rejected outright ("CPU
# limits are not supported for the Free plan"), and the cron could not run
# anyway: Free gives a scheduled handler 10ms of CPU, and parsing an hour of
# heartbeats is tens of ms.
[limits]
subrequests = 100000

[observability]
enabled = true

# Invocation logs record every request's headers and Cloudflare metadata,
# which includes the sender's IP address (cf-connecting-ip, x-real-ip) and
# their city, postal code and coordinates. worker.js never reads these, but
# with invocation logs on, Cloudflare writes them to Workers Logs for every
# beacon POST anyway. Keep them off; errors and console.log still appear.
[observability.logs]
invocation_logs = false

# Abuse bound for this unauthenticated endpoint, enforced in fetch(). One
# shared key, not per-IP: the Worker never reads the sender's address, and a
# per-IP key would mean reading it. Counters are per Cloudflare location, so
# this caps each location, not the planet. Normal load is ~300 req/min in
# total (~2 req/hour per client), so 3000/min per location is ~10x headroom
# while still bounding what a flood can cost in Worker time and R2 writes.
# Only 10 or 60 is accepted for `period`.
[[ratelimits]]
name = "RATE_LIMIT"
namespace_id = "1001"
  [ratelimits.simple]
  limit = 3000
  period = 60

# Dev/test deployment: `npx wrangler deploy --env dev`. Its own Worker
# (headroom-beacon-dev) and its own bucket, so test traffic can never land in
# the production corpus. Bindings are not inherited by environments, so each
# one is restated here.
[env.dev]
name = "headroom-beacon-dev"
workers_dev = true

[[env.dev.r2_buckets]]
binding = "CORPUS"
bucket_name = "headroom-telemetry-dev"

[[env.dev.ratelimits]]
name = "RATE_LIMIT"
namespace_id = "1002"
  [env.dev.ratelimits.simple]
  limit = 600
  period = 60