fix(admin): split uncoded errors by crash site, label signed-in visitors, scope external calls

- Errors without a code are grouped by their first app stack frame (or the
  logging module), so unrelated TypeErrors no longer share one issue.
- "visitor" is a signed-in user with no role on the repository; it is no
  longer shown as "not signed in". Anonymous viewers are counted apart.
- The issue page no longer offers "Open user" next to "Open repository":
  users and repositories are counted from different records.
- With a service, repository or user filter, failed external calls are looked
  up by the faults' request IDs instead of the newest 2000 calls overall.
- The page says when the 2000-failure cap was reached.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Thomas DurieuxandClaude Opus 5.5 committed 2026-11-29 16:35:34 +00:00
1 parent d3860f29ad
commit fdd8f58944
7 files changed
+74 -22

No files matched your search

+3 -4
View File
@@ -194,7 +194,6 @@
<ul class="errs-evidence" v-if="selectedIssue.cause.evidence.length"><li v-for="(line, i) in selectedIssue.cause.evidence" :key="i">{{ line }}</li></ul>
<div class="errs-actions">
<a class="btn btn-sm" v-if="selectedIssue.repos.length === 1" :href="errRepoHref(selectedIssue.repos[0].id)">Open repository</a>
<a class="btn btn-sm" v-if="selectedIssue.users.length === 1" :href="errUserHref(selectedIssue.users[0].id)">Open user</a>
<a class="btn btn-sm" href="/admin/#performance">Open Performance</a>
<button type="button" class="btn btn-sm" v-if="curlFor(selectedIssue.occurrences[0])" @click="copyValue(curlFor(selectedIssue.occurrences[0]), 'curl command')">Copy curl</button>
<a class="btn btn-sm" v-if="issueData.grafanaUrl" :href="safeUrl(issueData.grafanaUrl)" target="_blank" rel="noopener noreferrer">Open in Grafana</a>
@@ -230,8 +229,8 @@
<div class="errs-who">
<h3>Who hit it</h3>
<p class="errs-placeholder" v-if="selectedIssue.viewers.notRecorded === selectedIssue.count">not recorded on these records</p>
<p v-else><strong>{{ errNumber(selectedIssue.viewers.signedIn) }}</strong> by signed-in users · <strong>{{ errNumber(selectedIssue.viewers.visitors) }}</strong> by visitors without a session<template v-if="selectedIssue.viewers.notRecorded"> · <span class="errs-placeholder">{{ errNumber(selectedIssue.viewers.notRecorded) }} not recorded</span></template></p>
<p v-if="selectedIssue.users.length" class="errs-user-list">Users: <template v-for="(user, i) in selectedIssue.users.slice(0, 8)" :key="user.id"><template v-if="i">, </template><a :href="errUserHref(user.id)">{{ userName(user.id) ? '@' + userName(user.id) : user.id }}</a> <span class="errs-muted">({{ user.count }})</span></template><template v-if="selectedIssue.userCount > 8"> and {{ selectedIssue.userCount - 8 }} more</template></p>
<p v-else><strong>{{ errNumber(selectedIssue.viewers.signedIn) }}</strong> by owners, coauthors or admins · <strong>{{ errNumber(selectedIssue.viewers.visitors) }}</strong> by signed-in visitors · <strong>{{ errNumber(selectedIssue.viewers.anonymous || 0) }}</strong> not signed in<template v-if="selectedIssue.viewers.notRecorded"> · <span class="errs-placeholder">{{ errNumber(selectedIssue.viewers.notRecorded) }} not recorded</span></template></p>
<p v-if="selectedIssue.users.length" class="errs-user-list">Users affected (counted separately from the repositories above; see the occurrences for which record carried which): <template v-for="(user, i) in selectedIssue.users.slice(0, 8)" :key="user.id"><template v-if="i">, </template><a :href="errUserHref(user.id)">{{ userName(user.id) ? '@' + userName(user.id) : user.id }}</a> <span class="errs-muted">({{ user.count }})</span></template><template v-if="selectedIssue.userCount > 8"> and {{ selectedIssue.userCount - 8 }} more</template></p>
</div>
</section>
</div>
@@ -248,7 +247,7 @@
<li v-for="(o, index) in (showAllOccurrences ? selectedIssue.occurrences : selectedIssue.occurrences.slice(0, 10))" :key="index">
<a :href="occurrenceHref(index)" :data-occurrence="index">
<time :datetime="o.timestamp">{{ errClock(o.timestamp, true) }}</time>
<span class="errs-occ-main"><span class="errs-mono" v-if="o.repoId">{{ o.repoId }}</span><span class="errs-placeholder" v-else>no repository</span><span class="errs-occ-sub">{{ o.viewer ? (o.viewer === 'visitor' || o.viewer === 'anonymous' ? 'visitor' : (userName(o.userId) ? '@' + userName(o.userId) : o.viewer)) : 'viewer not recorded' }}<template v-if="o.ms !== undefined"> · {{ errNumber(o.ms) }} ms</template></span></span>
<span class="errs-occ-main"><span class="errs-mono" v-if="o.repoId">{{ o.repoId }}</span><span class="errs-placeholder" v-else>no repository</span><span class="errs-occ-sub">{{ o.viewer ? (o.viewer === 'anonymous' ? 'not signed in' : o.viewer === 'visitor' ? 'signed-in visitor' : (userName(o.userId) ? '@' + userName(o.userId) : o.viewer)) : 'viewer not recorded' }}<template v-if="o.ms !== undefined"> · {{ errNumber(o.ms) }} ms</template></span></span>
<span class="errs-status" :class="errStatusClass(o.status || o.httpStatus)" v-if="o.status || o.httpStatus">{{ o.status || o.httpStatus }}</span>
</a>
</li>
+4 -1
View File
@@ -83,7 +83,8 @@ export function waterfall(events, issue) {
/** Role-only chip for the request header: the owner is already linked beside it. */
export function viewerChip(viewer) {
if (!viewer) return "";
if (viewer === "visitor" || viewer === "anonymous") return "Viewer not signed in";
if (viewer === "anonymous") return "Viewer not signed in";
if (viewer === "visitor") return "Viewer: signed-in visitor";
return `Viewer: ${(SIGNED_IN[viewer] || viewer).toLowerCase()}`;
}
@@ -91,6 +92,7 @@ export function viewerChip(viewer) {
export function viewerLabel(viewer) {
if (!viewer) return "";
if (SIGNED_IN[viewer]) return `Signed in as ${SIGNED_IN[viewer].toLowerCase()}`;
if (viewer === "visitor") return "Signed-in visitor (no role on the repository)";
return "Viewer not signed in";
}
@@ -222,6 +224,7 @@ export const errorsAdminController = function (state, http, location, interval)
if (!data) return "";
if (data.source === "history" && data.centralState === "skipped") return "Central logs are not used while this switch is on.";
if (data.source === "history") return ({ disabled: "Central logs are not configured.", unreachable: "Central logs did not answer.", busy: "Central logs are busy.", misconfigured: "Central log configuration is invalid." })[data.centralState] || "";
if (data.faultLimitReached) return "Showing the newest 2,000 failures: older issues in this window may be missing. Narrow the window or filter by service.";
if (data.state === "partial") return "Partial: a record limit or an invalid record reduced coverage.";
return "";
};
+22 -8
View File
@@ -45,7 +45,7 @@ const NETWORK_CODES = new Set(["ECONNRESET", "ECONNREFUSED", "ETIMEDOUT", "ENOTF
const IGNORED = new Set(["process_heartbeat", "queue_heartbeat", "process_started", "job_started", "job_completed", "deployment"]);
// Request envelopes repeat a failure that a more specific record of the same request describes.
const ENVELOPES = new Set(["edge_request", "request_completed"]);
const SIGNED_IN = new Set(["owner", "coauthor", "admin"]);
const ACCOUNT_ROLES = new Set(["owner", "coauthor", "admin"]);
export const statusOf = (row: Row) => Number(row.status || row.httpStatus) || 0;
const codeOf = (row: Row) => String(row.errorCode || row.errorType || (row.event === "edge_request" ? `edge_${statusOf(row) || "5xx"}` : row.event) || "unknown");
@@ -64,18 +64,30 @@ export function recordKind(row: Row): RecordKind {
return "issue";
}
/**
* Without an error code, the code or type alone says little: every TypeError in
* the API would share one issue. The first app stack frame (or the module that
* logged it) tells those crash sites apart.
*/
function uncodedSite(row: Row) {
if (row.errorCode || row.event === "edge_request") return "";
return firstFrame(row.errorStack) || String(row.module || "");
}
export function issueTitle(row: Row) {
const code = codeOf(row);
if (TITLES[code]) return TITLES[code];
if (row.event === "edge_request") return `Edge proxy returned ${statusOf(row) || "5xx"}`;
if (!row.errorCode && row.errorType) return `Code crashed: ${row.errorType}`;
if (row.event === "job_failed" && !row.errorCode) return "Background job failed";
return code.replace(/_/g, " ").replace(/^./, c => c.toUpperCase());
const site = uncodedSite(row);
const at = site ? ` in ${site}` : "";
if (!row.errorCode && row.errorType) return `Code crashed: ${row.errorType}${at}`;
if (row.event === "job_failed" && !row.errorCode) return `Background job failed${at}`;
return code.replace(/_/g, " ").replace(/^./, c => c.toUpperCase()) + at;
}
export function issueId(row: Row) {
// One cause (a GitHub limit, an outage) hits many routes: routes are listed inside the issue.
return createHash("sha256").update(JSON.stringify([codeOf(row), String(row.service || "")])).digest("hex").slice(0, 16);
return createHash("sha256").update(JSON.stringify([codeOf(row), String(row.service || ""), uncodedSite(row)])).digest("hex").slice(0, 16);
}
const time = (row: Row) => Date.parse(String(row.timestamp));
@@ -84,7 +96,8 @@ const seconds = (ms: number) => ms >= 1000 ? `${(ms / 1000).toFixed(1).replace(/
const plural = (n: number, word: string) => `${n.toLocaleString("en-US")} ${word}${n === 1 ? "" : "s"}`;
const hostLabel = (host: string) => host === "storage" ? "Storage" : /github/.test(host) ? "GitHub" : host === "other" ? "An external service" : host;
function firstFrame(stack: unknown) {
const line = String(stack || "").split("\n").find(value => /\(?[\w./-]+\.[jt]s:\d+/.test(value));
// The first frame in our code: dependencies and Node internals say little about the crash site.
const line = String(stack || "").split("\n").find(value => /\(?[\w./-]+\.[jt]s:\d+/.test(value) && !/node_modules|node:/.test(value));
const match = line?.match(/([\w-]+\.[jt]s):(\d+)/);
return match ? `${match[1]}:${match[2]}` : "";
}
@@ -207,8 +220,9 @@ export function buildIssues(rows: Row[], options: IssueOptions) {
const jobs = new Set(sorted.map(row => row.jobId).filter(validTraceId));
const repos = countBy(sorted, "repoId", validProjectId);
const users = countBy(sorted, "userId", validUserId);
const viewers = { signedIn: 0, visitors: 0, notRecorded: 0 };
for (const row of sorted) viewers[SIGNED_IN.has(String(row.viewer)) ? "signedIn" : row.viewer ? "visitors" : "notRecorded"]++;
// "visitor" is signed in without a role on the repository; "anonymous" has no session.
const viewers = { signedIn: 0, visitors: 0, anonymous: 0, notRecorded: 0 };
for (const row of sorted) viewers[ACCOUNT_ROLES.has(String(row.viewer)) ? "signedIn" : row.viewer === "visitor" ? "visitors" : row.viewer === "anonymous" ? "anonymous" : "notRecorded"]++;
const routeCounts = new Map<string, { route: string; method: string; count: number; last: string }>();
for (const row of sorted) {
const route = String(row.route || (row.queue ? `job ${row.queue}` : ""));
+15 -3
View File
@@ -232,15 +232,27 @@ export async function issueRecords(options: IssueSource) {
try {
const scope = `${range(o)}${o.service ? ` service:${o.service}` : ""}${identity(o)}`;
const noise = "(event:request_slow OR event:request_cancelled)";
const [faults, expected, external, counts] = await Promise.all([
const failedCalls = `${range(o)} event:external_request (upstreamStatus:>=400 OR errorCode:*)`;
const filtered = Boolean(o.service || o.repoId || o.userId);
const [faults, expected, unscoped, counts] = await Promise.all([
rows(base, `${scope} ${FAULTS} NOT ${noise} NOT event:external_request | sort by (_time) desc`, 2001, controller.signal),
rows(base, `${scope} severity:info errorCode:* NOT event:external_request | sort by (_time) desc`, 501, controller.signal),
rows(base, `${range(o)} event:external_request (upstreamStatus:>=400 OR errorCode:*) | sort by (_time) desc`, 2001, controller.signal).catch(() => ({ records: [], partial: true })),
filtered ? Promise.resolve(null) : rows(base, `${failedCalls} | sort by (_time) desc`, 2001, controller.signal).catch(() => ({ records: [], partial: true })),
noiseCounts(base, `${scope} ${noise} | stats by (event) count() n`, controller.signal).catch(() => null),
]);
// With a filter, the newest 2000 failed calls overall can miss the ones behind
// the filtered faults: external calls carry no user and often no repository,
// so look them up by the faults' request IDs instead.
let external = unscoped;
if (!external) {
const ids = [...new Set(faults.records.map(row => row.requestId).filter(validTraceId))].slice(0, 200);
external = ids.length
? await rows(base, `${failedCalls} requestId:in(${ids.map(id => `"${id}"`).join(",")}) | sort by (_time) desc`, 2001, controller.signal).catch(() => ({ records: [], partial: true }))
: { records: [], partial: false };
}
const records = [...faults.records.slice(0, 2000), ...expected.records.slice(0, 500)];
return { ...common, state: faults.partial || expected.partial ? "partial" : records.length ? "ready" : "empty", records, external: external.records.slice(0, 2000),
externalPartial: external.partial, noise: counts, captured: records.length, limit: 2500 };
externalPartial: external.partial, noise: counts, captured: records.length, limit: 2500, faultLimit: 2000, faultLimitReached: faults.records.length >= 2000 };
} catch { return { ...common, state: "unreachable", records: [], external: [], noise: null }; }
finally { controller.abort(); clearTimeout(timer); active--; }
}
+1 -1
View File
@@ -161,7 +161,7 @@ router.get("/errors/issues", async (req, res) => {
source: useCentral ? "central" : "history", state: useCentral ? central.state : history!.state,
centralState: central?.state || "skipped", grafanaUrl: central?.grafanaUrl || null,
window: query.window, start: query.start, end: query.end, filters: { service: query.service, repoId: query.repoId, userId: query.userId },
captured: rows.length, redisCollecting: process.env.LOG_REDIS_MIRROR !== "off", ...built, names,
captured: rows.length, faultLimitReached: Boolean(useCentral && "faultLimitReached" in central && central.faultLimitReached), redisCollecting: process.env.LOG_REDIS_MIRROR !== "off", ...built, names,
});
});
+26 -2
View File
@@ -27,14 +27,35 @@ describe('admin error issues', () => {
const file = issues.find(issue => issue.code === 'upstream_error' && issue.service === 'api');
expect(file).to.include({ count: 3, requests: 3, repoCount: 2, userCount: 1, title: 'GitHub returned an error', failingNow: true, routeCount: 1, route: '/api/repo/:repoId/file/:path' });
expect(file.repos[0]).to.include({ id: 'repo-one', count: 2 });
expect(file.viewers).to.deep.equal({ signedIn: 1, visitors: 2, notRecorded: 0 });
expect(file.viewers).to.deep.equal({ signedIn: 1, visitors: 2, anonymous: 0, notRecorded: 0 });
expect(file.occurrences.map(o => o.requestId)).to.deep.equal([rid(1), rid(2), rid(3)]);
expect(file.trend.reduce((a, b) => a + b, 0)).to.equal(3);
expect(issues.find(issue => issue.code === 'TypeError').title).to.equal('Code crashed: TypeError');
expect(issues.find(issue => issue.code === 'TypeError').title).to.equal('Code crashed: TypeError in route');
expect(summary).to.include({ issues: 3, failingNow: 3, failedRecords: 5, repositories: 2, users: 1 });
expect(issueId(rows[0])).to.equal(file.id);
});
it('splits uncoded crashes by their first app frame, and uncoded warnings by module', () => {
const crash = (n, stack) => fault({ requestId: rid(n), errorCode: undefined, errorType: 'TypeError', status: 500,
errorStack: `TypeError: x\n at f (/app/node_modules/mongoose/lib/query.js:10:2)\n at node:internal/process/task_queues:95:5\n ${stack}` });
const warn = (n, module) => fault({ requestId: rid(n), errorCode: undefined, status: undefined, severity: 'warn', module });
const rows = [crash(1, 'at a (/app/build/core/Repository.js:42:7)'), crash(2, 'at a (/app/build/core/Repository.js:42:7)'),
crash(3, 'at b (/app/build/server/routes/file.js:9:3)'), warn(4, 'storage'), warn(5, 'zip'),
fault({ requestId: rid(6) }), fault({ requestId: rid(7), errorStack: 'at c (/app/build/x.js:1:1)' })];
const { issues } = buildIssues(rows, window);
const titles = issues.map(issue => [issue.title, issue.count]).sort();
expect(titles).to.deep.equal([
['Application log in storage', 1], ['Application log in zip', 1],
['Code crashed: TypeError in Repository.js:42', 2], ['Code crashed: TypeError in file.js:9', 1],
['GitHub returned an error', 2],
]);
});
it('labels signed-in visitors apart from viewers without a session', () => {
const rows = [fault({ requestId: rid(1), viewer: 'visitor' }), fault({ requestId: rid(2), viewer: 'anonymous' }), fault({ requestId: rid(3), viewer: 'coauthor' }), fault({ requestId: rid(4) })];
expect(buildIssues(rows, window).issues[0].viewers).to.deep.equal({ signedIn: 1, visitors: 1, anonymous: 1, notRecorded: 1 });
});
it('keeps one cause across routes in one issue and lists its routes, most frequent first', () => {
const routes = ['/api/user/all_repositories', '/api/repo/:owner/:repo', '/api/repo/:owner/:repo/readme', '/api/gist/source/:id', '/api/pr/:owner/:repo/:id'];
const limited = Array.from({ length: 102 }, (_, i) => fault({ requestId: rid(i), errorCode: 'github_rate_limit_exceeded', status: 429, severity: 'warn', ms: 7,
@@ -164,6 +185,9 @@ describe('admin error issues', () => {
expect(result.state).to.equal('ready');
expect(result.noise).to.deep.equal({ slow: 12, interrupted: 3 });
expect(result.external[0]).to.include({ event: 'external_request', upstreamHost: 'api.github.com', upstreamStatus: 502 });
// Filtered: external calls are looked up by the faults' request IDs, not the newest calls overall.
expect(queries.find(q => q.includes('event:external_request ('))).to.include(`requestId:in("${rid(1)}")`);
expect(result.faultLimitReached).to.equal(false);
const faults = queries.find(q => q.includes('severity:error'));
expect(faults).to.include('service:api repoId:"repo-one" userId:"' + USER + '"').and.include('NOT (event:request_slow OR event:request_cancelled)');
expect(result.records[0]).to.include({ repoId: 'repo-one', userId: USER, viewer: 'owner' });
+3 -3
View File
@@ -87,7 +87,7 @@ describe("Vue 3 UI", function () {
const now = new Date().toISOString();
return { id: "issue-1", title: "GitHub returned an error", code: "upstream_error", errorCode: "upstream_error", status: 502, service: "api", route: "/api/repo/:repoId/file/:path", method: "GET",
count: 3, requests: 3, jobs: 0, repoCount: 1, repos: [{ id: "repo-one", count: 3, last: now }], userCount: 1, users: [{ id: "65f0c0de0000000000000001", count: 1, last: now }],
viewers: { signedIn: 1, visitors: 2, notRecorded: 0 }, first: now, last: now, firstRelease: "abcdef1", newInRelease: null, failingNow: true, trend: [0, 1, 2],
viewers: { signedIn: 1, visitors: 2, anonymous: 0, notRecorded: 0 }, first: now, last: now, firstRelease: "abcdef1", newInRelease: null, failingNow: true, trend: [0, 1, 2],
routeCount: 2, routes: [{ route: "/api/repo/:repoId/file/:path", method: "GET", count: 2, last: now }, { route: "/api/repo/:repoId/zip", method: "GET", count: 1, last: now }], routeKnown: 3,
cause: { source: "github", label: "GitHub", summary: "GitHub answered 502 on GET /repos/{owner}/{repo}/contents/* in 3 of 3 failures.", detail: "", evidence: [] },
occurrences: [{ timestamp: now, requestId: ERR_REQ, repoId: "repo-one", viewer: "visitor", requestPath: "/api/repo/repo-one/file/a.py", method: "GET", route: "/api/repo/:repoId/file/:path", status: 502, service: "api" },
@@ -165,7 +165,7 @@ describe("Vue 3 UI", function () {
const repoLink = doc.querySelector(".errs-repos a[href='/admin/repositories?search=repo-one']");
expect(repoLink).to.not.equal(null);
expect(doc.querySelector(".errs-repos a[href='/admin/users/id:65f0c0de0000000000000001']").textContent).to.equal("@alice");
expect(doc.querySelector(".errs-who").textContent).to.include("1 by signed-in users").and.include("2 by visitors");
expect(doc.querySelector(".errs-who").textContent).to.include("1 by owners, coauthors or admins").and.include("2 by signed-in visitors").and.include("0 not signed in");
expect(doc.querySelector(".errs-list").style.display).to.equal("none");
[...doc.querySelectorAll(".errs-detail a.btn")].find(a => a.textContent.includes("All errors")).click(); await delay(60);
expect(doc.activeElement.getAttribute("data-issue-link")).to.equal("issue-1");
@@ -189,7 +189,7 @@ describe("Vue 3 UI", function () {
expect(trace.url.searchParams.get("id")).to.equal(ERR_REQ);
expect(trace.url.searchParams.get("window")).to.equal("24h");
expect(doc.querySelector("#errs-detail-title").textContent).to.equal("GET /api/repo/repo-one/file/a.py");
expect(doc.querySelector(".errs-chips").textContent).to.include("Viewer not signed in").and.include("repo-one").and.include("@alice");
expect(doc.querySelector(".errs-chips").textContent).to.include("Viewer: signed-in visitor").and.include("repo-one").and.include("@alice");
const steps = [...doc.querySelectorAll(".errs-waterfall li")];
expect(steps.map(li => li.querySelector("strong").textContent)).to.deep.equal(["edge request", "GitHub · GET", "upstream_error"]);
expect(steps[1].classList.contains("k-external")).to.equal(true);