funding

package
v1.833.310 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 4, 2026 License: Apache-2.0 Imports: 2 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package funding is the cash circuit-breaker. It is deliberately NOT under internal/: the HOST publishes into it (hanzoai/cloud computes upstream credit and burn, ai enforces the ceiling), so the seam has to cross the module boundary. Policy lives here with the enforcement it guards; the numbers arrive from whoever can see the vendor.

Package funding is the cash circuit-breaker: the one place that answers "may this request spend REAL money right now, and how much is left today".

WHY IT EXISTS. There are two separate moneys and, until this package, nothing connecting them. The commerce ledger is platform credit we ISSUE — accounting. The upstream provider bill is cash LEAVING THE BANK. On 2026-07-28 Hanzo had $250,573 of outstanding platform credit standing against $0.00 of remaining DigitalOcean promotional credit and a ~$65/day cash burn: every one of those issued dollars could convert 1:1 into cash, and no layer could even notice, because each was correctly answering its own question. The promo credit had in fact been exhausted for six weeks; invoices went $0.00 → $0.53 (June) → $1,824.45 (July) while the dashboard still showed a hardcoded grant.

WHY A CEILING AND NOT A REFUSAL. The obvious rule — "comp credit may not spend a paid provider" — is degenerate the moment the promo runs out: with credit at zero EVERY provider is paid-only, so that rule refuses every comp-funded request at once, including live customer demos. It converts a budget problem into an outage. A daily ceiling bounds the loss without the cliff, which is the actual ask: know what is left, and keep it filled.

DEFAULT OFF. A zero ceiling disables the breaker, so merging this changes no behaviour anywhere until someone deliberately arms it. A money guard that switches itself on during a deploy is its own incident.

FAIL OPEN, DELIBERATELY, AND ONLY HERE. This is a SECONDARY guard; the prepaid balance gate is the primary one and stays fail-closed (an unverifiable balance denies). If this breaker's own inputs are unknown — cloud has not pushed state, or the day rolled over — it ALLOWS. Fail-closed here would mean a stale telemetry push could halt all paid inference fleet-wide, which is a worse failure than one extra day of spend against a ceiling someone is already watching.

A READING EXPIRES. The paragraph above always named two unknowns, but only one of them could be seen: a State that was never published, and a State that has stopped being refreshed, are the same fact — nobody can currently say what is left — yet the second went on being the answer forever, because nothing here aged it. That is the gap that made arming the ceiling unsafe rather than merely ineffective: a reading captured at the ceiling would keep refusing every paid request long after the day it described had ended, and only a restart would clear it. State.Until closes it, so "we knew, once" decays into "we do not know" and lands on ALLOW like every other unknown.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Publish

func Publish(s State)

Publish replaces the funding state. cloud calls this from the same finance aggregation that renders the provider-credit board, so the breaker and the dashboard can never disagree about whether we are on cash. Passing a zero State disarms the breaker.

Types

type State

type State struct {
	// OnCash reports that upstream promotional credit is exhausted, so spend is
	// now real money. False while a grant still covers usage.
	OnCash bool
	// TodayCents is cash spent so far in the current UTC day.
	TodayCents int64
	// CeilingCents caps cash per UTC day. Zero (or negative) DISABLES the breaker.
	CeilingCents int64
	// Until is when this reading stops being believable: the publisher's next
	// refresh plus enough slack to survive one missed round, and never later than
	// the UTC midnight that ends the day TodayCents counts — past that boundary the
	// figure is not slightly wrong, it is a different day's.
	//
	// Zero means the reading never expires, which is what a publisher that cannot
	// say gets. That is the conservative default in the ALLOW direction only
	// because a publisher that sets no expiry is also the publisher that existed
	// before this field did; a publisher that CAN say must say.
	Until time.Time
}

State is what cloud knows about upstream funding, pushed in. It is a VALUE: the breaker reads no ledger and no vendor API, so the DECISION below is a pure function of what it was told and is trivially testable. Only freshness consults a clock, and it does so in Current — the accessor that already answers "what do we know", which is the question staleness changes the answer to.

func Current

func Current() State

Current returns the last published State, or the zero State (breaker disarmed) when cloud has never pushed one — the standalone-ai case, and the reason a missing publisher cannot halt inference.

A reading past its Until is returned as the zero State too, for the same reason and by the same rule: both are "nobody can say", and this package answers that with ALLOW. Handling it here rather than in Refuse keeps the policy pure and puts the clock in the one place that already decides what is known.

func (State) Refuse

func (s State) Refuse() bool

Refuse reports whether this request must be turned away to protect the bank.

It refuses only when all three are true: the ceiling is armed, upstream credit is gone, and today's cash has already reached the ceiling. Any unknown leaves the request allowed — see the fail-open note above.

func (State) RemainingCents

func (s State) RemainingCents() int64

RemainingCents is today's unspent cash allowance, never negative. It is the number worth putting in an error message: it tells an operator how much room is left rather than only that they ran out.

func (State) Stale added in v1.833.28

func (s State) Stale(now time.Time) bool

Stale reports whether this reading has outlived its Until. A reading with no Until never goes stale.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL