[PR #6238] [MERGED] feat(clients): cap how many times a client may auto-renew #6193

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/6238
Author: @n0ctal
Created: 8/17/2026
Status: ✅ Merged
Merged: 8/18/2026
Merged by: @MHSanaei

Base: main ← Head: upstream-auto-renew-max-count


📝 Commits (4)

  • f97b683 feat(clients): cap how many times a client may auto-renew
  • a5caeae fix(clients): persist the auto-renew cap and stop the capped churn
  • 5f3588c fix(clients): let the renewal cap be changed after creation
  • 8e3810a chore: drop the accidentally committed dist build stub

📊 Changes

29 files changed (+508 additions, -27 deletions)

View changed files

📝 frontend/public/openapi.json (+25 -0)
📝 frontend/src/generated/examples.ts (+6 -0)
📝 frontend/src/generated/schemas.ts (+21 -0)
📝 frontend/src/generated/types.ts (+4 -0)
📝 frontend/src/generated/zod.ts (+4 -0)
📝 frontend/src/pages/clients/ClientBulkAddModal.tsx (+11 -0)
📝 frontend/src/pages/clients/ClientFormModal.tsx (+14 -0)
📝 frontend/src/pages/clients/ClientInfoModal.tsx (+10 -0)
📝 frontend/src/schemas/client.ts (+5 -0)
📝 internal/database/model/model.go (+10 -0)
📝 internal/web/service/client_crud.go (+16 -0)
📝 internal/web/service/client_link.go (+1 -0)
📝 internal/web/service/client_paging.go (+2 -0)
➕ internal/web/service/inbound_autorenew_maxcount_test.go (+287 -0)
📝 internal/web/service/inbound_traffic.go (+23 -1)
📝 internal/web/translation/ar-EG.json (+4 -1)
📝 internal/web/translation/en-US.json (+4 -1)
📝 internal/web/translation/es-ES.json (+4 -1)
📝 internal/web/translation/fa-IR.json (+4 -1)
📝 internal/web/translation/id-ID.json (+4 -1)

...and 9 more files

📄 Description

Closes #5804.

Summary

Auto-renew runs forever. A prepaid or fixed-term client keeps receiving new periods until an operator remembers to switch it off, and there is no way to say "renew this three times, then let it lapse".

This adds a per-client maximum. Zero keeps today's behaviour, so nothing changes for anyone who does not set one.

The part that is easy to get wrong

Renewal catches up: if a client's expiry is three periods in the past, the existing loop advances it until it reaches the present. With a cap, that loop has to stop counting as well as stop renewing, otherwise a client who was away for three cycles receives all three regardless of what the operator paid for — the cap would only apply to clients who happened to be seen every period.

So the catch-up spends one allowance per period and stops at the last period the cap covers. A client capped at two, three periods behind, ends up exactly two periods forward — still expired, and correctly so, rather than jumping to the present.

Behaviour

  • resetMax per client, default 0 = unlimited.
  • resetCount records how many renewals have fired.
  • Selection skips clients that have spent their allowance, so they expire like any client without auto-renew.
  • Both fields ride the existing settings/traffic sync, so a client edited through the panel or the API keeps them in step.

Validation

Three tests: a capped client that has spent its allowance is not renewed while its neighbour with one left is; a three-periods-behind client capped at two lands exactly two periods forward and stays expired; a client with no cap renews as before.

Mutation-checked, both halves separately:

  • dropping the selection filter → renewed count = 2, want 1: only the client with an allowance left
  • dropping the cap check inside the catch-up loop → reset count = 4, want the 2 the cap allowed

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

Risk

Low. The new column defaults to 0 on existing rows, which is "no cap", so upgraded installs behave exactly as before until someone sets a value.


🔄 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/6238 **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-auto-renew-max-count` --- ### 📝 Commits (4) - [`f97b683`](https://github.com/MHSanaei/3x-ui/commit/f97b683878742b0845abfb74accef6b77280c6e6) feat(clients): cap how many times a client may auto-renew - [`a5caeae`](https://github.com/MHSanaei/3x-ui/commit/a5caeaef3f92a2f2de830e2f40913c7e0c1d4a6a) fix(clients): persist the auto-renew cap and stop the capped churn - [`5f3588c`](https://github.com/MHSanaei/3x-ui/commit/5f3588ce6bb1dccbc8309bc08a6b47f164e6626d) fix(clients): let the renewal cap be changed after creation - [`8e3810a`](https://github.com/MHSanaei/3x-ui/commit/8e3810a41bad668a73c48b2dbdc5762a336740c6) chore: drop the accidentally committed dist build stub ### 📊 Changes **29 files changed** (+508 additions, -27 deletions) <details> <summary>View changed files</summary> 📝 `frontend/public/openapi.json` (+25 -0) 📝 `frontend/src/generated/examples.ts` (+6 -0) 📝 `frontend/src/generated/schemas.ts` (+21 -0) 📝 `frontend/src/generated/types.ts` (+4 -0) 📝 `frontend/src/generated/zod.ts` (+4 -0) 📝 `frontend/src/pages/clients/ClientBulkAddModal.tsx` (+11 -0) 📝 `frontend/src/pages/clients/ClientFormModal.tsx` (+14 -0) 📝 `frontend/src/pages/clients/ClientInfoModal.tsx` (+10 -0) 📝 `frontend/src/schemas/client.ts` (+5 -0) 📝 `internal/database/model/model.go` (+10 -0) 📝 `internal/web/service/client_crud.go` (+16 -0) 📝 `internal/web/service/client_link.go` (+1 -0) 📝 `internal/web/service/client_paging.go` (+2 -0) ➕ `internal/web/service/inbound_autorenew_maxcount_test.go` (+287 -0) 📝 `internal/web/service/inbound_traffic.go` (+23 -1) 📝 `internal/web/translation/ar-EG.json` (+4 -1) 📝 `internal/web/translation/en-US.json` (+4 -1) 📝 `internal/web/translation/es-ES.json` (+4 -1) 📝 `internal/web/translation/fa-IR.json` (+4 -1) 📝 `internal/web/translation/id-ID.json` (+4 -1) _...and 9 more files_ </details> ### 📄 Description Closes #5804. ## Summary Auto-renew runs forever. A prepaid or fixed-term client keeps receiving new periods until an operator remembers to switch it off, and there is no way to say "renew this three times, then let it lapse". This adds a per-client maximum. Zero keeps today's behaviour, so nothing changes for anyone who does not set one. ## The part that is easy to get wrong Renewal catches up: if a client's expiry is three periods in the past, the existing loop advances it until it reaches the present. With a cap, that loop has to stop counting as well as stop renewing, otherwise a client who was away for three cycles receives all three regardless of what the operator paid for — the cap would only apply to clients who happened to be seen every period. So the catch-up spends one allowance per period and stops at the last period the cap covers. A client capped at two, three periods behind, ends up exactly two periods forward — still expired, and correctly so, rather than jumping to the present. ## Behaviour - `resetMax` per client, default 0 = unlimited. - `resetCount` records how many renewals have fired. - Selection skips clients that have spent their allowance, so they expire like any client without auto-renew. - Both fields ride the existing settings/traffic sync, so a client edited through the panel or the API keeps them in step. ## Validation Three tests: a capped client that has spent its allowance is not renewed while its neighbour with one left is; a three-periods-behind client capped at two lands exactly two periods forward and stays expired; a client with no cap renews as before. Mutation-checked, both halves separately: - dropping the selection filter → `renewed count = 2, want 1: only the client with an allowance left` - dropping the cap check inside the catch-up loop → `reset count = 4, want the 2 the cap allowed` `go build ./...`, `go vet`, `golangci-lint`, `make gen-check` clean; 36 Go packages green; frontend typecheck, eslint and the unit suite green. ## Risk Low. The new column defaults to 0 on existing rows, which is "no cap", so upgraded installs behave exactly as before until someone sets a value. --- <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#6193
No description provided.