[PR #6967] feat(inbounds): REALITY watch - replace a dead REALITY target with a tested spare #6550

Open
opened 2026-11-02 04:09:33 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/6967
Author: @Plus98ir
Created: 10/26/2026
Status: 🔄 Open

Base: main ← Head: feat/reality-watch


📝 Commits (8)

  • efd1a52 feat(inbounds): REALITY watch - replace a dead REALITY target with a tested spare
  • 4674988 fix(inbounds): REALITY watch never replaces a local target
  • dc6199b feat(inbounds): REALITY watch shows latency, spares table at full width
  • d16e975 feat(inbounds): set REALITY watch spares while creating the inbound
  • 7a50379 fix(inbounds): pass the request context to REALITY test port helpers
  • fb2ccf1 Merge remote-tracking branch 'origin/main' into feat/reality-watch
  • fee7ed1 chore(inbounds): drop an AmneziaWG test leftover from the REALITY watch branch
  • 10dd871 fix(inbounds): make REALITY watch switches safe around admin edits and Hosts

📊 Changes

42 files changed (+3615 additions, -22 deletions)

View changed files

📝 docs/content/docs/en/reference/api/meta.json (+1 -0)
➕ docs/content/docs/en/reference/api/reality-watch.mdx (+68 -0)
📝 docs/public/openapi.json (+506 -0)
📝 frontend/public/openapi.json (+506 -0)
📝 frontend/src/generated/examples.ts (+36 -0)
📝 frontend/src/generated/schemas.ts (+126 -0)
📝 frontend/src/generated/types.ts (+26 -0)
📝 frontend/src/generated/zod.ts (+29 -0)
📝 frontend/src/pages/api-docs/endpoints.ts (+50 -0)
📝 frontend/src/pages/inbounds/form/InboundFormModal.tsx (+31 -6)
➕ frontend/src/pages/inbounds/form/security/RealityWatchSection.tsx (+305 -0)
📝 frontend/src/pages/inbounds/form/security/reality.tsx (+21 -1)
➕ frontend/src/pages/inbounds/form/security/realityWatch.ts (+15 -0)
📝 frontend/src/test/__snapshots__/inbound-form-blocks.test.tsx.snap (+2 -0)
📝 frontend/src/test/inbound-form-modal.test.tsx (+55 -1)
➕ frontend/src/test/reality-watch-draft.test.tsx (+39 -0)
➕ frontend/src/test/reality-watch-spares.test.ts (+23 -0)
📝 internal/web/controller/api.go (+3 -0)
➕ internal/web/controller/reality_watch.go (+93 -0)
➕ internal/web/job/reality_watch_job.go (+20 -0)

...and 22 more files

📄 Description

Why

The REALITY target scanner finds good targets, but nothing notices when the one in use stops working. Every client then fails until the admin edits the inbound by hand.

What

Each REALITY inbound can keep spare targets, set in a new "Keep REALITY working" section of the REALITY tab. Spares are picked with the existing target scanner.

Every 10 minutes the panel checks each watched target from this server with the scanner's own probe (TLS 1.3 + h2 + X25519 + a valid certificate). A target that has TLS 1.3 but misses the rest of that bar gets the real REALITY test below, and that result decides, so a working target is not replaced for lacking h2. After 3 failed checks in a row, an inbound with Replace automatically on moves to the first spare that passes:

  1. the same probe, and
  2. a real REALITY connection: a throwaway Xray REALITY server (target = the spare) and client on loopback, fetching https://<sni>/ through them.

The probe alone is not enough: a site can pass TLS 1.3 + h2 and still break REALITY's handshake, which would cut every client right after the switch.

Only target and serverNames change, plus any of this inbound's Hosts that use REALITY and pin an old server name. The edit is saved through UpdateInbound on a fresh copy of the inbound, so it reaches Xray (and the runtime) exactly like an admin's edit, and clients get the new SNI with their next subscription update.

In the UI, each spare has a real-test button and a switch-now button. Switch-now runs the same two checks and is refused if either fails. On success the open editor takes the new target and server names, so its Save keeps the switch. The switch history is shown below the spares.

REALITY watch section

Safety

  • Nothing passes, nothing changes: no switch happens when no spare passes both checks, and that outage is logged once rather than on every check.
  • No switch on a blip: a good check resets the failure count.
  • Node inbounds are not checked or switched: their REALITY server runs on the node, so this server's view says nothing about them. The API refuses a manual switch for them too.
  • The admin's edit wins: if the target changed during a check, the switch is dropped. Other fields saved during a check are kept.
  • The API stays responsive: no lock is held during network checks, and overlapping cycles do not run, so one outage is not counted twice.
  • Local targets are never replaced: a bare port, a unix socket, a private or loopback address, or a domain that resolves to one. Admins front REALITY with a local server on purpose. The probe's SSRF guard blocks these targets, and treating that as a failure would move the inbound to a public spare.
  • Separate storage: the watch settings live in their own setting key (realityWatch), so the inbound model, the generated Xray config and the share links are untouched, and no migration is needed.

API

/panel/api/realityWatch/{list, status/:id, save/:id, switch/:id, test}, documented in endpoints.ts. switch/:id returns the inbound's new status. The structs are in StructAllow, and the OpenAPI copy and the reality-watch.mdx page are regenerated.

Tests

  • internal/web/service/reality_watch_test.go runs against a real DB, with the probe and the real test stubbed. It covers:

    • switching only on the third failed check in a row;
    • skipping a spare that fails the real test;
    • no switch, and a single log line, when nothing works;
    • a good check resetting the count;
    • no switch when auto switch is off;
    • node inbounds and local targets never checked;
    • the manual switch being refused on a failing spare;
    • spare normalization;
    • an edit saved during a check being kept, and a target changed during a check not being switched;
    • the API answering during a check, and overlapping cycles not running;
    • the real test deciding a target the scanner dislikes;
    • Host SNIs following a switch;
    • a manual switch being refused on a node inbound.

    I removed each safeguard once to confirm that a test goes red.

  • reality_watch_xray_e2e_test.go runs the real test against a real Xray binary, and is skipped unless XRAY_E2E_BINARY is set. I ran it on a Linux server with xray-linux-amd64:

    • common targets pass and an unreachable one fails;
    • with a wrong client key it fails (connection reset), so it tests REALITY itself rather than plain TLS.
  • frontend/src/test/reality-watch-spares.test.ts covers spare normalization in the UI.

  • frontend/src/test/inbound-form-modal.test.tsx switches in the editor, presses Save and checks the update carries the new target.


🔄 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/6967 **Author:** [@Plus98ir](https://github.com/Plus98ir) **Created:** 10/26/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `feat/reality-watch` --- ### 📝 Commits (8) - [`efd1a52`](https://github.com/MHSanaei/3x-ui/commit/efd1a526a787a18c640d3f30afb484110ee38ae5) feat(inbounds): REALITY watch - replace a dead REALITY target with a tested spare - [`4674988`](https://github.com/MHSanaei/3x-ui/commit/46749889db34c98bbb4aca0dfcfe3f40eae96fdc) fix(inbounds): REALITY watch never replaces a local target - [`dc6199b`](https://github.com/MHSanaei/3x-ui/commit/dc6199b13c01fea492f3b242acc6917404b967a8) feat(inbounds): REALITY watch shows latency, spares table at full width - [`d16e975`](https://github.com/MHSanaei/3x-ui/commit/d16e9751f4961cd8f778cca3fb516c85640ba6af) feat(inbounds): set REALITY watch spares while creating the inbound - [`7a50379`](https://github.com/MHSanaei/3x-ui/commit/7a5037965754284f7c2b819294574342846d104a) fix(inbounds): pass the request context to REALITY test port helpers - [`fb2ccf1`](https://github.com/MHSanaei/3x-ui/commit/fb2ccf1e61822fd3f57ee9ea5424beaa2689c1f0) Merge remote-tracking branch 'origin/main' into feat/reality-watch - [`fee7ed1`](https://github.com/MHSanaei/3x-ui/commit/fee7ed1422547d0b6af39d460757ad44abd642f7) chore(inbounds): drop an AmneziaWG test leftover from the REALITY watch branch - [`10dd871`](https://github.com/MHSanaei/3x-ui/commit/10dd871d6aaa5d824b599f4680f9af617756a11a) fix(inbounds): make REALITY watch switches safe around admin edits and Hosts ### 📊 Changes **42 files changed** (+3615 additions, -22 deletions) <details> <summary>View changed files</summary> 📝 `docs/content/docs/en/reference/api/meta.json` (+1 -0) ➕ `docs/content/docs/en/reference/api/reality-watch.mdx` (+68 -0) 📝 `docs/public/openapi.json` (+506 -0) 📝 `frontend/public/openapi.json` (+506 -0) 📝 `frontend/src/generated/examples.ts` (+36 -0) 📝 `frontend/src/generated/schemas.ts` (+126 -0) 📝 `frontend/src/generated/types.ts` (+26 -0) 📝 `frontend/src/generated/zod.ts` (+29 -0) 📝 `frontend/src/pages/api-docs/endpoints.ts` (+50 -0) 📝 `frontend/src/pages/inbounds/form/InboundFormModal.tsx` (+31 -6) ➕ `frontend/src/pages/inbounds/form/security/RealityWatchSection.tsx` (+305 -0) 📝 `frontend/src/pages/inbounds/form/security/reality.tsx` (+21 -1) ➕ `frontend/src/pages/inbounds/form/security/realityWatch.ts` (+15 -0) 📝 `frontend/src/test/__snapshots__/inbound-form-blocks.test.tsx.snap` (+2 -0) 📝 `frontend/src/test/inbound-form-modal.test.tsx` (+55 -1) ➕ `frontend/src/test/reality-watch-draft.test.tsx` (+39 -0) ➕ `frontend/src/test/reality-watch-spares.test.ts` (+23 -0) 📝 `internal/web/controller/api.go` (+3 -0) ➕ `internal/web/controller/reality_watch.go` (+93 -0) ➕ `internal/web/job/reality_watch_job.go` (+20 -0) _...and 22 more files_ </details> ### 📄 Description ## Why The REALITY target scanner finds good targets, but nothing notices when the one in use stops working. Every client then fails until the admin edits the inbound by hand. ## What Each REALITY inbound can keep **spare targets**, set in a new "Keep REALITY working" section of the REALITY tab. Spares are picked with the existing target scanner. Every 10 minutes the panel checks each watched target from this server with the scanner's own probe (TLS 1.3 + h2 + X25519 + a valid certificate). A target that has TLS 1.3 but misses the rest of that bar gets the real REALITY test below, and that result decides, so a working target is not replaced for lacking h2. After **3 failed checks in a row**, an inbound with *Replace automatically* on moves to the first spare that passes: 1. the same probe, **and** 2. **a real REALITY connection**: a throwaway Xray REALITY server (target = the spare) and client on loopback, fetching `https://<sni>/` through them. The probe alone is not enough: a site can pass TLS 1.3 + h2 and still break REALITY's handshake, which would cut every client right after the switch. Only `target` and `serverNames` change, plus any of this inbound's Hosts that use REALITY and pin an old server name. The edit is saved through `UpdateInbound` on a fresh copy of the inbound, so it reaches Xray (and the runtime) exactly like an admin's edit, and clients get the new SNI with their next subscription update. In the UI, each spare has a real-test button and a switch-now button. Switch-now runs the same two checks and is refused if either fails. On success the open editor takes the new target and server names, so its Save keeps the switch. The switch history is shown below the spares. ![REALITY watch section](https://raw.githubusercontent.com/Plus98ir/3x-ui/9dbc9183/reality-watch.png) ## Safety - **Nothing passes, nothing changes:** no switch happens when no spare passes both checks, and that outage is logged once rather than on every check. - **No switch on a blip:** a good check resets the failure count. - **Node inbounds are not checked or switched:** their REALITY server runs on the node, so this server's view says nothing about them. The API refuses a manual switch for them too. - **The admin's edit wins:** if the target changed during a check, the switch is dropped. Other fields saved during a check are kept. - **The API stays responsive:** no lock is held during network checks, and overlapping cycles do not run, so one outage is not counted twice. - **Local targets are never replaced:** a bare port, a unix socket, a private or loopback address, or a domain that resolves to one. Admins front REALITY with a local server on purpose. The probe's SSRF guard blocks these targets, and treating that as a failure would move the inbound to a public spare. - **Separate storage:** the watch settings live in their own setting key (`realityWatch`), so the inbound model, the generated Xray config and the share links are untouched, and no migration is needed. ## API `/panel/api/realityWatch/{list, status/:id, save/:id, switch/:id, test}`, documented in `endpoints.ts`. `switch/:id` returns the inbound's new status. The structs are in `StructAllow`, and the OpenAPI copy and the `reality-watch.mdx` page are regenerated. ## Tests - `internal/web/service/reality_watch_test.go` runs against a real DB, with the probe and the real test stubbed. It covers: - switching only on the third failed check in a row; - skipping a spare that fails the real test; - no switch, and a single log line, when nothing works; - a good check resetting the count; - no switch when auto switch is off; - node inbounds and local targets never checked; - the manual switch being refused on a failing spare; - spare normalization; - an edit saved during a check being kept, and a target changed during a check not being switched; - the API answering during a check, and overlapping cycles not running; - the real test deciding a target the scanner dislikes; - Host SNIs following a switch; - a manual switch being refused on a node inbound. I removed each safeguard once to confirm that a test goes red. - `reality_watch_xray_e2e_test.go` runs the real test against a real Xray binary, and is skipped unless `XRAY_E2E_BINARY` is set. I ran it on a Linux server with xray-linux-amd64: - common targets pass and an unreachable one fails; - with a wrong client key it fails (`connection reset`), so it tests REALITY itself rather than plain TLS. - `frontend/src/test/reality-watch-spares.test.ts` covers spare normalization in the UI. - `frontend/src/test/inbound-form-modal.test.tsx` switches in the editor, presses Save and checks the update carries the new target. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
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#6550
No description provided.