[GH-ISSUE #6556] [Bug]: Subscription outbound links become incorrectly mapped after deleting and re-adding an inbound #4395

Closed
opened 2026-10-31 20:39:22 +07:00 by bsakaguchi · 4 comments
Owner

Originally created by @dicreat on GitHub (Sep 15, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6556

Describe the bug

Summary

After deleting and re-adding an inbound that was previously included in an outbound subscription, the subscription links become incorrectly mapped to the corresponding server locations. The Balancer Settings also retain the original link names, but the active route points to a newly created link that is not selected in the balancer configuration.

Environment

  • 3x-ui version: 3.8.0
  • Configuration: one inbound node with multiple outbound connections
  • Outbound connections are created using the Subscription functionality in the Outbounds section.
  • Subscription prefix: sub

Initial configuration

I had three outbound connections to servers in different locations:

  • France — sub-france
  • Germany — sub-germany
  • Sweden — sub-sweden

All three outbounds were added through the Subscription functionality in the Outbounds section and worked correctly in the Balancer.

The Balancer initially contained the following three links:

  • sub-france
  • sub-germany
  • sub-sweden

How to reproduce the problem

  1. Create three outbound connections using the Subscription functionality:

    • France
    • Germany
    • Sweden
  2. Use sub as the subscription prefix.

  3. Add all three outbounds to a Balancer.

  4. Verify that all three links work correctly and correspond to the expected server locations.

  5. Delete the France inbound/server.

  6. The France entry is automatically removed from the subscription of the inbound node.

  7. Create a new France inbound/server.

  8. Add the new France inbound to the same subscription.

  9. Check the resulting subscription links.

  10. Open Balancer Settings and inspect the configured routes and active route.

Expected behavior

After deleting the France inbound and adding a new France inbound to the subscription:

  • The new France outbound should be correctly associated with sub-france.

  • The existing links should retain their original server/location mapping:

    • sub-france → France
    • sub-germany → Germany
    • sub-sweden → Sweden
  • No unexpected link such as sub-sweden-1 should be created unless explicitly required.

  • The Balancer should continue to use exactly the links selected in its configuration.

  • The active route should always be one of the currently configured/selected balancer targets.

Actual behavior

After adding the new France inbound to the subscription, the subscription entries become incorrectly associated with the server IP addresses:

Subscription link IP address displayed
sub-germany France
sub-sweden Germany
sub-sweden-1 Sweden

The expected sub-france link is no longer present in the subscription in the expected form.

At the same time, Balancer Settings still shows the original link names:

  • sub-france
  • sub-germany
  • sub-sweden

However, the active route is shown as sub-sweden-1.

When I edit the Balancer, sub-sweden-1 is not selected as one of the balancer targets and should not participate in load balancing.

This means that the Balancer appears to be using a link that is not actually selected in its configuration.

Impact

This can lead to incorrect traffic routing because subscription link names no longer correspond to their actual server locations. More importantly, the Balancer may select and use a dynamically created link (sub-sweden-1) that is not selected in the Balancer configuration.

This makes the relationship between Subscriptions, Outbounds, and Balancer Settings inconsistent and can result in traffic being routed through an unexpected server.

Additional observation

The issue appears to be related to how subscription entries are identified and/or updated after an inbound is deleted and subsequently re-added. It looks as if the existing subscription entries may be matched by their position/index rather than by a stable identifier, causing the server addresses to shift between subscription names.

The fact that sub-sweden-1 becomes the active route while it is not selected in the Balancer Settings may indicate that the Balancer retains a stale reference to a previous outbound/subscription entry.

Relevant logs


Screenshots

No response

3x-ui version

3.8.0

Xray-core version

No response

How did you install 3x-ui?

install.sh script

Operating system

Ubuntu 24

Which parts of the panel are affected?

Subscription (share links / Clash / JSON)

Browser (only if it is a UI bug)

No response

Is the panel behind a reverse proxy or CDN?

None

Before submitting

  • I searched existing issues and this bug has not been reported.
  • I am running the latest released version of 3x-ui (or have verified the bug still exists on it).
  • This bug report is written in English.
  • I have redacted any sensitive data (tokens, real domains, client UUIDs).
Originally created by @dicreat on GitHub (Sep 15, 2026). Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6556 ### Describe the bug ### Summary After deleting and re-adding an inbound that was previously included in an outbound subscription, the subscription links become incorrectly mapped to the corresponding server locations. The Balancer Settings also retain the original link names, but the active route points to a newly created link that is not selected in the balancer configuration. ### Environment * 3x-ui version: **3.8.0** * Configuration: one inbound node with multiple outbound connections * Outbound connections are created using the **Subscription** functionality in the Outbounds section. * Subscription prefix: **`sub`** ### Initial configuration I had three outbound connections to servers in different locations: * France — `sub-france` * Germany — `sub-germany` * Sweden — `sub-sweden` All three outbounds were added through the Subscription functionality in the Outbounds section and worked correctly in the Balancer. The Balancer initially contained the following three links: * `sub-france` * `sub-germany` * `sub-sweden` ### How to reproduce the problem 1. Create three outbound connections using the Subscription functionality: * France * Germany * Sweden 2. Use `sub` as the subscription prefix. 3. Add all three outbounds to a Balancer. 4. Verify that all three links work correctly and correspond to the expected server locations. 5. Delete the France inbound/server. 6. The France entry is automatically removed from the subscription of the inbound node. 7. Create a new France inbound/server. 8. Add the new France inbound to the same subscription. 9. Check the resulting subscription links. 10. Open **Balancer Settings** and inspect the configured routes and active route. ### Expected behavior After deleting the France inbound and adding a new France inbound to the subscription: * The new France outbound should be correctly associated with `sub-france`. * The existing links should retain their original server/location mapping: * `sub-france` → France * `sub-germany` → Germany * `sub-sweden` → Sweden * No unexpected link such as `sub-sweden-1` should be created unless explicitly required. * The Balancer should continue to use exactly the links selected in its configuration. * The active route should always be one of the currently configured/selected balancer targets. ### Actual behavior After adding the new France inbound to the subscription, the subscription entries become incorrectly associated with the server IP addresses: | Subscription link | IP address displayed | | ----------------- | -------------------- | | `sub-germany` | **France** | | `sub-sweden` | **Germany** | | `sub-sweden-1` | **Sweden** | The expected `sub-france` link is no longer present in the subscription in the expected form. At the same time, **Balancer Settings** still shows the original link names: * `sub-france` * `sub-germany` * `sub-sweden` However, the **active route** is shown as `sub-sweden-1`. When I edit the Balancer, `sub-sweden-1` is **not selected** as one of the balancer targets and should not participate in load balancing. This means that the Balancer appears to be using a link that is not actually selected in its configuration. ### Impact This can lead to incorrect traffic routing because subscription link names no longer correspond to their actual server locations. More importantly, the Balancer may select and use a dynamically created link (`sub-sweden-1`) that is not selected in the Balancer configuration. This makes the relationship between **Subscriptions**, **Outbounds**, and **Balancer Settings** inconsistent and can result in traffic being routed through an unexpected server. ### Additional observation The issue appears to be related to how subscription entries are identified and/or updated after an inbound is deleted and subsequently re-added. It looks as if the existing subscription entries may be matched by their position/index rather than by a stable identifier, causing the server addresses to shift between subscription names. The fact that `sub-sweden-1` becomes the active route while it is not selected in the Balancer Settings may indicate that the Balancer retains a stale reference to a previous outbound/subscription entry. ### Relevant logs ```shell ``` ### Screenshots _No response_ ### 3x-ui version 3.8.0 ### Xray-core version _No response_ ### How did you install 3x-ui? install.sh script ### Operating system Ubuntu 24 ### Which parts of the panel are affected? Subscription (share links / Clash / JSON) ### Browser (only if it is a UI bug) _No response_ ### Is the panel behind a reverse proxy or CDN? None ### Before submitting - [x] I searched [existing issues](../issues?q=is%3Aissue) and this bug has not been reported. - [x] I am running the latest released version of 3x-ui (or have verified the bug still exists on it). - [x] This bug report is written in English. - [x] I have redacted any sensitive data (tokens, real domains, client UUIDs).
bsakaguchi 2026-10-31 20:39:22 +07:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@github-actions[bot] commented on GitHub (Sep 15, 2026):

Thanks for the very precise write-up — your "Additional observation" is correct, and it is actually two separate things:

  1. The balancer picking sub-sweden-1 is not a 3x-ui defect. A balancer selector entry is a tag prefix in xray-core, not an exact tag. sub-sweden therefore also selects sub-sweden-1. This is already documented and was answered before in #5560.
  2. The tag/server remapping is real. Subscription tags are assigned by identity first and by list position second, and the positional step is what can hand an existing tag to a physically different server. Part of this was fixed in v3.8.0; the part that is not fixed is that a mapping which already went wrong is stored in the database and never repaired — so upgrading does not undo what you are seeing.

internal/web/service/outbound_subscription.go:642:

- If you use a *prefix/wildcard* selector (e.g. "hk-*", "sg-.*"), then any
  *new* servers that the subscription later returns will automatically be
  eligible for that balancer on the next Xray reload

and docs/content/docs/en/operations/outbounds-routing.mdx:156:

A balancer groups outbounds by a selector (tag prefixes, including the wildcard pools from outbound subscriptions)

The panel relies on this itself — internal/sub/json_service.go:537 builds a whole balancer from a single prefix entry:

balancerEntry := map[string]any{
	"tag":      subBalancerTag,
	"selector": []string{prefix},
	...

So with sub-sweden in the selector, sub-sweden-1 is a legitimate member as far as xray-core is concerned, which is why it shows up as the active route while the edit dialog does not show it ticked. The Selector field in the balancer dialog (frontend/src/pages/xray/balancers/BalancerFormModal.tsx:250-255) is an AntD mode="tags" select whose options are existing tags, which makes it look like exact selection — it is not. There is no exact-match mode in the xray-core balancer API.

2. Why the names stopped matching the locations

Tag assignment lives in assignStableTags, internal/web/service/outbound_subscription.go:472. Three steps, in order:

// 1. identity reuse
if old, ok := prev[id]; ok && old != "" {        // line 489
	candidate = old
// 2. positional reuse
	if old, ok := prevTagByIndex[i]; ok && old != "" && !reservedStableTags[old] {  // line 495
		candidate = old
// 3. fresh allocation
	candidate = link.SuggestTag(prefix, remark, i)   // line 509

Step 2 is the one that bites you. prevTagByIndex is built purely from the array position of the previous fetch (lines 408-420), so when France disappears from the upstream subscription and something else lands on its index, that entry inherits France's tag. The -1 suffix you see comes from the collision loop at lines 513-515, so sub-sweden-1 is a tag that was pushed aside, not a deliberately created server.

This is intentional as a best-effort heuristic — TestAssignStableTags/falls_back_to_the_previous_tag_at_the_same_position (internal/web/service/outbound_subscription_test.go:194) pins exactly that behaviour — but it is also the mechanism by which a tag ends up pointing at a different country.

What v3.8.0 already fixed: commit 8abe87b6 ("fix(outbounds): preserve stable subscription tags", PR #6345, shipped in v3.8.0) added reservedStableTags so an inserted link can no longer steal the tag of a server that is still in the list. That is the same family as #6341 (Netherlands / Netherlands-1).

What it did not fix — and is why your panel does not self-heal: the identity→tag map is persisted at lines 429-433/445 into the link_identities column, and step 1 (line 489) reuses it unconditionally on every refresh. Once a wrong pairing is in there, it is a fixed point: every subsequent refresh reproduces it. The column is json:"-" (internal/database/model/model.go:1260), Update never touches it (lines 211-243), and nothing in the UI or API can reset it. v3.8.0 was released one day before you filed this, so the swap you are looking at was almost certainly produced by the pre-v3.8.0 algorithm and then frozen in the database.

A second, smaller inconsistency at the same spot: link_identities is written from the unfiltered parse (line 430 iterates identities) while last_fetched_outbounds — the source of prevTagByIndex — is written from the filtered kept slice (lines 439-444). If any outbound is dropped by filterOutboundsRejectedByCore, the positional map is off by one from then on.

How to get your panel back to a correct state

  1. Reset the subscription's stored mapping. Easiest: delete the outbound subscription in Xray → Outbounds → Subscriptions and add it again with the same URL and prefix sub. Delete (line 246) hard-deletes the row, so the next refresh allocates every tag fresh from the remarks (sub-france, sub-germany, sub-sweden).

    If you prefer to keep the subscription row and its settings, clear just the two columns:

    systemctl stop x-ui
    cp /etc/x-ui/x-ui.db /etc/x-ui/x-ui.db.bak
    sqlite3 /etc/x-ui/x-ui.db \
      "UPDATE outbound_subscriptions SET link_identities='', last_fetched_outbounds='' WHERE id=<subscription id>;"
    systemctl start x-ui
    

    Then hit Refresh on the subscription.

  2. Re-select the balancer members afterwards, since the tags were re-allocated — and make sure no remaining tag is a prefix of another (sub-sweden vs sub-sweden-1), or the balancer will keep pulling in the longer one.

One thing I could not determine

Your exact table (sub-germany → France, sub-sweden → Germany, sub-sweden-1 → Sweden) is a clean one-position shift, which the algorithm only produces when prev is empty at that refresh while prevTagByIndex still holds the older, shorter list. I could not reproduce that from the v3.8.0 code path with an intact identity map, so I cannot tell whether your panel hit a still-open hole or is showing pre-v3.8.0 damage. The single thing that settles it is the current content of that row — please paste the output of (redact hosts/UUIDs, they appear in the identity strings):

sqlite3 /etc/x-ui/x-ui.db \
  "SELECT id, tag_prefix, link_identities, last_fetched_outbounds FROM outbound_subscriptions;"

If link_identities is empty/{} while last_fetched_outbounds has entries, that is a live bug and pins it exactly. I have labelled this "clarification needed" for that reason; everything above stands either way.


Verdict: Confirmed bug
Severity: Medium
Confidence: Medium
Root cause: assignStableTags positional fallback, internal/web/service/outbound_subscription.go:495 — a link whose identity is unknown inherits the tag that sat at its index in the previous fetch, so removing a server and adding another re-points an existing tag at a different physical server. Compounded by the persisted identity→tag map (link_identities, written at lines 429-433/445, reused unconditionally at line 489) having no reset path: json:"-" at internal/database/model/model.go:1260, untouched by Update at lines 211-243. Introduced with the feature in 0daedd3d (feat: add support for subscription-based outbounds with auto-update, #5037).
Already fixed: Partially — 8abe87b6 ("fix(outbounds): preserve stable subscription tags", #6345) is in v3.8.0 and stops an inserted link from stealing the tag of a server still present in the batch. The positional fallback itself, the unfiltered/filtered index mismatch (lines 430 vs 439-444) and the missing repair path for an already-swapped link_identities are all still present on the default branch.
Duplicate of: None. Related: #5560 (balancer selector is a prefix match — same explanation for the sub-sweden-1 active route), #6341 (the Netherlands-1 duplicate, fixed by the same commit).
Evidence: internal/web/service/outbound_subscription.go:495 if old, ok := prevTagByIndex[i]; ok && old != "" && !reservedStableTags[old] {; lines 513-515 for k := 1; used[final] || (reservedStableTags[final] && final != identityTag); k++ { final = fmt.Sprintf("%s-%d", candidate, k) } (source of the -1 suffix); lines 408-420 build prevTagByIndex from array position only; lines 439-444 persist the filtered kept slice while line 430 persists identities for the unfiltered parse; internal/database/model/model.go:1260 LinkIdentities string \json:"-"`; test TestAssignStableTags/falls_back_to_the_previous_tag_at_the_same_positionatinternal/web/service/outbound_subscription_test.go:194pins the positional fallback as intended;internal/sub/json_service.go:537anddocs/content/docs/en/operations/outbounds-routing.mdx:156establish that balancer selectors are prefixes;git tag --contains 8abe87b6→v3.8.0, dev-latest. Not determined: Whether the reporter's exact one-position shift is reachable on v3.8.0 or is pre-v3.8.0 state frozen in the database. Settled by the link_identities/last_fetched_outbounds` values of that row (query above).

Suggested fix: Reserve the previous tag set, not just the tags of identities still in the batch, so a brand-new link never inherits a removed link's tag via prevTagByIndex — or drop the positional fallback for links whose identity was never seen. Building prevTagByIndex from the same unfiltered list that link_identities is built from would also remove the off-by-one after a core-rejected outbound. Separately, a way to reset a subscription's stored identity map without deleting the subscription would let users out of an already-swapped state.

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

<!-- gh-comment-id:5681036494 --> @github-actions[bot] commented on GitHub (Sep 15, 2026): Thanks for the very precise write-up — your "Additional observation" is correct, and it is actually **two separate things**: 1. **The balancer picking `sub-sweden-1` is not a 3x-ui defect.** A balancer `selector` entry is a **tag prefix** in xray-core, not an exact tag. `sub-sweden` therefore also selects `sub-sweden-1`. This is already documented and was answered before in #5560. 2. **The tag/server remapping is real.** Subscription tags are assigned by identity first and **by list position** second, and the positional step is what can hand an existing tag to a physically different server. Part of this was fixed in **v3.8.0**; the part that is *not* fixed is that a mapping which already went wrong is stored in the database and never repaired — so upgrading does not undo what you are seeing. --- ## 1. Why the balancer uses a link you did not select `internal/web/service/outbound_subscription.go:642`: ``` - If you use a *prefix/wildcard* selector (e.g. "hk-*", "sg-.*"), then any *new* servers that the subscription later returns will automatically be eligible for that balancer on the next Xray reload ``` and `docs/content/docs/en/operations/outbounds-routing.mdx:156`: > A **balancer** groups outbounds by a **selector** (tag prefixes, including the wildcard pools from outbound subscriptions) The panel relies on this itself — `internal/sub/json_service.go:537` builds a whole balancer from a single prefix entry: ```go balancerEntry := map[string]any{ "tag": subBalancerTag, "selector": []string{prefix}, ... ``` So with `sub-sweden` in the selector, **`sub-sweden-1` is a legitimate member** as far as xray-core is concerned, which is why it shows up as the active route while the edit dialog does not show it ticked. The Selector field in the balancer dialog (`frontend/src/pages/xray/balancers/BalancerFormModal.tsx:250-255`) is an AntD `mode="tags"` select whose *options* are existing tags, which makes it look like exact selection — it is not. There is no exact-match mode in the xray-core balancer API. ## 2. Why the names stopped matching the locations Tag assignment lives in `assignStableTags`, `internal/web/service/outbound_subscription.go:472`. Three steps, in order: ```go // 1. identity reuse if old, ok := prev[id]; ok && old != "" { // line 489 candidate = old // 2. positional reuse if old, ok := prevTagByIndex[i]; ok && old != "" && !reservedStableTags[old] { // line 495 candidate = old // 3. fresh allocation candidate = link.SuggestTag(prefix, remark, i) // line 509 ``` Step 2 is the one that bites you. `prevTagByIndex` is built purely from the *array position* of the previous fetch (lines 408-420), so when France disappears from the upstream subscription and something else lands on its index, that entry inherits France's tag. The `-1` suffix you see comes from the collision loop at lines 513-515, so `sub-sweden-1` is a tag that was *pushed aside*, not a deliberately created server. This is intentional as a best-effort heuristic — `TestAssignStableTags/falls_back_to_the_previous_tag_at_the_same_position` (`internal/web/service/outbound_subscription_test.go:194`) pins exactly that behaviour — but it is also the mechanism by which a tag ends up pointing at a different country. **What v3.8.0 already fixed:** commit `8abe87b6` ("fix(outbounds): preserve stable subscription tags", PR #6345, shipped in v3.8.0) added `reservedStableTags` so an inserted link can no longer steal the tag of a server that is *still in the list*. That is the same family as #6341 (`Netherlands` / `Netherlands-1`). **What it did not fix — and is why your panel does not self-heal:** the identity→tag map is persisted at lines 429-433/445 into the `link_identities` column, and step 1 (line 489) reuses it unconditionally on every refresh. Once a wrong pairing is in there, it is a fixed point: every subsequent refresh reproduces it. The column is `json:"-"` (`internal/database/model/model.go:1260`), `Update` never touches it (lines 211-243), and nothing in the UI or API can reset it. v3.8.0 was released one day before you filed this, so the swap you are looking at was almost certainly produced by the pre-v3.8.0 algorithm and then frozen in the database. A second, smaller inconsistency at the same spot: `link_identities` is written from the **unfiltered** parse (line 430 iterates `identities`) while `last_fetched_outbounds` — the source of `prevTagByIndex` — is written from the **filtered** `kept` slice (lines 439-444). If any outbound is dropped by `filterOutboundsRejectedByCore`, the positional map is off by one from then on. ## How to get your panel back to a correct state 1. **Reset the subscription's stored mapping.** Easiest: delete the outbound subscription in **Xray → Outbounds → Subscriptions** and add it again with the same URL and prefix `sub`. `Delete` (line 246) hard-deletes the row, so the next refresh allocates every tag fresh from the remarks (`sub-france`, `sub-germany`, `sub-sweden`). If you prefer to keep the subscription row and its settings, clear just the two columns: ```bash systemctl stop x-ui cp /etc/x-ui/x-ui.db /etc/x-ui/x-ui.db.bak sqlite3 /etc/x-ui/x-ui.db \ "UPDATE outbound_subscriptions SET link_identities='', last_fetched_outbounds='' WHERE id=<subscription id>;" systemctl start x-ui ``` Then hit **Refresh** on the subscription. 2. **Re-select the balancer members afterwards**, since the tags were re-allocated — and make sure no remaining tag is a prefix of another (`sub-sweden` vs `sub-sweden-1`), or the balancer will keep pulling in the longer one. ## One thing I could not determine Your exact table (`sub-germany` → France, `sub-sweden` → Germany, `sub-sweden-1` → Sweden) is a clean one-position shift, which the algorithm only produces when `prev` is **empty** at that refresh while `prevTagByIndex` still holds the older, shorter list. I could not reproduce that from the v3.8.0 code path with an intact identity map, so I cannot tell whether your panel hit a still-open hole or is showing pre-v3.8.0 damage. The single thing that settles it is the current content of that row — please paste the output of (redact hosts/UUIDs, they appear in the identity strings): ```bash sqlite3 /etc/x-ui/x-ui.db \ "SELECT id, tag_prefix, link_identities, last_fetched_outbounds FROM outbound_subscriptions;" ``` If `link_identities` is empty/`{}` while `last_fetched_outbounds` has entries, that is a live bug and pins it exactly. I have labelled this "clarification needed" for that reason; everything above stands either way. --- Verdict: Confirmed bug Severity: Medium Confidence: Medium Root cause: `assignStableTags` positional fallback, `internal/web/service/outbound_subscription.go:495` — a link whose identity is unknown inherits the tag that sat at its index in the previous fetch, so removing a server and adding another re-points an existing tag at a different physical server. Compounded by the persisted identity→tag map (`link_identities`, written at lines 429-433/445, reused unconditionally at line 489) having no reset path: `json:"-"` at `internal/database/model/model.go:1260`, untouched by `Update` at lines 211-243. Introduced with the feature in `0daedd3d` (feat: add support for subscription-based outbounds with auto-update, #5037). Already fixed: Partially — `8abe87b6` ("fix(outbounds): preserve stable subscription tags", #6345) is in **v3.8.0** and stops an inserted link from stealing the tag of a server still present in the batch. The positional fallback itself, the unfiltered/filtered index mismatch (lines 430 vs 439-444) and the missing repair path for an already-swapped `link_identities` are all still present on the default branch. Duplicate of: None. Related: #5560 (balancer selector is a prefix match — same explanation for the `sub-sweden-1` active route), #6341 (the `Netherlands-1` duplicate, fixed by the same commit). Evidence: `internal/web/service/outbound_subscription.go:495` `if old, ok := prevTagByIndex[i]; ok && old != "" && !reservedStableTags[old] {`; lines 513-515 `for k := 1; used[final] || (reservedStableTags[final] && final != identityTag); k++ { final = fmt.Sprintf("%s-%d", candidate, k) }` (source of the `-1` suffix); lines 408-420 build `prevTagByIndex` from array position only; lines 439-444 persist the **filtered** `kept` slice while line 430 persists identities for the **unfiltered** parse; `internal/database/model/model.go:1260` `LinkIdentities string \`json:"-"\``; test `TestAssignStableTags/falls_back_to_the_previous_tag_at_the_same_position` at `internal/web/service/outbound_subscription_test.go:194` pins the positional fallback as intended; `internal/sub/json_service.go:537` and `docs/content/docs/en/operations/outbounds-routing.mdx:156` establish that balancer selectors are prefixes; `git tag --contains 8abe87b6` → `v3.8.0`, `dev-latest`. Not determined: Whether the reporter's exact one-position shift is reachable on v3.8.0 or is pre-v3.8.0 state frozen in the database. Settled by the `link_identities` / `last_fetched_outbounds` values of that row (query above). Suggested fix: Reserve the *previous* tag set, not just the tags of identities still in the batch, so a brand-new link never inherits a removed link's tag via `prevTagByIndex` — or drop the positional fallback for links whose identity was never seen. Building `prevTagByIndex` from the same unfiltered list that `link_identities` is built from would also remove the off-by-one after a core-rejected outbound. Separately, a way to reset a subscription's stored identity map without deleting the subscription would let users out of an already-swapped state. *This reply was generated automatically; a maintainer may follow up.* <!-- claude-issue:analyst -->
Author
Owner

@dicreat commented on GitHub (Sep 15, 2026):

sqlite3 /etc/x-ui/x-ui.db
"SELECT id, tag_prefix, link_identities, last_fetched_outbounds FROM outbound_subscriptions;"

3|sub|
{
"vless:vless:// ... &type=tcp": "sub-sweden-1",
"vless:vless:// .... &type=tcp": "sub-germany",
"vless:vless:// ... &type=tcp": "sub-sweden"
}

<!-- gh-comment-id:5681221697 --> @dicreat commented on GitHub (Sep 15, 2026): sqlite3 /etc/x-ui/x-ui.db \ "SELECT id, tag_prefix, link_identities, last_fetched_outbounds FROM outbound_subscriptions;" 3|sub| { "vless:vless:// ... &type=tcp": "sub-sweden-1", "vless:vless:// .... &type=tcp": "sub-germany", "vless:vless:// ... &type=tcp": "sub-sweden" }
Author
Owner

@github-actions[bot] commented on GitHub (Sep 15, 2026):

Thanks — that row settles it, and it upgrades the finding.

Two things are now confirmed: (1) the wrong mapping is frozen in your database, which is why upgrading did not repair it, and (2) I can now name the mechanism that let it happen on v3.8.0 — for Reality inbounds a 3x-ui subscription serves a different link on every request, so the consuming panel never recognises a server it already knows and falls back to matching by list position.

1. What your row shows

The JSON you pasted is the third column, link_identities — the identity → tag map written at internal/web/service/outbound_subscription.go:445 (sub.LinkIdentities = string(identJSON)). It holds three entries and no sub-france: sub-sweden-1, sub-germany, sub-sweden.

That map is reused unconditionally on every refresh, outbound_subscription.go:489:

if old, ok := prev[id]; ok && old != "" {
	candidate = old

So the mapping you are seeing is a fixed point: each refresh reproduces it exactly. Nothing in the UI or API clears that column (LinkIdentities string \json:"-"`—internal/database/model/model.go:1260`), which is why the panel cannot self-heal. That part of my earlier comment stands.

2. Why identity matching failed in the first place

A vless link's identity is the whole canonical link minus the remark — internal/util/link/outbound.go:282:

identity := "vless:" + u.Scheme + "://" + id + "@" + host + ":" + strconv.Itoa(port) + "?" + canonicalQuery(params)

and params := u.Query() (line 268) is the full query string — sid and sni included.

But 3x-ui's own subscription server picks both of those at random on every single request for a reality inbound, internal/sub/service.go:1923 and :1931:

params["sni"], _ = sNames[random.Num(len(sNames))].(string)
...
params["sid"], _ = shortIds[random.Num(len(shortIds))].(string)

(the JSON subscription does the same at internal/sub/json_service.go:795 and :801). And a freshly created reality inbound gets eight shortIds by default — frontend/src/utils/index.ts:230-232:

const lengths = [2, 4, 6, 8, 10, 12, 14, 16].sort(() => Math.random() - 0.5);
return lengths.map((len) => this.randomSeq(len, { type: 'hex' })).join(',');

written into shortIds whenever the security dropdown is switched to reality (frontend/src/pages/inbounds/form/useSecurityActions.ts:337).

The consequence chain, all on current main:

  1. Upstream link text changes on every fetch → every identity is new → prev never matches.
  2. reservedStableTags is built only from identities found in prev (outbound_subscription.go:476), so it stays empty — the v3.8.0 guard from 8abe87b6 never engages.
  3. Every tag is therefore assigned by the positional fallback, outbound_subscription.go:495:
    if old, ok := prevTagByIndex[i]; ok && old != "" && !reservedStableTags[old] {
    	candidate = old
    
  4. Add a server anywhere but the end of the list and every tag slides up one position; the server pushed off the end gets a fresh tag from its remark, which collides and becomes -1 (outbound_subscription.go:512-515).

Step 4 with the new France landing at index 0 produces your table exactly: index 0 inherits sub-germany, index 1 inherits sub-sweden, index 2 has no previous tag at that index, so link.SuggestTag("sub", "Sweden", 2) → sub-sweden, which is already used → sub-sweden-1.

What I still cannot confirm: that your upstream is reality-with-multiple-sid/sni. Your identity strings are redacted exactly where sid= would be. One check — run this twice and compare:

curl -s '<your subscription URL>' | base64 -d | grep -o 'sid=[^&]*'

Different values between the two runs means this is your case.

3. Getting your panel back — and keeping it there

  1. Clear the stored state. As before, and it must be both columns, since last_fetched_outbounds is what drives the positional fallback:

    systemctl stop x-ui
    cp /etc/x-ui/x-ui.db /etc/x-ui/x-ui.db.bak
    sqlite3 /etc/x-ui/x-ui.db \
      "UPDATE outbound_subscriptions SET link_identities='', last_fetched_outbounds='' WHERE id=3;"
    systemctl start x-ui
    

    Then press Refresh on the subscription. Deleting and re-adding the subscription has the same effect.

  2. Stop the churn at the source, if the upstream panels are yours. On each upstream reality inbound, keep a single shortId and a single SNI. random.Num(1) always returns 0, so the served link becomes byte-stable, identity reuse starts working, and tags then survive an add/remove. Without this, the same drift returns the next time a server is added or removed upstream.

  3. Re-select the balancer members afterwards, and avoid leaving sub-sweden and sub-sweden-1 side by side — a balancer selector is a tag prefix, which is the separate reason sub-sweden-1 showed up as the active route (my earlier comment, and #5560).

@MHSanaei — flagging this one: the positional fallback is not a rare last resort, it is the only path taken whenever the upstream is a default 3x-ui reality inbound.


Verdict: Confirmed bug
Severity: High
Confidence: High
Root cause: Subscription tag stability depends on the link text being identical between fetches — internal/util/link/outbound.go:282 builds the identity from canonicalQuery(params), i.e. the full query string — but internal/sub/service.go:1923 and :1931 re-randomise sni and sid on every request for a reality inbound, and frontend/src/utils/index.ts:230-232 gives a new reality inbound eight shortIds by default. prev therefore never matches, reservedStableTags (internal/web/service/outbound_subscription.go:476) stays empty, the 8abe87b6 guard never fires, and every tag is assigned by list position at internal/web/service/outbound_subscription.go:495. Any insertion or removal above the end of the list then re-points existing tags — and the balancers that select them — at physically different servers. The identity feature dates to 0daedd3d (feat: subscription-based outbounds with auto-update, #5037).
Already fixed: No. 8abe87b6 ("fix(outbounds): preserve stable subscription tags", #6345, in v3.8.0) only protects tags of identities that are still matched, so it is inert on this path. Still present on the default branch; the only commits on the file since are 9f07951b (user agents).
Duplicate of: None. Related: #5560 (balancer selector is a prefix match — explains the sub-sweden-1 active route), #6341 (Netherlands-1, same family, fixed by 8abe87b6).
Evidence: internal/util/link/outbound.go:268 params := u.Query() and :282 identity := "vless:" + ... + "?" + canonicalQuery(params); internal/sub/service.go:1923 params["sni"], _ = sNames[random.Num(len(sNames))].(string) and :1931 params["sid"], _ = shortIds[random.Num(len(shortIds))].(string); internal/sub/json_service.go:795/:801 (same for the JSON sub); frontend/src/utils/index.ts:230-232 (eight shortIds) consumed at frontend/src/pages/inbounds/form/useSecurityActions.ts:337; internal/web/service/outbound_subscription.go:476 (reserved set built only from matched identities), :489 (unconditional identity reuse), :495 (positional fallback), :512-515 (the -N collision suffix), :445 (the map is persisted); internal/database/model/model.go:1260 LinkIdentities string \json:"-"`— no reset path; reporter's row:link_identitiesholds three entries, none of themsub-france. deriveSpiderX (internal/sub/service.go:1963) shows the deterministic-per-client pattern already exists in this file. Not determined: Whether this reporter's upstream is specifically a reality inbound with more than one shortId/SNI — the sid=part of their identity strings is redacted. Settled by fetching the subscription URL twice and diffing thesid=/sni=` values.

Suggested fix: Exclude the parameters the subscription server deliberately randomises (sid, sni) from the identity string in ParseLink, or make the subscription's choice deterministic per client the way deriveSpiderX already does — either one restores identity reuse and takes the positional fallback off the common path. Independently, reserving the entire previous tag set rather than only the tags of still-matched identities would stop a new link from inheriting a removed link's tag. A way to clear a subscription's stored mapping from the UI would let users out of an already-swapped state without hand-editing the database.

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

<!-- gh-comment-id:5681318985 --> @github-actions[bot] commented on GitHub (Sep 15, 2026): Thanks — that row settles it, and it upgrades the finding. Two things are now confirmed: (1) the wrong mapping is **frozen in your database**, which is why upgrading did not repair it, and (2) I can now name the mechanism that let it happen on v3.8.0 — for **Reality** inbounds a 3x-ui subscription serves a *different link on every request*, so the consuming panel never recognises a server it already knows and falls back to matching **by list position**. ## 1. What your row shows The JSON you pasted is the third column, `link_identities` — the identity → tag map written at `internal/web/service/outbound_subscription.go:445` (`sub.LinkIdentities = string(identJSON)`). It holds three entries and **no `sub-france`**: `sub-sweden-1`, `sub-germany`, `sub-sweden`. That map is reused unconditionally on every refresh, `outbound_subscription.go:489`: ```go if old, ok := prev[id]; ok && old != "" { candidate = old ``` So the mapping you are seeing is a fixed point: each refresh reproduces it exactly. Nothing in the UI or API clears that column (`LinkIdentities string \`json:"-"\`` — `internal/database/model/model.go:1260`), which is why the panel cannot self-heal. That part of my earlier comment stands. ## 2. Why identity matching failed in the first place A vless link's identity is the whole canonical link minus the remark — `internal/util/link/outbound.go:282`: ```go identity := "vless:" + u.Scheme + "://" + id + "@" + host + ":" + strconv.Itoa(port) + "?" + canonicalQuery(params) ``` and `params := u.Query()` (line 268) is the **full** query string — `sid` and `sni` included. But 3x-ui's own subscription server picks both of those **at random on every single request** for a reality inbound, `internal/sub/service.go:1923` and `:1931`: ```go params["sni"], _ = sNames[random.Num(len(sNames))].(string) ... params["sid"], _ = shortIds[random.Num(len(shortIds))].(string) ``` (the JSON subscription does the same at `internal/sub/json_service.go:795` and `:801`). And a freshly created reality inbound gets **eight** shortIds by default — `frontend/src/utils/index.ts:230-232`: ```ts const lengths = [2, 4, 6, 8, 10, 12, 14, 16].sort(() => Math.random() - 0.5); return lengths.map((len) => this.randomSeq(len, { type: 'hex' })).join(','); ``` written into `shortIds` whenever the security dropdown is switched to reality (`frontend/src/pages/inbounds/form/useSecurityActions.ts:337`). The consequence chain, all on current `main`: 1. Upstream link text changes on every fetch → **every identity is new** → `prev` never matches. 2. `reservedStableTags` is built only from identities found in `prev` (`outbound_subscription.go:476`), so it stays **empty** — the v3.8.0 guard from `8abe87b6` never engages. 3. Every tag is therefore assigned by the positional fallback, `outbound_subscription.go:495`: ```go if old, ok := prevTagByIndex[i]; ok && old != "" && !reservedStableTags[old] { candidate = old ``` 4. Add a server anywhere but the end of the list and every tag slides up one position; the server pushed off the end gets a fresh tag from its remark, which collides and becomes `-1` (`outbound_subscription.go:512-515`). Step 4 with the new France landing at index 0 produces your table exactly: index 0 inherits `sub-germany`, index 1 inherits `sub-sweden`, index 2 has no previous tag at that index, so `link.SuggestTag("sub", "Sweden", 2)` → `sub-sweden`, which is already used → **`sub-sweden-1`**. **What I still cannot confirm:** that your upstream is reality-with-multiple-`sid`/`sni`. Your identity strings are redacted exactly where `sid=` would be. One check — run this twice and compare: ```bash curl -s '<your subscription URL>' | base64 -d | grep -o 'sid=[^&]*' ``` Different values between the two runs means this is your case. ## 3. Getting your panel back — and keeping it there 1. **Clear the stored state.** As before, and it must be **both** columns, since `last_fetched_outbounds` is what drives the positional fallback: ```bash systemctl stop x-ui cp /etc/x-ui/x-ui.db /etc/x-ui/x-ui.db.bak sqlite3 /etc/x-ui/x-ui.db \ "UPDATE outbound_subscriptions SET link_identities='', last_fetched_outbounds='' WHERE id=3;" systemctl start x-ui ``` Then press **Refresh** on the subscription. Deleting and re-adding the subscription has the same effect. 2. **Stop the churn at the source, if the upstream panels are yours.** On each upstream reality inbound, keep a **single** shortId and a **single** SNI. `random.Num(1)` always returns `0`, so the served link becomes byte-stable, identity reuse starts working, and tags then survive an add/remove. Without this, the same drift returns the next time a server is added or removed upstream. 3. **Re-select the balancer members afterwards**, and avoid leaving `sub-sweden` and `sub-sweden-1` side by side — a balancer selector is a tag *prefix*, which is the separate reason `sub-sweden-1` showed up as the active route (my earlier comment, and #5560). @MHSanaei — flagging this one: the positional fallback is not a rare last resort, it is the only path taken whenever the upstream is a default 3x-ui reality inbound. --- Verdict: Confirmed bug Severity: High Confidence: High Root cause: Subscription tag stability depends on the link text being identical between fetches — `internal/util/link/outbound.go:282` builds the identity from `canonicalQuery(params)`, i.e. the full query string — but `internal/sub/service.go:1923` and `:1931` re-randomise `sni` and `sid` on **every** request for a reality inbound, and `frontend/src/utils/index.ts:230-232` gives a new reality inbound eight shortIds by default. `prev` therefore never matches, `reservedStableTags` (`internal/web/service/outbound_subscription.go:476`) stays empty, the `8abe87b6` guard never fires, and every tag is assigned by list position at `internal/web/service/outbound_subscription.go:495`. Any insertion or removal above the end of the list then re-points existing tags — and the balancers that select them — at physically different servers. The identity feature dates to `0daedd3d` (feat: subscription-based outbounds with auto-update, #5037). Already fixed: No. `8abe87b6` ("fix(outbounds): preserve stable subscription tags", #6345, in v3.8.0) only protects tags of identities that are *still matched*, so it is inert on this path. Still present on the default branch; the only commits on the file since are `9f07951b` (user agents). Duplicate of: None. Related: #5560 (balancer selector is a prefix match — explains the `sub-sweden-1` active route), #6341 (`Netherlands-1`, same family, fixed by `8abe87b6`). Evidence: `internal/util/link/outbound.go:268` `params := u.Query()` and `:282` `identity := "vless:" + ... + "?" + canonicalQuery(params)`; `internal/sub/service.go:1923` `params["sni"], _ = sNames[random.Num(len(sNames))].(string)` and `:1931` `params["sid"], _ = shortIds[random.Num(len(shortIds))].(string)`; `internal/sub/json_service.go:795`/`:801` (same for the JSON sub); `frontend/src/utils/index.ts:230-232` (eight shortIds) consumed at `frontend/src/pages/inbounds/form/useSecurityActions.ts:337`; `internal/web/service/outbound_subscription.go:476` (reserved set built only from matched identities), `:489` (unconditional identity reuse), `:495` (positional fallback), `:512-515` (the `-N` collision suffix), `:445` (the map is persisted); `internal/database/model/model.go:1260` `LinkIdentities string \`json:"-"\`` — no reset path; reporter's row: `link_identities` holds three entries, none of them `sub-france`. `deriveSpiderX` (`internal/sub/service.go:1963`) shows the deterministic-per-client pattern already exists in this file. Not determined: Whether this reporter's upstream is specifically a reality inbound with more than one shortId/SNI — the `sid=` part of their identity strings is redacted. Settled by fetching the subscription URL twice and diffing the `sid=`/`sni=` values. Suggested fix: Exclude the parameters the subscription server deliberately randomises (`sid`, `sni`) from the identity string in `ParseLink`, or make the subscription's choice deterministic per client the way `deriveSpiderX` already does — either one restores identity reuse and takes the positional fallback off the common path. Independently, reserving the *entire* previous tag set rather than only the tags of still-matched identities would stop a new link from inheriting a removed link's tag. A way to clear a subscription's stored mapping from the UI would let users out of an already-swapped state without hand-editing the database. *This reply was generated automatically; a maintainer may follow up.* <!-- claude-issue:analyst -->
Author
Owner

@dicreat commented on GitHub (Sep 15, 2026):

root@vm4619404:~# curl -s 'https://my-sub-link/sub-link' | base64 -d | grep -o 'sid=[^&]*'
sid=0b683fcd
sid=7702fcb6696d
sid=23ba7330a3
root@vm4619404:~# curl -s 'https://my-sub-link/sub-link' | base64 -d | grep -o 'sid=[^&]*'
sid=556c804f2593f4
sid=7702fcb6696d
sid=f7a581628295
root@vm4619404:~# curl -s 'https://my-sub-link/sub-link' | base64 -d | grep -o 'sid=[^&]*'
sid=f2d5
sid=73
sid=fbbb68
root@vm4619404:~# curl -s 'https://my-sub-link/sub-link' | base64 -d | grep -o 'sid=[^&]*'
sid=7d
sid=29e316f2aa
sid=19a9
root@vm4619404:~# curl -s 'https://my-sub-link/sub-link' | base64 -d | grep -o 'sid=[^&]*'
sid=d60d354e1f
sid=9171
sid=f7a581628295

<!-- gh-comment-id:5681540532 --> @dicreat commented on GitHub (Sep 15, 2026): ``` root@vm4619404:~# curl -s 'https://my-sub-link/sub-link' | base64 -d | grep -o 'sid=[^&]*' sid=0b683fcd sid=7702fcb6696d sid=23ba7330a3 root@vm4619404:~# curl -s 'https://my-sub-link/sub-link' | base64 -d | grep -o 'sid=[^&]*' sid=556c804f2593f4 sid=7702fcb6696d sid=f7a581628295 root@vm4619404:~# curl -s 'https://my-sub-link/sub-link' | base64 -d | grep -o 'sid=[^&]*' sid=f2d5 sid=73 sid=fbbb68 root@vm4619404:~# curl -s 'https://my-sub-link/sub-link' | base64 -d | grep -o 'sid=[^&]*' sid=7d sid=29e316f2aa sid=19a9 root@vm4619404:~# curl -s 'https://my-sub-link/sub-link' | base64 -d | grep -o 'sid=[^&]*' sid=d60d354e1f sid=9171 sid=f7a581628295 ```
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#4395
No description provided.