Skip to content

feat(api): connected-record usage and an enforced record allowance (#518) - #1286

Merged
athvin merged 1 commit into
mainfrom
feat/518-usage-allowance
Nov 27, 2026
Merged

athvin merged 1 commit into
mainfrom
feat/518-usage-allowance

Conversation

@athvin

@athvin athvin commented Nov 27, 2026 •

Copy link
Copy Markdown
Owner

Closes #518

Post-merge is part of this pull request. The ledger below records whether
the follow-up work actually happened. /land-pr closes it.

What

Usage and entitlement for the API product. Unit = connected records (standardized source records summed over datasets) — the unit the public pricing page already states, so no new pricing promise. GET /v1/orgs/{org}/usage; operator PATCH /v1/orgs/{org}/allowance (new nullable orgs.record_allowance); deliveries 402 at the limit; docs "How usage is measured" + 402 in the error table; readiness record updated.

Why

#518: decide the commercial unit and pilot policy, enforce it, prevent double-charging, let admins inspect usage through the public contract, and have the launch proof verify it.

Proof

  • pg_launch_proof (DuckLake + Postgres): each dataset reports exactly its delivered records despite a redelivery and an idempotent retry; total = sum; allowance set to the total → at_limit, push 402, reads 200, tenant cannot change its allowance (403); lifting it → push 202.
  • Full cargo test -p er-server against Postgres; frontend unit suite (1104); make check exit 0.

Risk & rollback

Additive nullable column; no allowance is set on any existing org, so nothing is enforced until an operator sets one. A revert leaves the column (harmless).

Post-merge ledger

Closed by: agent · session Claude Code:24d16c2e-fec6-49d8-9797-060338df4848 on brians-MacBook-Pro · 2026-11-27T02:01:21Z

Specific to this change

Context — plan, discoveries, measurements, files

Plan

Discoveries

  • The commercial unit was already decided in public copy (docs Usage section, frontend/src/lib/pricing/config.ts tiers by total records); the ticket's open question was enforcement, not pricing.
  • The existing erweb.usage_events ledger meters AI calls, not billable data, and the docs already said so; it is unchanged.
  • Policy decisions (owner asked me to decide): measure on demand from the lake rather than keep a counter (distinct by construction, no drift); refuse only new data at the limit; fail open on a count error; 402 as the stable status.

Measurements

Files

🤖 Generated with Claude Code

)

The commercial unit the pricing page already promises — connected records,
summed across every system — is now measured and enforced:

- GET /v1/orgs/{org}/usage (viewer+): each dataset's standardized records at
  its latest snapshot, the total, the allowance, what remains, at_limit.
  Distinct records by construction, so retries, idempotent replays and
  re-deliveries never double-count; a failed or canceled run lands nothing.
- orgs.record_allowance (nullable = unlimited), set by the operator through
  PATCH /v1/orgs/{org}/allowance (a tenant key gets 403).
- JSON pushes, file imports and new uploads are refused with 402 once the
  total reaches the allowance; reads, reviews, corrections and exports
  continue. A count that cannot be taken fails open.

The launch proof checks the counts, the 402 at the limit, reads at the
limit, and recovery when the allowance is lifted.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions

github-actions Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

The marketing preview was removed because this PR is closed or merged.

@athvin
athvin merged commit 248e296 into main Nov 27, 2026
48 checks passed
@athvin
athvin temporarily deployed to marketing-preview November 27, 2026 01:21 — with GitHub Actions Inactive
athvin added a commit that referenced this pull request Nov 27, 2026
… epic and #1279's duplicates Parquet export (#1300)

#1286 (248e296) was one commit, d245d4a. Its parent was a fresh main
(8b5b25a), but 75 files in its tree were the versions from dc45fd1:
a tree from an old worktree was committed on top of a new base. The
squash was CLEAN and the old code is self-consistent, so every gate
passed while it undid:

