Skip to content

credit lease SDK primitives: check / trackWithReservation / prewarm#121

Merged
bpapillon merged 1 commit into
mainfrom
credit-lease-sdk-primitives
Jun 7, 2026
Merged

credit lease SDK primitives: check / trackWithReservation / prewarm#121
bpapillon merged 1 commit into
mainfrom
credit-lease-sdk-primitives

Conversation

@bpapillon

@bpapillon bpapillon commented May 21, 2026

Copy link
Copy Markdown
Contributor

Adds client-side credit burndown enforcement: check() preflight-reserves credits against locally-held leases (tranches acquired transactionally from the API), trackWithReservation() settles actual usage and refunds the delta to the lease, prewarm() / identify({ prewarm }) warm leases ahead of a session's first check, and getCreditBalance() exposes a lease-aware balance for display. Opt-in via a creditLeases config block; existing checkFlag / identify / track are unchanged.

Lease-bearing checks require DataStream so the SDK has the cached flag + company to find the credit condition and substitute the lease balance for WASM eval; without it, check falls through to a plain checkFlag. The new preflight options (usage / event_usage) thread through every client-side eval path (datastream, replicator, plain checkFlag), not just leasing.

Lease + reservation state lives in the cache backend: with Redis configured (an existing dataStream.redisClient is reused automatically; creditLeases.redisClient only to point elsewhere), balances and the reservation table are shared cross-pod with atomic mutations via single-key Lua scripts (check-and-decrement on tryReserve, claim-and-refund on consume) and client-side lease/reservation expiry. Without Redis, single-pod in-memory stores. No new runtime dependency.

@bpapillon bpapillon force-pushed the credit-lease-sdk-primitives branch 8 times, most recently from 5915cef to 2b0ea18 Compare May 23, 2026 17:40
@bpapillon bpapillon force-pushed the credit-lease-sdk-primitives branch 10 times, most recently from 407a9fd to abdf779 Compare June 3, 2026 04:22
@bpapillon bpapillon force-pushed the credit-lease-sdk-primitives branch 2 times, most recently from fd67284 to 69651e0 Compare June 3, 2026 21:21
@bpapillon bpapillon self-assigned this Jun 3, 2026
@bpapillon bpapillon force-pushed the credit-lease-sdk-primitives branch 8 times, most recently from e9fb366 to 5e69073 Compare June 6, 2026 01:07
Client-side credit lease + reservation gating on check/trackWithReservation,
with in-memory or Redis-backed lease and reservation stores. Adds prewarm,
getCreditBalance (lease-aware, expired-lease safe), and lease-matched credit
selection on mixed-credit flags.
@bpapillon bpapillon force-pushed the credit-lease-sdk-primitives branch from ad97192 to 0bc9f63 Compare June 7, 2026 04:34
@bpapillon bpapillon marked this pull request as ready for review June 7, 2026 04:38
@bpapillon bpapillon requested a review from a team as a code owner June 7, 2026 04:38
@bpapillon bpapillon merged commit 406b5b2 into main Jun 7, 2026
5 checks passed
@bpapillon bpapillon deleted the credit-lease-sdk-primitives branch June 7, 2026 04:47
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.

2 participants