Line data Source code
1 : import type { Op } from '@comfyorg/comfy-multi-player'
2 :
3 : import { reportError } from '@comfyorg/telemetry/reportError'
4 : import { api } from '@/scripts/api'
5 :
6 : import { recordDevEvent } from './devPanelLog'
7 :
8 : /** Which caller invoked `OpSender.abortIfUnbound`: a refused resubscribe, or a tab-switch retarget. */
9 : export type UnboundAbortReason = 'subscribe_refused' | 'retarget'
10 :
11 : type LostEditKind =
12 : | 'undeliverable'
13 : | 'unconfirmed'
14 : | 'unacknowledged'
15 : | 'mint_divergence'
16 : | 'host_rejected'
17 :
18 0 : export function reportLostEdit(
19 : kind: LostEditKind,
20 : ops: readonly (Pick<Op, 'op'> & Partial<Pick<Op, 'op_id'>>)[],
21 : cause: {
22 : code: string
23 : errorType?: string
24 : workflowId?: string
25 : graphId?: string
26 : nodeId?: string | number
27 : classType?: string
28 : widget?: string
29 : message?: string
30 : failedIndex?: number
31 : /** Which caller drove the `'unbound'` code. Undefined for every other code. */
32 : reason?: UnboundAbortReason
33 : },
34 : { shouldReport = true }: { shouldReport?: boolean } = {}
35 : ): void {
36 0 : const { errorType = `failure_syncing_agent_edit_${kind}`, ...detail } = cause
37 0 : const context = {
38 : ...detail,
39 : workflowId: cause.workflowId,
40 : opId: ops[0]?.op_id,
41 : opIds: ops.map((op) => op.op_id),
42 : operations: ops.map((op) => op.op)
43 : }
44 0 : if (shouldReport)
45 0 : reportError(new Error(errorType), {
46 : surface: 'agent',
47 : errorType,
48 : fingerprint: [errorType],
49 : level: kind === 'host_rejected' ? 'warning' : 'error',
50 : tags: {
51 : tab: api.clientId,
52 : outcome: kind,
53 : code: cause.code,
54 : ...(cause.reason ? { reason: cause.reason } : {})
55 : },
56 : context
57 : })
58 0 : if (kind === 'mint_divergence' || kind === 'host_rejected') {
59 0 : recordDevEvent(kind, context, { level: 'warn' })
60 : } else {
61 0 : recordDevEvent('human_ops_settled', { state: kind, ops })
62 : }
63 : }
|