- the cinematic epic #1253: #1272, #1275, #1278, #1280, #1282, #1283
  and #1285, with their tests and visual baselines;
- #1279's Parquet export for duplicate groups (exports.rs, read.rs,
  export_write.rs and the ExportIn doc comment).

This is the merge #1286 should have produced, computed rather than
hand-picked:

1. Give d245d4a's tree its real parent, dc45fd1.
2. Three-way merge it into 2b8f0b8, the main it landed on, with base
   dc45fd1. No conflicts.
3. Carry the difference from 248e296 onto today's main with another
   three-way merge. No conflicts.

#1286's own work is kept: the usage endpoint, the record allowance, and
the docs on usage and the 402.

Closes #1299

Co-authored-by: bmoore813 <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
athvin pushed a commit that referenced this pull request Nov 27, 2026
…sion

#1286 was one commit whose parent was a fresh main but whose tree came from
an old worktree. It undid seven merged pull requests, and every gate was
green: the squash was CLEAN and the old code was self-consistent. #1310
nearly did the same that day. The diff reads as a feature that also deletes
things. What gives it away is that each file's new content is a version
main already had and moved past.

`stale tree guard` (stale-tree-guard.yml) walks each changed file's history
on main and names the commits a return would undo. A file brought back
with the content it had before main deleted it is the same finding.
Deletions alone are not findings. It is graded on main's own history:
- three or more source files returning fails;
- fewer warn (#1302 deliberately took back two lines of #877);
- screenshot baselines are reported and never counted (#1298's CTA
  baseline landed on old bytes).

Replayed against #1286's commit and main's last 40 merges, each on its true
parent:
- #1286 fails, on 33 source files;
- so does #1300, the restore, its mirror image, a revert that would
  carry `revert-ok`;
- three merges warn;
- the other 35 are silent.

The self-test runs first in the job. It covers the #1286 shape, a partial
revert, a baseline on old bytes, a genuine change, both exemptions (a
`Revert…` title and the `revert-ok` label) and a shallow clone, which is
refused rather than passed. The check is not required yet, by the order the
ci-and-supply-chain skill gives.

Closes #1307

Co-Authored-By: Claude Opus 5.5 <[email protected]>
athvin added a commit that referenced this pull request Nov 27, 2026
…sion (#1315)

* wip: claim #1307 — flag a pull request whose files revert to an older main version

* feat(ci): flag a pull request whose files return to an older main version

#1286 was one commit whose parent was a fresh main but whose tree came from
an old worktree. It undid seven merged pull requests, and every gate was
green: the squash was CLEAN and the old code was self-consistent. #1310
nearly did the same that day. The diff reads as a feature that also deletes
things. What gives it away is that each file's new content is a version
main already had and moved past.

`stale tree guard` (stale-tree-guard.yml) walks each changed file's history
on main and names the commits a return would undo. A file brought back
with the content it had before main deleted it is the same finding.
Deletions alone are not findings. It is graded on main's own history:
- three or more source files returning fails;
- fewer warn (#1302 deliberately took back two lines of #877);
- screenshot baselines are reported and never counted (#1298's CTA
  baseline landed on old bytes).

Replayed against #1286's commit and main's last 40 merges, each on its true
parent:
- #1286 fails, on 33 source files;
- so does #1300, the restore, its mirror image, a revert that would
  carry `revert-ok`;
- three merges warn;
- the other 35 are silent.

The self-test runs first in the job. It covers the #1286 shape, a partial
revert, a baseline on old bytes, a genuine change, both exemptions (a
`Revert…` title and the `revert-ok` label) and a shallow clone, which is
refused rather than passed. The check is not required yet, by the order the
ci-and-supply-chain skill gives.

Closes #1307

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: bmoore813 <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>

This branch was previously deployed

1 inactive deployment
marketing-preview — d245d4ad Deployed Nov 27, 2026 by athvin via remove closed PR previews #84
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

E3 — API usage, entitlements and commercial metering

2 participants