fix: stop refetching run history on every case write

Reading the case list before the first await made the whole job-history query a
dependency of it, so every save, delete and Load more refetched up to 1000 job
rows and blanked the column. Read untracked instead.

- an empty Last run cell now distinguishes never-ran from not-found-within the
  page bound, which the comment already claimed and the cell did not
- reloading a dataset no longer replaces a populated table with a skeleton
- keep the score-parser comment that describes every shape it handles

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
hugocasa
2026-08-12 00:03:25 +02:00
parent a3a9ef142e
commit 128f078bad
2 changed files with 19 additions and 7 deletions
+2 -1
View File
@@ -1476,7 +1476,8 @@ mod with_storage {
serde_json::Value::Object(map) => match map.get("score") {
Some(serde_json::Value::Number(n)) => n.as_f64(),
Some(serde_json::Value::Bool(b)) => Some(if *b { 1.0 } else { 0.0 }),
// An agent scorer answers in `output`, which is itself often a JSON string.
// An agent scorer wraps its answer in `output`: a number, a boolean, a
// structured {score}, or a string holding any of those.
_ => match map.get("output") {
Some(serde_json::Value::Number(n)) => n.as_f64(),
Some(serde_json::Value::Bool(b)) => Some(if *b { 1.0 } else { 0.0 }),
@@ -372,19 +372,25 @@
// per row. The child agent job shares the prefix with a `/a` suffix, so only exact case
// segments count.
let lastRunByCase = $state<Record<string, Job>>({})
// True when the page bound was hit before every case was accounted for, so an empty cell means
// "not found in recent runs" rather than "never ran".
let runsTruncated = $state(false)
let runsGeneration = 0
async function loadLastRuns(dataset: string | undefined, agent: string | undefined) {
const generation = ++runsGeneration
lastRunByCase = {}
runsTruncated = false
if (!ws || !dataset || !agent) return
// Read untracked: naming `cases` in a tracked position would make this whole job-history
// query a dependency of the case list, refetching it on every save, delete and Load more.
const wanted = untrack(() => new Set(cases.map((c) => c.id)))
const prefix = `${agent}/${dataset}/`
const RUNS_PAGE_SIZE = 200
// Paged until every loaded case has been seen, because one newest-first page covers only
// the most recent runs: a dataset with more history than that would report cases as never
// run. Bounded, so a long history cannot turn opening a dataset into a crawl cases still
// unseen at the bound keep their honest "never seen in recent runs" blank.
// the most recent runs: a dataset with more history than that reported cases as never run.
// Bounded, so a long history cannot turn opening a dataset into a crawl; a case not reached
// within the bound reads as unknown rather than claiming it never ran.
const MAX_RUN_PAGES = 5
const wanted = new Set(cases.map((c) => c.id))
try {
const byCase: Record<string, Job> = {}
// listJobs pages by a created_before cursor, not a page number.
@@ -409,6 +415,7 @@
if (!before) break
}
lastRunByCase = byCase
runsTruncated = [...wanted].some((id) => !byCase[id])
} catch {
// A missing run history must not empty the table.
}
@@ -526,7 +533,7 @@
</Button>
<div class="flex-1 min-h-0 overflow-auto">
{#if loadingCases}
{#if loadingCases && cases.length === 0}
<Skeleton layout={[[2], [2], [2]]} />
{:else if !selectedDataset}
<div class="text-xs text-tertiary p-2">
@@ -584,7 +591,11 @@
: 'running'}
</span>
{:else}
<span class="text-tertiary">never</span>
<span class="text-tertiary" title={runsTruncated
? 'No run found in the most recent runs of this dataset'
: 'Never run'}>
{runsTruncated ? '—' : 'never'}
</span>
{/if}
</Cell>
<Cell last>