Skip to content

Commit c8ab214

Browse files
d-csclaude
andcommitted
fix(webapp): narrow synthetic-span machinePreset against the canonical enum
\`SyntheticRun.machinePreset\` is a plain string sourced from the mollifier snapshot, but \`SpanRun.machinePreset\` is the typed \`MachinePresetName\` enum (micro / small-1x / small-2x / medium-1x / medium-2x / large-1x / large-2x). The direct assignment failed \`tsc --noEmit\` and CI typecheck. Validate via \`MachinePresetName.safeParse\` and collapse unknown values to \`undefined\` so a stale preset returned by the buffer doesn't bleed into the UI as a typed-but-unknown value. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent f36c576 commit c8ab214

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

apps/webapp/app/v3/mollifier/syntheticSpanRun.server.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,20 @@ import {
44
extractIdempotencyKeyScope,
55
getUserProvidedIdempotencyKey,
66
} from "@trigger.dev/core/v3/serverOnly";
7+
import { MachinePresetName } from "@trigger.dev/core/v3/schemas";
78
import type { SpanRun } from "~/presenters/v3/SpanPresenter.server";
89
import type { SyntheticRun } from "./readFallback.server";
910

11+
// `SyntheticRun.machinePreset` is sourced from the snapshot payload as
12+
// a plain string, but `SpanRun.machinePreset` is the narrowed enum.
13+
// Validate against the canonical enum so an unknown / stale preset
14+
// string collapses to undefined rather than fighting the type checker.
15+
function narrowMachinePreset(value: string | undefined): SpanRun["machinePreset"] {
16+
if (value === undefined) return undefined;
17+
const parsed = MachinePresetName.safeParse(value);
18+
return parsed.success ? parsed.data : undefined;
19+
}
20+
1021
// Synthesise a SpanRun-shaped object from a buffered run so the run-detail
1122
// page's right-side details panel renders identically to a PG-resident
1223
// run. The shape matches `SpanPresenter.getRun`'s return value exactly;
@@ -147,7 +158,7 @@ export async function buildSyntheticSpanRun(args: {
147158
traceId: run.traceId ?? "",
148159
spanId: run.spanId ?? "",
149160
isCached: false,
150-
machinePreset: run.machinePreset,
161+
machinePreset: narrowMachinePreset(run.machinePreset),
151162
taskEventStore: "taskEvent",
152163
externalTraceId: undefined,
153164
};

0 commit comments

Comments
 (0)