Turn any idea, plan, or codebase into a beautiful interactive diagram. An agent skill for Claude Code, Codex, and more.
HTML agent-skillsai-agentsarchitecture-diagramclaude-codeclaude-skillscodexcoding-agentsdeepseek-harnessdeveloper-toolsdiagramsdiagrams-as-codedsh-pluginflowchartllmmermaidopencodesequence-diagramsoftware-architecturesystem-designvisualization
fix: reject unrepresentable waterfall timing before drawing
杨嘉伟bcb4d0ee28ff
diff --git a/archify/renderers/waterfall/render-waterfall.mjs b/archify/renderers/waterfall/render-waterfall.mjsindex da74ef82..b7c32aff 100644--- a/archify/renderers/waterfall/render-waterfall.mjs+++ b/archify/renderers/waterfall/render-waterfall.mjs@@ -66,6 +66,9 @@ for (const [index, span] of raw.entries()) {const hasDuration = Number.isFinite(span.duration);const timing = (message, fixes) => fail('waterfall/invalid-timing', `Span "${span.id}" ${message}`, { path: `/spans/${index}`, nodeId: span.id },{ start: span.start, end: span.end ?? null, duration: span.duration ?? null, status: span.status ?? 'ok' }, fixes);+ if (hasDuration && !Number.isFinite(span.start + span.duration)) {+ timing('has a derived end outside the finite numeric range.', ['Rescale the recorded timing and unit to a representable range.']);+ }if (hasEnd && span.end < span.start) timing(`ends (${span.end}) before it starts (${span.start}).`, ['Correct start or end from the recorded timing.']);if (hasEnd && hasDuration && Math.abs(span.end - span.start - span.duration) > 1e-9) {timing(`states end ${span.end} and duration ${span.duration}, which disagree with start ${span.start}.`, ['Keep only one of end or duration.']);@@ -126,7 +129,7 @@ const rows = [];}(spans.filter((span) => span.parent === undefined), 0));function number(value) {- const rounded = Math.round(value * 100) / 100;+ const rounded = Math.abs(value) > Number.MAX_VALUE / 100 ? value : Math.round(value * 100) / 100;return rounded.toLocaleString('en-US', { maximumFractionDigits: 2 });}const formatDuration = (value) => `${number(value)} ${unitLabel}`;@@ -157,6 +160,12 @@ const labelW = Math.ceil(Math.max(140, ...rows.map(nameWidth)));const axisX0 = layout.margin + labelW + layout.columnGap;const axisX1 = axisX0 + layout.axisWidth;const scale = wall > 0 ? layout.axisWidth / wall : 0;+if (!Number.isFinite(scale)) {+ throwDiagnosticProblems('Waterfall validation failed', ['The recorded range cannot form a finite axis scale.'], {+ code: 'waterfall/invalid-timing', subject: { diagramType: 'waterfall', path: '/spans' },+ evidence: { start: t0, end: t1, wall }, supportedFixes: ['Rescale the recorded timing and unit to a representable range.'],+ });+}const xOf = (t) => Math.round((axisX0 + (t - t0) * scale) * 100) / 100;const rowsTop = layout.top + layout.axisH;diff --git a/test/waterfall-rendering.test.mjs b/test/waterfall-rendering.test.mjsindex ea302e9f..f47366f1 100644--- a/test/waterfall-rendering.test.mjs+++ b/test/waterfall-rendering.test.mjs@@ -71,6 +71,29 @@ test('waterfall: large timestamps terminate when tick increments are below floatassert.ok(report.rows[0].x1 > report.rows[0].x0);});+test('waterfall: unrepresentable derived timing is rejected without writing invalid geometry', () => {+ for (const span of [+ { id: 'request', name: 'Request', start: 1e308, duration: 1e308 },+ { id: 'request', name: 'Request', start: 0, duration: Number.MIN_VALUE },+ ]) {+ const diagram = clone(small);+ diagram.spans = [span];+ const result = run(diagram);+ assert.equal(result.status, 1, result.stderr || result.error?.message);+ assert.match(result.stderr, /finite/);+ assert.equal(fs.existsSync(result.output), false);+ }+});++test('waterfall: finite very large timing labels do not overflow while formatting', () => {+ const diagram = clone(small);+ diagram.spans = [{ id: 'request', name: 'Request', start: 1e307, end: 1.1e307 }];+ const result = run(diagram);+ assert.equal(result.status, 0, result.stderr || result.error?.message);+ const html = fs.readFileSync(result.output, 'utf8');+ assert.doesNotMatch(html, /(?:NaN|Infinity|∞)/);+});+test('waterfall: percentages name their denominator and are never summed into the parent', () => {const html = fs.readFileSync(run(small).output, 'utf8');assert.match(html, /data-node-id="payment"[^>]*aria-label="[^"]*400–1,050 ms · 650 ms · 54% of 1,200 ms wall-clock/);