caelum0x e28bc91c91 fix: pool Insights event caps org-wide instead of per-site
OrgCollector (one Durable Object per org) was tracking each site's monthly
event count independently and comparing it to the org's full plan
events_limit on every site. Since every site of an org is seeded with the
SAME events_limit (apps/console/lib/sites.ts copies the org's single
entitlement onto each app), an org with N sites/apps could store up to N x
its plan's event quota by spreading traffic across sites -- free capacity
the plan never intended to grant, and inconsistent with the console's own
Insights dashboard, which already sums month_events across every app of the
org before comparing to the same events_limit (lib/insights-view.ts).

Track and cap usage per org-month (pooled across every site the org has)
instead of per-site-month. Updated collector-sim.test.mjs's load test, whose
old per-site-independent-limits setup no longer matches real org/site data
shape, and added a collector.test.mjs case that pins the pooled behavior
across two sites of one org. Docs (README.md, contract/INGEST-API.md)
updated to describe the pooled cap.

Verified: apps/insights-edge's full test suite (87 tests across
collector.test.mjs, collector-sim.test.mjs, replay, selfserve, SEO and
tracker-script suites) passes clean after the fix.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-24 18:14:38 +03:00
..