From 3152ef34dba5dcb4af056eb1d957ee922af259e1 Mon Sep 17 00:00:00 2001 From: Deep Mehta Date: Sat, 6 Jun 2026 15:46:32 -0700 Subject: [PATCH] feat(telemetry): tag execution events with source_layer="comfyui" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Every event emitted from executionTap originates in the ComfyUI Python subprocess (parsed from its stdout/stderr). Adding source_layer to the shared baseContext makes engine-origin errors filterable in PostHog without renaming the event family — so existing dashboards keep working while triage gets a clean filter: event = 'comfy.desktop.execution.error' AND properties.source_layer = 'comfyui' Covers all six emissions (started / completed / first_completed / error x2 / session_summary). A new test asserts the tag is present on every event family this tap emits. --- src/main/lib/executionTap.test.ts | 28 ++++++++++++++++++++++++++++ src/main/lib/executionTap.ts | 7 ++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/main/lib/executionTap.test.ts b/src/main/lib/executionTap.test.ts index 174da34b..016582bd 100644 --- a/src/main/lib/executionTap.test.ts +++ b/src/main/lib/executionTap.test.ts @@ -176,6 +176,34 @@ describe('executionTap', () => { expect(events).toContain('comfy.desktop.execution.completed') }) + it('tags every emission with source_layer="comfyui" so engine-origin events are filterable in PostHog', () => { + const tap = createExecutionTap({ installationId: 'inst-1' }) + tap.ingest( + [ + 'got prompt', + 'Prompt executed in 1.0 seconds', + 'Failed to validate prompt for output 7:', + 'Traceback (most recent call last):', + ' File "x.py", line 1, in ', + ' raise RuntimeError("boom")', + 'RuntimeError: boom', + '', + 'next-line' + ].join('\n'), + 'stderr' + ) + tap.flushSummary() + // Cover every event family this tap emits — none should leak without the tag. + const families = new Set(captured.map((c) => c.event)) + expect(families).toContain('comfy.desktop.execution.started') + expect(families).toContain('comfy.desktop.execution.completed') + expect(families).toContain('comfy.desktop.execution.error') + expect(families).toContain('comfy.desktop.execution.session_summary') + for (const c of captured) { + expect(c.ctx['source_layer']).toBe('comfyui') + } + }) + it('redacts Bearer tokens and api keys from traceback messages (secret scrub)', () => { const bearer = 'Bearer ' + 'a'.repeat(30) const apiKey = 's' + 'k-' + 'a'.repeat(24) diff --git a/src/main/lib/executionTap.ts b/src/main/lib/executionTap.ts index 49cce339..795b12bb 100644 --- a/src/main/lib/executionTap.ts +++ b/src/main/lib/executionTap.ts @@ -83,10 +83,15 @@ export function createExecutionTap(opts: { tracebackPhase: 'none' } + // Every event emitted from this tap originates in the ComfyUI Python + // subprocess (parsed from its stdout/stderr). Tagging at the baseContext + // level lets PostHog separate engine-origin errors from any future + // shell-origin emissions without renaming the event family. const baseContext = { installation_id: state.installationId, variant: state.variant, - release: state.release + release: state.release, + source_layer: 'comfyui' as const } function pushPromptStart(): void {