[GH-ISSUE #6106] [Feature]: Support calendar-based monthly Auto Renew for clients #4220

Closed
opened 2026-10-31 20:38:04 +07:00 by bsakaguchi · 2 comments
Owner

Originally created by @JacktheRanger on GitHub (Jul 26, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6106

Client Auto Renew currently accepts only a fixed interval in days. A value such as 30 creates a rolling 30-day cycle anchored to the client's expiry time, so it drifts relative to calendar-month billing cycles because months have 28, 29, 30, or 31 days.

Related to #6071 and #3462. #6071 adds a configurable day-of-month for inbound traffic resets, but it does not change the per-client Auto Renew schedule or advance client expiry dates on a calendar boundary.

Describe the solution you'd like

Add a calendar-based renewal mode to each client's Auto Renew setting while keeping the current interval-days mode for backward compatibility.

Suggested behavior:

  • Renewal mode: Interval (days) or Calendar monthly.
  • For Calendar monthly, configure a renewal day from 1 to 31 and use the panel's configured time zone.
  • On the renewal boundary, reset the client's traffic counters, advance its expiry to the next calendar renewal date, and re-enable it if it was disabled because of quota or expiry.
  • If the selected day does not exist in a shorter month, renew on that month's final day, consistent with #6071.
  • Prevent duplicate renewal within the same billing period.
  • If the panel was offline at the scheduled boundary, perform one catch-up renewal after startup.
  • Existing clients using the integer day interval must continue to behave exactly as they do today.

Alternatives you've considered

  • Setting Auto Renew to 30 days: the renewal date drifts across calendar months.
  • Using inbound Traffic Reset = Monthly: this resets traffic counters, but it does not provide calendar-based per-client expiry renewal.
  • Using an external cron job or API script: possible, but fragile and duplicates logic already owned by the panel.

Concrete use case

A server or provider plan resets its monthly allowance on the first day of each calendar month at 00:00 UTC. Clients are assigned monthly traffic quotas and should start a fresh quota/expiry window on that same boundary.

With Auto Renew set to 30 days, a client renewed on August 1 would renew on August 31, then September 30, and continue drifting away from the provider's billing cycle. A calendar-month mode with renewal day 1 and the panel time zone set to UTC would keep the client lifecycle aligned.

Mockups, screenshots, or examples

Example client form:

Auto Renew mode: [Interval (days) | Calendar monthly]
Renewal day:     [1]
Time zone:       Panel time zone (UTC)

This complements #6071: that PR schedules inbound traffic resets by day of month, while this request applies calendar scheduling to each client's Auto Renew lifecycle.

Which parts of the panel would this affect?

Frontend (UI / panel pages), Backend (API endpoints, login, settings), Statistics / traffic counters, Database / migrations, Multi-node (sub-nodes)

Are you willing to help?

  • I'd like to implement this feature myself and open a PR.
  • I can help test once a PR is open.

Before submitting

  • I searched existing issues and this feature has not been requested.
  • This feature request is written in English.
Originally created by @JacktheRanger on GitHub (Jul 26, 2026). Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6106 ### Is your feature request related to a problem? Client Auto Renew currently accepts only a fixed interval in days. A value such as 30 creates a rolling 30-day cycle anchored to the client's expiry time, so it drifts relative to calendar-month billing cycles because months have 28, 29, 30, or 31 days. Related to #6071 and #3462. #6071 adds a configurable day-of-month for inbound traffic resets, but it does not change the per-client Auto Renew schedule or advance client expiry dates on a calendar boundary. ### Describe the solution you'd like Add a calendar-based renewal mode to each client's Auto Renew setting while keeping the current interval-days mode for backward compatibility. Suggested behavior: - Renewal mode: `Interval (days)` or `Calendar monthly`. - For `Calendar monthly`, configure a renewal day from 1 to 31 and use the panel's configured time zone. - On the renewal boundary, reset the client's traffic counters, advance its expiry to the next calendar renewal date, and re-enable it if it was disabled because of quota or expiry. - If the selected day does not exist in a shorter month, renew on that month's final day, consistent with #6071. - Prevent duplicate renewal within the same billing period. - If the panel was offline at the scheduled boundary, perform one catch-up renewal after startup. - Existing clients using the integer day interval must continue to behave exactly as they do today. ### Alternatives you've considered - Setting Auto Renew to 30 days: the renewal date drifts across calendar months. - Using inbound `Traffic Reset = Monthly`: this resets traffic counters, but it does not provide calendar-based per-client expiry renewal. - Using an external cron job or API script: possible, but fragile and duplicates logic already owned by the panel. ### Concrete use case A server or provider plan resets its monthly allowance on the first day of each calendar month at 00:00 UTC. Clients are assigned monthly traffic quotas and should start a fresh quota/expiry window on that same boundary. With Auto Renew set to 30 days, a client renewed on August 1 would renew on August 31, then September 30, and continue drifting away from the provider's billing cycle. A calendar-month mode with renewal day 1 and the panel time zone set to UTC would keep the client lifecycle aligned. ### Mockups, screenshots, or examples Example client form: ``` Auto Renew mode: [Interval (days) | Calendar monthly] Renewal day: [1] Time zone: Panel time zone (UTC) ``` This complements #6071: that PR schedules inbound traffic resets by day of month, while this request applies calendar scheduling to each client's Auto Renew lifecycle. ### Which parts of the panel would this affect? Frontend (UI / panel pages), Backend (API endpoints, login, settings), Statistics / traffic counters, Database / migrations, Multi-node (sub-nodes) ### Are you willing to help? - [ ] I'd like to implement this feature myself and open a PR. - [x] I can help test once a PR is open. ### Before submitting - [x] I searched [existing issues](../issues?q=is%3Aissue) and this feature has not been requested. - [x] This feature request is written in English.
bsakaguchi 2026-10-31 20:38:04 +07:00
Author
Owner

@github-actions[bot] commented on GitHub (Jul 26, 2026):

Confirmed against the source: client Auto Renew is purely interval-based today, and there is no calendar-month mode.

What the code does now:

  • The per-client field is reset, an integer number of days (internal/database/model/model.go:821, UI label Auto Renew (days) in internal/web/translation/en-US.json:776).
  • Renewal happens in autoRenewClients (internal/web/service/inbound_traffic.go:290), called from AddTraffic (line 56), which runs on the @every 5s traffic poll (cadenceXrayTraffic, internal/web/web.go:289).
  • The advance is a fixed-millisecond step, which is exactly the drift you describe:
newExpiryTime := traffic.ExpiryTime
for newExpiryTime < now {
    newExpiryTime += (int64(traffic.Reset) * 86400000)
}

internal/web/service/inbound_traffic.go:377-380. 86400000 ms is one fixed day, so nothing in this path is calendar-aware.

Two of the behaviors on your list already exist in interval mode and would carry over to a calendar mode:

  • Catch-up after downtime: the loop starts from the previous expiry and adds whole periods until it is in the future, so a panel that was offline performs one renewal on the next poll, anchored to the old expiry rather than to the moment the panel came back.
  • No duplicate renewal in a period: the selection query is reset > 0 and expiry_time > 0 and expiry_time <= ? (line 302), and the loop leaves expiry in the future, so the row is not picked up again.

A panel time zone also already exists and is honored by the scheduler: the timeLocation setting (default Local, internal/web/service/setting.go:69, read by GetTimeLocation at line 699) is passed to the cron scheduler as cron.WithLocation(loc) (internal/web/web.go:494-495). Setting it to UTC in panel settings is what your example would need.

Your assessment of the alternatives is accurate. Inbound Traffic Reset = monthly is registered as @monthly (internal/web/web.go:353) and ResetAllClientTraffics sets enable = true, up = 0, down = 0 (internal/web/service/client_traffic.go:166-168) but never writes expiry_time, so a client that is past its expiry is disabled again on the next poll by disableInvalidClients (depleted clause at internal/web/service/inbound_traffic.go:757). That is a counter reset, not a lifecycle renewal.

Two scope points worth recording for whoever picks this up:

  1. Multi-node. autoRenewClients deliberately renews only clients with at least one local inbound (i.node_id IS NULL, line 307); node-hosted clients renew on the node's own panel and are merged back through nodeClientRenewed (internal/web/service/inbound_node.go:804). Any new mode/day fields would have to travel in the node sync payload, or master and node would compute different boundaries.
  2. Schema. reset is a single integer column, so a mode plus a day-of-month needs a migration in internal/database/db.go, regenerated API schemas, and the new i18n keys added to all 13 files in internal/web/translation/.

This is not a duplicate of #3462 or PR #6071 — both target counter resets on a day of month, while this targets per-client expiry advancement — so it stays open as a separate request. #5804 touches the same reset field and may be worth designing alongside it. Labeled as a new feature; scheduling is the maintainer's call, and I cannot commit to whether or when it will be implemented.

This reply was generated automatically. A maintainer may follow up.

<!-- gh-comment-id:5082078790 --> @github-actions[bot] commented on GitHub (Jul 26, 2026): Confirmed against the source: client Auto Renew is purely interval-based today, and there is no calendar-month mode. What the code does now: - The per-client field is `reset`, an integer number of days (`internal/database/model/model.go:821`, UI label `Auto Renew (days)` in `internal/web/translation/en-US.json:776`). - Renewal happens in `autoRenewClients` (`internal/web/service/inbound_traffic.go:290`), called from `AddTraffic` (line 56), which runs on the `@every 5s` traffic poll (`cadenceXrayTraffic`, `internal/web/web.go:289`). - The advance is a fixed-millisecond step, which is exactly the drift you describe: ```go newExpiryTime := traffic.ExpiryTime for newExpiryTime < now { newExpiryTime += (int64(traffic.Reset) * 86400000) } ``` `internal/web/service/inbound_traffic.go:377-380`. 86400000 ms is one fixed day, so nothing in this path is calendar-aware. Two of the behaviors on your list already exist in interval mode and would carry over to a calendar mode: - Catch-up after downtime: the loop starts from the previous expiry and adds whole periods until it is in the future, so a panel that was offline performs one renewal on the next poll, anchored to the old expiry rather than to the moment the panel came back. - No duplicate renewal in a period: the selection query is `reset > 0 and expiry_time > 0 and expiry_time <= ?` (line 302), and the loop leaves expiry in the future, so the row is not picked up again. A panel time zone also already exists and is honored by the scheduler: the `timeLocation` setting (default `Local`, `internal/web/service/setting.go:69`, read by `GetTimeLocation` at line 699) is passed to the cron scheduler as `cron.WithLocation(loc)` (`internal/web/web.go:494-495`). Setting it to `UTC` in panel settings is what your example would need. Your assessment of the alternatives is accurate. Inbound `Traffic Reset = monthly` is registered as `@monthly` (`internal/web/web.go:353`) and `ResetAllClientTraffics` sets `enable = true, up = 0, down = 0` (`internal/web/service/client_traffic.go:166-168`) but never writes `expiry_time`, so a client that is past its expiry is disabled again on the next poll by `disableInvalidClients` (depleted clause at `internal/web/service/inbound_traffic.go:757`). That is a counter reset, not a lifecycle renewal. Two scope points worth recording for whoever picks this up: 1. Multi-node. `autoRenewClients` deliberately renews only clients with at least one local inbound (`i.node_id IS NULL`, line 307); node-hosted clients renew on the node's own panel and are merged back through `nodeClientRenewed` (`internal/web/service/inbound_node.go:804`). Any new mode/day fields would have to travel in the node sync payload, or master and node would compute different boundaries. 2. Schema. `reset` is a single integer column, so a mode plus a day-of-month needs a migration in `internal/database/db.go`, regenerated API schemas, and the new i18n keys added to all 13 files in `internal/web/translation/`. This is not a duplicate of #3462 or PR #6071 — both target counter resets on a day of month, while this targets per-client expiry advancement — so it stays open as a separate request. #5804 touches the same `reset` field and may be worth designing alongside it. Labeled as a new feature; scheduling is the maintainer's call, and I cannot commit to whether or when it will be implemented. *This reply was generated automatically. A maintainer may follow up.*
Author
Owner

@babaproyqgmuroe-arch commented on GitHub (Aug 15, 2026):

Auto Renew mode: [Interval (days) | Calendar monthly]
Renewal day: [1]
Time zone: Panel time zone (UTC)

<!-- gh-comment-id:5302499938 --> @babaproyqgmuroe-arch commented on GitHub (Aug 15, 2026): Auto Renew mode: [Interval (days) | Calendar monthly] Renewal day: [1] Time zone: Panel time zone (UTC)
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#4220
No description provided.