Skip to content

Land billing-core Phase 2: combinators and checkout reservation - #2

Merged
FlyOverCoderKY merged 4 commits into
mainfrom
cursor/billing-core-phase-2-30a9
Aug 15, 2026
Merged

FlyOverCoderKY merged 4 commits into
mainfrom
cursor/billing-core-phase-2-30a9

Conversation

@FlyOverCoderKY

Copy link
Copy Markdown
Contributor

Phase 2 of Billing Core: declared invariant combinators and the single-opportunity checkout reservation, in-tree and unpublished.

What landed

  • @pegma/billing-core (0.1.0, unpublished) now includes:
    • sticky — a host-declared flag that only flips one way, enforced inside the update decider so a later price reversion cannot clear it
    • firstWins — a host-declared field or named group whose first write is permanent (consent capture under concurrent deliveries)
    • Checkout reservation — mint inside a decider; refuse when redeemed, live-subscribed, or already reserved and unexpired; read the winning id back from storage; release best-effort; expire by TTL from the injected @pegma/spine Clock
  • A reservation-only row is still applyable for the first provider event. A corrupt row that already carries subscription state without a watermark stays a conservative keep.
  • Granting statuses (trialing, active, past_due) redeem the one-per-customer offer and clear the reservation. offerRedeemed is sticky.
  • Race tests run unchanged over createMemoryStore() and Azure Tables against real Azurite:
    • Sticky one-way flip, including concurrent deliveries that try to clear it
    • firstWins under concurrent deliveries, then a later event that cannot change the group
    • Concurrent reservation admits exactly one winner
    • Decider re-run mints a different id; the caller’s id is the stored record
    • TTL expiry from the injected clock
    • Refuse redeemed / subscribed / reserved; release best-effort

Explicitly not in this PR

  • Snapshot reconciliation / always-write sweep (Phase 3)
  • packages/billing-stripe (Phase 4)
  • RetireGolden host swap (Phase 5)

Plan status is Phase 2 in-tree, unpublished. Do not merge from this PR unless a reviewer asks. Do not publish or tag.

Open in Web Open in Cursor 

Phase 2 of billing-core: sticky and firstWins combinators run inside
the update decider, and reservation ids are minted per decider run then
read back from storage. TTL uses the injected Clock.

Co-authored-by: Fly Over Coder <FlyOverCoder@gmail.com>
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for security reviews. Please try again later.

Applying a granting event also redeems the offer, so the subscribed
gate is asserted against a stored live row that is not yet redeemed.

Co-authored-by: Fly Over Coder <FlyOverCoder@gmail.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8800b29a4c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/billing-core/src/index.ts Resolved
Comment thread packages/billing-core/src/index.ts Resolved
Comment thread packages/billing-core/src/index.ts Resolved
Comment thread packages/billing-core/src/index.ts Resolved
Comment thread packages/billing-core/src/index.ts Resolved
Reject forbidden host field names, require reservation provenance
before skipping the watermark, freeze empty-string firstWins writes,
keep the encoder compile-checked complete, and redeem from granting
history so a Phase 1 cancel cannot reopen the offer.

Co-authored-by: Fly Over Coder <FlyOverCoder@gmail.com>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 68b2e71. Configure here.

Comment thread packages/billing-core/src/index.ts Resolved
Terminal canceled/unpaid without a granting status no longer burns
the one-per-customer reservation. Live or historically granting rows
still redeem, including a Phase 1 active row that later cancels.

Co-authored-by: Fly Over Coder <FlyOverCoder@gmail.com>
@FlyOverCoderKY
FlyOverCoderKY merged commit 8ed94f2 into main Aug 15, 2026
5 checks passed
@FlyOverCoderKY
FlyOverCoderKY deleted the cursor/billing-core-phase-2-30a9 branch August 15, 2026 17:34
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