Repository navigation
fix: preserve monotonic offer redemption across event ordering - #7
Conversation
|
OpenRouter review posted ( |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
OpenRouter pull-request review
Verdict: issues
Scope: full-pr (full-pr)
Mode: initial
Commit: c49acb08af9b295966a8d1cdc0ee7a464dcf2d17
Judge: openai/gpt-5.6-luna
Cost: $0.2597 (lanes $0.2583 + judge $0.0013)
Lanes
meta/muse-spark-1.2: ok (0 finding(s), 73.2s, 251624+7023 tokens (150709 cached), 6 tool round(s), via Meta, $0.18)z-ai/glm-5.3-flash: ok (3 finding(s), 632.1s, 1736545+50630 tokens (1654528 cached), 29 tool round(s), via InferenceNet, $0.0797)
Findings
🟠 Issue 1 — Stale redemption evidence is still dropped on non-terminal rows, so a redeemed one-per-customer offer can be reserved twice
packages/billing-core/src/index.ts:927 · risk · identified by z-ai/glm-5.3-flash
Concrete failure: event E2 (status: "incomplete", eventAt T2, no offer flag) applies onto a reservation-only or otherwise non-terminal row; the redemption event E1 (eventAt T1 < T2, offerRedeemed: true, or a granting status) arrives afterwards. decideLedgerApplication takes the incoming < watermark branch, recordsOfferRedemption returns false because current.status is incomplete rather than canceled/unpaid, and the row keeps offerRedeemed: false. Once the earlier reservation expires or is released, decideReservation (which refuses only on offerRedeemed, subscribed, or a live reservation) mints a fresh reservation, and the host lets the customer redeem the one-per-customer offer a second time — the exact revenue-leak failure mode this package exists to prevent. The equal-rank flavor loses the same way: a same-second, equal-rank evidence event arriving later is dropped without recording.
🔵 Issue 2 — README states offer-redemption monotonicity unconditionally; the implementation only guarantees it for terminal rows
packages/billing-core/README.md:74 · nit · identified by z-ai/glm-5.3-flash
packages/billing-core/README.md line 74 opens with "Offer redemption is monotonic across delivery order." as an unconditional property, but the very next sentences scope the mechanism to "a terminal row". For a non-terminal row (e.g. incomplete) a late event carrying offerRedeemed: true — or a stale granting event — is still dropped with no evidence recorded, so a host reading only the lead sentence will assume reserve() can never mint a reservation after redemption and will not defend against the duplicate-redemption scenario described in the code finding.
🔵 Issue 3 — Spec docs still state the superseded absolute keep/drop rules without the redemption-evidence exception
packages/billing-core/src/index.ts:957 · nit · identified by z-ai/glm-5.3-flash
The PR changes arbitration so that a rejected event can now cause a durable write, but three specification statements still describe the old absolute rule:
packages/billing-core/src/index.ts:956-960— thedecideLedgerApplicationsummary says "Equal rank at the equal second drops the later arrival" and "An existing row with no usable watermark that already carries subscription state is untrusted: keep, never apply because the event arrived", directly above the new paragraph describing an evidence write for exactly those cases.packages/billing-core/src/index.ts:34-35— theLifecycleStatusdoc repeats "Equal rank at the equal second drops the later arrival."docs/PROJECT_PLAN.md:64-71— "an event applies only if strictly newer thanmax(eventAt, snapshotAt)... Equal rank at the equal second drops the later arrival — conservative staleness until a strictly newer event arrives", untouched by this PR.
Cost: AGENTS.md designates the plan doc and these docblocks as the reference a fresh implementer reads; someone reimplementing or reviewing the decider from the summary sentences alone will omit the evidence write, or will be surprised that a "dropped" event returns applied: true with a generation bump.
|
Updated the lifecycle and ordering documentation in 796feb4. |
There was a problem hiding this comment.
OpenRouter pull-request review
Verdict: clean
Scope: latest-commit (commit-range)
Mode: verify
Commit: 796feb4e36891e353e8300e2aaae190724096bdc
Judge: openai/gpt-5.6-luna
Cost: $0.1498 (lanes $0.1496 + judge $0.0001)
Lanes
meta/muse-spark-1.2: ok (0 finding(s), 47.3s, 97352+2251 tokens (113 cached), 3 tool round(s), via Meta, $0.13)z-ai/glm-5.3-flash: ok (0 finding(s), 95.4s, 394836+12306 tokens (338816 cached), 17 tool round(s), via CoreWeave, $0.0185)
Round 2 resolution
- ✅
r1-1fixed correctly — Stale redemption evidence is still dropped on non-terminal rows, so a redeemed one-per-customer offer can be reserved twice: recordsOfferRedemption now only requires current.offerRedeemed===false && (event.offerRedeemed || isGrantingStatus) — the current.status === canceled/unpaid gate was removed, and keepOrRecordOfferRedemption preserves lifecycle watermark, provider/reservation/host fields while bumping snapshotGeneration. Verified in index.ts:923-947 and decideLedgerApplication:971-1005. New coverage confirms incomp… - 2 nit finding(s) from earlier rounds retired (severity floor for follow-up rounds is
risk). - Open findings after this round: 0 (0 bug-severity).
No structured findings from the successful lane(s).
Summary
Testing
CI=1 pnpm run format:checkon Node 22 and 24CI=1 pnpm run checkon Node 22 and 24CI=1 pnpm teston Node 22 and 24 — 172 tests passed with real Azurite