[GH-ISSUE #5804] [Feature]: Add a maximum renewal count for client Auto Renew #4033

Closed
opened 2026-10-31 20:36:41 +07:00 by bsakaguchi · 1 comment
Owner

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

I manage some clients with fixed-term or prepaid plans.

Image

Currently, the client field "Auto Renew (days)" is useful, but once it is enabled, the client keeps renewing indefinitely after expiration. This works for unlimited recurring plans, but it does not fit fixed packages.

For example:

  • Initial client duration: 30 days
  • Auto Renew (days): 30
  • Maximum renewal count: 3

The expected total service period should be:

30 initial days + 3 renewals × 30 days = 120 days total, approximately 4 months.

At the moment, 3X-UI can auto-renew the client repeatedly, but there is no built-in way to stop auto-renewal after a fixed number of renewal cycles.

Describe the solution you'd like

Please add an optional "Max Auto Renew Count" field for each client, next to the existing "Auto Renew (days)" field.

Image

Suggested behavior:

  • Auto Renew (days) = 0:

    • Auto Renew remains disabled, same as the current behavior.
  • Auto Renew (days) > 0 and Max Auto Renew Count is empty or 0:

    • Keep the current behavior: unlimited auto-renewal.
    • This preserves backward compatibility.
  • Auto Renew (days) > 0 and Max Auto Renew Count > 0:

    • The client can only be auto-renewed this many times.
    • Each successful auto-renewal should increase a stored "renewals used" counter.
    • After the maximum count is reached, the client should no longer be auto-renewed on the next expiration.

Example:

  • Initial expiry: day 30
  • Auto Renew (days): 30
  • Max Auto Renew Count: 3

Expected timeline:

  1. Day 30: first auto-renewal, new expiry becomes day 60, renewals used = 1/3
  2. Day 60: second auto-renewal, new expiry becomes day 90, renewals used = 2/3
  3. Day 90: third auto-renewal, new expiry becomes day 120, renewals used = 3/3
  4. Day 120: no more auto-renewal; the client expires normally

The existing auto-renew behavior should remain the same during each allowed renewal:

  • Extend the expiry time by the configured Auto Renew days
  • Reset the traffic counters for the new quota window
  • Re-enable the client if the current auto-renew logic already does that

The new setting should only limit how many times this process can happen.

Suggested UI:

  • Auto Renew (days): [30]
  • Max Auto Renew Count: [3]
  • Renewals Used: 0/3

Suggested backend/API changes:

  • Store the maximum renewal count per client.
  • Store the number of renewals already used per client.
  • Update the auto-renew logic to check the remaining renewal count before renewing.
  • If the panel catches up multiple missed periods, each added renewal period should consume one renewal count.
  • Expose these fields through the client API so they can be shown and edited in the panel.

Alternatives you've considered

I considered manually disabling Auto Renew after several cycles, or setting a final expiry date manually. However, this is error-prone when managing many clients.

External scripts are also possible, but they duplicate logic that already exists in 3X-UI. Since the current Auto Renew logic already handles expiry extension and traffic reset, adding a renewal limit inside the panel would be more reliable and easier to maintain.

Concrete use case

A client buys a fixed 4-month package with monthly quota reset.

Configuration:

  • Initial duration: 30 days
  • Auto Renew (days): 30
  • Max Auto Renew Count: 3

Expected result:

  • The client gets the initial 30 days.
  • Then the client is auto-renewed 3 times.
  • Traffic is reset at each renewal, as Auto Renew currently does.
  • The total active period is 120 days, approximately 4 months.
  • After the third renewal has been used, the client should expire normally at the next expiry time instead of being renewed forever.

Mockups, screenshots, or examples

No response

Which parts of the panel would this affect?

Frontend (UI / panel pages), Backend (API endpoints, login, settings), Statistics / traffic counters, Database / migrations

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 @jeef111111 on GitHub (Jul 5, 2026). Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5804 ### Is your feature request related to a problem? I manage some clients with fixed-term or prepaid plans. <img width="58" height="29" alt="Image" src="https://github.com/user-attachments/assets/51e0cb8f-366e-4f9c-8b26-9396131e69e9" /> Currently, the client field "Auto Renew (days)" is useful, but once it is enabled, the client keeps renewing indefinitely after expiration. This works for unlimited recurring plans, but it does not fit fixed packages. For example: - Initial client duration: 30 days - Auto Renew (days): 30 - Maximum renewal count: 3 The expected total service period should be: 30 initial days + 3 renewals × 30 days = 120 days total, approximately 4 months. At the moment, 3X-UI can auto-renew the client repeatedly, but there is no built-in way to stop auto-renewal after a fixed number of renewal cycles. ### Describe the solution you'd like Please add an optional "Max Auto Renew Count" field for each client, next to the existing "Auto Renew (days)" field. <img width="58" height="29" alt="Image" src="https://github.com/user-attachments/assets/25a4ed83-5415-4f4b-955d-c4dc8b960d90" /> Suggested behavior: - Auto Renew (days) = 0: - Auto Renew remains disabled, same as the current behavior. - Auto Renew (days) > 0 and Max Auto Renew Count is empty or 0: - Keep the current behavior: unlimited auto-renewal. - This preserves backward compatibility. - Auto Renew (days) > 0 and Max Auto Renew Count > 0: - The client can only be auto-renewed this many times. - Each successful auto-renewal should increase a stored "renewals used" counter. - After the maximum count is reached, the client should no longer be auto-renewed on the next expiration. Example: - Initial expiry: day 30 - Auto Renew (days): 30 - Max Auto Renew Count: 3 Expected timeline: 1. Day 30: first auto-renewal, new expiry becomes day 60, renewals used = 1/3 2. Day 60: second auto-renewal, new expiry becomes day 90, renewals used = 2/3 3. Day 90: third auto-renewal, new expiry becomes day 120, renewals used = 3/3 4. Day 120: no more auto-renewal; the client expires normally The existing auto-renew behavior should remain the same during each allowed renewal: - Extend the expiry time by the configured Auto Renew days - Reset the traffic counters for the new quota window - Re-enable the client if the current auto-renew logic already does that The new setting should only limit how many times this process can happen. Suggested UI: - Auto Renew (days): [30] - Max Auto Renew Count: [3] - Renewals Used: 0/3 Suggested backend/API changes: - Store the maximum renewal count per client. - Store the number of renewals already used per client. - Update the auto-renew logic to check the remaining renewal count before renewing. - If the panel catches up multiple missed periods, each added renewal period should consume one renewal count. - Expose these fields through the client API so they can be shown and edited in the panel. ### Alternatives you've considered I considered manually disabling Auto Renew after several cycles, or setting a final expiry date manually. However, this is error-prone when managing many clients. External scripts are also possible, but they duplicate logic that already exists in 3X-UI. Since the current Auto Renew logic already handles expiry extension and traffic reset, adding a renewal limit inside the panel would be more reliable and easier to maintain. ### Concrete use case A client buys a fixed 4-month package with monthly quota reset. Configuration: - Initial duration: 30 days - Auto Renew (days): 30 - Max Auto Renew Count: 3 Expected result: - The client gets the initial 30 days. - Then the client is auto-renewed 3 times. - Traffic is reset at each renewal, as Auto Renew currently does. - The total active period is 120 days, approximately 4 months. - After the third renewal has been used, the client should expire normally at the next expiry time instead of being renewed forever. ### Mockups, screenshots, or examples _No response_ ### Which parts of the panel would this affect? Frontend (UI / panel pages), Backend (API endpoints, login, settings), Statistics / traffic counters, Database / migrations ### 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 - [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:36:41 +07:00
Author
Owner

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

Confirmed: this feature does not exist today. There is no renewal-count tracking anywhere in the codebase.

What "Auto Renew (days)" actually does, confirmed in source:

  • The field is Client.Reset (an int, in days) — internal/database/model/model.go:615. The UI label "Auto Renew (days)" and its description "(0 = disable)" are in internal/web/translation/en-US.json:769-770.
  • The renewal itself runs in autoRenewClients in internal/web/service/inbound_traffic.go:284-442, invoked from addTrafficLocked on every traffic-report cycle. It selects client_traffics rows where reset > 0 and expiry_time > 0 and expiry_time <= now, then for each one:
    newExpiryTime := traffic.ExpiryTime
    for newExpiryTime < now {
        newExpiryTime += (int64(traffic.Reset) * 86400000)
    }
    
    (internal/web/service/inbound_traffic.go:371-374) — this is also the "catch-up" behavior you referenced: if the panel was offline across multiple periods, it keeps adding one Reset period at a time until the expiry is back in the future, then resets Up/Down to 0 and re-enables the client if it was disabled.
  • There is genuinely no persisted "renewals used" or "max renewal count" anywhere: not in model.Client, not in model.ClientRecord (the DB-backed client row, internal/database/model/model.go:620-645), not in xray.ClientTraffic, and no such column in any migration in internal/database/db.go. So today Reset > 0 is unconditionally indefinite, exactly as described in the issue.

I searched open/closed issues for prior requests along these lines and did not find an existing duplicate, so this is being tracked as a new request.

Implementing it as described would touch, at minimum:

  • model.Client / model.ClientRecord (new columns, e.g. renewal count fields, plus a migration in internal/database/db.go),
  • autoRenewClients in internal/web/service/inbound_traffic.go (decrement/check remaining count, including making the catch-up loop consume one count per period as requested),
  • the client edit form in frontend/src/pages/clients/ and the corresponding Zod schema/generated types,
  • the client REST API request/response structs and frontend/src/pages/api-docs/endpoints.ts,
  • new i18n keys across all 13 locale files in internal/web/translation/.

This is a reasonable, backward-compatible feature request (0/empty preserves current unlimited behavior), but it requires new implementation work across the backend, DB schema, and frontend — it is not something already available today.

This reply was generated automatically; a maintainer may follow up.

<!-- gh-comment-id:4884742519 --> @github-actions[bot] commented on GitHub (Jul 5, 2026): Confirmed: this feature does not exist today. There is no renewal-count tracking anywhere in the codebase. What "Auto Renew (days)" actually does, confirmed in source: - The field is `Client.Reset` (an int, in days) — `internal/database/model/model.go:615`. The UI label "Auto Renew (days)" and its description "(0 = disable)" are in `internal/web/translation/en-US.json:769-770`. - The renewal itself runs in `autoRenewClients` in `internal/web/service/inbound_traffic.go:284-442`, invoked from `addTrafficLocked` on every traffic-report cycle. It selects `client_traffics` rows where `reset > 0 and expiry_time > 0 and expiry_time <= now`, then for each one: ```go newExpiryTime := traffic.ExpiryTime for newExpiryTime < now { newExpiryTime += (int64(traffic.Reset) * 86400000) } ``` (`internal/web/service/inbound_traffic.go:371-374`) — this is also the "catch-up" behavior you referenced: if the panel was offline across multiple periods, it keeps adding one `Reset` period at a time until the expiry is back in the future, then resets `Up`/`Down` to 0 and re-enables the client if it was disabled. - There is genuinely no persisted "renewals used" or "max renewal count" anywhere: not in `model.Client`, not in `model.ClientRecord` (the DB-backed client row, `internal/database/model/model.go:620-645`), not in `xray.ClientTraffic`, and no such column in any migration in `internal/database/db.go`. So today `Reset > 0` is unconditionally indefinite, exactly as described in the issue. I searched open/closed issues for prior requests along these lines and did not find an existing duplicate, so this is being tracked as a new request. Implementing it as described would touch, at minimum: - `model.Client` / `model.ClientRecord` (new columns, e.g. renewal count fields, plus a migration in `internal/database/db.go`), - `autoRenewClients` in `internal/web/service/inbound_traffic.go` (decrement/check remaining count, including making the catch-up loop consume one count per period as requested), - the client edit form in `frontend/src/pages/clients/` and the corresponding Zod schema/generated types, - the client REST API request/response structs and `frontend/src/pages/api-docs/endpoints.ts`, - new i18n keys across all 13 locale files in `internal/web/translation/`. This is a reasonable, backward-compatible feature request (0/empty preserves current unlimited behavior), but it requires new implementation work across the backend, DB schema, and frontend — it is not something already available today. *This reply was generated automatically; a maintainer may follow up.*
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#4033
No description provided.