Skip to content

Commit 532dd67

Browse files
committed
fix: reconcile duplicate diagnostic stage revisions
1 parent 990e4f1 commit 532dd67

2 files changed

Lines changed: 27 additions & 2 deletions

File tree

apps/web/__tests__/unit/desktop-log-upload.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,30 @@ describe("desktop diagnostic reconstruction", () => {
137137
expect(
138138
analysis.operations[0].stages.map((stage) => stage.revision),
139139
).toEqual([1, 2, 3]);
140+
expect(analysis.operations[0].stages[1]).toEqual({
141+
revision: 2,
142+
stage: "rendering",
143+
elapsedMs: 600,
144+
outcome: "in_progress",
145+
});
146+
});
147+
148+
it("keeps the newest duplicate stage in either input order", () => {
149+
const stale = record({ revision: 2, elapsedMs: 1 });
150+
const current = record({ revision: 2, stage: "rendering", elapsedMs: 600 });
151+
for (const [snapshot, logged] of [
152+
[stale, current],
153+
[current, stale],
154+
]) {
155+
const analysis = analyzeDesktopDiagnostics(logLine(logged), {
156+
operations: { records: [snapshot] },
157+
});
158+
expect(analysis.operations[0]).toMatchObject({
159+
stage: "rendering",
160+
elapsedMs: 600,
161+
stages: [{ revision: 2, stage: "rendering", elapsedMs: 600 }],
162+
});
163+
}
140164
});
141165

142166
it("links a failed worker to its parent and retains the build and settings", () => {

apps/web/lib/desktop-diagnostic-analysis.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,9 @@ export function analyzeDesktopDiagnostics(log: string, context: unknown) {
9797
) {
9898
operation.latest = record;
9999
}
100-
if (!operation.stages.has(record.revision)) {
101-
if (operation.stages.size >= 32) {
100+
const previousStage = operation.stages.get(record.revision);
101+
if (!previousStage || record.elapsedMs > previousStage.elapsedMs) {
102+
if (!previousStage && operation.stages.size >= 32) {
102103
omittedStages++;
103104
} else {
104105
operation.stages.set(record.revision, {

0 commit comments

Comments
 (0)