Fix false stale Fleet reports caused by clock skew

This commit is contained in:
2026-09-19 20:17:43 -04:00
parent 345839fbd4
commit 1d073779fe
9 changed files with 224 additions and 15 deletions
+4 -4
View File
@@ -154,9 +154,9 @@
let hasDiagnosticIssue = $derived(effectiveHealth !== 'online' && effectiveHealth !== 'starting');
function ago(iso: string | null): string {
function ago(iso: string | null, now: number): string {
if (!iso) return 'never';
const d = Date.now() - new Date(iso).getTime();
const d = now - new Date(iso).getTime();
if (d < 60_000) return `${Math.max(1, Math.floor(d / 1000))}s ago`;
if (d < 3_600_000) return `${Math.floor(d / 60_000)}m ago`;
if (d < 86_400_000) return `${Math.floor(d / 3_600_000)}h ago`;
@@ -270,7 +270,7 @@
{/if}
{#if effectiveHealth !== 'online'}
<div class="metric-cell">
<Stat label="Last seen" value={ago(effectiveSeen)} size="md" tween={false} />
<Stat label="Last seen" value={ago(effectiveSeen, $uiNow)} size="md" tween={false} />
</div>
{/if}
</div>
@@ -517,7 +517,7 @@
{/if}
</span>
<span class="hist-files">{mine.files_changed} file{mine.files_changed === 1 ? '' : 's'}</span>
<span class="hist-when">{ago(d.started_at)}</span>
<span class="hist-when">{ago(d.started_at, $uiNow)}</span>
{#if mine.error}<span class="hist-err">{mine.error}</span>{/if}
</a>
{/each}