[PR #6239] [MERGED] feat(clients): renew on a calendar day instead of a rolling interval #6194

Closed
opened 2026-11-02 04:07:01 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/6239
Author: @n0ctal
Created: 8/17/2026
Status: ✅ Merged
Merged: 8/18/2026
Merged by: @MHSanaei

Base: main ← Head: upstream-calendar-auto-renew


📝 Commits (5)

  • bfa7168 feat(clients): renew on a calendar day instead of a rolling interval
  • 0fa46b8 fix(clients): persist the calendar renewal day on the client record
  • 9de6efc fix(clients): let the billing day be changed after creation
  • 5b6f244 chore: drop the accidentally committed dist build stub
  • 45b1431 Merge branch 'main' into pr/6239

📊 Changes

34 files changed (+730 additions, -10 deletions)

View changed files

📝 frontend/public/openapi.json (+17 -0)
📝 frontend/src/generated/examples.ts (+4 -0)
📝 frontend/src/generated/schemas.ts (+15 -0)
📝 frontend/src/generated/types.ts (+3 -0)
📝 frontend/src/generated/zod.ts (+3 -0)
📝 frontend/src/lib/remark/remarkVariables.ts (+1 -0)
📝 frontend/src/pages/clients/ClientBulkAddModal.tsx (+11 -0)
📝 frontend/src/pages/clients/ClientFormModal.tsx (+14 -0)
📝 frontend/src/schemas/client.ts (+3 -0)
📝 internal/database/model/model.go (+10 -0)
📝 internal/sub/remark_vars.go (+5 -0)
➖ internal/web/dist/.gitkeep (+0 -0)
➕ internal/web/service/calendar_renew.go (+42 -0)
➕ internal/web/service/calendar_renew_test.go (+116 -0)
📝 internal/web/service/client_crud.go (+16 -0)
📝 internal/web/service/client_link.go (+1 -0)
📝 internal/web/service/client_paging.go (+4 -2)
➕ internal/web/service/inbound_autorenew_calendar_test.go (+391 -0)
📝 internal/web/service/inbound_node.go (+6 -5)
📝 internal/web/service/inbound_traffic.go (+26 -3)

...and 14 more files

📄 Description

Closes #6106.

Summary

Auto-renew advances the expiry by a fixed number of milliseconds. A client set to 30 days drifts against the calendar: renewing on 31 January lands on 2 March, and after a year the billing day has wandered a fortnight from wherever the operator's own plan resets.

This adds a per-client renewal day. When set, the expiry steps whole calendar months at midnight in the panel's configured time zone.

The two cases worth naming

Short months. A client billed on the 31st renews on 28 February and returns to 31 March. It does not decay to the 28th permanently, which is what "advance by one month" does if you implement it as "add 30 days" or let time.Date roll 31 February forward into March.

Daylight saving. Because the step is a calendar operation in the panel's zone rather than an addition of hours, a renewal that crosses a DST boundary still lands on local midnight instead of drifting an hour twice a year.

Behaviour

  • resetDay per client, 0–31; 0 keeps today's interval mode, so existing clients are untouched.
  • Selection accepts either mode; the advance loop picks the calendar step when a day is set.
  • Catch-up works as before: a client several months behind steps month by month until its expiry is in the future, landing on the billing day rather than on "today plus a month".
  • The panel's time zone is read once per run, falling back to UTC with a warning if the setting cannot be read — renewals continuing is better than renewals stopping because of a settings read.

One defensive change

The interval branch now refuses a zero step. It is unreachable while the selection filter holds, and I kept it anyway: that loop is for expiry < now { expiry += reset*24h }, it runs on the single traffic writer, and a zero interval reaching it would hang every panel mutation queued behind it. I found this while mutation-testing — removing the calendar branch turned the suite from failing into hanging, which is a considerably worse way to learn about it.

Validation

Date arithmetic is covered directly: clamping in February (leap and common), returning to the 31st afterwards, 30-day months, December rolling into January, same-month vs next-month boundaries, the panel zone being honoured, and a DST crossing still landing on local midnight.

End to end through autoRenewClients: a calendar client lands on its billing day with counters reset and re-enabled; a client billed on the 31st gets the clamped day; an interval client still moves by exactly the old fixed step.

Mutation-checked: disabling the calendar branch turns the calendar test red; removing the short-month clamp turns the clamping tests red.

go build ./..., go vet, golangci-lint, make gen-check clean; 36 Go packages green; frontend typecheck, eslint and the unit suite green.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/MHSanaei/3x-ui/pull/6239 **Author:** [@n0ctal](https://github.com/n0ctal) **Created:** 8/17/2026 **Status:** ✅ Merged **Merged:** 8/18/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `upstream-calendar-auto-renew` --- ### 📝 Commits (5) - [`bfa7168`](https://github.com/MHSanaei/3x-ui/commit/bfa7168271ff751b3877adc4b84b6b91821fa655) feat(clients): renew on a calendar day instead of a rolling interval - [`0fa46b8`](https://github.com/MHSanaei/3x-ui/commit/0fa46b8a6fd340aa4c08e3799607942f2668f622) fix(clients): persist the calendar renewal day on the client record - [`9de6efc`](https://github.com/MHSanaei/3x-ui/commit/9de6efc19c6ededecb2d209ffcedf98e67fde663) fix(clients): let the billing day be changed after creation - [`5b6f244`](https://github.com/MHSanaei/3x-ui/commit/5b6f24460d292f6274268ed40f0dc94247af9f95) chore: drop the accidentally committed dist build stub - [`45b1431`](https://github.com/MHSanaei/3x-ui/commit/45b143176e280ddc7f2e86cce3465fd5db9c76b7) Merge branch 'main' into pr/6239 ### 📊 Changes **34 files changed** (+730 additions, -10 deletions) <details> <summary>View changed files</summary> 📝 `frontend/public/openapi.json` (+17 -0) 📝 `frontend/src/generated/examples.ts` (+4 -0) 📝 `frontend/src/generated/schemas.ts` (+15 -0) 📝 `frontend/src/generated/types.ts` (+3 -0) 📝 `frontend/src/generated/zod.ts` (+3 -0) 📝 `frontend/src/lib/remark/remarkVariables.ts` (+1 -0) 📝 `frontend/src/pages/clients/ClientBulkAddModal.tsx` (+11 -0) 📝 `frontend/src/pages/clients/ClientFormModal.tsx` (+14 -0) 📝 `frontend/src/schemas/client.ts` (+3 -0) 📝 `internal/database/model/model.go` (+10 -0) 📝 `internal/sub/remark_vars.go` (+5 -0) ➖ `internal/web/dist/.gitkeep` (+0 -0) ➕ `internal/web/service/calendar_renew.go` (+42 -0) ➕ `internal/web/service/calendar_renew_test.go` (+116 -0) 📝 `internal/web/service/client_crud.go` (+16 -0) 📝 `internal/web/service/client_link.go` (+1 -0) 📝 `internal/web/service/client_paging.go` (+4 -2) ➕ `internal/web/service/inbound_autorenew_calendar_test.go` (+391 -0) 📝 `internal/web/service/inbound_node.go` (+6 -5) 📝 `internal/web/service/inbound_traffic.go` (+26 -3) _...and 14 more files_ </details> ### 📄 Description Closes #6106. ## Summary Auto-renew advances the expiry by a fixed number of milliseconds. A client set to 30 days drifts against the calendar: renewing on 31 January lands on 2 March, and after a year the billing day has wandered a fortnight from wherever the operator's own plan resets. This adds a per-client renewal day. When set, the expiry steps whole calendar months at midnight in the panel's configured time zone. ## The two cases worth naming **Short months.** A client billed on the 31st renews on 28 February and returns to 31 March. It does not decay to the 28th permanently, which is what "advance by one month" does if you implement it as "add 30 days" or let `time.Date` roll 31 February forward into March. **Daylight saving.** Because the step is a calendar operation in the panel's zone rather than an addition of hours, a renewal that crosses a DST boundary still lands on local midnight instead of drifting an hour twice a year. ## Behaviour - `resetDay` per client, 0–31; 0 keeps today's interval mode, so existing clients are untouched. - Selection accepts either mode; the advance loop picks the calendar step when a day is set. - Catch-up works as before: a client several months behind steps month by month until its expiry is in the future, landing on the billing day rather than on "today plus a month". - The panel's time zone is read once per run, falling back to UTC with a warning if the setting cannot be read — renewals continuing is better than renewals stopping because of a settings read. ## One defensive change The interval branch now refuses a zero step. It is unreachable while the selection filter holds, and I kept it anyway: that loop is `for expiry < now { expiry += reset*24h }`, it runs on the single traffic writer, and a zero interval reaching it would hang every panel mutation queued behind it. I found this while mutation-testing — removing the calendar branch turned the suite from failing into hanging, which is a considerably worse way to learn about it. ## Validation Date arithmetic is covered directly: clamping in February (leap and common), returning to the 31st afterwards, 30-day months, December rolling into January, same-month vs next-month boundaries, the panel zone being honoured, and a DST crossing still landing on local midnight. End to end through `autoRenewClients`: a calendar client lands on its billing day with counters reset and re-enabled; a client billed on the 31st gets the clamped day; an interval client still moves by exactly the old fixed step. Mutation-checked: disabling the calendar branch turns the calendar test red; removing the short-month clamp turns the clamping tests red. `go build ./...`, `go vet`, `golangci-lint`, `make gen-check` clean; 36 Go packages green; frontend typecheck, eslint and the unit suite green. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:07:01 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MHSanaei/3x-ui#6194
No description provided.