fix: address PR review feedback on websocket reconnect telemetry

1. Fire reconnect event unconditionally so had_active_jobs varies
   (was always true since it was inside an activeJobCount > 0 guard)
2. Capture activeJobsCount at disconnect time, not reconnect time,
   since the queue store hasn't refreshed yet on reconnect
3. Add PostHog provider tests for trackWebSocketReconnected
This commit is contained in:
Matt Miller
2026-03-20 10:02:40 -07:00
parent 92abd71213
commit 53d09ab869
2 changed files with 50 additions and 8 deletions

View File

@@ -236,6 +236,48 @@ describe('PostHogTelemetryProvider', () => {
})
})
describe('websocket reconnect', () => {
it('captures reconnect event with metadata', async () => {
const provider = createProvider()
await vi.dynamicImportSettled()
provider.trackWebSocketReconnected({
disconnect_duration_ms: 5000,
had_active_jobs: true,
active_job_count: 3
})
expect(hoisted.mockCapture).toHaveBeenCalledWith(
TelemetryEvents.WEBSOCKET_RECONNECTED,
{
disconnect_duration_ms: 5000,
had_active_jobs: true,
active_job_count: 3
}
)
})
it('captures reconnect event when no jobs were active', async () => {
const provider = createProvider()
await vi.dynamicImportSettled()
provider.trackWebSocketReconnected({
disconnect_duration_ms: 1200,
had_active_jobs: false,
active_job_count: 0
})
expect(hoisted.mockCapture).toHaveBeenCalledWith(
TelemetryEvents.WEBSOCKET_RECONNECTED,
{
disconnect_duration_ms: 1200,
had_active_jobs: false,
active_job_count: 0
}
)
})
})
describe('page view', () => {
it('captures page view with page_name property', async () => {
const provider = createProvider()

View File

@@ -254,10 +254,12 @@ const reconnectingMessage: ToastMessageOptions = {
}
let disconnectedAt: number | null = null
let activeJobCountAtDisconnect = 0
const onReconnecting = () => {
if (disconnectedAt === null) {
disconnectedAt = Date.now()
activeJobCountAtDisconnect = queueStore.activeJobsCount
}
if (!settingStore.get('Comfy.Toast.DisableReconnectingToast')) {
toast.remove(reconnectingMessage)
@@ -267,15 +269,13 @@ const onReconnecting = () => {
const onReconnected = () => {
if (disconnectedAt !== null) {
const activeJobCount = queueStore.activeJobsCount
if (activeJobCount > 0) {
telemetry?.trackWebSocketReconnected({
disconnect_duration_ms: Date.now() - disconnectedAt,
had_active_jobs: true,
active_job_count: activeJobCount
})
}
telemetry?.trackWebSocketReconnected({
disconnect_duration_ms: Date.now() - disconnectedAt,
had_active_jobs: activeJobCountAtDisconnect > 0,
active_job_count: activeJobCountAtDisconnect
})
disconnectedAt = null
activeJobCountAtDisconnect = 0
}
if (!settingStore.get('Comfy.Toast.DisableReconnectingToast')) {
toast.remove(reconnectingMessage)