Skip to content

[PM-39816] fix: Raise migrated Password Manager seats to cover Secrets Manager seats - #7904

Merged
amorask-bitwarden merged 3 commits into
mainfrom
billing/PM-39816/teams-starter-sm-seats
Jul 1, 2026
Merged

amorask-bitwarden merged 3 commits into
mainfrom
billing/PM-39816/teams-starter-sm-seats

Conversation

@amorask-bitwarden

@amorask-bitwarden amorask-bitwarden commented Jun 30, 2026 •

Copy link
Copy Markdown
Contributor

🎟️ Tracking

PM-39816 — QA bug under parent PM-37512 (Support migration of Teams Starter), epic PM-37496.

📔 Objective

The Teams Starter → current Teams migration recomputed the Password Manager (PM) seat count from occupied members (floored at 1) while passing the Secrets Manager (SM) seat count through untouched. When an org held more SM seats than occupied PM members, the migration produced SM seats > PM seats, violating the current Teams invariant that SM ≤ PM.

This raises the billed/persisted PM seat count to cover SM at the three migration seat-count sites, so the migration completes (never aborts) with PM ≥ SM:

  • Stage 1 — Phase-2 Stripe schedule (PriceIncreaseScheduler)
  • Stage 2 — cycle-time DB reconcile (SubscriptionUpdatedHandler)
  • Stage 3 — renewal-email quote (UpcomingInvoiceHandler)

The SM source is bound per domain: the Stripe-facing sites (Stage 1, renewal email) floor PM on the surviving Stripe SM seat line quantity (the exact billed value); the DB reconcile floors Organization.Seats on Organization.SmSeats. The two agree in normal operation; binding each site to its own domain keeps both the Stripe and DB invariants correct under DB↔Stripe drift, and a drift warning in Stage 1 surfaces any divergence.

The clamp lives on the shared packaged-source path, so it also covers the Teams 2019 → current migration (same target plan, same latent reconcile bug). Tests lock in both Teams Starter PlanTypes (21, 16) and Teams 2019.

Server-only, webhook-driven, gated by the existing PM35215_BusinessPlanPriceMigration flag — purely additive (orgs without SM seats are unaffected). Preventive: a data-warehouse check found 0 production orgs currently in the SM > PM state.

Tests: unit coverage proving PM ≥ SM after migration at all three sites for both Teams Starter PlanTypes and Teams 2019, plus the SM-with-zero-occupied edge and the DB-below-Stripe-line drift case.

…s Manager seats

The Teams Starter migration recomputed Password Manager seats from occupied
members while passing Secrets Manager seats through untouched, so an org with
more SM seats than occupied members migrated into SM > PM, violating the
current Teams invariant SM <= PM. Floor the billed/persisted PM seat count on
the SM seats at the three migration seat-count sites so the migration completes
with PM >= SM.

The clamp gates on the shared packaged-source path, so it also covers the
Teams 2019 -> current migration, which lands on the same target and hits the
same invariant via the same latent reconcile bug. Tests lock in the behavior
for both Teams Starter PlanTypes (21, 16) and Teams 2019.

Stripe-facing sites (Phase-2 schedule, renewal email) floor on the surviving
Stripe SM seat line quantity (the exact billed value); the cycle-time DB
reconcile floors Organization.Seats on Organization.SmSeats. A drift warning in
the scheduler surfaces any DB<->Stripe SM divergence. Gated by the existing
PM35215_BusinessPlanPriceMigration flag.
@amorask-bitwarden amorask-bitwarden added ai-review Request a Claude code review t:bugfix Change Type - Bugfix labels Jun 30, 2026
@github-actions

github-actions Bot commented Jun 30, 2026 •

Copy link
Copy Markdown
Contributor

🤖 Bitwarden Claude Code Review

Overall Assessment: APPROVE

Reviewed the Teams Starter / Teams 2019 → current Teams migration bugfix that raises the migrated Password Manager seat count to cover Secrets Manager seats (enforcing the SM ≤ PM invariant) at all three migration sites: the Phase-2 Stripe schedule (PriceIncreaseScheduler), the cycle-time DB reconcile (SubscriptionUpdatedHandler), and the renewal-email quote (UpcomingInvoiceHandler). The SM seat line is correctly matched on SecretsManager.StripeSeatPlanId, which is distinct from the service-account plan id, so the collapse targets the right line. The Math.Max floor is idempotent and never lowers SmSeats, and the change is purely additive behind the existing PM35215_BusinessPlanPriceMigration flag. Unit coverage exercises both Teams Starter PlanTypes and Teams 2019, plus the zero-occupied and DB↔Stripe drift edge cases.

Code Review Details

No findings. The three seat-count sites bind SM to the correct domain source (Stripe line for the billing-facing sites, Organization.SmSeats for the DB reconcile), the drift warning logs only org id and seat counts (no sensitive data), and the renamed CalculatePasswordManagerSeatCountAsync has no orphaned references.

@codecov

codecov Bot commented Jun 30, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 76.19048% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 61.28%. Comparing base (425293d) to head (cc9e149).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/Core/Billing/Pricing/PriceIncreaseScheduler.cs 71.42% 0 Missing and 4 partials ⚠️
...Services/Implementations/UpcomingInvoiceHandler.cs 83.33% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #7904   +/-   ##
=======================================
  Coverage   61.28%   61.28%           
=======================================
  Files        2226     2226           
  Lines       98296    98313   +17     
  Branches     8884     8889    +5     
=======================================
+ Hits        60241    60255   +14     
+ Misses      35935    35934    -1     
- Partials     2120     2124    +4     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@amorask-bitwarden
amorask-bitwarden marked this pull request as ready for review July 1, 2026 13:16
@amorask-bitwarden
amorask-bitwarden requested a review from a team as a code owner July 1, 2026 13:16
@sonarqubecloud

sonarqubecloud Bot commented Jul 1, 2026

Copy link
Copy Markdown

@amorask-bitwarden
amorask-bitwarden merged commit dd5c725 into main Jul 1, 2026
46 checks passed
@amorask-bitwarden
amorask-bitwarden deleted the billing/PM-39816/teams-starter-sm-seats branch July 1, 2026 18:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-review Request a Claude code review t:bugfix Change Type - Bugfix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants