diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 58ad65a3b..9f8c2c9d3 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -155,6 +155,16 @@ jobs:
exit 1
fi
+ - name: PostgreSQL online attribution regressions
+ run: |
+ set -o pipefail
+ go test -p=1 ./internal/web/job ./internal/web/service -run '^Test(InboundOnlineAvailabilityDistinguishesEmptyFromMissing|SetRemoteTraffic_RemapsActiveInboundTreeAndCentralTags|XrayTrafficRetryDoesNotPublishOnlineStateAcrossCoreReplacement)$' -count=1 -v | tee /tmp/postgres-online-attribution.log
+ passed=$(grep -c -- '^--- PASS: Test' /tmp/postgres-online-attribution.log || true)
+ if [ "$passed" -ne 3 ]; then
+ echo "expected 3 passing PostgreSQL online attribution tests, got $passed" >&2
+ exit 1
+ fi
+
- name: PostgreSQL node client push ordering
run: |
set -o pipefail
diff --git a/docs/content/docs/en/reference/api/clients.mdx b/docs/content/docs/en/reference/api/clients.mdx
index 725bcacf2..86194e023 100644
--- a/docs/content/docs/en/reference/api/clients.mdx
+++ b/docs/content/docs/en/reference/api/clients.mdx
@@ -336,10 +336,9 @@ _openapi:
- depth: 2
title: Online client emails grouped by the panelGuid of the node that physically
hosts each client. The local panel uses its own GUID; each node (at any
- depth in a chain) uses its GUID. Lets the inbounds page attribute online
- status to the real node instead of the intermediate one it syncs
- through.
- url: '#online-client-emails-grouped-by-the-panelguid-of-the-node-that-physically-hosts-each-client-the-local-panel-uses-its-own-guid-each-node-at-any-depth-in-a-chain-uses-its-guid-lets-the-inbounds-page-attribute-online-status-to-the-real-node-instead-of-the-intermediate-one-it-syncs-through'
+ depth in a chain) uses its GUID. An empty list means the node reported
+ no online clients. An absent GUID means there is no usable report.
+ url: '#online-client-emails-grouped-by-the-panelguid-of-the-node-that-physically-hosts-each-client-the-local-panel-uses-its-own-guid-each-node-at-any-depth-in-a-chain-uses-its-guid-an-empty-list-means-the-node-reported-no-online-clients-an-absent-guid-means-there-is-no-usable-report'
- depth: 2
title: Per-client source IPs grouped by the panelGuid of the node that observed
them. Lets the central panel attribute and enforce per-client IP limits
@@ -348,10 +347,12 @@ _openapi:
url: '#per-client-source-ips-grouped-by-the-panelguid-of-the-node-that-observed-them-lets-the-central-panel-attribute-and-enforce-per-client-ip-limits-using-the-real-visitor-ips-each-node-sees-instead-of-the-address-of-the-intermediate-panel-it-syncs-through'
- depth: 2
title: Inbound tags that carried traffic within the heartbeat window, grouped by
- the hosting node's panelGuid. Pairs with onlinesByGuid so the inbounds
- page only marks a multi-inbound client online on the inbounds it
- actually used. Nodes that do not report per-inbound activity are absent.
- url: '#inbound-tags-that-carried-traffic-within-the-heartbeat-window-grouped-by-the-hosting-nodes-panelguid-pairs-with-onlinesbyguid-so-the-inbounds-page-only-marks-a-multi-inbound-client-online-on-the-inbounds-it-actually-used-nodes-that-do-not-report-per-inbound-activity-are-absent'
+ the hosting node's panelGuid. Use with onlinesByGuid to scope online
+ counts. An empty list means no active tags, an absent GUID means there
+ is no usable report, and null means a confirmed legacy node lacks the
+ activity endpoint. The reserved NUL tag (U+0000) marks a partial report.
+ Inbounds whose tags are absent remain unknown.
+ url: '#inbound-tags-that-carried-traffic-within-the-heartbeat-window-grouped-by-the-hosting-nodes-panelguid-use-with-onlinesbyguid-to-scope-online-counts-an-empty-list-means-no-active-tags-an-absent-guid-means-there-is-no-usable-report-and-null-means-a-confirmed-legacy-node-lacks-the-activity-endpoint-the-reserved-nul-tag-u0000-marks-a-partial-report-inbounds-whose-tags-are-absent-remain-unknown'
- depth: 2
title: Map of client email → last-seen unix timestamp.
url: '#map-of-client-email--last-seen-unix-timestamp'
@@ -681,21 +682,22 @@ _openapi:
id: list-the-emails-of-currently-connected-clients-last-seen-within-the-heartbeat-window-deduped-across-every-node
- content: Online client emails grouped by the panelGuid of the node that
physically hosts each client. The local panel uses its own GUID; each
- node (at any depth in a chain) uses its GUID. Lets the inbounds page
- attribute online status to the real node instead of the intermediate
- one it syncs through.
- id: online-client-emails-grouped-by-the-panelguid-of-the-node-that-physically-hosts-each-client-the-local-panel-uses-its-own-guid-each-node-at-any-depth-in-a-chain-uses-its-guid-lets-the-inbounds-page-attribute-online-status-to-the-real-node-instead-of-the-intermediate-one-it-syncs-through
+ node (at any depth in a chain) uses its GUID. An empty list means the
+ node reported no online clients. An absent GUID means there is no
+ usable report.
+ id: online-client-emails-grouped-by-the-panelguid-of-the-node-that-physically-hosts-each-client-the-local-panel-uses-its-own-guid-each-node-at-any-depth-in-a-chain-uses-its-guid-an-empty-list-means-the-node-reported-no-online-clients-an-absent-guid-means-there-is-no-usable-report
- content: Per-client source IPs grouped by the panelGuid of the node that
observed them. Lets the central panel attribute and enforce per-client
IP limits using the real visitor IPs each node sees, instead of the
address of the intermediate panel it syncs through.
id: per-client-source-ips-grouped-by-the-panelguid-of-the-node-that-observed-them-lets-the-central-panel-attribute-and-enforce-per-client-ip-limits-using-the-real-visitor-ips-each-node-sees-instead-of-the-address-of-the-intermediate-panel-it-syncs-through
- content: Inbound tags that carried traffic within the heartbeat window, grouped
- by the hosting node's panelGuid. Pairs with onlinesByGuid so the
- inbounds page only marks a multi-inbound client online on the inbounds
- it actually used. Nodes that do not report per-inbound activity are
- absent.
- id: inbound-tags-that-carried-traffic-within-the-heartbeat-window-grouped-by-the-hosting-nodes-panelguid-pairs-with-onlinesbyguid-so-the-inbounds-page-only-marks-a-multi-inbound-client-online-on-the-inbounds-it-actually-used-nodes-that-do-not-report-per-inbound-activity-are-absent
+ by the hosting node's panelGuid. Use with onlinesByGuid to scope
+ online counts. An empty list means no active tags, an absent GUID
+ means there is no usable report, and null means a confirmed legacy
+ node lacks the activity endpoint. The reserved NUL tag (U+0000) marks
+ a partial report. Inbounds whose tags are absent remain unknown.
+ id: inbound-tags-that-carried-traffic-within-the-heartbeat-window-grouped-by-the-hosting-nodes-panelguid-use-with-onlinesbyguid-to-scope-online-counts-an-empty-list-means-no-active-tags-an-absent-guid-means-there-is-no-usable-report-and-null-means-a-confirmed-legacy-node-lacks-the-activity-endpoint-the-reserved-nul-tag-u0000-marks-a-partial-report-inbounds-whose-tags-are-absent-remain-unknown
- content: Map of client email → last-seen unix timestamp.
id: map-of-client-email--last-seen-unix-timestamp
- content: Traffic counters for a client identified by email.
diff --git a/docs/public/openapi.json b/docs/public/openapi.json
index fee39fb9a..afb1a2f6b 100644
--- a/docs/public/openapi.json
+++ b/docs/public/openapi.json
@@ -13886,7 +13886,7 @@
"tags": [
"Clients"
],
- "summary": "Online client emails grouped by the panelGuid of the node that physically hosts each client. The local panel uses its own GUID; each node (at any depth in a chain) uses its GUID. Lets the inbounds page attribute online status to the real node instead of the intermediate one it syncs through.",
+ "summary": "Online client emails grouped by the panelGuid of the node that physically hosts each client. The local panel uses its own GUID; each node (at any depth in a chain) uses its GUID. An empty list means the node reported no online clients. An absent GUID means there is no usable report.",
"operationId": "post_panel_api_clients_onlinesByGuid",
"responses": {
"200": {
@@ -13971,7 +13971,7 @@
"tags": [
"Clients"
],
- "summary": "Inbound tags that carried traffic within the heartbeat window, grouped by the hosting node's panelGuid. Pairs with onlinesByGuid so the inbounds page only marks a multi-inbound client online on the inbounds it actually used. Nodes that do not report per-inbound activity are absent.",
+ "summary": "Inbound tags that carried traffic within the heartbeat window, grouped by the hosting node's panelGuid. Use with onlinesByGuid to scope online counts. An empty list means no active tags, an absent GUID means there is no usable report, and null means a confirmed legacy node lacks the activity endpoint. The reserved NUL tag (U+0000) marks a partial report. Inbounds whose tags are absent remain unknown.",
"operationId": "post_panel_api_clients_activeInbounds",
"responses": {
"200": {
@@ -20262,8 +20262,10 @@
"type": "array",
"items": {
"type": "string"
- }
- }
+ },
+ "nullable": true
+ },
+ "description": "Empty lists mean no active tags, absent GUIDs mean no usable report, and null denotes legacy nodes without per-inbound activity. The reserved NUL tag (U+0000) marks a partial report. Unlisted inbounds stay unknown."
},
"lastOnlineMap": {
"type": "object",
diff --git a/frontend/public/openapi.json b/frontend/public/openapi.json
index fee39fb9a..afb1a2f6b 100644
--- a/frontend/public/openapi.json
+++ b/frontend/public/openapi.json
@@ -13886,7 +13886,7 @@
"tags": [
"Clients"
],
- "summary": "Online client emails grouped by the panelGuid of the node that physically hosts each client. The local panel uses its own GUID; each node (at any depth in a chain) uses its GUID. Lets the inbounds page attribute online status to the real node instead of the intermediate one it syncs through.",
+ "summary": "Online client emails grouped by the panelGuid of the node that physically hosts each client. The local panel uses its own GUID; each node (at any depth in a chain) uses its GUID. An empty list means the node reported no online clients. An absent GUID means there is no usable report.",
"operationId": "post_panel_api_clients_onlinesByGuid",
"responses": {
"200": {
@@ -13971,7 +13971,7 @@
"tags": [
"Clients"
],
- "summary": "Inbound tags that carried traffic within the heartbeat window, grouped by the hosting node's panelGuid. Pairs with onlinesByGuid so the inbounds page only marks a multi-inbound client online on the inbounds it actually used. Nodes that do not report per-inbound activity are absent.",
+ "summary": "Inbound tags that carried traffic within the heartbeat window, grouped by the hosting node's panelGuid. Use with onlinesByGuid to scope online counts. An empty list means no active tags, an absent GUID means there is no usable report, and null means a confirmed legacy node lacks the activity endpoint. The reserved NUL tag (U+0000) marks a partial report. Inbounds whose tags are absent remain unknown.",
"operationId": "post_panel_api_clients_activeInbounds",
"responses": {
"200": {
@@ -20262,8 +20262,10 @@
"type": "array",
"items": {
"type": "string"
- }
- }
+ },
+ "nullable": true
+ },
+ "description": "Empty lists mean no active tags, absent GUIDs mean no usable report, and null denotes legacy nodes without per-inbound activity. The reserved NUL tag (U+0000) marks a partial report. Unlisted inbounds stay unknown."
},
"lastOnlineMap": {
"type": "object",
diff --git a/frontend/src/pages/api-docs/endpoints.ts b/frontend/src/pages/api-docs/endpoints.ts
index 8e41e0bf9..a92ac3320 100644
--- a/frontend/src/pages/api-docs/endpoints.ts
+++ b/frontend/src/pages/api-docs/endpoints.ts
@@ -1964,7 +1964,7 @@ export const sections: readonly Section[] = [
method: 'POST',
path: '/panel/api/clients/onlinesByGuid',
summary:
- 'Online client emails grouped by the panelGuid of the node that physically hosts each client. The local panel uses its own GUID; each node (at any depth in a chain) uses its GUID. Lets the inbounds page attribute online status to the real node instead of the intermediate one it syncs through.',
+ 'Online client emails grouped by the panelGuid of the node that physically hosts each client. The local panel uses its own GUID; each node (at any depth in a chain) uses its GUID. An empty list means the node reported no online clients. An absent GUID means there is no usable report.',
response:
'{\n "success": true,\n "obj": {\n "a1b2-...": ["user1"],\n "c3d4-...": ["user1", "user2"]\n }\n}',
},
@@ -1980,7 +1980,7 @@ export const sections: readonly Section[] = [
method: 'POST',
path: '/panel/api/clients/activeInbounds',
summary:
- "Inbound tags that carried traffic within the heartbeat window, grouped by the hosting node's panelGuid. Pairs with onlinesByGuid so the inbounds page only marks a multi-inbound client online on the inbounds it actually used. Nodes that do not report per-inbound activity are absent.",
+ "Inbound tags that carried traffic within the heartbeat window, grouped by the hosting node's panelGuid. Use with onlinesByGuid to scope online counts. An empty list means no active tags, an absent GUID means there is no usable report, and null means a confirmed legacy node lacks the activity endpoint. The reserved NUL tag (U+0000) marks a partial report. Inbounds whose tags are absent remain unknown.",
response:
'{\n "success": true,\n "obj": {\n "a1b2-...": ["in-443-tcp", "in-8443-tcp"]\n }\n}',
},
diff --git a/frontend/src/pages/api-docs/websocket-events.ts b/frontend/src/pages/api-docs/websocket-events.ts
index 98ce384f8..681e4f938 100644
--- a/frontend/src/pages/api-docs/websocket-events.ts
+++ b/frontend/src/pages/api-docs/websocket-events.ts
@@ -140,7 +140,12 @@ const trafficPayloadSchema = {
},
onlineClients: stringArray,
onlineByGuid: stringArrayMap,
- activeInbounds: stringArrayMap,
+ activeInbounds: {
+ type: 'object',
+ additionalProperties: { ...stringArray, nullable: true },
+ description:
+ 'Empty lists mean no active tags, absent GUIDs mean no usable report, and null denotes legacy nodes without per-inbound activity. The reserved NUL tag (U+0000) marks a partial report. Unlisted inbounds stay unknown.',
+ },
lastOnlineMap: timestampMap,
},
oneOf: [
diff --git a/frontend/src/pages/inbounds/list/InboundStatsModal.tsx b/frontend/src/pages/inbounds/list/InboundStatsModal.tsx
index 27f638262..6a3916ab1 100644
--- a/frontend/src/pages/inbounds/list/InboundStatsModal.tsx
+++ b/frontend/src/pages/inbounds/list/InboundStatsModal.tsx
@@ -1,5 +1,6 @@
import { useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
+import { onlineStatusLabel } from './onlineStatusLabel';
import { Modal, Tag } from 'antd';
import { SizeFormatter, IntlUtil, ColorUtils } from '@/utils';
@@ -133,9 +134,17 @@ export default function InboundStatsModal({
{clientCount[record.id].clients}
+ {clientCount[record.id].onlineAttribution &&
+ clientCount[record.id].online.length === 0 && (
+
+ {t('online')}: {onlineStatusLabel(clientCount[record.id], t)}
+
+ )}
{clientCount[record.id].online.length > 0 && (
{clientCount[record.id].online.length} {t('online')}
+ {clientCount[record.id].onlineAttribution === 'node' &&
+ ` (${t('pages.inbounds.node')})`}
)}
{clientCount[record.id].depleted.length > 0 && (
diff --git a/frontend/src/pages/inbounds/list/onlineStatusLabel.ts b/frontend/src/pages/inbounds/list/onlineStatusLabel.ts
new file mode 100644
index 000000000..8a9f26ba7
--- /dev/null
+++ b/frontend/src/pages/inbounds/list/onlineStatusLabel.ts
@@ -0,0 +1,18 @@
+import type { TFunction } from 'i18next';
+
+import type { ClientCountEntry } from './types';
+
+export function onlineStatusLabel(entry: ClientCountEntry, t: TFunction) {
+ switch (entry.onlineAttribution) {
+ case 'pending':
+ return t('loading');
+ case 'inbound':
+ return '0';
+ case 'node':
+ return `0 (${t('pages.inbounds.node')})`;
+ case 'unsupported':
+ return `${t('pages.nodes.statusValues.unknown')} (${t('pages.inbounds.node')})`;
+ default:
+ return t('pages.nodes.statusValues.unknown');
+ }
+}
diff --git a/frontend/src/pages/inbounds/list/types.ts b/frontend/src/pages/inbounds/list/types.ts
index ab76e334e..6e7d5ac44 100644
--- a/frontend/src/pages/inbounds/list/types.ts
+++ b/frontend/src/pages/inbounds/list/types.ts
@@ -45,6 +45,7 @@ export interface ClientCountEntry {
depleted: string[];
expiring: string[];
online: string[];
+ onlineAttribution?: 'pending' | 'unavailable' | 'inbound' | 'node' | 'unsupported';
}
export interface InboundSpeedEntry {
diff --git a/frontend/src/pages/inbounds/list/useInboundColumns.tsx b/frontend/src/pages/inbounds/list/useInboundColumns.tsx
index 1d2a7c8bb..fc1d10d05 100644
--- a/frontend/src/pages/inbounds/list/useInboundColumns.tsx
+++ b/frontend/src/pages/inbounds/list/useInboundColumns.tsx
@@ -1,5 +1,6 @@
import { useMemo, type ReactElement } from 'react';
import { useTranslation } from 'react-i18next';
+import { onlineStatusLabel } from './onlineStatusLabel';
import { Popover, Switch, Tag, Tooltip, type TableColumnType } from 'antd';
import { TeamOutlined } from '@ant-design/icons';
@@ -366,9 +367,18 @@ export function useInboundColumns({
)}
+ {cc.onlineAttribution && cc.online.length === 0 && (
+
+ {t('online')}: {onlineStatusLabel(cc, t)}
+
+ )}
{cc.online.length > 0 && (
{cc.online.map((e) => (
@@ -383,6 +393,7 @@ export function useInboundColumns({
style={{ margin: 0, padding: '0 2px' }}
>
{cc.online.length}
+ {cc.onlineAttribution === 'node' && ` (${t('pages.inbounds.node')})`}
)}
diff --git a/frontend/src/pages/inbounds/useInbounds.ts b/frontend/src/pages/inbounds/useInbounds.ts
index b69de541a..8911c0ce6 100644
--- a/frontend/src/pages/inbounds/useInbounds.ts
+++ b/frontend/src/pages/inbounds/useInbounds.ts
@@ -54,6 +54,7 @@ interface ClientRollup {
depleted: string[];
expiring: string[];
online: string[];
+ onlineAttribution: 'pending' | 'unavailable' | 'inbound' | 'node' | 'unsupported';
comments: Map;
}
@@ -101,12 +102,12 @@ async function fetchOnlineClientsByGuid(): Promise> {
// Pairs with the per-node online map so a client attached to several inbounds
// is only marked online on the ones that actually moved bytes — Xray's
// user-level stat can't attribute traffic to a single inbound on its own.
-async function fetchActiveInboundsByNode(): Promise> {
+async function fetchActiveInboundsByNode(): Promise> {
const msg = await HttpUtil.post('/panel/api/clients/activeInbounds', undefined, { silent: true });
if (!msg?.success) throw new Error(msg?.msg || 'Failed to fetch activeInbounds');
const validated = parseMsg(msg, ActiveInboundsByNodeSchema, 'clients/activeInbounds');
return validated.obj && typeof validated.obj === 'object'
- ? (validated.obj as Record)
+ ? (validated.obj as Record)
: {};
}
@@ -119,13 +120,28 @@ function toGuidOnlineMap(data: Record): Map,
+): Map | null> {
+ const map = new Map | null>();
+ for (const [key, tags] of Object.entries(data)) {
+ if (tags === null) map.set(key, null);
+ else if (Array.isArray(tags)) map.set(key, new Set(tags));
+ }
+ return map;
+}
+
// Most pushes repeat the previous online sets; handing back a new Map anyway
// re-ran the client rollup over every inbound on each traffic event.
-function sameGuidSets(a: Map>, b: Map>): boolean {
+function sameGuidSets(
+ a: ReadonlyMap | null>,
+ b: ReadonlyMap | null>,
+): boolean {
if (a.size !== b.size) return false;
for (const [key, set] of b) {
const prev = a.get(key);
- if (!prev || prev.size !== set.size) return false;
+ if (prev === set) continue;
+ if (!prev || !set || prev.size !== set.size) return false;
for (const value of set) if (!prev.has(value)) return false;
}
return true;
@@ -240,12 +256,11 @@ export function useInbounds() {
// hosts it, attributing a sub-node's clients to that sub-node (#4983).
const [onlineByGuid, setOnlineByGuid] = useState