Repository navigation
fix(subscription): tie-break view phase order by sort hint - #5201
Conversation
Phases skipped via startingPhase are zero length and share ActiveFrom with the next phase. The view sorted only by ActiveFrom on top of an unordered DB query, so their order was nondeterministic, which could reject addons whose fromPlanPhase is the skipped phase. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository: openmeterio/openmeter/.coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (1)
Included review availability: Your plan provides up to 8 included reviews per hour; 5 remain after this review. 📝 WalkthroughWalkthrough
ChangesSubscription phase ordering
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: Merge Risk: ⚪ Minimal · up to Equal-start subscription phases now have deterministic ordering consistent with their specifications. No actionable merge risk remains beyond normal checks. 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
| if i.SortHint != nil && j.SortHint != nil { | ||
| if diff := cmp.Compare(*i.SortHint, *j.SortHint); diff != 0 { | ||
| return diff | ||
| } | ||
| } | ||
|
|
||
| return strings.Compare(i.Key, j.Key) |
There was a problem hiding this comment.
Ordering lacks regression coverage The existing test for phases with the same start time uses
test_phase_1, test_phase_2, and so on. Those keys sort in the same order as their SortHints, so the test would pass even if this comparator fell back to key order. A test with keys in a different order would protect the phase ordering that addon eligibility checks rely on.
Prompt To Fix With AI
This is a comment left during a code review.
Path: openmeter/subscription/subscriptionview.go
Line: 341-347
Comment:
**Ordering lacks regression coverage** The existing test for phases with the same start time uses `test_phase_1`, `test_phase_2`, and so on. Those keys sort in the same order as their SortHints, so the test would pass even if this comparator fell back to key order. A test with keys in a different order would protect the phase ordering that addon eligibility checks rely on.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
startingPhasekeep earlier phases as zero-length, so they shareActiveFromwith the starting phaseNewSubscriptionViewsorted phases only byActiveFrom(stable) over a phase query with noORDER BY-> order of same-start phases was whatever PG returnedsView.Phasesin order to enforcefromPlanPhase; withfromPlanPhase=trialand sub started atdefault,defaultcould come first -> bogusaddon ... can be only added starting with phase trial, current phase is defaultSortHint, then key, same asSubscriptionSpec.GetSortedPhases🤖 Generated with Claude Code
Summary by CodeRabbit
The PR appears safe to merge, though a targeted regression test would protect the new ordering behavior.
Fix with agent prompt
Summary
The PR makes subscription views order phases with equal start times by SortHint, then key, rather than relying on database order. This aligns the view with spec ordering for phases made zero-length by
startingPhase.Reviews (1) · Last reviewed commit: "fix(subscription): tie-break view phase ..."