Skip to content

Commit bc6f79f

Browse files
authored
fix(db): purge agentic availability rows (NULL-safe isl/osl match) (#554)
apply-overrides' availability cleanup matched rows with a row-value IN on (model, isl, osl, ...), which never matches agentic rows (isl/osl NULL), so a purge left the agentic availability row behind (found purging run 29089300938). Rewrite the match and the orphan NOT EXISTS with IS NOT DISTINCT FROM on isl/osl. No change for fixed-seq rows (non-null isl/osl behave as before). 中文:apply-overrides 的 availability 清理用行值 IN 匹配 (model, isl, osl, ...), 对 agentic 行(isl/osl 为 NULL)永不匹配,导致清理后残留 agentic availability 行 (在清理 run 29089300938 时发现)。改用 IS NOT DISTINCT FROM 做 NULL 安全匹配; 定长序列(isl/osl 非空)行为不变。
1 parent f113ef3 commit bc6f79f

1 file changed

Lines changed: 24 additions & 14 deletions

File tree

packages/db/src/apply-overrides.ts

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -200,11 +200,14 @@ async function purge(wrIds: number[]): Promise<void> {
200200
`;
201201
}
202202

203-
// Orphaned availability rows
203+
// Orphaned availability rows. NULL-safe on isl/osl (`IS NOT DISTINCT FROM`)
204+
// so agentic rows are matched too: agentic_traces availability has isl/osl
205+
// NULL, and a row-value `IN` / `=` never matches NULL — which previously
206+
// left agentic availability rows behind after a purge.
204207
if (availKeys.length > 0) {
205208
const models = availKeys.map((r) => r.model as string);
206-
const isls = availKeys.map((r) => r.isl as number);
207-
const osls = availKeys.map((r) => r.osl as number);
209+
const isls = availKeys.map((r) => r.isl as number | null);
210+
const osls = availKeys.map((r) => r.osl as number | null);
208211
const precisions = availKeys.map((r) => r.precision as string);
209212
const hardwares = availKeys.map((r) => r.hardware as string);
210213
const frameworks = availKeys.map((r) => r.framework as string);
@@ -214,20 +217,27 @@ async function purge(wrIds: number[]): Promise<void> {
214217

215218
await tx`
216219
DELETE FROM availability a
217-
WHERE (a.model, a.isl, a.osl, a.precision, a.hardware, a.framework, a.spec_method, a.disagg, a.date)
218-
IN (
219-
SELECT t.model, t.isl::int, t.osl::int, t.precision, t.hardware,
220-
t.framework, t.spec_method, t.disagg::boolean, t.date::date
221-
FROM unnest(
222-
${models}::text[], ${isls}::int[], ${osls}::int[],
223-
${precisions}::text[], ${hardwares}::text[], ${frameworks}::text[],
224-
${specMethods}::text[], ${disaggs}::text[], ${dates}::text[]
225-
) AS t(model, isl, osl, precision, hardware, framework, spec_method, disagg, date)
226-
)
220+
USING (
221+
SELECT t.model, t.isl::int AS isl, t.osl::int AS osl, t.precision, t.hardware,
222+
t.framework, t.spec_method, t.disagg::boolean AS disagg, t.date::date AS date
223+
FROM unnest(
224+
${models}::text[], ${isls}::int[], ${osls}::int[],
225+
${precisions}::text[], ${hardwares}::text[], ${frameworks}::text[],
226+
${specMethods}::text[], ${disaggs}::text[], ${dates}::text[]
227+
) AS t(model, isl, osl, precision, hardware, framework, spec_method, disagg, date)
228+
) k
229+
WHERE a.model = k.model
230+
AND a.isl IS NOT DISTINCT FROM k.isl
231+
AND a.osl IS NOT DISTINCT FROM k.osl
232+
AND a.precision = k.precision AND a.hardware = k.hardware
233+
AND a.framework = k.framework AND a.spec_method = k.spec_method
234+
AND a.disagg = k.disagg AND a.date = k.date
227235
AND NOT EXISTS (
228236
SELECT 1 FROM benchmark_results br
229237
JOIN configs c ON c.id = br.config_id
230-
WHERE c.model = a.model AND br.isl = a.isl AND br.osl = a.osl
238+
WHERE c.model = a.model
239+
AND br.isl IS NOT DISTINCT FROM a.isl
240+
AND br.osl IS NOT DISTINCT FROM a.osl
231241
AND c.precision = a.precision AND c.hardware = a.hardware
232242
AND c.framework = a.framework AND c.spec_method = a.spec_method
233243
AND c.disagg = a.disagg AND br.date = a.date AND br.error IS NULL

0 commit comments

Comments
 (0)