Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions apps/insights/src/prompts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,11 @@ export async function fetchInsightHistory(
.select({
title: analyticsInsights.title,
description: analyticsInsights.description,
type: analyticsInsights.type,
severity: analyticsInsights.severity,
rootCause: analyticsInsights.rootCause,
changePercent: analyticsInsights.changePercent,
subjectKey: analyticsInsights.subjectKey,
createdAt: analyticsInsights.createdAt,
runId: analyticsInsights.runId,
})
.from(analyticsInsights)
.where(
Expand All @@ -113,30 +111,32 @@ export async function fetchInsightHistory(
)
)
.orderBy(desc(analyticsInsights.createdAt))
.limit(RECENT_INSIGHTS_PROMPT_LIMIT);
.limit(50);

if (rows.length === 0) {
return "";
}

const subjectCounts = new Map<string, number>();
for (const row of rows) {
subjectCounts.set(
row.subjectKey,
(subjectCounts.get(row.subjectKey) ?? 0) + 1
);
const key = row.subjectKey || row.title;
subjectCounts.set(key, (subjectCounts.get(key) ?? 0) + 1);
}

const seen = new Set<string>();
const lines: string[] = [];
for (const row of rows) {
if (seen.has(row.subjectKey)) {
if (lines.length >= RECENT_INSIGHTS_PROMPT_LIMIT) {
break;
}
const key = row.subjectKey || row.title;
if (seen.has(key)) {
continue;
}
seen.add(row.subjectKey);
seen.add(key);
Comment on lines 126 to +136
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Use a dedicated counter for unique subjects rather than lines.length, so insights with description and rootCause don't erroneously reduce the number of distinct subjects shown. The PR description explicitly calls for "12 unique subjects" but the current guard measures output lines.

Suggested change
const seen = new Set<string>();
const lines: string[] = [];
for (const row of rows) {
if (seen.has(row.subjectKey)) {
if (lines.length >= RECENT_INSIGHTS_PROMPT_LIMIT) {
break;
}
const key = row.subjectKey || row.title;
if (seen.has(key)) {
continue;
}
seen.add(row.subjectKey);
seen.add(key);
const seen = new Set<string>();
const lines: string[] = [];
let subjectCount = 0;
for (const row of rows) {
if (subjectCount >= RECENT_INSIGHTS_PROMPT_LIMIT) {
break;
}
const key = row.subjectKey || row.title;
if (seen.has(key)) {
continue;
}
seen.add(key);
subjectCount++;

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!


const date = dayjs(row.createdAt).format("YYYY-MM-DD");
const recurrence = subjectCounts.get(row.subjectKey) ?? 1;
const recurrence = subjectCounts.get(key) ?? 1;
const recurring = recurrence > 1 ? ` (reported ${recurrence}x)` : "";
const change =
row.changePercent === null
Expand Down
22 changes: 11 additions & 11 deletions packages/evals/ui/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -794,16 +794,16 @@ <h2 class="panel-title">Latest model board</h2>
const id = escapeHtml(c.id);
const cost = (c.metrics?.costUsd || 0) + (c.metrics?.judgeCostUsd || 0);
return `<tr>
<td><div class="case-id" title="${id}">${id}</div></td>
<td><span class="pill cat">${escapeHtml(c.category || "case")}</span></td>
<td><span class="pill ${c.passed ? "pass" : "fail"}">${c.passed ? "Pass" : "Fail"}</span></td>
<td class="num ${scoreTone(c.scores?.tool_routing ?? 0)}">${c.scores?.tool_routing ?? "--"}</td>
<td class="num ${scoreTone(c.scores?.quality ?? 0)}">${c.scores?.quality ?? "--"}</td>
<td class="num">${((c.metrics?.latencyMs || 0) / 1000).toFixed(1)}s</td>
<td class="num">${c.metrics?.steps ?? "--"}</td>
<td class="num">${money(cost)}</td>
<td><button class="row-action" data-open-case="${id}" type="button">Inspect</button></td>
</tr><tr><td colspan="9"><div class="detail ${openId === c.id ? "open" : ""}" id="detail-${id}">${detail(c)}</div></td></tr>`;
<td><div class="case-id" title="${id}">${id}</div></td>
<td><span class="pill cat">${escapeHtml(c.category || "case")}</span></td>
<td><span class="pill ${c.passed ? "pass" : "fail"}">${c.passed ? "Pass" : "Fail"}</span></td>
<td class="num ${scoreTone(c.scores?.tool_routing ?? 0)}">${c.scores?.tool_routing ?? "--"}</td>
<td class="num ${scoreTone(c.scores?.quality ?? 0)}">${c.scores?.quality ?? "--"}</td>
<td class="num">${((c.metrics?.latencyMs || 0) / 1000).toFixed(1)}s</td>
<td class="num">${c.metrics?.steps ?? "--"}</td>
<td class="num">${money(cost)}</td>
<td><button class="row-action" data-open-case="${id}" type="button">Inspect</button></td>
</tr><tr><td colspan="9"><div class="detail ${openId === c.id ? "open" : ""}" id="detail-${id}">${detail(c)}</div></td></tr>`;
}

function detail(c) {
Expand All @@ -815,7 +815,7 @@ <h2 class="panel-title">Latest model board</h2>
.map((t) => `<span class="pill cat">${escapeHtml(t)}</span>`)
.join("") || '<span class="sub">No tools called</span>';
return `<div class="box"><h3>Response</h3><pre>${escapeHtml(c.response || "No response captured.")}</pre></div>
<div class="box"><h3>Failures</h3><ul class="fail-list">${failures}</ul><h3 style="margin-top:14px">Tools</h3><div class="tools">${tools}</div></div>`;
<div class="box"><h3>Failures</h3><ul class="fail-list">${failures}</ul><h3 style="margin-top:14px">Tools</h3><div class="tools">${tools}</div></div>`;
}

function toggle(id) {
Expand Down
Loading