From f4ed34202721c461b050abdbf8a38183192e34e0 Mon Sep 17 00:00:00 2001 From: repo-worker-tmp-code-b Date: Wed, 11 Nov 2026 07:18:28 -0600 Subject: [PATCH] aggregator: read AA configs/CAI from canonical measurement_events, retire benchmark_results (code#4401 tranche 2) --- .../aggregator/scripts/collect-fleet-feed.ts | 2 +- pm-stack/aggregator/src/aa-batch-sql.ts | 25 +++++++++++++++---- pm-stack/aggregator/src/aa.ts | 5 ++-- pm-stack/aggregator/src/model.ts | 4 +-- 4 files changed, 26 insertions(+), 10 deletions(-) diff --git a/pm-stack/aggregator/scripts/collect-fleet-feed.ts b/pm-stack/aggregator/scripts/collect-fleet-feed.ts index 7767e482c5..1ef03fd884 100644 --- a/pm-stack/aggregator/scripts/collect-fleet-feed.ts +++ b/pm-stack/aggregator/scripts/collect-fleet-feed.ts @@ -44,7 +44,7 @@ // section and logs only that it was omitted. // - the AA cost explorer data — Supabase `ainventory` (the AA // import: v_rankings, v_threshold_metrics, -// benchmark_results — both the AA Intelligence Index rows and the +// measurement_events — both the AA Intelligence Index rows and the // Coding Agent Index rows, kept as separate benchmark families — // the Test_Runs data, and the price event log's v_current_prices), // read through v_latest_import_batch via the Management API SQL endpoint. diff --git a/pm-stack/aggregator/src/aa-batch-sql.ts b/pm-stack/aggregator/src/aa-batch-sql.ts index 920a0eb627..6d5f9517e0 100644 --- a/pm-stack/aggregator/src/aa-batch-sql.ts +++ b/pm-stack/aggregator/src/aa-batch-sql.ts @@ -549,6 +549,17 @@ select coalesce(( * The full AA section payload for one batch (null = latest). This mirrors the * collector's previous AA_SQL exactly except that every batch predicate and * both latest-pinned views now take the same batch expression. + * + * Tranche 2 of code#4401 (2026-11-11): the 'configs' and 'cai' sections no + * longer read the frozen ainventory.benchmark_results table; they read the + * canonical ainventory.measurement_events store. Canonical events carry no + * sheet import_batch identity, so those two sections ignore the batch + * expression and scope to the latest workbook-import ingest batch — the + * events' own equivalent of the latest import batch — with the filters that + * reproduce the retired table's latest-batch rows exactly (verified by + * full-row EXCEPT comparison before the table was dropped: configs 35/35, + * cai 27/27, zero differences either way). benchmark_results is dropped; + * measurement_events is the one canonical read path for benchmark facts. */ export function aaPayloadSql(batch: string | null): string { const b = batchExpression(batch); @@ -591,12 +602,14 @@ select jsonb_build_object( 'configs', coalesce(( select jsonb_agg(jsonb_build_object( 'modelName', model_name, 'benchmark', benchmark, 'effort', effort, - 'intelligence', value_num, 'costPerTaskUsd', cost_per_task_usd, 'speedTps', speed_tps + 'intelligence', value_num, 'costPerTaskUsd', cost_per_task_usd, 'speedTps', output_tps ) order by model_name, effort) - from ainventory.benchmark_results br - where br.import_batch = ${b} + from ainventory.measurement_events br + where br.ingest_batch_id = (select ingest_batch_id from ainventory.measurement_events + where source_kind = 'workbook-import' order by ingested_at desc limit 1) and br.benchmark like 'AA Intelligence Index%' and br.metric = 'intelligence_index' + and br.benchmark_version is null ), '[]'::jsonb), 'testRunRows', coalesce(( select jsonb_agg(jsonb_build_object('rowIndex', row_index, 'cells', data->'cells') order by row_index) @@ -617,10 +630,12 @@ select jsonb_build_object( 'sweAtlas', nullif(raw->>'swe_atlas_qna_pct', '')::numeric, 'snapshotDate', nullif(raw->>'snapshot_date', ''), 'sourceUrl', nullif(raw->>'source_url', '') ) order by value_num desc nulls last, model_name) - from ainventory.benchmark_results br - where br.import_batch = ${b} + from ainventory.measurement_events br + where br.ingest_batch_id = (select ingest_batch_id from ainventory.measurement_events + where source_kind = 'workbook-import' order by ingested_at desc limit 1) and br.benchmark like 'Artificial Analysis Coding Agent Index%' and br.metric = 'cai_index_score' + and br.raw->>'benchmark_version' is not null ), '[]'::jsonb), 'prices', coalesce(( select jsonb_agg(jsonb_build_object( diff --git a/pm-stack/aggregator/src/aa.ts b/pm-stack/aggregator/src/aa.ts index fd54de7398..2e5240d627 100644 --- a/pm-stack/aggregator/src/aa.ts +++ b/pm-stack/aggregator/src/aa.ts @@ -1,7 +1,8 @@ // The AA cost explorer as data. The source of record is the Supabase // `ainventory` schema (the AA import: v_rankings, -// v_threshold_metrics, benchmark_results, and the Test_Runs data in -// sheet_rows, all read through v_latest_import_batch). The collector +// v_threshold_metrics, measurement_events (the canonical benchmark +// store, code#4401), and the Test_Runs data in sheet_rows, read +// through v_latest_import_batch where the store carries batch identity). The collector // queries it, assembles the section with the helpers here, and embeds // it in the fleet feed; the aggregator renders the section as-is. // Everything in this module is pure and unit-tested (test/aa.test.ts), diff --git a/pm-stack/aggregator/src/model.ts b/pm-stack/aggregator/src/model.ts index f56e2c0854..ff27f1192f 100644 --- a/pm-stack/aggregator/src/model.ts +++ b/pm-stack/aggregator/src/model.ts @@ -851,7 +851,7 @@ export interface AaThreshold { usdPerUsablePoint: number | null; } -/** One AA Intelligence Index row of ainventory.benchmark_results. */ +/** One AA Intelligence Index row of ainventory.measurement_events (canonical, code#4401). */ export interface AaConfig { modelName: string; benchmark: string; @@ -880,7 +880,7 @@ export interface AaTestRun { } /** - * One Coding Agent Index row of ainventory.benchmark_results (the + * One Coding Agent Index row of ainventory.measurement_events (the * import's Coding_Agent_Results rows): a model + effort + agent * harness observation, kept strictly separate from the AA Intelligence * Index — no score conversion between the indexes (the ChatGPT