Skip to content

fix(subscription): tie-break view phase order by sort hint - #5201

Merged
GAlexIHU merged 1 commit into
mainfrom
claude/addon-phase-trial-error-4b3092
Sep 25, 2026
Merged

GAlexIHU merged 1 commit into
mainfrom
claude/addon-phase-trial-error-4b3092

Conversation

@GAlexIHU

@GAlexIHU GAlexIHU commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor
  • subs started via startingPhase keep earlier phases as zero-length, so they share ActiveFrom with the starting phase
  • NewSubscriptionView sorted phases only by ActiveFrom (stable) over a phase query with no ORDER BY -> order of same-start phases was whatever PG returned
  • addon create / change quantity walk sView.Phases in order to enforce fromPlanPhase; with fromPlanPhase=trial and sub started at default, default could come first -> bogus addon ... can be only added starting with phase trial, current phase is default
  • fix: tie-break by SortHint, then key, same as SubscriptionSpec.GetSortedPhases

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Subscription phases with the same start time now follow a consistent order, improving the reliability of phase displays.

RetriggerConfidence Score: 4/5

The PR appears safe to merge, though a targeted regression test would protect the new ordering behavior.

Fix All in Claude CodeFindings

  1. P2 Ordering lacks regression coverage ▶
Fix with agent prompt
### Issue 1
openmeter/subscription/subscriptionview.go:341-347
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.

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!

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

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 ..."

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]>
@GAlexIHU
GAlexIHU requested a review from a team as a code owner September 24, 2026 14:38
@GAlexIHU GAlexIHU added the release-note/bug-fix Release note: Bug Fixes label Sep 24, 2026
@coderabbitai

coderabbitai Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

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 configuration

Configuration used: Repository: openmeterio/openmeter/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 05ebf8bd-b8c3-4dcb-9a0e-89ec3687ad99

📥 Commits

Reviewing files that changed from the base of the PR and between 441a124 and 7f25f2b.

📒 Files selected for processing (1)
  • openmeter/subscription/subscriptionview.go

Included review availability: Your plan provides up to 8 included reviews per hour; 5 remain after this review.


📝 Walkthrough

Walkthrough

NewSubscriptionView now sorts phases by ActiveFrom, then by SortHint when both phases have one, and finally by Key.

Changes

Subscription phase ordering

Layer / File(s) Summary
Phase sorting
openmeter/subscription/subscriptionview.go
The phase comparator now applies ActiveFrom, SortHint when both phases have one, and Key as tie-breakers. The implementation adds cmp and strings imports.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: chrisgacsal

Merge Risk: ⚪ Minimal · up to 7f25f

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)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: fixing subscription view phase ordering by using SortHint as a tie-breaker.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Comment on lines +341 to +347
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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 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!

Fix in Claude Code Fix in Codex

@GAlexIHU
GAlexIHU enabled auto-merge (squash) September 24, 2026 14:46
@GAlexIHU
GAlexIHU disabled auto-merge September 25, 2026 13:40
@GAlexIHU
GAlexIHU merged commit 49638d2 into main Sep 25, 2026
29 of 31 checks passed
@GAlexIHU
GAlexIHU deleted the claude/addon-phase-trial-error-4b3092 branch September 25, 2026 13:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-note/bug-fix Release note: Bug Fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants