feat(phase725): bot-registry.json spans and dedicated heal mixin

Add bot-registry-json-mixin with partition heal cursors, migrate bot
registry platform spans from bot.json, and expose guildBotRegistryJsonCount
in the guild view (v0.8.701).

Co-authored-by: Cursor <[email protected]>
This commit is contained in:
Raven Scott
2026-06-03 09:15:13 -04:00
co-authored by Cursor
parent 48ab2c64e5
commit 054c18abb7
4 changed files with 86 additions and 120 deletions
+2
View File
@@ -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 725 (v0.8.701):** Dedicated bot registry & webhook execute export JSON — `bot-registry-json-mixin.js`, `webhook-json-mixin.js`, spans `bot-registry.json` / `webhook.json`, deep links `openBotRegistryJson` / `openWebhookExecuteExportJson`. Bundle: `npm run test:ci-phase725`.
**Phase 724 (v0.8.700):** Dedicated worker release & integration manifest export JSON — `worker-release-json-mixin.js`, `integration-manifest-json-mixin.js`, spans `worker-release.json` / `integration-manifest.json`, `getIntegrationManifestExportJsonExport`, `clearIntegrationManifestExportJsonExports`, deep links `openWorkerReleaseJson` / `openIntegrationManifestJson`. Bundle: `npm run test:ci-phase724`.
**Phase 695 (v0.8.670):** Slash registry JSON & invoke audit — `slash-json-mixin.js`, `slash.json` spans (`guildSlashRegistryCount`), `pushSlashRegistryJsonToMesh`, `pushSlashInvokeAuditExportToMesh`, deep link `openSlashJson`. Bundle: `npm run test:ci-phase695`.
+2 -106
View File
@@ -1,113 +1,9 @@
'use strict'
/** @deprecated Phase 725 — registry heal in bot-registry-json-mixin; webhook heal in webhook-json-mixin */
const botJsonMixin = {
_botRegistryJsonGossipKeys: null,
_botJsonHealWatermark: null,
_webhookExecuteJsonHealWatermark: null,
_initBotJsonMixinState () {
if (!this._botRegistryJsonGossipKeys) {
this._botRegistryJsonGossipKeys = new Set()
}
},
_shouldGossipBotRegistryJson (slice) {
this._initBotJsonMixinState()
if (!slice?.guildId || !slice?.signature) return true
const hash = `${slice.guildId}:${slice.exportedAt || 0}:${slice.signature}`
if (this._botRegistryJsonGossipKeys.has(hash)) return false
this._botRegistryJsonGossipKeys.add(hash)
if (this._botRegistryJsonGossipKeys.size > 8192) {
const first = this._botRegistryJsonGossipKeys.values().next().value
if (first) this._botRegistryJsonGossipKeys.delete(first)
}
_shouldGossipWebhookExecuteExportJsonLegacy (slice) {
return true
},
_shouldGossipWebhookExecuteExportJson (slice) {
this._initBotJsonMixinState()
if (!slice?.guildId || !slice?.signature) return true
const hash = `webhook:${slice.guildId}:${slice.exportedAt || 0}:${slice.signature}`
if (this._botRegistryJsonGossipKeys.has(hash)) return false
this._botRegistryJsonGossipKeys.add(hash)
return true
},
async _healBotRegistryExportCursorOnPartition (guildId) {
const gid = guildId || this.guild?.guild?.id || null
const span = this.log.time('bot.json', {
spanKind: 'bot.json',
guildId: gid,
context: 'heal.registry'
})
try {
if (!gid || !this.deliveryReceipts) {
span.end({ relisted: 0, skipped: true, guildBotRegistryCount: 0 })
return { relisted: 0, skipped: true }
}
await this._initDeliveryReceipts(gid)
const rows = await this.deliveryReceipts.listBotRegistryJsonExports(64)
let relisted = 0
for (const row of rows) {
if (this._shouldGossipBotRegistryJson(row)) relisted++
}
const watermark = Date.now()
this._botJsonHealWatermark = watermark
span.end({
relisted,
watermark,
guildBotRegistryCount: rows.length,
bridgeKind: 'bot.json'
})
return { relisted, watermark, guildBotRegistryCount: rows.length }
} catch (err) {
this.log.error('bot.json error', {
guildId: gid,
context: 'heal.registry',
error: err?.message || String(err)
})
span.fail(err)
return { relisted: 0, error: err?.message || String(err) }
}
},
async _healWebhookExecuteExportCursorOnPartition (guildId) {
const gid = guildId || this.guild?.guild?.id || null
const span = this.log.time('bot.json', {
spanKind: 'bot.json',
guildId: gid,
context: 'heal.execute'
})
try {
if (!gid || !this.deliveryReceipts) {
span.end({ relisted: 0, skipped: true, guildBotRegistryCount: 0 })
return { relisted: 0, skipped: true }
}
await this._initDeliveryReceipts(gid)
const rows = await this.deliveryReceipts.listWebhookExecuteExportJsonExports(64)
let relisted = 0
for (const row of rows) {
if (this._shouldGossipWebhookExecuteExportJson(row)) relisted++
}
const watermark = Date.now()
this._webhookExecuteJsonHealWatermark = watermark
span.end({
relisted,
watermark,
guildBotRegistryCount: rows.length,
webhookCount: rows[0]?.webhookCount || 0,
bridgeKind: 'bot.json'
})
return { relisted, watermark, webhookCount: rows[0]?.webhookCount || 0 }
} catch (err) {
this.log.error('bot.json error', {
guildId: gid,
context: 'heal.execute',
error: err?.message || String(err)
})
span.fail(err)
return { relisted: 0, error: err?.message || String(err) }
}
}
}
+65
View File
@@ -0,0 +1,65 @@
'use strict'
const botRegistryJsonMixin = {
_botRegistryExportJsonGossipKeys: null,
_botRegistryJsonHealWatermark: null,
_initBotRegistryJsonMixinState () {
if (!this._botRegistryExportJsonGossipKeys) {
this._botRegistryExportJsonGossipKeys = new Set()
}
},
_shouldGossipBotRegistryExportJson (slice) {
this._initBotRegistryJsonMixinState()
if (!slice?.guildId || !slice?.signature) return true
const hash = `${slice.guildId}:${slice.exportedAt || 0}:${slice.signature}`
if (this._botRegistryExportJsonGossipKeys.has(hash)) return false
this._botRegistryExportJsonGossipKeys.add(hash)
if (this._botRegistryExportJsonGossipKeys.size > 8192) {
const first = this._botRegistryExportJsonGossipKeys.values().next().value
if (first) this._botRegistryExportJsonGossipKeys.delete(first)
}
return true
},
async _healBotRegistryJsonExportCursorOnPartition (guildId) {
const gid = guildId || this.guild?.guild?.id || null
const span = this.log.time('bot-registry.json', {
spanKind: 'bot-registry.json',
guildId: gid,
context: 'heal.bot-registry'
})
try {
if (!gid || !this.deliveryReceipts) {
span.end({ relisted: 0, skipped: true, guildBotRegistryJsonCount: 0 })
return { relisted: 0, skipped: true }
}
await this._initDeliveryReceipts(gid)
const rows = await this.deliveryReceipts.listBotRegistryJsonExports(64)
let relisted = 0
for (const row of rows) {
if (this._shouldGossipBotRegistryExportJson(row)) relisted++
}
const watermark = Date.now()
this._botRegistryJsonHealWatermark = watermark
span.end({
relisted,
watermark,
guildBotRegistryJsonCount: rows.length,
bridgeKind: 'bot-registry.json'
})
return { relisted, watermark, guildBotRegistryJsonCount: rows.length }
} catch (err) {
this.log.error('bot-registry.json error', {
guildId: gid,
context: 'heal.bot-registry',
error: err?.message || String(err)
})
span.fail(err)
return { relisted: 0, error: err?.message || String(err) }
}
}
}
module.exports = { botRegistryJsonMixin }
+17 -14
View File
@@ -1797,10 +1797,10 @@ class PearcordPlatform extends EventEmitter {
const integrationManifestJsonHeal = await this._healIntegrationManifestJsonExportCursorOnPartition(gid).catch(() => ({
relisted: 0
}))
const botRegistryJsonHeal = await this._healBotRegistryExportCursorOnPartition(gid).catch(() => ({
const botRegistryJsonHeal = await this._healBotRegistryJsonExportCursorOnPartition(gid).catch(() => ({
relisted: 0
}))
const webhookExecuteJsonHeal = await this._healWebhookExecuteExportCursorOnPartition(gid).catch(() => ({
const webhookExecuteJsonHeal = await this._healWebhookExecuteJsonExportCursorOnPartition(gid).catch(() => ({
relisted: 0
}))
const slashRegistryJsonHeal = await this._healSlashRegistryJsonExportCursorOnPartition(gid).catch(() => ({
@@ -14146,20 +14146,20 @@ class PearcordPlatform extends EventEmitter {
async getBotRegistryJsonExport () {
const gid = this.guild?.guild?.id || null
const span = this.log.time('bot.json', {
spanKind: 'bot.json',
const span = this.log.time('bot-registry.json', {
spanKind: 'bot-registry.json',
guildId: gid,
context: 'read'
})
try {
if (!this.guild?.guild) {
span.end({ guildBotRegistryCount: 0, skipped: true })
span.end({ guildBotRegistryJsonCount: 0, skipped: true })
return null
}
await this._initDeliveryReceipts(this.guild.guild.id)
const row = await this.deliveryReceipts.getBotRegistryJsonExport()
if (!row?.signature) {
span.end({ guildBotRegistryCount: row ? 1 : 0, hasSignature: false, bridgeKind: 'bot.json' })
span.end({ guildBotRegistryJsonCount: row ? 1 : 0, hasSignature: false, bridgeKind: 'bot-registry.json' })
return row
}
const verified = verifyBotRegistryJson(exportBodyFromSlice(row) || row.jsonBody || row.jsonBody, row.signature, {
@@ -14168,14 +14168,14 @@ class PearcordPlatform extends EventEmitter {
})
const out = { ...row, signatureValid: verified.ok }
span.end({
guildBotRegistryCount: 1,
guildBotRegistryJsonCount: 1,
hasSignature: true,
signatureValid: verified.ok,
bridgeKind: 'bot.json'
bridgeKind: 'bot-registry.json'
})
return out
} catch (err) {
this.log.error('bot.json error', {
this.log.error('bot-registry.json error', {
guildId: gid,
context: 'read',
error: err?.message || String(err)
@@ -14222,8 +14222,8 @@ class PearcordPlatform extends EventEmitter {
async pushBotRegistryJsonToMesh () {
const gid = this.guild?.guild?.id || null
const span = this.log.time('bot.json', {
spanKind: 'bot.json',
const span = this.log.time('bot-registry.json', {
spanKind: 'bot-registry.json',
guildId: gid,
context: 'mesh.push'
})
@@ -14254,13 +14254,13 @@ class PearcordPlatform extends EventEmitter {
exportedAt: exported.exportedAt
})
span.end({
guildBotRegistryCount: exported.botCount || 1,
guildBotRegistryJsonCount: exported.botCount || 1,
meshPushed: true,
bridgeKind: 'bot.json'
bridgeKind: 'bot-registry.json'
})
return exported
} catch (err) {
this.log.error('bot.json error', {
this.log.error('bot-registry.json error', {
guildId: gid,
context: 'mesh.push',
error: err?.message || String(err)
@@ -33959,6 +33959,7 @@ class PearcordPlatform extends EventEmitter {
lastIntegrationManifestExport,
botRegistryJsonMeta,
botRegistryJsonRows,
guildBotRegistryJsonCount: (botRegistryJsonRows || []).length,
webhookExecuteExportJsonRows,
webhookExecuteExportJsonMeta,
guildWebhookExecuteEntries,
@@ -34748,6 +34749,7 @@ const { digestJsonMixin } = require('./digest-json-mixin')
const { relayJsonMixin } = require('./relay-json-mixin')
const { workerJsonMixin } = require('./worker-json-mixin')
const { botJsonMixin } = require('./bot-json-mixin')
const { botRegistryJsonMixin } = require('./bot-registry-json-mixin')
const { slashJsonMixin } = require('./slash-json-mixin')
const { oauthJsonMixin } = require('./oauth-json-mixin')
const { inviteJsonMixin } = require('./invite-json-mixin')
@@ -34807,6 +34809,7 @@ Object.assign(PearcordPlatform.prototype, digestJsonMixin)
Object.assign(PearcordPlatform.prototype, relayJsonMixin)
Object.assign(PearcordPlatform.prototype, workerJsonMixin)
Object.assign(PearcordPlatform.prototype, botJsonMixin)
Object.assign(PearcordPlatform.prototype, botRegistryJsonMixin)
Object.assign(PearcordPlatform.prototype, slashJsonMixin)
Object.assign(PearcordPlatform.prototype, oauthJsonMixin)
Object.assign(PearcordPlatform.prototype, inviteJsonMixin)