[PR #5520] [MERGED] fix(flow): restore XTLS Vision when an inbound becomes flow-eligible #5911

Closed
opened 2026-11-02 04:04:58 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/5520
Author: @rqzbeh
Created: 6/23/2026
Status: ✅ Merged
Merged: 6/24/2026
Merged by: @MHSanaei

Base: main ← Head: fix/restore-vision-flow-on-eligible


📝 Commits (3)

  • ab9fb89 fix(flow): restore XTLS Vision when an inbound becomes flow-eligible
  • fec9adf style(flow): serialize restored settings with MarshalIndent
  • 9a05c31 perf(flow): batch the intended-flow lookup and run it on the active tx

📊 Changes

6 files changed (+337 additions, -0 deletions)

View changed files

➕ internal/web/service/client_effective_flow_test.go (+64 -0)
📝 internal/web/service/client_lookup.go (+38 -0)
📝 internal/web/service/inbound.go (+8 -0)
➕ internal/web/service/inbound_flow_restore.go (+90 -0)
➕ internal/web/service/inbound_flow_restore_test.go (+96 -0)
📝 internal/web/service/inbound_migration.go (+41 -0)

📄 Description

Summary

Restore the XTLS Vision flow on VLESS clients when an inbound becomes flow-eligible, fixing flow=xtls-rprx-vision silently missing from generated configs / share links / subscriptions.

Why

clientWithInboundFlow strips Vision from a client whenever the target inbound is not flow-eligible at client-write time — e.g. an XHTTP inbound before its vlessenc (ML-KEM) encryption is set, or a client attached to such an inbound. That gate is correct, but nothing ever restored the flow once the inbound later became eligible: an inbound edit stores its settings verbatim and never re-gates its clients.

Result: enabling encryption on an existing XHTTP inbound (or attaching clients before encryption was set) leaves every client on it without flow. The subscription then faithfully emits links without flow=xtls-rprx-vision. This shows up most visibly on node inbounds and on any inbound where vlessenc was turned on after the clients already existed, while a sibling inbound configured vision-first keeps it — so the same client gets vision on one endpoint and not another.

Diagnosed on a live multi-node deployment (master + 3 nodes, PostgreSQL): the per-inbound flow (client_inbounds.flow_override, mirrored into each inbound's settings JSON) was empty on the affected inbounds while a sibling reality inbound held vision for the same client. Re-saving the client restored it end-to-end (master → node → subscription), confirming the gate/push/sub paths are correct and the gap is purely the missing re-evaluation.

What

  • UpdateInbound: after the new stream/settings are finalized, re-add Vision to clients that currently carry no flow but whose intended flow (their flow_override on a sibling inbound) is Vision — only when the inbound is now flow-eligible (inboundCanEnableTlsFlow).
  • MigrationRestoreVisionFlow: an idempotent boot migration that applies the same repair to existing installs and refreshes flow_override via SyncInbound.
  • Batched, transaction-local flow resolution (EffectiveFlowsByEmails): the intended flow for every empty-flow client on the inbound is resolved in a single join over client_inbounds + clients (lowest inbound_id wins), instead of two queries per client. The lookup also runs on the active write transaction in UpdateInbound rather than a separate pooled connection. See the perf note below.

Conservative by design: never invents a flow for a client that has none anywhere, never overwrites an explicit flow, no-op on healthy installs and on later boots.

Performance / correctness of the lookup

The first revision resolved each empty-flow client with a per-client helper that issued two queries (GetRecordByEmail + EffectiveFlow). A client that genuinely uses no Vision keeps an empty flow forever, so it was re-queried on every UpdateInbound and every boot — O(clients) queries per save on a Reality/TCP or XHTTP+vlessenc inbound carrying many non-Vision clients, executed inside the serialized writer transaction. This is now a single batched query (chunked for the SQLite bind-var limit), and restoreVisionFlowForEligibleInbound takes the active tx so the read uses the writer's own connection while it holds the lock (the boot migration still passes nil → GetDB()).

Type of change

  • Bug fix

Areas affected

  • Backend (API endpoints, login, settings)
  • Xray config generation
  • Subscription (share links / Clash / JSON)
  • Database / migrations
  • Multi-node (sub-nodes)

How was this tested?

  • inbound_flow_restore_test.go: restores Vision for a client whose sibling has it, skips a client with no Vision intent, no-op on ineligible (xhttp without vlessenc) and non-VLESS inbounds — now exercised through the batched resolver.
  • client_effective_flow_test.go (new): EffectiveFlowsByEmails takes the lowest-inbound_id flow_override, skips emails with no non-empty flow anywhere, skips unknown emails, and is a no-op (no query) on empty input.
  • go build ./..., go vet ./..., and go test ./... pass.
  • Verified the underlying behavior on a live master+nodes deployment: re-applying Vision on a previously-empty node XHTTP inbound propagated to the node DB and into the subscription link.

Breaking changes

None. Behavior only adds flow back where it was intended; existing explicit flows are untouched.

Checklist

  • I tested the change locally and confirmed the described behavior.
  • I added or updated tests for the new behavior.
  • go build ./... and the test suite pass locally.
  • For frontend changes: N/A (backend only).
  • I updated the Wiki / README / API docs if user-facing behavior changed.
  • My commits follow the project's existing message style.
  • I have no unrelated changes mixed into this PR.

🤖 Generated with Claude Code


🔄 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/5520 **Author:** [@rqzbeh](https://github.com/rqzbeh) **Created:** 6/23/2026 **Status:** ✅ Merged **Merged:** 6/24/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `fix/restore-vision-flow-on-eligible` --- ### 📝 Commits (3) - [`ab9fb89`](https://github.com/MHSanaei/3x-ui/commit/ab9fb892a53f8d0a9949f645bac970e5afe079e8) fix(flow): restore XTLS Vision when an inbound becomes flow-eligible - [`fec9adf`](https://github.com/MHSanaei/3x-ui/commit/fec9adf2a03fbb730f0b3029f35dd8ba530b67bd) style(flow): serialize restored settings with MarshalIndent - [`9a05c31`](https://github.com/MHSanaei/3x-ui/commit/9a05c31406e8003eeaf6f28c405c1c0c005024b3) perf(flow): batch the intended-flow lookup and run it on the active tx ### 📊 Changes **6 files changed** (+337 additions, -0 deletions) <details> <summary>View changed files</summary> ➕ `internal/web/service/client_effective_flow_test.go` (+64 -0) 📝 `internal/web/service/client_lookup.go` (+38 -0) 📝 `internal/web/service/inbound.go` (+8 -0) ➕ `internal/web/service/inbound_flow_restore.go` (+90 -0) ➕ `internal/web/service/inbound_flow_restore_test.go` (+96 -0) 📝 `internal/web/service/inbound_migration.go` (+41 -0) </details> ### 📄 Description ## Summary Restore the XTLS Vision flow on VLESS clients when an inbound becomes flow-eligible, fixing `flow=xtls-rprx-vision` silently missing from generated configs / share links / subscriptions. ## Why `clientWithInboundFlow` strips Vision from a client whenever the target inbound is **not flow-eligible at client-write time** — e.g. an XHTTP inbound before its `vlessenc` (ML-KEM) encryption is set, or a client attached to such an inbound. That gate is correct, but nothing ever restored the flow once the inbound *later* became eligible: an inbound edit stores its settings verbatim and never re-gates its clients. Result: enabling encryption on an existing XHTTP inbound (or attaching clients before encryption was set) leaves every client on it without flow. The subscription then faithfully emits links without `flow=xtls-rprx-vision`. This shows up most visibly on **node inbounds** and on any inbound where vlessenc was turned on after the clients already existed, while a sibling inbound configured vision-first keeps it — so the same client gets vision on one endpoint and not another. Diagnosed on a live multi-node deployment (master + 3 nodes, PostgreSQL): the per-inbound flow (`client_inbounds.flow_override`, mirrored into each inbound's `settings` JSON) was empty on the affected inbounds while a sibling reality inbound held vision for the same client. Re-saving the client restored it end-to-end (master → node → subscription), confirming the gate/push/sub paths are correct and the gap is purely the missing re-evaluation. ## What - **`UpdateInbound`**: after the new stream/settings are finalized, re-add Vision to clients that currently carry no flow but whose intended flow (their `flow_override` on a sibling inbound) is Vision — only when the inbound is now flow-eligible (`inboundCanEnableTlsFlow`). - **`MigrationRestoreVisionFlow`**: an idempotent boot migration that applies the same repair to existing installs and refreshes `flow_override` via `SyncInbound`. - **Batched, transaction-local flow resolution** (`EffectiveFlowsByEmails`): the intended flow for every empty-flow client on the inbound is resolved in a **single** join over `client_inbounds` + `clients` (lowest `inbound_id` wins), instead of two queries per client. The lookup also runs on the active write transaction in `UpdateInbound` rather than a separate pooled connection. See the perf note below. Conservative by design: never invents a flow for a client that has none anywhere, never overwrites an explicit flow, no-op on healthy installs and on later boots. ### Performance / correctness of the lookup The first revision resolved each empty-flow client with a per-client helper that issued two queries (`GetRecordByEmail` + `EffectiveFlow`). A client that genuinely uses no Vision keeps an empty flow forever, so it was re-queried on every `UpdateInbound` and every boot — O(clients) queries per save on a Reality/TCP or XHTTP+vlessenc inbound carrying many non-Vision clients, executed inside the serialized writer transaction. This is now a single batched query (chunked for the SQLite bind-var limit), and `restoreVisionFlowForEligibleInbound` takes the active `tx` so the read uses the writer's own connection while it holds the lock (the boot migration still passes `nil` → `GetDB()`). ## Type of change - [x] Bug fix ## Areas affected - [x] Backend (API endpoints, login, settings) - [x] Xray config generation - [x] Subscription (share links / Clash / JSON) - [x] Database / migrations - [x] Multi-node (sub-nodes) ## How was this tested? - `inbound_flow_restore_test.go`: restores Vision for a client whose sibling has it, skips a client with no Vision intent, no-op on ineligible (xhttp without vlessenc) and non-VLESS inbounds — now exercised through the batched resolver. - `client_effective_flow_test.go` (new): `EffectiveFlowsByEmails` takes the lowest-`inbound_id` `flow_override`, skips emails with no non-empty flow anywhere, skips unknown emails, and is a no-op (no query) on empty input. - `go build ./...`, `go vet ./...`, and `go test ./...` pass. - Verified the underlying behavior on a live master+nodes deployment: re-applying Vision on a previously-empty node XHTTP inbound propagated to the node DB and into the subscription link. ## Breaking changes None. Behavior only adds flow back where it was intended; existing explicit flows are untouched. ## Checklist - [x] I tested the change locally and confirmed the described behavior. - [x] I added or updated tests for the new behavior. - [x] `go build ./...` and the test suite pass locally. - [ ] For frontend changes: N/A (backend only). - [ ] I updated the Wiki / README / API docs if user-facing behavior changed. - [x] My commits follow the project's existing message style. - [x] I have no unrelated changes mixed into this PR. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:04:58 +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#5911
No description provided.