[GH-ISSUE #5497] [Feature]: Add individual auto-reset cycles for each client #3837

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

Originally created by @ruoyunfu on GitHub (Jun 22, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5497

I'm currently managing multiple clients with different traffic plans. While 3X-UI supports periodic traffic reset at the inbound level, it resets traffic for all clients in that inbound simultaneously.

For example:

  • Client A has a monthly plan with 1000GB, resetting on the 1st of each month.
  • Client B has a weekly plan with 200GB, resetting every Monday.

Currently, I have to manually click the "Reset Traffic" button for each client, which is inefficient and error‑prone.

Describe the solution you'd like

I would like to see a feature that allows each client to have its own independent auto‑reset cycle. This could be implemented by adding the following options in the "Edit Client" interface:

  1. Enable Auto‑Reset – a toggle to turn the feature on/off for this specific client.
  2. Reset Cycle – a dropdown menu to select Daily, Weekly, Monthly, or Custom (Cron Expression).
  3. Reset Rules:
    • If Weekly is selected, an additional option to choose the day of the week (e.g., Monday, Sunday).
    • If Monthly is selected, an option to choose the day of the month (e.g., 1st, 15th).
    • If Custom is selected, a text field for a Cron expression (e.g., 0 0 5 * * for the 5th of each month).
  4. Traffic Quota After Reset – an option to either Reset to the original limit or Reset to a custom value (in GB).
  5. Behavior – the traffic counter (Up/Down) should be reset to zero, and the Total traffic should be restored to the specified value, regardless of how much was used in the previous cycle.

On the backend side, each client record should store the reset settings (e.g., reset_enabled, reset_period, reset_cron, reset_quota). A new scheduled job (or an extension of the existing PeriodicTrafficResetJob) should check each client’s individual settings and apply the reset accordingly.

The current inbound‑level reset is a good start, but it does not support clients with varying billing cycles. This feature would greatly improve management efficiency for those of us handling many clients with diverse plans. Thank you for considering this request!

Alternatives you've considered

No response

Concrete use case

No response

Mockups, screenshots, or examples

No response

Which parts of the panel would this affect?

No response

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 @ruoyunfu on GitHub (Jun 22, 2026). Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5497 ### Is your feature request related to a problem? I'm currently managing multiple clients with different traffic plans. While 3X-UI supports periodic traffic reset at the inbound level, it resets traffic for all clients in that inbound simultaneously. For example: - Client A has a monthly plan with 1000GB, resetting on the 1st of each month. - Client B has a weekly plan with 200GB, resetting every Monday. Currently, I have to manually click the "Reset Traffic" button for each client, which is inefficient and error‑prone. ### Describe the solution you'd like I would like to see a feature that allows each client to have its own independent auto‑reset cycle. This could be implemented by adding the following options in the "Edit Client" interface: 1. **Enable Auto‑Reset** – a toggle to turn the feature on/off for this specific client. 2. **Reset Cycle** – a dropdown menu to select `Daily`, `Weekly`, `Monthly`, or `Custom (Cron Expression)`. 3. **Reset Rules**: - If `Weekly` is selected, an additional option to choose the day of the week (e.g., Monday, Sunday). - If `Monthly` is selected, an option to choose the day of the month (e.g., 1st, 15th). - If `Custom` is selected, a text field for a Cron expression (e.g., `0 0 5 * *` for the 5th of each month). 4. **Traffic Quota After Reset** – an option to either `Reset to the original limit` or `Reset to a custom value` (in GB). 5. **Behavior** – the traffic counter (Up/Down) should be reset to zero, and the `Total` traffic should be restored to the specified value, regardless of how much was used in the previous cycle. On the backend side, each client record should store the reset settings (e.g., `reset_enabled`, `reset_period`, `reset_cron`, `reset_quota`). A new scheduled job (or an extension of the existing `PeriodicTrafficResetJob`) should check each client’s individual settings and apply the reset accordingly. The current inbound‑level reset is a good start, but it does not support clients with varying billing cycles. This feature would greatly improve management efficiency for those of us handling many clients with diverse plans. Thank you for considering this request! ### Alternatives you've considered _No response_ ### Concrete use case _No response_ ### Mockups, screenshots, or examples _No response_ ### Which parts of the panel would this affect? _No response_ ### 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.
Author
Owner

@github-actions[bot] commented on GitHub (Jun 22, 2026):

This is a valid feature request with no exact duplicate in the issue tracker. The closest prior issue (#5285) was a generic question that was closed without any implementation.

What currently exists

Traffic reset is implemented at the inbound level only. The Inbound model (internal/database/model/model.go:56) has a trafficReset field that accepts never | hourly | daily | weekly | monthly. Four instances of PeriodicTrafficResetJob are registered in internal/web/web.go:345-351 (at @hourly, @daily, @weekly, @monthly). When a job fires, PeriodicTrafficResetJob.Run() (internal/web/job/periodic_traffic_reset_job.go:26) fetches all inbounds whose trafficReset matches the period and calls ResetAllClientTraffics for each — resetting every client in that inbound simultaneously.

What the existing client Reset field does (not the same thing)

The Client and ClientRecord models each carry a Reset int field (model.go:606/628, comment: "Reset period in days"). This is not a periodic traffic-reset cycle. It drives autoRenewClients (internal/web/service/inbound_traffic.go:285): when a client's traffic quota or expiry is reached, the expiry time is extended by Reset * 86 400 000 ms (i.e., N days) and the Up/Down counters are zeroed as a side effect of the renewal — see line 374. This is expiry auto-renewal, not a calendar-scheduled traffic reset.

What the feature request requires

There is currently no mechanism to reset a client's traffic counter on a per-client schedule independently of the inbound's own cycle. Implementing what you describe would require at minimum:

  • New columns on clients / ClientRecord (e.g., client_traffic_reset string using the same never|hourly|daily|weekly|monthly vocabulary, or a freeform cron expression, plus last_client_traffic_reset_time int64) with a database migration.
  • A corresponding field on the Client JSON struct and on xray.ClientTraffic so the value is propagated through the existing traffic-accounting layer.
  • Extension of PeriodicTrafficResetJob (or a new job) to also query ClientRecord rows whose client_traffic_reset matches the current period, then call ResetClientTraffic per matched client — independently of the inbound-level reset.
  • Frontend changes in the client create/edit form (the ClientFormSchema in frontend/src/schemas/client.ts and the corresponding React form component) to expose the new per-client cycle selector.
  • If custom cron expressions are desired, a cron parser would need to be evaluated on each job tick, which adds complexity.

The "traffic quota after reset" variant (restoring totalGB to a specific value rather than the original limit) would additionally require storing that override value and plumbing it through ResetClientTraffic / UpdateClientStat.

This request is noted as a valid enhancement. Implementation scope is non-trivial (schema migration, backend job logic, frontend form, and multi-node propagation considerations). A PR is welcome — see the contributing guidelines.

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

<!-- gh-comment-id:4774034380 --> @github-actions[bot] commented on GitHub (Jun 22, 2026): This is a valid feature request with no exact duplicate in the issue tracker. The closest prior issue (#5285) was a generic question that was closed without any implementation. **What currently exists** Traffic reset is implemented at the *inbound* level only. The `Inbound` model (`internal/database/model/model.go:56`) has a `trafficReset` field that accepts `never | hourly | daily | weekly | monthly`. Four instances of `PeriodicTrafficResetJob` are registered in `internal/web/web.go:345-351` (at `@hourly`, `@daily`, `@weekly`, `@monthly`). When a job fires, `PeriodicTrafficResetJob.Run()` (`internal/web/job/periodic_traffic_reset_job.go:26`) fetches all inbounds whose `trafficReset` matches the period and calls `ResetAllClientTraffics` for each — resetting every client in that inbound simultaneously. **What the existing client `Reset` field does (not the same thing)** The `Client` and `ClientRecord` models each carry a `Reset int` field (model.go:606/628, comment: "Reset period in days"). This is not a periodic traffic-reset cycle. It drives `autoRenewClients` (`internal/web/service/inbound_traffic.go:285`): when a client's traffic quota or expiry is reached, the expiry time is extended by `Reset * 86 400 000 ms` (i.e., N days) and the Up/Down counters are zeroed as a side effect of the renewal — see line 374. This is expiry auto-renewal, not a calendar-scheduled traffic reset. **What the feature request requires** There is currently no mechanism to reset a client's traffic counter on a per-client schedule independently of the inbound's own cycle. Implementing what you describe would require at minimum: - New columns on `clients` / `ClientRecord` (e.g., `client_traffic_reset` string using the same `never|hourly|daily|weekly|monthly` vocabulary, or a freeform cron expression, plus `last_client_traffic_reset_time int64`) with a database migration. - A corresponding field on the `Client` JSON struct and on `xray.ClientTraffic` so the value is propagated through the existing traffic-accounting layer. - Extension of `PeriodicTrafficResetJob` (or a new job) to also query `ClientRecord` rows whose `client_traffic_reset` matches the current period, then call `ResetClientTraffic` per matched client — independently of the inbound-level reset. - Frontend changes in the client create/edit form (the `ClientFormSchema` in `frontend/src/schemas/client.ts` and the corresponding React form component) to expose the new per-client cycle selector. - If custom cron expressions are desired, a cron parser would need to be evaluated on each job tick, which adds complexity. The "traffic quota after reset" variant (restoring `totalGB` to a specific value rather than the original limit) would additionally require storing that override value and plumbing it through `ResetClientTraffic` / `UpdateClientStat`. This request is noted as a valid enhancement. Implementation scope is non-trivial (schema migration, backend job logic, frontend form, and multi-node propagation considerations). A PR is welcome — see the contributing guidelines. *This reply was generated automatically; a maintainer may follow up.*
Author
Owner

@lthcode commented on GitHub (Jul 14, 2026):

Great feature!

<!-- gh-comment-id:4968903941 --> @lthcode commented on GitHub (Jul 14, 2026): Great feature!
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#3837
No description provided.