feat: organization credit system — metered checks, balance gate, runway projection#84
Open
rathorevaibhav wants to merge 20 commits into
Open
feat: organization credit system — metered checks, balance gate, runway projection#84rathorevaibhav wants to merge 20 commits into
rathorevaibhav wants to merge 20 commits into
Conversation
Covers schema/ledger/metering/enforcement, runway projection, scheduled rollup + warnings, default grant, org credits page, header chip, super-admin panel, and monitor-form impact preview. Execution deferred until issue #23 tenancy merges to main. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…ance gate The credit-system enforcement gate (Monitor::scopeEnabled()) now requires the owning organization to have credit_balance > 0. This test's organization fixture had the DB-default balance of 0, causing even the kept monitor to be excluded. The test's intent (trashed monitors excluded from Spatie repository) remains untouched—only the fixture needs funding to satisfy the credit gate as a precondition. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…zero-crossing, notification isolation, UI/docs polish Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Monetization foundation: organizations hold a credit balance; every executed check (uptime, certificate, domain) costs 1 credit, decremented atomically per check. At balance ≤ 0 all of the org's checks pause via a query-level gate (no monitor config is touched) and resume on the next scheduler tick after a grant. Runway is projected from live monitor configuration and surfaces everywhere: warning emails, an always-visible header chip, the org credits page, the super-admin panel, and live impact previews on the monitor forms.
Design spec:
plans/2026-07-02-credit-system-design.md· Implementation plan:plans/2026-07-02-credit-system-implementation-plan.mdWhat's included
credit_transactions(grants/adjustments/nightly usage-debit rollups) with row-locked writes andbalance_afteraudit snapshots;credit_usage_dailypowers the usage breakdownCreditMeteringService— two writes per check, race-free zero-crossing (atomic conditional UPDATE gates the one-shot "monitoring paused" email), never throws into the check pipelineMonitor::scopeEnabledoverride gates uptime + certificate selection through Spatie's repository; domain command gated incl.--force. Incidentally fixes a vendor OR-precedence bug that selected uptime-only monitors for certificate checksCreditRunwayService+ mirrored JS util), used by daily warning escalation (low→critical), shared Inertia props, header chip,/creditspage, super-admin grant panel, and monitor-form previewscredits:grant {amount} --org=|--all(auditable rollout/top-up path),credits:rollup-usage(00:15, idempotent),credits:evaluate-warnings(00:30)Migrating adds
credit_balance = 0to every existing organization, which pauses all their checks. Immediately afterphp artisan migrate, run:Env:
CREDITS_DEFAULT_GRANT,CREDITS_WARNING_LOW_DAYS,CREDITS_WARNING_CRITICAL_DAYS(see.env.example). Details in the spec's Rollout section.Billing policy decisions (documented in spec)
Testing
Accepted follow-ups (non-blocking)
Notification class dedup + body-line tests;
scopeFunded()helper for the 3× balance-gate closure; DB unique on rollup idempotency key; render-or-drop unusedusageByDay.byType; chip TONES dedup; suppress "(currently 0)" on the create-form preview.🤖 Generated with Claude Code