mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 19:11:53 +07:00
[GH-ISSUE #6883] [Feature]: Persist when a client was depleted (quota exhausted / expired) and expose it via API #4570
Labels
No labels
backlog
bug
clarification needed
documentation
duplicate
enhancement
github_actions
good first issue
invalid
javascript
New Feature
PR welcomed
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
MHSanaei/3x-ui#4570
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @aibedini on GitHub (Oct 20, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6883
Is your feature request related to a problem?
3x-ui disables a client automatically once its quota is used up or its expiry passes, but it does not record when or why that happened. Panels, subscription pages and external tooling therefore cannot answer "at what time did this account run out of data?".
What the code does today (checked against current main):
disableInvalidClients(internal/web/service/inbound_disable.go) selects rows matchingtotal > 0 AND up + down >= totalorexpiry_time > 0 AND expiry_time <= now, then setsclient_traffics.enable = falseandclients.enable = false. No timestamp or reason is stored.expiry_timealready gives the exact moment for expiry, but nothing equivalent exists for quota exhaustion.clients.updated_atis bumped when the client is disabled, but it also changes on every unrelated edit, so it cannot be trusted as a depletion time.lastOnlineis only bumped on a non-zero traffic delta, so it is a rough approximation of the last consumed byte, not a depletion marker.Result: anyone who wants to show "your data ran out at 14:32" or audit when accounts were cut off has to poll
client_trafficscontinuously and guess from the first poll that seesup + down >= total. That is inaccurate, wasteful, and impossible to backfill after the fact.Describe the solution you'd like
Record the depletion event at the moment the panel itself detects it, and expose it.
Storage: add two columns to
client_traffics(GORM AutoMigrate, default 0 / "" = unknown, fully backward compatible):depleted_at(int64, Unix ms)depleted_reason(string: "traffic" | "expiry")Writing: in
disableInvalidClients, when a client is flipped to disabled because of depletion, set both fields in the same transaction.depleted_at= detection time (precision = traffic job interval; please document this).depleted_at=expiry_time(the exact boundary).Clearing: reset both fields when the client stops being depleted: traffic reset, expiry extended, quota raised, or renewal (the code paths that already guard "enable only once counters are zero", e.g.
client_traffic.go,client_bulk.go).Exposure:
depletedAtanddepletedReasonin the existing client responses (/panel/api/clients/get/{email},/panel/api/clients/traffic/{email}, and the list/inbound client objects).lastOnlinein docs/custom-subscription-templates.md).Remote nodes / multi-panel: when a node disables a client through the node traffic sync, the master should receive and persist the same two fields rather than stamping its own sync time. For depletion triggered by the cross-panel
client_global_trafficscheck, reason should still be "traffic".No new history table is required for this request; an append-only event log could be a later extension.
Alternatives you've considered
client_trafficsfrom outside and recording the first poll whereup + down >= total: precision is only as good as the poll interval, nothing exists for accounts that depleted before polling started, and every consumer has to build the same machinery.clients.updated_at: changes on any edit, so it is unreliable.lastOnlineas a proxy: only approximates the last consumed byte and is unrelated to expiry.Concrete use case
I run a management layer on top of 3x-ui that serves customers a subscription page and sends renewal reminders. Customers regularly ask "when did my data run out?", and support needs to tell whether an account was cut off two minutes or two days ago before deciding how to handle a renewal dispute.
Today we reconstruct this from our own polling, which gives wrong or missing answers for accounts that depleted between polls or before the tooling existed. With
depletedAtanddepletedReasonprovided by the panel, the subscription page could show "Data ran out at 14:32" directly, support could audit cut-offs, and any third-party tool using the API would get the same accurate data with no extra polling.Scale example: ~hundreds of clients across several inbounds and multiple nodes, where polling every client continuously just to detect one transition is wasteful.
Mockups, screenshots, or examples
Example API response (new fields at the end):
{
"email": "user1",
"enable": false,
"up": 10737418240,
"down": 10737418240,
"total": 21474836480,
"expiryTime": 1795080448277,
"lastOnline": 1792401120000,
"depletedAt": 1792401160000,
"depletedReason": "traffic"
}
Expiry case: "depletedAt" equals "expiryTime", "depletedReason": "expiry".
Never depleted / unknown (including clients depleted before upgrade): "depletedAt": 0, "depletedReason": "".
UI idea: in the clients table, a small tooltip on the "Depleted" badge: "Data exhausted · 2026-10-20 14:32".
Which parts of the panel would this affect?
No response
Are you willing to help?
Before submitting
@github-actions[bot] commented on GitHub (Oct 20, 2026):
This is a valid feature request. Your description of current behaviour is accurate: the panel disables depleted clients but records neither when it happened nor why. I checked every claim in the report against
mainand found nothing to correct.What the code does today
disableInvalidClients(internal/web/service/inbound_disable.go:80) selects rows withdepletedCond, whose local form is (inbound_disable.go:60-61). On a panel that holds freshclient_global_trafficsrows from a master, a third branch is added: a cross-panelEXISTScheck (inbound_disable.go:46-53).Update("enable", false)onclient_traffics(inbound_disable.go:163-165) andUpdates(map[string]any{"enable": false, "updated_at": now})onclients(inbound_disable.go:173-175). No reason or depletion timestamp is stored, and the selecteddepletedRowsare never classified by which branch matched.xray.ClientTraffic(internal/xray/client_traffic.go:5-30) hasExpiryTime,LastOnlineandLastSubFetch, but no depletion field. A grep ofinternal/finds nodepleted_ator similar column. The only "depleted" values are computed live: the sub-page checkisDepleted := traffic.Total > 0 && (traffic.Up+traffic.Down) >= traffic.Total(internal/sub/service.go:416) and thedepletedstatus ininternal/sub/remark_vars.go:301.Notes for whoever implements it
enable = true(inbound_disable.go:86), so setting the stamp in that same pass writes it once. Manual admin disables never go through this function, so they would never get a stamp.Up+Down,TotalandExpiryTime, because the SQL doesn't say which branch matched. A row that matched only theclient_global_trafficsbranch would be"traffic", as you proposed.Updates(map[string]any{"enable": true, "up": 0, "down": 0})calls:client_traffic.go:87,:177,:222andinbound_traffic.go:684(ResetClientTrafficByEmail). Those are where the new fields would be reset. Extending the expiry or raising the quota needs separate handling, because those edits don't zero the counters.SetRemoteTraffic(internal/web/service/inbound_node.go:392), which receivesruntime.TrafficSnapshot.Inbounds(internal/web/runtime/remote.go:748). My inference, which I did not trace to the merge code: newClientTrafficcolumns would travel in that snapshot, but the master's merge would need an explicit rule to take the node's stamp and not overwrite it with its own sync time. The node contract tests ininternal/web/node_contract_test.goandinternal/nodee2e/cover that path.example:tags and openapigen output forClientTraffic, plus a DB migration ininternal/database/db.go, as the repository rules require for model changes.Duplicates. I found none. Related but different requests: #6314 (auto-renew immediately on depletion) and #6354 (a webhook for auto-renew). Neither stores a depletion time.
Verdict: Feature request
This reply was generated automatically; a maintainer may follow up.