fix: make home's failed-runs ask ai clickable, add failed filter and runs link (#12174)

* fix: make the home failed-runs count's ask ai reachable, add a failed filter and runs link

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: clear the failed filter with its last failure, keep the window tooltip

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* refactor: use design-system buttons in the failed-runs menu

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: fall back to getAll for set-cookie in the pages preview proxy

The Pages function runs without a compatibility date, where Headers has no
getSetCookie, so every proxied API call failed with a 500.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* refactor: use a design-system button for the header's failed runs link

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Ruben Fiszel
2026-11-03 13:29:08 +01:00
committed by GitHub
co-authored by Claude Opus 5.5
parent df2a631e77
commit 795ded9d19
3 changed files with 108 additions and 21 deletions
@@ -6,6 +6,7 @@
import {
allRunsHref,
askAI,
failedRunsHref,
canAskAI,
collisionPrefixes,
itemKey,
@@ -154,7 +155,7 @@
{/if}
<div
class="flex items-center gap-2 px-1.5 pb-1 {data
class="flex items-center gap-1 px-1.5 pb-1 whitespace-nowrap {data
? 'mt-1.5 pt-2 border-t border-border-light'
: 'pt-1'}"
>
@@ -165,6 +166,16 @@
All runs
<ExternalLink size={12} />
</a>
{#if data && data.failed_runs > 0}
<Button
variant="subtle"
unifiedSize="sm"
endIcon={{ icon: ExternalLink }}
href={failedRunsHref(folder, data.window_hours)}
>
Failed runs
</Button>
{/if}
{#if onShowPanel}
<div class="ml-auto">
<Button
@@ -1,12 +1,14 @@
<script lang="ts">
import { Button, Skeleton } from '$lib/components/common'
import { ExternalLink, PanelRightClose } from 'lucide-svelte'
import { ExternalLink, ListFilter, PanelRightClose, Sparkles } from 'lucide-svelte'
import Popover from '$lib/components/meltComponents/Popover.svelte'
import RecentRunRow from './RecentRunRow.svelte'
import {
allRunsHref,
askAI,
canAskAI,
collisionPrefixes,
failedRunsHref,
itemKey,
totalLabel,
windowLabel,
@@ -29,6 +31,16 @@
// The failed count also holds runs an item has since recovered from; Ask AI attaches only
// the items still failing, so it shows only when there is one.
let failing = $derived(data?.items.filter((i) => i.status === 'failure') ?? [])
// Every item the failed count is made of, recovered ones included.
let failedItems = $derived(data?.items.filter((i) => i.failed_runs > 0) ?? [])
let onlyFailing = $state(false)
let failedMenuOpen = $state(false)
// The menu holding the toggle goes once the last failure is resolved: the filter must go with it.
let filtering = $derived(onlyFailing && failedItems.length > 0)
$effect(() => {
if (data && failedItems.length === 0) onlyFailing = false
})
let shownItems = $derived(filtering ? failedItems : (data?.items ?? []))
let windowText = $derived(data ? windowLabel(data.window_hours) : '')
let prefixes = $derived(data && !folder ? collisionPrefixes(data.items) : new Map())
</script>
@@ -44,30 +56,79 @@
{/if}
{#if data}
<span
class="relative min-w-0 truncate text-xs font-normal text-hint wm-page-in"
class="flex items-baseline min-w-0 text-xs font-normal text-hint wm-page-in"
title="{windowText} · {totalLabel(data)} · {data.failed_runs} failed"
>
{#if data.failed_runs > 0}
<span class="group/failed relative">
<span class="text-red-600 dark:text-red-400">{data.failed_runs}</span> failed
{#if canAskAI() && failing.length > 0}
<button
class="absolute left-full top-1/2 -translate-y-1/2 ml-1 h-5 px-1.5 rounded text-[11px] font-medium text-ai bg-ai/10 hover:bg-ai/15 whitespace-nowrap opacity-0 pointer-events-none group-hover/failed:opacity-100 group-hover/failed:pointer-events-auto focus:opacity-100 focus:pointer-events-auto"
onclick={() =>
askAI(
{ kind: 'failing', items: failing },
'Investigate why these items are failing'
)}
>
Ask AI
</button>
{/if}
</span>
<!-- A popover rather than a hover-revealed button: its content stays open while the
pointer travels to it, where a button beside the count vanished on the way. -->
<Popover
openOnHover
debounceDelay={140}
placement="bottom-start"
bind:isOpen={failedMenuOpen}
triggerAttrs={{ 'aria-label': `${data.failed_runs} failed runs` }}
class="shrink-0 -mx-1 px-1 rounded whitespace-nowrap hover:bg-surface-hover {filtering ||
failedMenuOpen
? 'bg-surface-hover'
: ''}"
>
{#snippet trigger()}
<span class="text-red-600 dark:text-red-400">{data.failed_runs}</span> failed
{/snippet}
{#snippet content()}
<div class="flex flex-col p-1 min-w-[200px] text-xs">
<!-- Items past the listed ones can hold the whole count: nothing to filter to. -->
{#if failedItems.length > 0}
<Button
variant="subtle"
unifiedSize="sm"
btnClasses="justify-start"
startIcon={{ icon: ListFilter }}
onclick={() => {
onlyFailing = !onlyFailing
failedMenuOpen = false
}}
>
{filtering ? 'Show all items' : `Show only failed (${failedItems.length})`}
</Button>
{/if}
{#if canAskAI() && failing.length > 0}
<Button
variant="subtle"
unifiedSize="sm"
btnClasses="justify-start text-ai hover:bg-ai/10"
startIcon={{ icon: Sparkles }}
onclick={() => {
failedMenuOpen = false
askAI(
{ kind: 'failing', items: failing },
'Investigate why these items are failing'
)
}}
>
Ask AI about {failing.length} failing item{failing.length === 1 ? '' : 's'}
</Button>
{/if}
<Button
variant="subtle"
unifiedSize="sm"
btnClasses="justify-start"
startIcon={{ icon: ExternalLink }}
href={failedRunsHref(folder, data.window_hours)}
>
View failed runs
</Button>
</div>
{/snippet}
</Popover>
{:else}
{totalLabel(data)}
<span class="truncate">{totalLabel(data)}</span>
{/if}
<!-- Room goes to the folder name first; the window stays in the tooltip. -->
<span class="max-[1180px]:hidden {folder ? 'hidden' : ''}"> · {windowText}</span>
<span class="truncate max-[1180px]:hidden {folder ? 'hidden' : ''}">
&nbsp;· {windowText}</span
>
</span>
{/if}
</h2>
@@ -102,7 +163,7 @@
{:else if data}
<!-- Fades in once, when the first read lands; refreshes update the rows in place. -->
<div class="wm-page-in">
{#each data.items as item (itemKey(item))}
{#each shownItems as item (itemKey(item))}
<RecentRunRow
{item}
now={runs.now}
@@ -5,6 +5,7 @@ import { IsDocumentVisible, useInterval } from 'runed'
import { persistedResource } from '$lib/persistedResource.svelte'
import { homeComposerContext } from '$lib/components/sessions/homeComposerContext.svelte'
import { runContextElement } from '$lib/components/copilot/chat/context'
import { runsTimeframes } from '$lib/components/runs/timeframes'
export type RecentRuns = ListRecentRunsResponse
export type RecentRunItem = RecentRuns['items'][number]
@@ -129,6 +130,20 @@ export function allRunsHref(folder: string | undefined) {
return folder ? `/runs?folder=${encodeURIComponent(folder)}` : '/runs'
}
/** The runs page over the runs the failed count is made of: unresolved failures of the window. */
export function failedRunsHref(folder: string | undefined, windowHours: number) {
const params = new URLSearchParams({ status: 'failure', resolved: 'unresolved' })
if (folder) params.set('folder', folder)
// A preset timeframe stays relative to now, where a `min_ts` would freeze at render.
const timeframe = runsTimeframes.find((t) => {
const { minTs, maxTs } = t.computeMinMax()
const span = minTs && maxTs ? Date.parse(maxTs) - Date.parse(minTs) : NaN
return Math.abs(span - windowHours * 3600_000) < 1000
})
if (timeframe) params.set('timeframe', timeframe.label)
return `/runs?${params}`
}
export function windowLabel(hours: number) {
return hours > 24 && hours % 24 === 0 ? `last ${hours / 24}d` : `last ${hours}h`
}