The best way to control Claude Code, Codex and more from any computer or phone
fix(diagnostics): include browser trace failures (#23438)
Aditya Garud committed
Oct 31, 2026 at 02:18 UTC
3a537d2c916e61493e91fd104e3fc525116d980d
2 files changed
+41
-15
apps/server/src/diagnostics/TraceDiagnostics.test.ts
+29
@@ -61,6 +61,35 @@ function readTraces(fileSystem: Partial<FileSystem.FileSystem>) {
61
}
62
63
describe("TraceDiagnostics", () => {
64
+ it("includes browser failures and interruptions in diagnostics", () => {
65
+ const diagnostics = aggregateLines(
66
+ [
67
+ { status: { code: "2", message: "Browser request failed" }, attributes: {} },
68
+ { status: { code: "0" }, attributes: { "effect.fiber.interrupted": true } },
69
+ { status: { code: "1", message: "Interrupted" }, attributes: {} },
70
+ { status: { code: "1" }, attributes: {} },
71
+ ].map((outcome, index) =>
72
+ JSON.stringify({
73
+ type: "otlp-span",
74
+ name: "browser.request",
75
+ traceId: `trace-${index}`,
76
+ spanId: `span-${index}`,
77
+ startTimeUnixNano: ns(index * 100),
78
+ endTimeUnixNano: ns(index * 100 + 10),
79
+ durationMs: 10,
80
+ ...outcome,
81
+ }),
82
+ ),
83
+ );
84
+
85
+ assert.equal(diagnostics.recordCount, 4);
86
+ assert.equal(diagnostics.failureCount, 1);
87
+ assert.equal(diagnostics.interruptionCount, 2);
88
+ assert.equal(diagnostics.topSpansByCount[0]?.failureCount, 1);
89
+ assert.equal(diagnostics.commonFailures[0]?.cause, "Browser request failed");
90
+ assert.equal(diagnostics.latestFailures[0]?.cause, "Browser request failed");
91
+ });
92
+
93
it.effect("aggregates failures, slow spans, log levels, and parse errors", () =>
94
Effect.sync(() => {
95
const diagnostics = aggregateLines([
apps/server/src/diagnostics/TraceDiagnostics.ts
+12
-15
@@ -18,17 +18,6 @@ import * as Result from "effect/Result";
18
import * as Schema from "effect/Schema";
19
import * as Stream from "effect/Stream";
20
21
-interface TraceRecordLike {
22
- readonly name?: unknown;
23
- readonly traceId?: unknown;
24
- readonly spanId?: unknown;
25
- readonly startTimeUnixNano?: unknown;
26
- readonly endTimeUnixNano?: unknown;
27
- readonly durationMs?: unknown;
28
- readonly exit?: unknown;
29
- readonly events?: unknown;
30
-}
31
-
21
interface TraceEventLike {
22
readonly name?: unknown;
23
readonly timeUnixNano?: unknown;
@@ -85,7 +74,7 @@ export function toRotatedTracePaths(
74
return [...backups, traceFilePath];
75
}
76
88
-function isRecordObject(value: unknown): value is TraceRecordLike {
77
+function isRecordObject(value: unknown): value is Readonly<Record<string, unknown>> {
78
return typeof value === "object" && value !== null;
79
}
80
@@ -253,8 +242,13 @@ export function makeTraceDiagnosticsAggregator(
242
lastSpanAt === null || DateTime.isGreaterThan(endedAt, lastSpanAt) ? endedAt : lastSpanAt;
243
244
const exitTag = readExitTag(parsed.exit);
256
- const isFailure = exitTag === "Failure";
257
- const isInterrupted = exitTag === "Interrupted";
245
+ const status = isRecordObject(parsed.status) ? parsed.status : {};
246
+ const attributes = isRecordObject(parsed.attributes) ? parsed.attributes : {};
247
+ const isFailure = exitTag === "Failure" || status.code === "2";
248
+ const isInterrupted =
249
+ exitTag === "Interrupted" ||
250
+ attributes["effect.fiber.interrupted"] === true ||
251
+ status.message === "Interrupted";
252
if (isFailure) failureCount += 1;
253
if (isInterrupted) interruptionCount += 1;
254
@@ -277,7 +271,10 @@ export function makeTraceDiagnosticsAggregator(
271
insertBounded(slowestSpans, spanItem, TOP_LIMIT, slowestFirst);
272
273
if (isFailure) {
280
- const cause = readExitCause(parsed.exit);
274
+ const cause =
275
+ exitTag === "Failure"
276
+ ? readExitCause(parsed.exit)
277
+ : (toStringValue(status.message)?.trim() ?? "Failure");
278
insertBounded(latestFailures, { ...spanItem, cause }, RECENT_LIMIT, latestEndedFirst);
279
280
const failureKey = `${name}\0${cause}`;