[GH-ISSUE #5681] [Bug]: LeastPing is limited to Obserbatory only #3952

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

Originally created by @ilya-practicum on GitHub (Jun 30, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5681

Describe the bug

3x-ui should allow to use burstObseravtory for LeastPing balancer strategy since xray support it. Since 3.4.2 pull request https://github.com/MHSanaei/3x-ui/pull/5627 was merged that limits users to Observatory only if LeastPing balancer is used. The full discussion with pull request author is provided in the pull request itself.

I disagree about the situation. Xray provides burstObservatory and make it possible to be used with LeastPing balancer. There are scenarious where burstObservatory is used for LeastPing. Here is one config when burstObservatory may be useful for LeastPing balancer:
You have two outbounds with little difference in ping. If you use Observatory then oubounds will be constantly switching because of little ping variations. You may switch to burstObservatory then ping will be calculated as average value of series of pings and that will prevent unnecessary constant outbound switching.

Please, let user to decide what to choose - Observatory or BurstObservatory. For now leastPing supports burstObservatory in xray so it should be added as an option to leastPing in 3x-ui also. BurstObservatory uses average of ping series to calculate Delay and it may be very useful. It also provides connectivity and httpMethod features that are useful also.

How to reproduce the problem

  1. Create balancer with LeastPing strategy
  2. You are limited to Observatory only, burstObservatory is not allowed

Expected behavior

You should be able to setup burstObservatory for LeastPing strategy

Actual behavior

No response

Relevant logs


Screenshots

No response

3x-ui version

3.4.2

Xray-core version

No response

How did you install 3x-ui?

Docker / Docker Compose

Operating system

Debian 13

Which parts of the panel are affected?

No response

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 @ilya-practicum on GitHub (Jun 30, 2026). Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5681 ### Describe the bug 3x-ui should allow to use burstObseravtory for LeastPing balancer strategy since xray support it. Since 3.4.2 pull request https://github.com/MHSanaei/3x-ui/pull/5627 was merged that limits users to Observatory only if LeastPing balancer is used. The full discussion with pull request author is provided in the pull request itself. I disagree about the situation. Xray provides burstObservatory and make it possible to be used with LeastPing balancer. There are scenarious where burstObservatory is used for LeastPing. Here is one config when burstObservatory may be useful for LeastPing balancer: You have two outbounds with little difference in ping. If you use Observatory then oubounds will be constantly switching because of little ping variations. You may switch to burstObservatory then ping will be calculated as average value of series of pings and that will prevent unnecessary constant outbound switching. Please, let user to decide what to choose - Observatory or BurstObservatory. For now leastPing supports burstObservatory in xray so it should be added as an option to leastPing in 3x-ui also. BurstObservatory uses average of ping series to calculate Delay and it may be very useful. It also provides connectivity and httpMethod features that are useful also. ### How to reproduce the problem 1. Create balancer with LeastPing strategy 2. You are limited to Observatory only, burstObservatory is not allowed ### Expected behavior You should be able to setup burstObservatory for LeastPing strategy ### Actual behavior _No response_ ### Relevant logs ```shell ``` ### Screenshots _No response_ ### 3x-ui version 3.4.2 ### Xray-core version _No response_ ### How did you install 3x-ui? Docker / Docker Compose ### Operating system Debian 13 ### Which parts of the panel are affected? _No response_ ### 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:36:07 +07:00
Author
Owner

@github-actions[bot] commented on GitHub (Jun 30, 2026):

The reported behaviour is intentional as of 3.4.2 (PR #5627), but the use case you describe is technically valid and the restriction is worth revisiting. Here is what the source shows.

What the code does today

syncObservatories in frontend/src/pages/xray/balancers/balancer-helpers.ts (lines 50–56) hard-wires the mapping:

  • leastPing → observatory (standard, single-sample delay)
  • leastLoad → burstObservatory
  • random / roundRobin with fallbackTag → burstObservatory

When leastPing balancers exist, the function unconditionally creates/updates the observatory block and never touches burstObservatory on their behalf.

The design rationale from PR #5627

The PR author @nima1024m explained in the PR discussion that:

  1. leastPing in xray-core reads only the Alive and Delay fields from whatever extension.Observatory provider is registered; regular observatory already supplies both, so burst is not strictly required.
  2. Both observatory and burstObservatory register globally as the same extension.Observatory dependency in xray-core. Running both blocks in the same config risks Xray resolving the regular observer first and leaving burst-requiring strategies (leastLoad, fallback random/roundRobin) without averaged health-ping data.

Why your use case is valid

burstObservatory.pingConfig.sampling causes Delay to be calculated as an average over a series of probes rather than a single round-trip. leastPing selects the outbound with the smallest Delay, so it will consume that averaged value correctly — the PR author confirmed this in the #5627 comments: "leastPing can work with burstObservatory, because burstObservatory also implements the same extension.Observatory interface."

Your scenario (two outbounds with small ping variance causing constant oscillation) is a real edge case where the averaging behaviour of burstObservatory provides stability that regular observatory cannot.

Pending related work

PR #5674 (open, not yet merged) addresses mixed-strategy configs by upgrading to a single burstObservatory whenever any burst-required strategy is present and including leastPing selectors in that block. It does not add a user-facing choice for leastPing-only configs; those would still use regular observatory.

What would need to change for this request

The syncObservatories function and the observatory settings UI in ObservatorySettingsTab.tsx would need to allow the user to select the observer type for a leastPing-only config. The constraint to keep in mind is the single-global-observer limitation: if the user picks burstObservatory for leastPing, the observatory block must be absent (and vice versa), regardless of which strategies exist.

This is a product decision for the maintainers. The technical capability exists in xray-core; the question is whether the panel should expose the choice explicitly or default to burstObservatory for all observer-backed strategies.


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

<!-- gh-comment-id:4842294682 --> @github-actions[bot] commented on GitHub (Jun 30, 2026): The reported behaviour is intentional as of 3.4.2 (PR #5627), but the use case you describe is technically valid and the restriction is worth revisiting. Here is what the source shows. **What the code does today** `syncObservatories` in `frontend/src/pages/xray/balancers/balancer-helpers.ts` (lines 50–56) hard-wires the mapping: - `leastPing` → `observatory` (standard, single-sample delay) - `leastLoad` → `burstObservatory` - `random` / `roundRobin` with `fallbackTag` → `burstObservatory` When `leastPing` balancers exist, the function unconditionally creates/updates the `observatory` block and never touches `burstObservatory` on their behalf. **The design rationale from PR #5627** The PR author `@nima1024m` explained in the PR discussion that: 1. `leastPing` in xray-core reads only the `Alive` and `Delay` fields from whatever `extension.Observatory` provider is registered; regular `observatory` already supplies both, so burst is not strictly required. 2. Both `observatory` and `burstObservatory` register globally as the same `extension.Observatory` dependency in xray-core. Running both blocks in the same config risks Xray resolving the regular observer first and leaving burst-requiring strategies (`leastLoad`, fallback `random`/`roundRobin`) without averaged health-ping data. **Why your use case is valid** `burstObservatory.pingConfig.sampling` causes `Delay` to be calculated as an average over a series of probes rather than a single round-trip. `leastPing` selects the outbound with the smallest `Delay`, so it will consume that averaged value correctly — the PR author confirmed this in the #5627 comments: "leastPing can work with burstObservatory, because burstObservatory also implements the same extension.Observatory interface." Your scenario (two outbounds with small ping variance causing constant oscillation) is a real edge case where the averaging behaviour of `burstObservatory` provides stability that regular `observatory` cannot. **Pending related work** PR #5674 (open, not yet merged) addresses mixed-strategy configs by upgrading to a single `burstObservatory` whenever any burst-required strategy is present and including `leastPing` selectors in that block. It does not add a user-facing choice for `leastPing`-only configs; those would still use regular `observatory`. **What would need to change for this request** The `syncObservatories` function and the observatory settings UI in `ObservatorySettingsTab.tsx` would need to allow the user to select the observer type for a `leastPing`-only config. The constraint to keep in mind is the single-global-observer limitation: if the user picks `burstObservatory` for `leastPing`, the `observatory` block must be absent (and vice versa), regardless of which strategies exist. This is a product decision for the maintainers. The technical capability exists in xray-core; the question is whether the panel should expose the choice explicitly or default to `burstObservatory` for all observer-backed strategies. --- *This reply was generated automatically; a maintainer may follow up.*
Author
Owner

@github-actions[bot] commented on GitHub (Jun 30, 2026):

Claude finished @MHSanaei's task in 5m 23s —— View job


Claude's review

Todo list

  • Read issue body and prior automated comment
  • Read balancer-helpers.ts and the Observatory settings UI
  • Check PR #5627 (merged restriction) and PR #5674 (open, related) for current status
  • Check backend/Go-side involvement (none — confirmed frontend-only)
  • Verify claims about xray-core's extension.Observatory behavior directly against the vendored source
  • Post review findings and recommendation

Verdict

The previous automated comment's conclusion holds up, and I can now confirm it directly against the exact xray-core source vendored in go.mod (github.com/xtls/xray-core v1.260327.1-0.20260627131803-45cf2898ab12), not just the PR discussion. This is a legitimate enhancement request, not a regression — the current restriction is more conservative than xray-core actually requires.

What the vendored xray-core source actually does

  • LeastPingStrategy.PickOutbound (xray-core app/router/strategy_leastping.go) calls RequireFeatures for extension.Observatory, then does:

    if result, ok := observeReport.(*observatory.ObservationResult); ok { ... }
    

    It only needs Alive and Delay off a value that type-asserts to the concrete *observatory.ObservationResult struct — not just anything satisfying the extension.Observatory interface.

  • burst.Observer.GetObservation (app/observatory/burst/burstobserver.go) builds and returns exactly that type:

    func (o *Observer) GetObservation(ctx context.Context) (proto.Message, error) {
        return &observatory.ObservationResult{Status: o.createResult()}, nil
    }
    

    with Delay: value.getStatistics().Average.Milliseconds() — the averaged ping the issue is asking for. So the type assertion in leastPing succeeds against burst's output, and leastPing reads the averaged delay correctly. This is a stronger confirmation than "they implement the same interface" (mentioned in the PR #5627 discussion) — it's the same concrete result struct.

  • The real constraint is in core/xray.go's feature resolver:

    func getFeature(allFeatures []features.Feature, t reflect.Type) features.Feature {
        for _, f := range allFeatures {
            if reflect.TypeOf(f.Type()) == t { return f }
        }
        return nil
    }
    

    Both observatory.Observer.Type() and burst.Observer.Type() return the same extension.ObservatoryType(). If a config contains both an observatory and a burstObservatory app block, every strategy that requires Observatory — leastPing, leastLoad, fallback random/roundRobin — binds to whichever block appears first in config.App; the second block still runs its probe loop but is never consulted by anything. That's the failure mode PR #5627 was guarding against, and it's real.

Conclusion: the single-observer-per-config invariant from #5627 is correct and necessary, but it does not require leastPing specifically to be the one pinned to observatory. A leastPing-only config can run on burstObservatory alone (no observatory block at all) and the strategy will read the averaged delay correctly.

Where the restriction actually lives in 3x-ui

  • frontend/src/pages/xray/balancers/balancer-helpers.ts:50-56 — syncObservatories unconditionally creates/maintains t.observatory whenever any leastPing balancer exists, with no path to t.burstObservatory for a leastPing-only setup.
  • Locked in by frontend/src/test/balancer-observatory-sync.test.ts:89, 'creates observatory for leastPing (required by the strategy)' — the "(required by the strategy)" framing is exactly the assumption this issue disputes, and the source-level check above agrees it's not accurate as stated.
  • ObservatorySettingsTab.tsx is read-only/auto-managed by design (per #5627: "users can't add or delete them by hand"). The Segmented control at lines 224-234 only appears when both blocks already happen to coexist (e.g. legacy data) — it's a display switch, not a way to choose burst for leastPing.

Does the open PR #5674 fix this?

No. #5674 is unmerged, and per its own description it keeps observatory "for leastPing when it is the only observer-backed strategy" — it only changes the mixed-strategy case (leastPing alongside leastLoad/fallback), folding leastPing's selectors into the shared burstObservatory there. A leastPing-only config — this issue's scenario — is untouched by #5674.

If this is implemented

Not a bug fix in the sense of broken current behavior (the merged restriction does prevent a real dual-observer failure mode) — it's an enhancement to relax an unnecessarily strict default. A reasonable approach, for whoever picks this up:

  1. In syncObservatories, stop hardcoding observatory for leastPing: if an observer block already exists (from a prior mixed state, or a user choice), keep using it; only create a fresh observatory as the default when neither block exists yet.
  2. Add an explicit opt-in in ObservatorySettingsTab.tsx (e.g. a toggle, enabled only when no burst-required strategy is already forcing the choice) that converts the active block between observatory and burstObservatory, carrying over subjectSelector.
  3. Update balancer-observatory-sync.test.ts (starting with the test at line 89) and observatory-settings-tab.test.tsx.
  4. Add the new toggle's strings to all 13 locale files in internal/web/translation/.
  5. Sequence after #5674 merges — both PRs touch balancer-helpers.ts and ObservatorySettingsTab.tsx, so building on top of #5674 avoids rebasing a second large diff through the same sync function.

Scope is frontend-only, same as #5627/#5674 — Observatory/Burst settings are raw JSON inside the xrayTemplateConfig setting saved through the existing /panel/api/xray/update route, no Go or DB changes needed.

This is a research-only review on an issue thread, so I haven't made any code changes. Happy to implement this if asked on a PR.

<!-- gh-comment-id:4848535678 --> @github-actions[bot] commented on GitHub (Jun 30, 2026): **Claude finished @MHSanaei's task in 5m 23s** —— [View job](https://github.com/MHSanaei/3x-ui/actions/runs/28480902510) --- ### Claude's review **Todo list** - [x] Read issue body and prior automated comment - [x] Read `balancer-helpers.ts` and the Observatory settings UI - [x] Check PR #5627 (merged restriction) and PR #5674 (open, related) for current status - [x] Check backend/Go-side involvement (none — confirmed frontend-only) - [x] Verify claims about xray-core's `extension.Observatory` behavior directly against the vendored source - [x] Post review findings and recommendation ### Verdict The previous automated comment's conclusion holds up, and I can now confirm it directly against the exact xray-core source vendored in `go.mod` (`github.com/xtls/xray-core v1.260327.1-0.20260627131803-45cf2898ab12`), not just the PR discussion. This is a legitimate enhancement request, not a regression — the current restriction is *more* conservative than xray-core actually requires. ### What the vendored xray-core source actually does - `LeastPingStrategy.PickOutbound` (xray-core `app/router/strategy_leastping.go`) calls `RequireFeatures` for `extension.Observatory`, then does: ```go if result, ok := observeReport.(*observatory.ObservationResult); ok { ... } ``` It only needs `Alive` and `Delay` off a value that type-asserts to the concrete `*observatory.ObservationResult` struct — not just anything satisfying the `extension.Observatory` interface. - `burst.Observer.GetObservation` (`app/observatory/burst/burstobserver.go`) builds and returns exactly that type: ```go func (o *Observer) GetObservation(ctx context.Context) (proto.Message, error) { return &observatory.ObservationResult{Status: o.createResult()}, nil } ``` with `Delay: value.getStatistics().Average.Milliseconds()` — the averaged ping the issue is asking for. So the type assertion in `leastPing` succeeds against burst's output, and `leastPing` reads the averaged delay correctly. This is a stronger confirmation than "they implement the same interface" (mentioned in the PR #5627 discussion) — it's the same concrete result struct. - The real constraint is in `core/xray.go`'s feature resolver: ```go func getFeature(allFeatures []features.Feature, t reflect.Type) features.Feature { for _, f := range allFeatures { if reflect.TypeOf(f.Type()) == t { return f } } return nil } ``` Both `observatory.Observer.Type()` and `burst.Observer.Type()` return the same `extension.ObservatoryType()`. If a config contains *both* an `observatory` and a `burstObservatory` app block, every strategy that requires `Observatory` — `leastPing`, `leastLoad`, fallback `random`/`roundRobin` — binds to whichever block appears first in `config.App`; the second block still runs its probe loop but is never consulted by anything. That's the failure mode PR #5627 was guarding against, and it's real. **Conclusion:** the single-observer-per-config invariant from #5627 is correct and necessary, but it does not require `leastPing` specifically to be the one pinned to `observatory`. A `leastPing`-only config can run on `burstObservatory` alone (no `observatory` block at all) and the strategy will read the averaged delay correctly. ### Where the restriction actually lives in 3x-ui - `frontend/src/pages/xray/balancers/balancer-helpers.ts:50-56` — `syncObservatories` unconditionally creates/maintains `t.observatory` whenever any `leastPing` balancer exists, with no path to `t.burstObservatory` for a leastPing-only setup. - Locked in by `frontend/src/test/balancer-observatory-sync.test.ts:89`, `'creates observatory for leastPing (required by the strategy)'` — the "(required by the strategy)" framing is exactly the assumption this issue disputes, and the source-level check above agrees it's not accurate as stated. - `ObservatorySettingsTab.tsx` is read-only/auto-managed by design (per #5627: "users can't add or delete them by hand"). The `Segmented` control at lines 224-234 only appears when both blocks already happen to coexist (e.g. legacy data) — it's a display switch, not a way to choose burst for `leastPing`. ### Does the open PR #5674 fix this? No. #5674 is unmerged, and per its own description it keeps `observatory` "for `leastPing` when it is the only observer-backed strategy" — it only changes the *mixed*-strategy case (`leastPing` alongside `leastLoad`/fallback), folding `leastPing`'s selectors into the shared `burstObservatory` there. A `leastPing`-only config — this issue's scenario — is untouched by #5674. ### If this is implemented Not a bug fix in the sense of broken current behavior (the merged restriction does prevent a real dual-observer failure mode) — it's an enhancement to relax an unnecessarily strict default. A reasonable approach, for whoever picks this up: 1. In `syncObservatories`, stop hardcoding `observatory` for `leastPing`: if an observer block already exists (from a prior mixed state, or a user choice), keep using it; only create a fresh `observatory` as the default when neither block exists yet. 2. Add an explicit opt-in in `ObservatorySettingsTab.tsx` (e.g. a toggle, enabled only when no burst-required strategy is already forcing the choice) that converts the active block between `observatory` and `burstObservatory`, carrying over `subjectSelector`. 3. Update `balancer-observatory-sync.test.ts` (starting with the test at line 89) and `observatory-settings-tab.test.tsx`. 4. Add the new toggle's strings to all 13 locale files in `internal/web/translation/`. 5. Sequence after #5674 merges — both PRs touch `balancer-helpers.ts` and `ObservatorySettingsTab.tsx`, so building on top of #5674 avoids rebasing a second large diff through the same sync function. Scope is frontend-only, same as #5627/#5674 — Observatory/Burst settings are raw JSON inside the `xrayTemplateConfig` setting saved through the existing `/panel/api/xray/update` route, no Go or DB changes needed. This is a research-only review on an issue thread, so I haven't made any code changes. Happy to implement this if asked on a PR.
Author
Owner

@MHSanaei commented on GitHub (Jul 2, 2026):

Accepted — the source-level review above confirms leastPing reads burstObservatory's averaged Delay correctly, so a leastPing-only config can run on burstObservatory alone. The single-observer-per-config invariant from #5627 stays, but leastPing doesn't need to be the one pinned to regular observatory.

Implementation is sequenced after PR #5674 merges, since both changes rewrite the same syncObservatories/ObservatorySettingsTab code and stacking them avoids rebasing one large diff through the other. Keeping this open until then.

<!-- gh-comment-id:4863453305 --> @MHSanaei commented on GitHub (Jul 2, 2026): Accepted — the source-level review above confirms leastPing reads burstObservatory's averaged `Delay` correctly, so a leastPing-only config can run on burstObservatory alone. The single-observer-per-config invariant from #5627 stays, but leastPing doesn't need to be the one pinned to regular observatory. Implementation is sequenced after PR #5674 merges, since both changes rewrite the same `syncObservatories`/`ObservatorySettingsTab` code and stacking them avoids rebasing one large diff through the other. Keeping this open until then.
Author
Owner

@ilya-practicum commented on GitHub (Jul 14, 2026):

Just a heads up, 3.5.0 does not allow to choose burstObservatory when leastPing startegy selected

<!-- gh-comment-id:4973100271 --> @ilya-practicum commented on GitHub (Jul 14, 2026): Just a heads up, 3.5.0 does not allow to choose burstObservatory when leastPing startegy selected
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#3952
No description provided.