Skip to content

Commit befbf79

Browse files
committed
fix(webapp,run-store): make the unroutable-id fallback actually catch, and count only routed traffic
Two defects from review of the previous commit. undefinedOnUnroutableId took the read as a promise, but RoutingRunStore.findRun is not async and resolves the shard before it returns anything, so an unroutable id threw while the argument was still being evaluated and never reached the try block. Every dashboard and resource route it was added to still answered a server error. It now takes a thunk, and a test covers the synchronous-throw case that types cannot. runops_shard_routed_total counted every call through the generic store lookup, which probes, fan-outs and fallback legs also use, so an unrouted miss credited legacy and a waitpoint home-miss counted twice. Counting moved to the two id-routed entry points, so the series means what its name says. Tests cover an unrouted miss and a probe leg.
1 parent 9b63809 commit befbf79

15 files changed

Lines changed: 234 additions & 146 deletions

apps/webapp/app/routes/@.runs.$runParam.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,19 @@ export async function loader({ params, request }: LoaderFunctionArgs) {
3535
}
3636

3737
const run = await undefinedOnUnroutableId(
38-
runStore.findRun(
39-
{
40-
friendlyId: runParam,
41-
},
42-
{
43-
select: {
44-
spanId: true,
45-
runtimeEnvironmentId: true,
38+
() =>
39+
runStore.findRun(
40+
{
41+
friendlyId: runParam,
42+
},
43+
{
44+
select: {
45+
spanId: true,
46+
runtimeEnvironmentId: true,
47+
},
4648
},
47-
},
48-
prisma
49-
),
49+
prisma
50+
),
5051
{ runParam: params.runParam ?? params.runId }
5152
);
5253

apps/webapp/app/routes/orgs.$organizationSlug.projects.$projectParam.runs.$runParam.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,18 @@ export const loader = async ({ request, params }: LoaderFunctionArgs) => {
1717
const { organizationSlug, projectParam, runParam } = ParamSchema.parse(params);
1818

1919
const run = await undefinedOnUnroutableId(
20-
runStore.findRun(
21-
{
22-
friendlyId: runParam,
23-
},
24-
{
25-
select: {
26-
projectId: true,
27-
runtimeEnvironmentId: true,
20+
() =>
21+
runStore.findRun(
22+
{
23+
friendlyId: runParam,
2824
},
29-
}
30-
),
25+
{
26+
select: {
27+
projectId: true,
28+
runtimeEnvironmentId: true,
29+
},
30+
}
31+
),
3132
{ runParam: params.runParam ?? params.runId }
3233
);
3334

apps/webapp/app/routes/projects.v3.$projectRef.runs.$runParam.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,20 @@ export async function loader({ params, request }: LoaderFunctionArgs) {
3838
}
3939

4040
const run = await undefinedOnUnroutableId(
41-
runStore.findRun(
42-
{
43-
friendlyId: validatedParams.runParam,
44-
},
45-
{
46-
select: {
47-
friendlyId: true,
48-
spanId: true,
49-
runtimeEnvironmentId: true,
41+
() =>
42+
runStore.findRun(
43+
{
44+
friendlyId: validatedParams.runParam,
5045
},
51-
},
52-
prisma
53-
),
46+
{
47+
select: {
48+
friendlyId: true,
49+
spanId: true,
50+
runtimeEnvironmentId: true,
51+
},
52+
},
53+
prisma
54+
),
5455
{ runParam: params.runParam ?? params.runId }
5556
);
5657

apps/webapp/app/routes/resources.orgs.$organizationSlug.projects.$projectParam.env.$envParam.runs.$runParam.realtime.v1.sessions.$sessionId.$io.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
6262
// Replica lag can null out a live run; a spurious 404 breaks the dashboard Agent tab subscription
6363
// (useRealtimeStream surfaces the error and does not auto-retry). Re-read the primary on a miss.
6464
const run =
65-
(await undefinedOnUnroutableId(runStore.findRun(runWhere, runArgs, $replica), {
65+
(await undefinedOnUnroutableId(() => runStore.findRun(runWhere, runArgs, $replica), {
6666
runParam: params.runParam,
6767
})) ??
68-
(await undefinedOnUnroutableId(runStore.findRunOnPrimary(runWhere, runArgs), {
68+
(await undefinedOnUnroutableId(() => runStore.findRunOnPrimary(runWhere, runArgs), {
6969
runParam: params.runParam,
7070
}));
7171

apps/webapp/app/routes/resources.orgs.$organizationSlug.projects.$projectParam.env.$envParam.runs.$runParam.realtime.v1.streams.$runId.$streamId.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
6161
// Replica lag can null out a live run; a spurious 404 breaks the dashboard Agent tab subscription
6262
// (useRealtimeStream surfaces the error and does not auto-retry). Re-read the primary on a miss.
6363
const run =
64-
(await undefinedOnUnroutableId(runStore.findRun(runWhere, runArgs, $replica), {
64+
(await undefinedOnUnroutableId(() => runStore.findRun(runWhere, runArgs, $replica), {
6565
runParam: params.runParam,
6666
})) ??
67-
(await undefinedOnUnroutableId(runStore.findRunOnPrimary(runWhere, runArgs), {
67+
(await undefinedOnUnroutableId(() => runStore.findRunOnPrimary(runWhere, runArgs), {
6868
runParam: params.runParam,
6969
}));
7070

apps/webapp/app/routes/resources.orgs.$organizationSlug.projects.$projectParam.env.$envParam.runs.$runParam.realtime.v1.streams.$runId.input.$streamId.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
6363
// Replica lag can null out a live run; a spurious 404 breaks the dashboard Agent tab input-stream
6464
// subscription (useRealtimeStream surfaces the error, no auto-retry). Re-read the primary on a miss.
6565
const run =
66-
(await undefinedOnUnroutableId(runStore.findRun(runWhere, runArgs, $replica), {
66+
(await undefinedOnUnroutableId(() => runStore.findRun(runWhere, runArgs, $replica), {
6767
runParam: params.runParam,
6868
})) ??
69-
(await undefinedOnUnroutableId(runStore.findRunOnPrimary(runWhere, runArgs), {
69+
(await undefinedOnUnroutableId(() => runStore.findRunOnPrimary(runWhere, runArgs), {
7070
runParam: params.runParam,
7171
}));
7272

apps/webapp/app/routes/resources.runs.$runParam.logs.download.ts

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,22 @@ export async function loader({ params, request }: LoaderFunctionArgs) {
3333
// membership is a control-plane concern resolved separately below — joining it here is a
3434
// cross-DB join that returns nothing once the run lives in run-ops.
3535
let run = await undefinedOnUnroutableId(
36-
runStore.findRun(
37-
{ friendlyId: parsedParams.runParam },
38-
{
39-
select: {
40-
friendlyId: true,
41-
traceId: true,
42-
organizationId: true,
43-
runtimeEnvironmentId: true,
44-
createdAt: true,
45-
completedAt: true,
46-
taskEventStore: true,
47-
taskIdentifier: true,
48-
},
49-
}
50-
),
36+
() =>
37+
runStore.findRun(
38+
{ friendlyId: parsedParams.runParam },
39+
{
40+
select: {
41+
friendlyId: true,
42+
traceId: true,
43+
organizationId: true,
44+
runtimeEnvironmentId: true,
45+
createdAt: true,
46+
completedAt: true,
47+
taskEventStore: true,
48+
taskIdentifier: true,
49+
},
50+
}
51+
),
5152
{ runParam: parsedParams.runParam }
5253
);
5354

apps/webapp/app/routes/resources.runs.$runParam.ts

Lines changed: 59 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -20,67 +20,68 @@ export const loader = async ({ request, params }: LoaderFunctionArgs) => {
2020
const parsedParams = v3RunParamsSchema.pick({ runParam: true }).parse(params);
2121

2222
const run = await undefinedOnUnroutableId(
23-
runStore.findRun(
24-
{
25-
friendlyId: parsedParams.runParam,
26-
},
27-
{
28-
select: {
29-
id: true,
30-
traceId: true,
31-
//metadata
32-
number: true,
33-
taskIdentifier: true,
34-
friendlyId: true,
35-
isTest: true,
36-
runTags: true,
37-
machinePreset: true,
38-
runtimeEnvironmentId: true,
39-
projectId: true,
40-
lockedById: true,
41-
lockedToVersionId: true,
42-
//status + duration
43-
status: true,
44-
startedAt: true,
45-
createdAt: true,
46-
updatedAt: true,
47-
queuedAt: true,
48-
completedAt: true,
49-
logsDeletedAt: true,
50-
//idempotency
51-
idempotencyKey: true,
52-
//delayed
53-
delayUntil: true,
54-
//ttl
55-
ttl: true,
56-
expiredAt: true,
57-
//queue
58-
queue: true,
59-
concurrencyKey: true,
60-
//schedule
61-
scheduleId: true,
62-
//usage
63-
baseCostInCents: true,
64-
costInCents: true,
65-
usageDurationMs: true,
66-
payload: true,
67-
payloadType: true,
68-
metadata: true,
69-
metadataType: true,
70-
maxAttempts: true,
71-
parentTaskRun: {
72-
select: {
73-
friendlyId: true,
23+
() =>
24+
runStore.findRun(
25+
{
26+
friendlyId: parsedParams.runParam,
27+
},
28+
{
29+
select: {
30+
id: true,
31+
traceId: true,
32+
//metadata
33+
number: true,
34+
taskIdentifier: true,
35+
friendlyId: true,
36+
isTest: true,
37+
runTags: true,
38+
machinePreset: true,
39+
runtimeEnvironmentId: true,
40+
projectId: true,
41+
lockedById: true,
42+
lockedToVersionId: true,
43+
//status + duration
44+
status: true,
45+
startedAt: true,
46+
createdAt: true,
47+
updatedAt: true,
48+
queuedAt: true,
49+
completedAt: true,
50+
logsDeletedAt: true,
51+
//idempotency
52+
idempotencyKey: true,
53+
//delayed
54+
delayUntil: true,
55+
//ttl
56+
ttl: true,
57+
expiredAt: true,
58+
//queue
59+
queue: true,
60+
concurrencyKey: true,
61+
//schedule
62+
scheduleId: true,
63+
//usage
64+
baseCostInCents: true,
65+
costInCents: true,
66+
usageDurationMs: true,
67+
payload: true,
68+
payloadType: true,
69+
metadata: true,
70+
metadataType: true,
71+
maxAttempts: true,
72+
parentTaskRun: {
73+
select: {
74+
friendlyId: true,
75+
},
7476
},
75-
},
76-
rootTaskRun: {
77-
select: {
78-
friendlyId: true,
77+
rootTaskRun: {
78+
select: {
79+
friendlyId: true,
80+
},
7981
},
8082
},
81-
},
82-
}
83-
),
83+
}
84+
),
8485
{ runParam: params.runParam ?? params.runId }
8586
);
8687

apps/webapp/app/routes/resources.taskruns.$runParam.debug.ts

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,22 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
2020
// project/org-membership auth is a control-plane concern resolved separately below —
2121
// joining it here is a cross-DB join that returns nothing once the run lives in run-ops.
2222
const run = await undefinedOnUnroutableId(
23-
runStore.findRun(
24-
{ friendlyId: runParam },
25-
{
26-
select: {
27-
id: true,
28-
engine: true,
29-
friendlyId: true,
30-
queue: true,
31-
concurrencyKey: true,
32-
queueTimestamp: true,
33-
runtimeEnvironmentId: true,
34-
projectId: true,
35-
},
36-
}
37-
),
23+
() =>
24+
runStore.findRun(
25+
{ friendlyId: runParam },
26+
{
27+
select: {
28+
id: true,
29+
engine: true,
30+
friendlyId: true,
31+
queue: true,
32+
concurrencyKey: true,
33+
queueTimestamp: true,
34+
runtimeEnvironmentId: true,
35+
projectId: true,
36+
},
37+
}
38+
),
3839
{ runParam: params.runParam ?? params.runId }
3940
);
4041

apps/webapp/app/routes/runs.$runParam.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,19 @@ export async function loader({ params, request }: LoaderFunctionArgs) {
1818
const { runParam } = ParamsSchema.parse(params);
1919

2020
const run = await undefinedOnUnroutableId(
21-
runStore.findRun(
22-
{
23-
friendlyId: runParam,
24-
},
25-
{
26-
select: {
27-
spanId: true,
28-
projectId: true,
29-
runtimeEnvironmentId: true,
21+
() =>
22+
runStore.findRun(
23+
{
24+
friendlyId: runParam,
3025
},
31-
}
32-
),
26+
{
27+
select: {
28+
spanId: true,
29+
projectId: true,
30+
runtimeEnvironmentId: true,
31+
},
32+
}
33+
),
3334
{ runParam: params.runParam ?? params.runId }
3435
);
3536

0 commit comments

Comments
 (0)