feat: enforce free-tier node ceiling and MCP gate#265
Conversation
Free outlines are capped at 2,000 live nodes and MCP agent access is a paid capability (#170). - DO: applyBatchGated/upsertNodesGated count net growth (distinct new ids) inside the write transaction and refuse only batches that would grow the outline past the cap. Edits, moves, deletes, and net-reducing batches always apply; an over-cap (downgraded) outline is never locked. Decision is the pure, unit-tested batchExceedsNodeLimit. - Worker: resolves the caller's plan (getPlan), skips the query for pure-delete batches, maps a refusal to 403 {error:"node_limit",limit}. - MCP: a free token still handshakes + lists tools, but every tools/call is refused with an in-protocol -32001 upgrade error. - Client: the 403 becomes a distinct NodesLimitError; the structural funnel shows one upgrade toast then rolls the optimistic insert back. Operator override is free: getPlan treats a hand-inserted active subscription row as paid. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Warning Review limit reached
Next review available in: 37 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (9)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Two issues surfaced by adversarial review of the entitlement change: - Owner account was misclassified as free on the node-write path: getPlan received the DO-resolved id (owner collapses to 'default'), missing the owner's comp/subscription row keyed on the real user.id. Pass the billing id (session.user.id) to the plan lookup while the DO stub keeps routing on the resolved id — mirroring the MCP branch. - Node-cap growth count could be bypassed by a batch that deletes and re-inserts the same id (double-subtracted the survivor). Replaced the independent insert/delete sets with a pure, unit-tested countNetGrowth (last-op-per-distinct-id), so an id that ends the batch present is one insert and a delete+reinsert nets zero. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Two issues surfaced by adversarial review of the entitlement change: - Owner account was misclassified as free on the node-write path: getPlan received the DO-resolved id (owner collapses to 'default'), missing the owner's comp/subscription row keyed on the real user.id. Pass the billing id (session.user.id) to the plan lookup while the DO stub keeps routing on the resolved id — mirroring the MCP branch. - Node-cap growth count could be bypassed by a batch that deletes and re-inserts the same id (double-subtracted the survivor). Replaced the independent insert/delete sets with a pure, unit-tested countNetGrowth (last-op-per-distinct-id), so an id that ends the batch present is one insert and a delete+reinsert nets zero. Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Summary
Free outlines are now capped at 2,000 live nodes and MCP agent access is a paid capability, so the free/paid line is enforced server-side rather than by convention.
Fixes #170
Changes
tools/callis refused with an in-protocol upgrade error — no read or write reaches the outline.applyBatchGated/upsertNodesGated): it counts net node growth by distinct id inside the write transaction and refuses only batches that grow the outline past the cap it's told.batchExceedsNodeLimit; the Worker resolves the caller's plan once per node-creating write (skipping pure-delete batches) and maps a refusal to403 {error:"node_limit",limit}.activesubscription row —getPlanalready treats it as paid, so no Stripe round-trip and no new override path.user.id(not the DO-routing id, which collapses the owner todefault), and a purecountNetGrowthcloses a delete+reinsert count bypass.Start here: change 6 — the owner billing-id fix and the delete+reinsert bypass, both found by adversarial review; the growth count now takes each id's last op.
Flow
Breaking / Migration
None. Additive: no schema change, no new
Nodefield. Existing alpha accounts (no subscription row) are free and unaffected until they cross the cap.Test plan
bun run typecheck/typecheck:worker/typecheck:test— greenbun test— passing, incl.batchExceedsNodeLimitboundary cases (under/at/over cap, downgraded outline never locked, net-reducing batch allowed),countNetGrowth(the delete+reinsert bypass case), and the MCP free-token gate (tools/call refused, discovery open)bun run lint,bun run fmt:check— cleanseedOutlinemocks the Worker, so the realgetPlan/DO cap never runs).