refactor(platform): mesh bounded and federation view mixins (Phase 740)
Extract _isGuildMeshBounded/_setGuildMeshBounded and federation/multi-guild view helpers (_guildSyncHealthRailForView, _federationSyncAggregateForView, _logMultiGuildMesh, etc.) to dedicated runtime mixins. Manifest 66 rows; runtime registry 6 modules. Class ~33864 lines. No behavior change. Co-authored-by: Cursor <[email protected]>
This commit is contained in:
@@ -54,6 +54,8 @@ Application facade: one `PearcordPlatform` class that wires identity, database,
|
||||
|
||||
**Phase 723 (v0.8.699):** Dedicated slash registry & invoke audit export JSON — `slash-registry-json-mixin.js`, `slash-invoke-audit-json-mixin.js`, spans `slash-registry.json` / `slash-invoke-audit.json`, `getSlashInvokeAuditExportJsonExport`, `clearSlashInvokeAuditExportJsonExports`, deep links `openSlashRegistryJson` / `openSlashInvokeAuditJson`. Bundle: `npm run test:ci-phase723`.
|
||||
|
||||
**Phase 740 (v0.8.716):** `platform-guild-mesh-bounded-mixin.js`, `platform-federation-view-mixin.js` (66 mixin rows). Bundle: `npm run test:ci-phase740`.
|
||||
|
||||
**Phase 739 (v0.8.715):** `platform-guild-open-fallback-mixin.js`, `platform-partition-heal-state-mixin.js` (64 mixin rows); `platform-runtime-mixin-registry.js`. Bundle: `npm run test:ci-phase739`.
|
||||
|
||||
**Phase 738 (v0.8.714):** `platform-hyperswarm-runtime-mixin.js`, `platform-session-startup-mixin.js` (62 mixin rows); `platform-class-imports.js`, `platform-index-export-manifest.js`. Bundle: `npm run test:ci-phase738`.
|
||||
|
||||
@@ -0,0 +1,169 @@
|
||||
'use strict'
|
||||
|
||||
const localScope = require('./platform-index-local-imports')
|
||||
const { getListingTtlMs } = require('pearcord-discovery')
|
||||
|
||||
/** Multi-guild mesh / federation sync view helpers (extracted from PearcordPlatform, Phase 740). */
|
||||
const platformFederationViewMixin = {
|
||||
_resolveViewDetailLevel (opts = {}) {
|
||||
const raw = String(opts.detail || '').trim().toLowerCase()
|
||||
if (raw === 'minimal' || raw === 'light' || raw === 'full' || raw === 'diagnostic') {
|
||||
return raw
|
||||
}
|
||||
if (opts.light === true) return 'light'
|
||||
return 'full'
|
||||
},
|
||||
|
||||
_logMultiGuildMesh (action, extra = {}) {
|
||||
this.log.info('guild.mesh.multi-scale', {
|
||||
spanKind: 'guild.mesh.multi-scale',
|
||||
action,
|
||||
activeGuildId: this.guild?.guild?.id || null,
|
||||
guildCount: (this.guilds || []).length,
|
||||
...extra
|
||||
})
|
||||
},
|
||||
|
||||
_logFederationSync (action, extra = {}) {
|
||||
this.log.info('discovery.mesh.federation', {
|
||||
spanKind: 'discovery.mesh.federation',
|
||||
action,
|
||||
activeGuildId: this.guild?.guild?.id || null,
|
||||
discoveryPeers: this.discovery?.peers?.size ?? 0,
|
||||
...extra
|
||||
})
|
||||
},
|
||||
|
||||
_federationSyncAggregateForView () {
|
||||
const rail = this._guildSyncHealthRailForView()
|
||||
const ids = Object.keys(rail)
|
||||
let syncingGuilds = 0
|
||||
let healingGuilds = 0
|
||||
let okGuilds = 0
|
||||
let boundedGuilds = 0
|
||||
for (const id of ids) {
|
||||
const st = rail[id]?.status
|
||||
if (st === 'syncing') syncingGuilds += 1
|
||||
else if (st === 'healing') healingGuilds += 1
|
||||
else if (st === 'bounded') boundedGuilds += 1
|
||||
else if (st === 'ok') okGuilds += 1
|
||||
}
|
||||
const activeGuildId = this.guild?.guild?.id || null
|
||||
let lastPartitionHealAt = this._federationAggregateHealAt || null
|
||||
for (const id of ids) {
|
||||
const healAt = this._getLastPartitionHeal(id)?.at
|
||||
if (healAt && (!lastPartitionHealAt || healAt > lastPartitionHealAt)) {
|
||||
lastPartitionHealAt = healAt
|
||||
}
|
||||
}
|
||||
return {
|
||||
guildCount: ids.length,
|
||||
syncingGuilds,
|
||||
healingGuilds,
|
||||
okGuilds,
|
||||
boundedGuilds,
|
||||
discoveryMeshLive: (this.discovery?.peers?.size ?? 0) > 0,
|
||||
discoveryPeers: this.discovery?.peers?.size ?? 0,
|
||||
discoveryMeshRefreshAt: this._discoveryMeshRefreshAt || null,
|
||||
activeGuildListingRefreshAt: activeGuildId
|
||||
? this._discoveryListingRefreshByGuild.get(activeGuildId) || null
|
||||
: null,
|
||||
listingTtlMs: getListingTtlMs(),
|
||||
lastPartitionHealAt,
|
||||
aggregateHealAt: this._federationAggregateHealAt || null
|
||||
}
|
||||
},
|
||||
|
||||
_guildSyncHealthRailForView () {
|
||||
const out = {}
|
||||
const ids = new Set([
|
||||
...(this.guilds || []).map((g) => g.id),
|
||||
...this._guildSyncHealthByGuild.keys()
|
||||
])
|
||||
for (const id of ids) {
|
||||
const h = this._guildSyncHealthByGuild.get(id)
|
||||
const pending = h ? h.pending !== false : true
|
||||
const healing = this._isPartitionHealInProgress(id)
|
||||
const bounded = this._isGuildMeshBounded(id)
|
||||
const retryMeta = this._guildMeshPeerRetryMetaByGuild.get(id) || {}
|
||||
const lastHealAt = Number(this._getLastPartitionHeal(id)?.at) || 0
|
||||
const replicating =
|
||||
!healing &&
|
||||
!pending &&
|
||||
!bounded &&
|
||||
(Number(h?.lastSparseAdded) > 0 ||
|
||||
(this._channelReplicationDiagByGuild.get(id)?.size ?? 0) > 0)
|
||||
let status = 'ok'
|
||||
if (healing) status = 'healing'
|
||||
else if (replicating) status = 'replicating'
|
||||
else if (pending) status = 'syncing'
|
||||
else if (bounded) status = 'bounded'
|
||||
const boundedStage = bounded
|
||||
? retryMeta.stage || (pending ? 'join-mesh' : 'peer-retry')
|
||||
: null
|
||||
const etaMs = Math.max(
|
||||
0,
|
||||
(Number(this._guildMeshPeerRetryMetaByGuild.get(id)?.nextRetryAt) || 0) -
|
||||
Date.now()
|
||||
)
|
||||
const boundedStatusHint = bounded
|
||||
? boundedStage === 'join-mesh'
|
||||
? etaMs > 0
|
||||
? `Joining server mesh — next retry in ${Math.ceil(etaMs / 1000)}s.`
|
||||
: 'Still joining the server mesh in the background — messages may lag until peers connect.'
|
||||
: boundedStage === 'peer-retry'
|
||||
? etaMs > 0
|
||||
? `Waiting for mesh peers — retry in ${Math.ceil(etaMs / 1000)}s.`
|
||||
: 'Waiting for mesh peers — Pearcord will retry automatically with spaced backoff.'
|
||||
: 'Mesh join is bounded — history and members may finish loading after reconnect.'
|
||||
: null
|
||||
const meshQuiet = localScope.shouldUseMeshQuietMode({
|
||||
peerCount: Number(h?.peers) || 0,
|
||||
meshBounded: bounded
|
||||
})
|
||||
out[id] = {
|
||||
status,
|
||||
pending: !!pending,
|
||||
meshBounded: bounded,
|
||||
boundedStage,
|
||||
boundedStatusHint,
|
||||
partitionHealInProgress: healing,
|
||||
meshReplicating: replicating,
|
||||
lastPartitionHealAt: lastHealAt || null,
|
||||
lastPartitionHealAgoMs: lastHealAt ? Math.max(0, Date.now() - lastHealAt) : null,
|
||||
gossipLaneCounts: this._guildGossipOutbox.laneCounts?.() || null,
|
||||
syncProgressPct: Number(h?.syncProgressPct) || 0,
|
||||
peers: Number(h?.peers) || 0,
|
||||
retryAttempt: Number(this._guildMeshPeerRetryMetaByGuild.get(id)?.attempt) || 0,
|
||||
retryDelayMs: Number(this._guildMeshPeerRetryMetaByGuild.get(id)?.delayMs) || 0,
|
||||
retryMaxAttempts: Number(this._guildMeshPeerRetryMetaByGuild.get(id)?.maxAttempts) || 0,
|
||||
nextRetryAt: Number(this._guildMeshPeerRetryMetaByGuild.get(id)?.nextRetryAt) || 0,
|
||||
retryCountdownMs: Math.max(
|
||||
0,
|
||||
(Number(this._guildMeshPeerRetryMetaByGuild.get(id)?.nextRetryAt) || 0) - Date.now()
|
||||
),
|
||||
lastPeerSeenAt: Number(h?.lastPeerSeenAt) || 0,
|
||||
peerRetryAttempt:
|
||||
Number(h?.peerRetryAttempt) ||
|
||||
Number(this._guildMeshPeerRetryMetaByGuild.get(id)?.attempt) ||
|
||||
0,
|
||||
stalePeersEvictedLast: Number(h?.stalePeersEvictedLast) || 0,
|
||||
stalePeersEvictedTotal:
|
||||
Number(this._guildMeshStalePeerEvictedTotalByGuild.get(id)) || 0,
|
||||
lastStalePeerEvictAt: Number(h?.lastStalePeerEvictAt) || 0,
|
||||
retrySpacingSource:
|
||||
this._guildMeshPeerRetryMetaByGuild.get(id)?.spacingSource || null,
|
||||
openFallbackThrottled:
|
||||
this._isGuildOpenFallbackThrottled() &&
|
||||
(id === this.guild?.guild?.id || id === this._guildLoadingGuildId),
|
||||
openFallbackThrottleRemainingMs: this._guildOpenFallbackThrottleRemainingMs(),
|
||||
meshQuiet,
|
||||
joinMeshEtaMs: etaMs,
|
||||
meshQuietPollMultiplier: meshQuiet ? localScope.meshQuietModePollMultiplier() : 1
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { platformFederationViewMixin }
|
||||
@@ -0,0 +1,26 @@
|
||||
'use strict'
|
||||
|
||||
/** Guild mesh bounded flag + retry stage seed (extracted from PearcordPlatform, Phase 740). */
|
||||
const platformGuildMeshBoundedMixin = {
|
||||
_isGuildMeshBounded (guildId) {
|
||||
if (!guildId) return false
|
||||
return !!this._guildMeshBoundedByGuild.get(guildId)
|
||||
},
|
||||
|
||||
_setGuildMeshBounded (guildId, bounded) {
|
||||
if (!guildId) return
|
||||
if (bounded) {
|
||||
this._guildMeshBoundedByGuild.set(guildId, true)
|
||||
const prev = this._guildMeshPeerRetryMetaByGuild.get(guildId) || {}
|
||||
this._guildMeshPeerRetryMetaByGuild.set(guildId, {
|
||||
...prev,
|
||||
stage: prev.stage || 'join-mesh'
|
||||
})
|
||||
} else {
|
||||
this._guildMeshBoundedByGuild.delete(guildId)
|
||||
this._guildMeshPeerRetryMetaByGuild.delete(guildId)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { platformGuildMeshBoundedMixin }
|
||||
@@ -4,7 +4,7 @@
|
||||
* Ordered PearcordPlatform prototype mixin registration (Phase 730).
|
||||
* Preserves assign order from index.js / apply-platform-mixins (Phase 727).
|
||||
*/
|
||||
const PLATFORM_MIXIN_ASSIGNMENT_COUNT = 64
|
||||
const PLATFORM_MIXIN_ASSIGNMENT_COUNT = 66
|
||||
|
||||
const PLATFORM_MIXIN_ASSIGNMENTS = [
|
||||
{ module: './polls-scheduling', export: 'pollSchedulingMixin' },
|
||||
@@ -70,6 +70,8 @@ const PLATFORM_MIXIN_ASSIGNMENTS = [
|
||||
{ module: './platform-session-startup-mixin', export: 'platformSessionStartupMixin' },
|
||||
{ module: './platform-guild-open-fallback-mixin', export: 'platformGuildOpenFallbackMixin' },
|
||||
{ module: './platform-partition-heal-state-mixin', export: 'platformPartitionHealStateMixin' },
|
||||
{ module: './platform-guild-mesh-bounded-mixin', export: 'platformGuildMeshBoundedMixin' },
|
||||
{ module: './platform-federation-view-mixin', export: 'platformFederationViewMixin' },
|
||||
{ module: './platform-diagnostics-mixin', export: 'platformDiagnosticsMixin' }
|
||||
]
|
||||
|
||||
|
||||
@@ -273,186 +273,6 @@ class PearcordPlatform extends EventEmitter {
|
||||
this._forumTagFilters = []
|
||||
}
|
||||
|
||||
_isGuildMeshBounded (guildId) {
|
||||
if (!guildId) return false
|
||||
return !!this._guildMeshBoundedByGuild.get(guildId)
|
||||
}
|
||||
|
||||
_setGuildMeshBounded (guildId, bounded) {
|
||||
if (!guildId) return
|
||||
if (bounded) {
|
||||
this._guildMeshBoundedByGuild.set(guildId, true)
|
||||
const prev = this._guildMeshPeerRetryMetaByGuild.get(guildId) || {}
|
||||
this._guildMeshPeerRetryMetaByGuild.set(guildId, {
|
||||
...prev,
|
||||
stage: prev.stage || 'join-mesh'
|
||||
})
|
||||
} else {
|
||||
this._guildMeshBoundedByGuild.delete(guildId)
|
||||
this._guildMeshPeerRetryMetaByGuild.delete(guildId)
|
||||
}
|
||||
}
|
||||
|
||||
_resolveViewDetailLevel (opts = {}) {
|
||||
const raw = String(opts.detail || '').trim().toLowerCase()
|
||||
if (raw === 'minimal' || raw === 'light' || raw === 'full' || raw === 'diagnostic') {
|
||||
return raw
|
||||
}
|
||||
if (opts.light === true) return 'light'
|
||||
return 'full'
|
||||
}
|
||||
|
||||
_logMultiGuildMesh (action, extra = {}) {
|
||||
this.log.info('guild.mesh.multi-scale', {
|
||||
spanKind: 'guild.mesh.multi-scale',
|
||||
action,
|
||||
activeGuildId: this.guild?.guild?.id || null,
|
||||
guildCount: (this.guilds || []).length,
|
||||
...extra
|
||||
})
|
||||
}
|
||||
|
||||
_logFederationSync (action, extra = {}) {
|
||||
this.log.info('discovery.mesh.federation', {
|
||||
spanKind: 'discovery.mesh.federation',
|
||||
action,
|
||||
activeGuildId: this.guild?.guild?.id || null,
|
||||
discoveryPeers: this.discovery?.peers?.size ?? 0,
|
||||
...extra
|
||||
})
|
||||
}
|
||||
|
||||
_federationSyncAggregateForView () {
|
||||
const rail = this._guildSyncHealthRailForView()
|
||||
const ids = Object.keys(rail)
|
||||
let syncingGuilds = 0
|
||||
let healingGuilds = 0
|
||||
let okGuilds = 0
|
||||
let boundedGuilds = 0
|
||||
for (const id of ids) {
|
||||
const st = rail[id]?.status
|
||||
if (st === 'syncing') syncingGuilds += 1
|
||||
else if (st === 'healing') healingGuilds += 1
|
||||
else if (st === 'bounded') boundedGuilds += 1
|
||||
else if (st === 'ok') okGuilds += 1
|
||||
}
|
||||
const activeGuildId = this.guild?.guild?.id || null
|
||||
let lastPartitionHealAt = this._federationAggregateHealAt || null
|
||||
for (const id of ids) {
|
||||
const healAt = this._getLastPartitionHeal(id)?.at
|
||||
if (healAt && (!lastPartitionHealAt || healAt > lastPartitionHealAt)) {
|
||||
lastPartitionHealAt = healAt
|
||||
}
|
||||
}
|
||||
return {
|
||||
guildCount: ids.length,
|
||||
syncingGuilds,
|
||||
healingGuilds,
|
||||
okGuilds,
|
||||
boundedGuilds,
|
||||
discoveryMeshLive: (this.discovery?.peers?.size ?? 0) > 0,
|
||||
discoveryPeers: this.discovery?.peers?.size ?? 0,
|
||||
discoveryMeshRefreshAt: this._discoveryMeshRefreshAt || null,
|
||||
activeGuildListingRefreshAt: activeGuildId
|
||||
? this._discoveryListingRefreshByGuild.get(activeGuildId) || null
|
||||
: null,
|
||||
listingTtlMs: getListingTtlMs(),
|
||||
lastPartitionHealAt,
|
||||
aggregateHealAt: this._federationAggregateHealAt || null
|
||||
}
|
||||
}
|
||||
|
||||
_guildSyncHealthRailForView () {
|
||||
const out = {}
|
||||
const ids = new Set([
|
||||
...(this.guilds || []).map((g) => g.id),
|
||||
...this._guildSyncHealthByGuild.keys()
|
||||
])
|
||||
for (const id of ids) {
|
||||
const h = this._guildSyncHealthByGuild.get(id)
|
||||
const pending = h ? h.pending !== false : true
|
||||
const healing = this._isPartitionHealInProgress(id)
|
||||
const bounded = this._isGuildMeshBounded(id)
|
||||
const retryMeta = this._guildMeshPeerRetryMetaByGuild.get(id) || {}
|
||||
const lastHealAt = Number(this._getLastPartitionHeal(id)?.at) || 0
|
||||
const replicating =
|
||||
!healing &&
|
||||
!pending &&
|
||||
!bounded &&
|
||||
(Number(h?.lastSparseAdded) > 0 ||
|
||||
(this._channelReplicationDiagByGuild.get(id)?.size ?? 0) > 0)
|
||||
let status = 'ok'
|
||||
if (healing) status = 'healing'
|
||||
else if (replicating) status = 'replicating'
|
||||
else if (pending) status = 'syncing'
|
||||
else if (bounded) status = 'bounded'
|
||||
const boundedStage = bounded
|
||||
? retryMeta.stage || (pending ? 'join-mesh' : 'peer-retry')
|
||||
: null
|
||||
const etaMs = Math.max(
|
||||
0,
|
||||
(Number(this._guildMeshPeerRetryMetaByGuild.get(id)?.nextRetryAt) || 0) -
|
||||
Date.now()
|
||||
)
|
||||
const boundedStatusHint = bounded
|
||||
? boundedStage === 'join-mesh'
|
||||
? etaMs > 0
|
||||
? `Joining server mesh — next retry in ${Math.ceil(etaMs / 1000)}s.`
|
||||
: 'Still joining the server mesh in the background — messages may lag until peers connect.'
|
||||
: boundedStage === 'peer-retry'
|
||||
? etaMs > 0
|
||||
? `Waiting for mesh peers — retry in ${Math.ceil(etaMs / 1000)}s.`
|
||||
: 'Waiting for mesh peers — Pearcord will retry automatically with spaced backoff.'
|
||||
: 'Mesh join is bounded — history and members may finish loading after reconnect.'
|
||||
: null
|
||||
const meshQuiet = localScope.shouldUseMeshQuietMode({
|
||||
peerCount: Number(h?.peers) || 0,
|
||||
meshBounded: bounded
|
||||
})
|
||||
out[id] = {
|
||||
status,
|
||||
pending: !!pending,
|
||||
meshBounded: bounded,
|
||||
boundedStage,
|
||||
boundedStatusHint,
|
||||
partitionHealInProgress: healing,
|
||||
meshReplicating: replicating,
|
||||
lastPartitionHealAt: lastHealAt || null,
|
||||
lastPartitionHealAgoMs: lastHealAt ? Math.max(0, Date.now() - lastHealAt) : null,
|
||||
gossipLaneCounts: this._guildGossipOutbox.laneCounts?.() || null,
|
||||
syncProgressPct: Number(h?.syncProgressPct) || 0,
|
||||
peers: Number(h?.peers) || 0,
|
||||
retryAttempt: Number(this._guildMeshPeerRetryMetaByGuild.get(id)?.attempt) || 0,
|
||||
retryDelayMs: Number(this._guildMeshPeerRetryMetaByGuild.get(id)?.delayMs) || 0,
|
||||
retryMaxAttempts: Number(this._guildMeshPeerRetryMetaByGuild.get(id)?.maxAttempts) || 0,
|
||||
nextRetryAt: Number(this._guildMeshPeerRetryMetaByGuild.get(id)?.nextRetryAt) || 0,
|
||||
retryCountdownMs: Math.max(
|
||||
0,
|
||||
(Number(this._guildMeshPeerRetryMetaByGuild.get(id)?.nextRetryAt) || 0) - Date.now()
|
||||
),
|
||||
lastPeerSeenAt: Number(h?.lastPeerSeenAt) || 0,
|
||||
peerRetryAttempt:
|
||||
Number(h?.peerRetryAttempt) ||
|
||||
Number(this._guildMeshPeerRetryMetaByGuild.get(id)?.attempt) ||
|
||||
0,
|
||||
stalePeersEvictedLast: Number(h?.stalePeersEvictedLast) || 0,
|
||||
stalePeersEvictedTotal:
|
||||
Number(this._guildMeshStalePeerEvictedTotalByGuild.get(id)) || 0,
|
||||
lastStalePeerEvictAt: Number(h?.lastStalePeerEvictAt) || 0,
|
||||
retrySpacingSource:
|
||||
this._guildMeshPeerRetryMetaByGuild.get(id)?.spacingSource || null,
|
||||
openFallbackThrottled:
|
||||
this._isGuildOpenFallbackThrottled() &&
|
||||
(id === this.guild?.guild?.id || id === this._guildLoadingGuildId),
|
||||
openFallbackThrottleRemainingMs: this._guildOpenFallbackThrottleRemainingMs(),
|
||||
meshQuiet,
|
||||
joinMeshEtaMs: etaMs,
|
||||
meshQuietPollMultiplier: meshQuiet ? localScope.meshQuietModePollMultiplier() : 1
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
_guildMeshPeerSeenMap (guildId) {
|
||||
const gid = guildId || this.guild?.guild?.id
|
||||
if (!gid) return null
|
||||
|
||||
@@ -5,7 +5,9 @@ const PLATFORM_RUNTIME_MIXIN_MODULES = [
|
||||
'./platform-hyperswarm-runtime-mixin',
|
||||
'./platform-session-startup-mixin',
|
||||
'./platform-guild-open-fallback-mixin',
|
||||
'./platform-partition-heal-state-mixin'
|
||||
'./platform-partition-heal-state-mixin',
|
||||
'./platform-guild-mesh-bounded-mixin',
|
||||
'./platform-federation-view-mixin'
|
||||
]
|
||||
|
||||
const PLATFORM_RUNTIME_MIXIN_COUNT = PLATFORM_RUNTIME_MIXIN_MODULES.length
|
||||
|
||||
Reference in New Issue
Block a user