Repository navigation
feat: report CMP event sink failures #17059
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| import type { CmpEvent } from '@comfyorg/comfy-multi-player' | ||
|
|
||
| import { reportError } from './reportError' | ||
| import { cmpEventSink } from './cmpEventSink' | ||
|
|
||
| vi.mock('./reportError', () => ({ reportError: vi.fn() })) | ||
|
|
||
| const event: CmpEvent = { | ||
| schema_version: 1, | ||
| type: 'op_rejected', | ||
| source: 'applyOps', | ||
| code: 'unknown_widget', | ||
| message: 'widget write rejected', | ||
| error_name: 'OpRejectedError', | ||
| op_id: '0123456789abcdef0123456789abcdef', | ||
| batch_index: 2 | ||
| } | ||
|
|
||
| describe('cmpEventSink', () => { | ||
| it('maps a cmp event to the generic error reporter', () => { | ||
| expect(cmpEventSink(event)).toBeUndefined() | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TRIVIAL — two assertions here restate the implementation rather than a behaviour.
Line 66, The
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed on both. Holding pending #17059 (comment). |
||
|
|
||
| expect(reportError).toHaveBeenCalledWith( | ||
| expect.objectContaining({ | ||
| name: 'OpRejectedError', | ||
| message: event.message | ||
| }), | ||
| { | ||
| errorType: 'cmp_event', | ||
| tags: { | ||
| cmp_event_schema_version: 1, | ||
| cmp_event_type: 'op_rejected', | ||
| cmp_event_source: 'applyOps', | ||
| cmp_event_code: 'unknown_widget', | ||
| cmp_event_error_name: 'OpRejectedError' | ||
| }, | ||
| context: { | ||
| op_id: event.op_id, | ||
| batch_index: 2 | ||
| } | ||
| } | ||
| ) | ||
| }) | ||
|
|
||
| it('omits absent optional fields for a minimal event', () => { | ||
| cmpEventSink({ | ||
| schema_version: 1, | ||
| type: 'clock_anomaly', | ||
| source: 'clock', | ||
| code: 'skew', | ||
| message: 'clock skew detected' | ||
| }) | ||
|
|
||
| expect(reportError).toHaveBeenLastCalledWith( | ||
| expect.objectContaining({ | ||
| name: 'CmpEvent', | ||
| message: 'clock skew detected' | ||
| }), | ||
| { | ||
| errorType: 'cmp_event', | ||
| tags: { | ||
| cmp_event_schema_version: 1, | ||
| cmp_event_type: 'clock_anomaly', | ||
| cmp_event_source: 'clock', | ||
| cmp_event_code: 'skew', | ||
| cmp_event_error_name: undefined | ||
| }, | ||
| context: {} | ||
| } | ||
| ) | ||
| }) | ||
|
|
||
| it('bounds diagnostic messages and accepts additive event names', () => { | ||
| cmpEventSink({ ...event, type: 'future_event', message: 'x'.repeat(2_000) }) | ||
|
|
||
| expect(reportError).toHaveBeenLastCalledWith( | ||
| expect.objectContaining({ message: 'x'.repeat(1_024) }), | ||
| expect.objectContaining({ | ||
| tags: expect.objectContaining({ cmp_event_type: 'future_event' }) | ||
| }) | ||
| ) | ||
| }) | ||
| }) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import type { CmpEvent, CmpEventSink } from '@comfyorg/comfy-multi-player' | ||
|
|
||
| import { reportError } from './reportError' | ||
|
|
||
| const MAX_MESSAGE_LENGTH = 1_024 | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TRIVIAL — a message truncated at exactly 1024 chars is indistinguishable from a complete one in Sentry. Appending a marker when the slice actually cuts costs a line and saves a reader guessing whether the diagnostic is whole.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Noted, a truncation marker is right. Holding pending #17059 (comment). |
||
| const DEFAULT_ERROR_NAME = 'CmpEvent' | ||
|
|
||
| const toError = (event: CmpEvent): Error => { | ||
| const error = new Error(event.message.slice(0, MAX_MESSAGE_LENGTH)) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SHOULD FIX — using the raw CMP rejection messages embed high-cardinality identifiers: Datadog RUM groups errors on the message, so every rejection becomes its own bucket. ADR-0019 is explicit that "stable codes and bounded structured context are preferred over message parsing", and
const error = new Error(`${event.type}: ${event.code}`)
error.name = event.error_name ?? DEFAULT_ERROR_NAME...with
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed, and it is the same point ADR-0019 makes about stable codes over message parsing. Holding pending #17059 (comment). |
||
| error.name = event.error_name ?? DEFAULT_ERROR_NAME | ||
| return error | ||
| } | ||
|
Comment on lines
+8
to
+12
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win 🔎 Supported by static analysis🤖 get_repo_knowledge executed:
Length of output: 47963 🏁 Script executed: #!/bin/bash
set -eu
printf '%s\n' '--- target file ---'
cat -n src/platform/telemetry/cmpEventSink.ts
printf '%s\n' '--- local guidance references ---'
rg -n -i "function declaration|function expression|pure function|arrow function|function .*declaration" docs src/platform/telemetry --glob '*.md' --glob '*.ts' --glob '*.tsx' | head -200
printf '%s\n' '--- TypeScript guidance ---'
cat -n docs/guidance/typescript.mdRepository: Comfy-Org/ComfyUI_frontend Length of output: 8034 Use function declarations for the pure helpers.
📍 Affects 1 file
🤖 Prompt for AI AgentsSource: Learnings |
||
|
|
||
| const definedContextOf = (event: CmpEvent): Record<string, unknown> => { | ||
| const context: Record<string, unknown> = {} | ||
| if (event.op_id !== undefined) context.op_id = event.op_id | ||
| if (event.batch_index !== undefined) context.batch_index = event.batch_index | ||
| return context | ||
| } | ||
|
Comment on lines
+14
to
+19
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TRIVIAL — this duplicates
Filtering
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fair, and your suggested fix is the better one because it is useful regardless of what happens to this file. Filtering Holding the local change pending #17059 (comment). Happy to split the |
||
|
|
||
| export const cmpEventSink: CmpEventSink = (event) => { | ||
|
christian-byrne marked this conversation as resolved.
Resolved
christian-byrne marked this conversation as resolved.
Resolved
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. BLOCKER — this adapter has no consumer, and the last time it was proposed the conclusion was to delete it.
That by itself would just be premature. The harder problem is that your own analysis on #16273 reached the opposite disposition:
That comment points at There is a real gap worth filling: applier rejections currently terminate as dev-panel events ( Please either link the follow-up that attaches this to a real seam, or make the case that the frontend should own it at all given the doc-host already does. If it does land unattached, note the repo convention for that:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're right, and I verified each claim before touching anything.
So there is no follow-up to link, and I don't have a case that the frontend should own this given the doc-host already passes I have not implemented the other six comments on this PR. Polishing an adapter whose existence is the open question is the wrong order. Recommendation: close #17059 and delete the branch. The real gap you identified (applier rejections terminating at Assigning to you for the close call since I shouldn't close it unilaterally. |
||
| reportError(toError(event), { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SHOULD FIX — no dedupe and no per-session cap. Every comparable adapter in this codebase bounds itself, because these callbacks fire from loops:
Mirroring the sibling in the same directory is about six lines: const MAX_REPORTS_PER_SESSION = 20
const reportedKeys = new Set<string>()
const shouldReport = (event: CmpEvent): boolean => {
const key = `${event.type}:${event.code}`
if (reportedKeys.has(key)) return false
if (reportedKeys.size >= MAX_REPORTS_PER_SESSION) return false
reportedKeys.add(key)
return true
}
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Valid. Confirmed Not implementing while the existence question in #17059 (comment) is open. If it does land, this is the first thing to add. |
||
| errorType: 'cmp_event', | ||
|
christian-byrne marked this conversation as resolved.
Resolved
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SHOULD FIX — The doc comment on Here an applier crash, an op rejection, and a batch-limit violation all collapse into one
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed, Holding pending #17059 (comment). |
||
| tags: { | ||
| cmp_event_schema_version: event.schema_version, | ||
| cmp_event_type: event.type, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ⚪ Nit — Only |
||
| cmp_event_source: event.source, | ||
| cmp_event_code: event.code, | ||
| cmp_event_error_name: event.error_name | ||
| }, | ||
| context: definedContextOf(event) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SHOULD FIX — no ADR-0019 says callers submit "a stable code, severity, cause, relevant context, and recovery outcome". The PR title says "event sink failures", but the sink accepts any A
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed. Holding pending #17059 (comment). |
||
| }) | ||
| return undefined | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.