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
2 changes: 2 additions & 0 deletions docs/internals/16_performance-regressions.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ heap, and first-request latency against a fake Anthropic API and the real `claud
server, not the agents, is the bottleneck.
- Upper bounds no user hits daily, such as 20 clients reconnecting at once, run only with
`--stress`; the default reconnect is a user's 3 devices holding 10 threads each.
- `--quick` shortens every window for a per-PR or nightly check; `compare` refuses to mix quick
and full runs. `server-metrics --help` says which scenario to trust for what.
- Test macOS, Windows, and Linux with `--no-agent-scope`: Linux systemd agent scopes mask
per-process polling paths that other platforms run.

Expand Down
27 changes: 27 additions & 0 deletions scripts/server-metrics-report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,33 @@ export function noiseRule(metric: string, rules: ReadonlyArray<NoiseRule> = NOIS
return rules.find((rule) => rule.pattern.test(metric)) ?? { floor: 0, gate: true };
}

/** An error and the errors it wraps as one line, outermost first, repeats left out. */
export function describeFailure(error: unknown): string {
const parts: string[] = [];
const seen = new Set<unknown>();
for (let at = error; at !== undefined && at !== null && !seen.has(at);) {
seen.add(at);
if (typeof at !== "object") {
parts.push(String(at));
break;
}
const tag = "_tag" in at && typeof at._tag === "string" ? at._tag : undefined;
const message = "message" in at && typeof at.message === "string" ? at.message.trim() : "";
const text = message || tag || String(at);
if (!parts.some((part) => part.includes(text))) parts.push(text);
at = "cause" in at ? at.cause : undefined;
}
return parts.join(": ");
}

/** Why two files cannot be compared at all: a quick run measures shorter windows than a full one. */
export function profileMismatch(before: ServerMetrics, after: ServerMetrics) {
const profile = (metrics: ServerMetrics) => metrics.meta.profile ?? "full";
return profile(before) === profile(after)
? undefined
: `before is a ${profile(before)} run and after a ${profile(after)} one; compare quick runs only with quick runs`;
}

/** Throughput, where a drop is the regression. */
export const higherIsBetter = (metric: string) => metric.endsWith("PerMin");

Expand Down
37 changes: 37 additions & 0 deletions scripts/server-metrics.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import {
compareMetrics,
competingBetween,
activityRenewalMissed,
describeFailure,
heapGrowth,
loadWarnings,
nextActivityReport,
noiseReport,
noisePairProblem,
parsePsCpuTime,
profileMismatch,
parseRunSelection,
pathRewrites,
pathSpellings,
Expand Down Expand Up @@ -347,6 +349,41 @@ describe("compareMetrics on the busy shell snapshot", () => {
});
});

describe("describeFailure", () => {
it.each([
["a plain error", new Error("boom"), "boom"],
[
"an RPC error wrapping the server's",
new Error("RpcClientError", { cause: new Error("Command x was already handled") }),
"RpcClientError: Command x was already handled",
],
["a tagged error with no message", { _tag: "TimeoutError" }, "TimeoutError"],
[
"a cause that repeats its wrapper",
new Error("lost: gone", { cause: new Error("gone") }),
"lost: gone",
],
["a string", "exit 1", "exit 1"],
])("%s", (_name, error, expected) => {
expect(describeFailure(error)).toBe(expected);
});
});

describe("profileMismatch", () => {
const withProfile = (profile?: string): ServerMetrics => ({
meta: profile === undefined ? meta : { ...meta, profile },
runs: [],
});
it.each([
["two full runs", withProfile("full"), withProfile("full"), false],
["a file from before profiles, against a full run", withProfile(), withProfile("full"), false],
["two quick runs", withProfile("quick"), withProfile("quick"), false],
["a full run against a quick one", withProfile(), withProfile("quick"), true],
])("%s", (_name, before, after, refused) => {
expect(profileMismatch(before, after) !== undefined).toBe(refused);
});
});

describe("heapGrowth", () => {
it("lists only constructors that grew, small growth included", () => {
const before = new Map([
Expand Down
Loading
Loading