credit lease SDK primitives: check / trackWithReservation / prewarm#121
Merged
Conversation
5915cef to
2b0ea18
Compare
407a9fd to
abdf779
Compare
fd67284 to
69651e0
Compare
e9fb366 to
5e69073
Compare
2810e4c to
7dfa1bf
Compare
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.
ad97192 to
0bc9f63
Compare
schematic-bot
approved these changes
Jun 7, 2026
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.
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, andgetCreditBalance()exposes a lease-aware balance for display. Opt-in via acreditLeasesconfig block; existingcheckFlag/identify/trackare 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,
checkfalls through to a plaincheckFlag. The new preflight options (usage/event_usage) thread through every client-side eval path (datastream, replicator, plaincheckFlag), not just leasing.Lease + reservation state lives in the cache backend: with Redis configured (an existing
dataStream.redisClientis reused automatically;creditLeases.redisClientonly to point elsewhere), balances and the reservation table are shared cross-pod with atomic mutations via single-key Lua scripts (check-and-decrement ontryReserve, claim-and-refund onconsume) and client-side lease/reservation expiry. Without Redis, single-pod in-memory stores. No new runtime dependency.