[PR #5674] [MERGED] fix(balancers): keep mixed strategies on one observer #5954

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

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/5674
Author: @nima1024m
Created: 6/30/2026
Status: ✅ Merged
Merged: 7/2/2026
Merged by: @MHSanaei

Base: main ← Head: fix-mixed-observatory-sync


📝 Commits (5)

  • bfbc3af fix(balancers): keep mixed strategies on one observer
  • edb44ac test(balancers): cover observer strategy combinations
  • 5d002c5 fix(balancers): clarify observer empty state
  • 3347b24 fix(balancers): remove mixed observer switch
  • 2519465 test(balancers): cover observer cleanup on deletion

📊 Changes

19 files changed (+496 additions, -63 deletions)

View changed files

📝 frontend/src/pages/xray/balancers/BalancersTab.tsx (+0 -1)
📝 frontend/src/pages/xray/balancers/ObservatorySettingsTab.tsx (+13 -21)
📝 frontend/src/pages/xray/balancers/balancer-helpers.ts (+29 -23)
📝 frontend/src/test/balancer-observatory-sync.test.ts (+260 -5)
➕ frontend/src/test/observatory-settings-tab.test.tsx (+47 -0)
📝 frontend/src/test/routing-reference-cleanup.test.ts (+121 -0)
📝 internal/web/translation/ar-EG.json (+2 -1)
📝 internal/web/translation/en-US.json (+2 -1)
📝 internal/web/translation/es-ES.json (+2 -1)
📝 internal/web/translation/fa-IR.json (+2 -1)
📝 internal/web/translation/id-ID.json (+2 -1)
📝 internal/web/translation/ja-JP.json (+2 -1)
📝 internal/web/translation/pt-BR.json (+2 -1)
📝 internal/web/translation/ru-RU.json (+2 -1)
📝 internal/web/translation/tr-TR.json (+2 -1)
📝 internal/web/translation/uk-UA.json (+2 -1)
📝 internal/web/translation/vi-VN.json (+2 -1)
📝 internal/web/translation/zh-CN.json (+2 -1)
📝 internal/web/translation/zh-TW.json (+2 -1)

📄 Description

Summary

This PR fixes how the Xray balancer editor manages observatory and burstObservatory when different balancer strategies are mixed in the same config.

The panel now keeps exactly one observer block active:

  • no observer for random or roundRobin balancers without a fallback
  • burstObservatory for random or roundRobin balancers with fallbackTag
  • observatory for leastPing when it is the only observer-backed strategy
  • burstObservatory for leastLoad
  • burstObservatory for mixed configs where leastPing is combined with any burst-required strategy

Why

Xray exposes both observatory and burstObservatory through the same global extension.Observatory dependency. If the generated config contains both blocks, Xray may resolve the regular observatory first. That can leave burst-required strategies, such as leastLoad or fallback random / roundRobin, without the burst health-ping behavior they need.

Because of that, disjoint selectors do not make it safe to keep one regular observer and one burst observer at the same time. The config should choose one observer type globally, then include the selectors for all balancers that need observer data.

Changes

  • Updated balancer observer sync so burst-required strategies take precedence globally.
  • Included leastPing selectors in burstObservatory.subjectSelector when any burst-required balancer exists.
  • Removed stale observatory when switching to burst mode, and removed stale burstObservatory when only leastPing remains.
  • Kept fallback-free random and roundRobin balancers observer-free so they remain simple routing changes.
  • Removed the Observatory / Burst Observatory switch from the settings UI because only one observer type is valid at a time.
  • Added a warning for legacy configs that still contain both observer blocks, explaining that saving balancers will normalize the config to one observer.
  • Clarified the empty Observatory tab text so it describes the actual auto-managed cases.
  • Added regression tests for standalone, mixed, stale-observer, deletion, outbound-cascade, fallback, and UI cases.

Deletion and Cascade Behavior

The direct balancer deletion and outbound deletion cascade paths both call the same observer sync logic. The new tests cover these important cases:

  • deleting the last leastPing balancer removes observatory
  • deleting the last leastLoad or fallback balancer removes burstObservatory
  • deleting the last burst-required balancer while leastPing remains switches from burstObservatory to observatory
  • deleting leastPing while a burst-required balancer remains keeps burstObservatory and removes the leastPing selector
  • deleting an outbound that empties a balancer selector applies the same observer normalization after the cascaded balancer removal

User Impact

Users no longer need to choose between Observatory and Burst Observatory manually. The panel derives the correct observer from the balancer strategies and selectors. Existing legacy configs with both observer blocks are still shown, but the UI warns that the mixed state is not supported and will be normalized on save.

Validation

  • npm test passed: 46 files / 667 tests
  • npm test -- src/test/routing-reference-cleanup.test.ts src/test/balancer-observatory-sync.test.ts src/test/observatory-settings-tab.test.tsx passed: 65 tests
  • npm run lint passed with one existing unrelated warning in SettingsPage.tsx
  • translation JSON parse check passed
  • git diff --check passed
  • Manual testing

🔄 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/5674 **Author:** [@nima1024m](https://github.com/nima1024m) **Created:** 6/30/2026 **Status:** ✅ Merged **Merged:** 7/2/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `fix-mixed-observatory-sync` --- ### 📝 Commits (5) - [`bfbc3af`](https://github.com/MHSanaei/3x-ui/commit/bfbc3af7639d025d47588c87bb62ba84657769e3) fix(balancers): keep mixed strategies on one observer - [`edb44ac`](https://github.com/MHSanaei/3x-ui/commit/edb44acf32f4f695cd202ce84b0f369686e60ec9) test(balancers): cover observer strategy combinations - [`5d002c5`](https://github.com/MHSanaei/3x-ui/commit/5d002c5118b2fcf2cfede7c8bea4565eaaab3974) fix(balancers): clarify observer empty state - [`3347b24`](https://github.com/MHSanaei/3x-ui/commit/3347b24ff21904843f6118eb127780ee5a67ad5e) fix(balancers): remove mixed observer switch - [`2519465`](https://github.com/MHSanaei/3x-ui/commit/25194657eca812fd2d74affa147af1b372fc2c9d) test(balancers): cover observer cleanup on deletion ### 📊 Changes **19 files changed** (+496 additions, -63 deletions) <details> <summary>View changed files</summary> 📝 `frontend/src/pages/xray/balancers/BalancersTab.tsx` (+0 -1) 📝 `frontend/src/pages/xray/balancers/ObservatorySettingsTab.tsx` (+13 -21) 📝 `frontend/src/pages/xray/balancers/balancer-helpers.ts` (+29 -23) 📝 `frontend/src/test/balancer-observatory-sync.test.ts` (+260 -5) ➕ `frontend/src/test/observatory-settings-tab.test.tsx` (+47 -0) 📝 `frontend/src/test/routing-reference-cleanup.test.ts` (+121 -0) 📝 `internal/web/translation/ar-EG.json` (+2 -1) 📝 `internal/web/translation/en-US.json` (+2 -1) 📝 `internal/web/translation/es-ES.json` (+2 -1) 📝 `internal/web/translation/fa-IR.json` (+2 -1) 📝 `internal/web/translation/id-ID.json` (+2 -1) 📝 `internal/web/translation/ja-JP.json` (+2 -1) 📝 `internal/web/translation/pt-BR.json` (+2 -1) 📝 `internal/web/translation/ru-RU.json` (+2 -1) 📝 `internal/web/translation/tr-TR.json` (+2 -1) 📝 `internal/web/translation/uk-UA.json` (+2 -1) 📝 `internal/web/translation/vi-VN.json` (+2 -1) 📝 `internal/web/translation/zh-CN.json` (+2 -1) 📝 `internal/web/translation/zh-TW.json` (+2 -1) </details> ### 📄 Description ## Summary This PR fixes how the Xray balancer editor manages `observatory` and `burstObservatory` when different balancer strategies are mixed in the same config. The panel now keeps exactly one observer block active: - no observer for `random` or `roundRobin` balancers without a fallback - `burstObservatory` for `random` or `roundRobin` balancers with `fallbackTag` - `observatory` for `leastPing` when it is the only observer-backed strategy - `burstObservatory` for `leastLoad` - `burstObservatory` for mixed configs where `leastPing` is combined with any burst-required strategy ## Why Xray exposes both `observatory` and `burstObservatory` through the same global `extension.Observatory` dependency. If the generated config contains both blocks, Xray may resolve the regular observatory first. That can leave burst-required strategies, such as `leastLoad` or fallback `random` / `roundRobin`, without the burst health-ping behavior they need. Because of that, disjoint selectors do not make it safe to keep one regular observer and one burst observer at the same time. The config should choose one observer type globally, then include the selectors for all balancers that need observer data. ## Changes - Updated balancer observer sync so burst-required strategies take precedence globally. - Included `leastPing` selectors in `burstObservatory.subjectSelector` when any burst-required balancer exists. - Removed stale `observatory` when switching to burst mode, and removed stale `burstObservatory` when only `leastPing` remains. - Kept fallback-free `random` and `roundRobin` balancers observer-free so they remain simple routing changes. - Removed the Observatory / Burst Observatory switch from the settings UI because only one observer type is valid at a time. - Added a warning for legacy configs that still contain both observer blocks, explaining that saving balancers will normalize the config to one observer. - Clarified the empty Observatory tab text so it describes the actual auto-managed cases. - Added regression tests for standalone, mixed, stale-observer, deletion, outbound-cascade, fallback, and UI cases. ## Deletion and Cascade Behavior The direct balancer deletion and outbound deletion cascade paths both call the same observer sync logic. The new tests cover these important cases: - deleting the last `leastPing` balancer removes `observatory` - deleting the last `leastLoad` or fallback balancer removes `burstObservatory` - deleting the last burst-required balancer while `leastPing` remains switches from `burstObservatory` to `observatory` - deleting `leastPing` while a burst-required balancer remains keeps `burstObservatory` and removes the `leastPing` selector - deleting an outbound that empties a balancer selector applies the same observer normalization after the cascaded balancer removal ## User Impact Users no longer need to choose between Observatory and Burst Observatory manually. The panel derives the correct observer from the balancer strategies and selectors. Existing legacy configs with both observer blocks are still shown, but the UI warns that the mixed state is not supported and will be normalized on save. ## Validation - `npm test` passed: 46 files / 667 tests - `npm test -- src/test/routing-reference-cleanup.test.ts src/test/balancer-observatory-sync.test.ts src/test/observatory-settings-tab.test.tsx` passed: 65 tests - `npm run lint` passed with one existing unrelated warning in `SettingsPage.tsx` - translation JSON parse check passed - `git diff --check` passed - Manual testing --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:05:16 +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#5954
No description provided.