kavach-go ServeOrReplay operations in showcase/openmeter/harness/internal/host/worker.go
Creates meter, feature, customer, and metered entitlement via real upstream Ent Postgres adapters.
Issues a recurring or scheduled grant via creditpgadapter.NewPostgresGrantRepo.
Writes metered events via real openmeter/streaming/clickhouse.Connector.BatchInsert over HTTP Native.
Resets entitlement usage at boundary and persists balance_snapshots + usage_resets via Ent Postgres.
Compares snapshot-accelerated GetEntitlementBalance against full-period ground truth.
Evaluates GetEntitlementBalanceHistory via ClickHouse HTTP and checks OverageAtStart vs GetBalanceAt.
Loads owner from Ent Postgres, queries ClickHouse HTTP, and runs Engine.Run across reset sub-periods.
openmeterio/openmeter @ f2da4096547f9e7f69ce1e2cde0525c2c2c01cea (100% git-clean)
Runs engine at reset time and persists the boundary snapshot via Ent balanceSnapshotRepo.Save.
Iterates reset periods, filters grants, picks Inclusive/Exclusive boundary behavior, and resets snapshots.
Validates ExactlyForGrants and controls grantsRecurredAtStart via ApplyStartRecurrences.
Extracts grantsRecurredAtStart at period.From and appends terminal [Until, Until] phase.
Seeds timestampedBalances from burn-down segments and accumulates per-window overage.
Real upstream Ent Postgres repositories via kavachpgx + ClickHouse HTTP Native streaming connector + openmeter_credit sink
Real upstream OpenMeter entgo.io/ent Postgres adapters (grants, balance_snapshots, entitlements, usage_resets, meters, features, customers) wrapped with kavachpgx.WrapStatefulConnector.
Real upstream openmeter/streaming/clickhouse.Connector over clickhouse-go/v2 HTTP Native protocol.
JSON status, balance, overage, and invariant telemetry emitted per step via kavach-go.
Declarative .kavach/invariants.yaml rules + credit conservation and window history consistency
Declarative YAML invariant (.kavach/invariants.yaml): credit balance and overage must never be negative.
Snapshot-resumed GetEntitlementBalance must match full-period ground truth.
History window OverageAtStart and BalanceAtStart must match point-in-time GetBalanceAt.
Snapshot recurrence double-apply, 2x overage history, and multi-reset grant mismatch
runBetweenResets re-applies grantsRecurredAtStart at idx == 0 even though the saved boundary snapshot already applied recurrence and burned overage.
GetEntitlementBalanceHistory seeds overage: segment.Overage (end-of-segment) instead of segment.OverageAtStart, inflating cumulative overage 2x.
Period 0 filters out future scheduled grant g2; Period 1 includes g2 without seeding snapshot.Balances[g2]=0, tripping ExactlyForGrants.