Skip to content

honor the operator on credit balance conditions - #32

Merged
ryanechternacht merged 2 commits into
mainfrom
honor-credit-condition-operator
Sep 4, 2026
Merged

honor the operator on credit balance conditions#32
ryanechternacht merged 2 commits into
mainfrom
honor-credit-condition-operator

Conversation

@ryanechternacht

Copy link
Copy Markdown
Member

When credits run out on a credit burndown entitlement, CheckFlag falls through to the flag default with rule_type: null and "No rules matched". The API writes two rules for the entitlement, an entitling plan_entitlement rule whose credit condition uses lt and a plan_entitlement_usage_exceeded rule whose condition uses gte, but checkCreditBalanceCondition ignored the operator and evaluated balance >= cost for both. The exceeded rule could never match, so a drained balance was indistinguishable from a plan that lacks the feature, and a flag with a true default kept entitling companies with zero credits.

The operator now picks the direction of the balance check: gt/gte match when the balance does not cover the cost, everything else when it does. Overage still short-circuits to "covered", so the exceeded rule stays quiet when overage is on. A drained balance returns value: false with rule_type: plan_entitlement_usage_exceeded, matching numeric entitlements. The API only writes credit conditions through NumericLimitCondition, which has always used lt for the entitling rule and gte for the exceeded rule, so existing rules pick up the fix without a migration.

Mirrors the same change to rulesengine-rust in schematichq/schematic-api. The API needs a go.mod bump to the tag cut from this.

@ryanechternacht
ryanechternacht marked this pull request as ready for review September 3, 2026 18:58
@ryanechternacht ryanechternacht self-assigned this Sep 3, 2026
A credit burndown entitlement is written as an entitling rule with an lt
credit condition and a usage-exceeded rule with a gte one, but the engine
returned balance >= cost for both, so the exceeded rule could never match.
A drained balance fell through to the flag default with no rule_type,
which is indistinguishable from a plan that lacks the feature and stays
entitled on any flag whose default is true.
@ryanechternacht
ryanechternacht force-pushed the honor-credit-condition-operator branch from 0fae2a1 to 7142f16 Compare September 4, 2026 15:14
@ryanechternacht
ryanechternacht merged commit 17ec565 into main Sep 4, 2026
2 checks passed
@ryanechternacht
ryanechternacht deleted the honor-credit-condition-operator branch September 4, 2026 15:42
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