fix: fence compaction commit and status

This commit is contained in:
2026-09-16 04:58:38 +09:00
parent c0fe20e8a2
commit cfe772ea7d
6 changed files with 145 additions and 23 deletions
@@ -1,4 +1,5 @@
<script lang="ts">
import type { InFlightCompaction } from "$lib/generated/protocol.ts";
import Spinner from "./Spinner.svelte";
import { formatRunElapsed, formatRunTokens } from "./run-status";
@@ -7,15 +8,16 @@
requests: number;
uploadTokens: number;
outputTokens: number;
compaction?: { phase: string } | null;
compaction?: InFlightCompaction | null;
};
let { startedAtMs, requests, uploadTokens, outputTokens, compaction = null }: Props =
$props();
let nowMs = $state(Date.now());
const clockStartedAtMs = $derived(compaction?.started_at_ms ?? startedAtMs);
$effect(() => {
startedAtMs;
clockStartedAtMs;
nowMs = Date.now();
const timer = window.setInterval(() => {
nowMs = Date.now();
@@ -23,7 +25,9 @@
return () => window.clearInterval(timer);
});
const elapsed = $derived(formatRunElapsed(nowMs - (startedAtMs ?? nowMs)));
const elapsed = $derived(
formatRunElapsed(nowMs - (clockStartedAtMs ?? nowMs)),
);
const requestLabel = $derived(requests === 1 ? "req" : "reqs");
</script>
@@ -248,6 +248,18 @@
liveWorkerState ?? (worker?.state === "stopped" ? "stopped" : "loading"),
);
const workerRunning = $derived(workerState === "running");
const compactionProgress = $derived.by(() => {
const state = consoleProjection.workerState?.state;
if (!state || typeof state !== "object" || !("busy" in state)) return null;
const progress = consoleProjection.compaction;
if (!progress) return null;
const busy = state.busy;
if (!busy || typeof busy !== "object") return null;
const valid = progress.trigger === "manual"
? "maintenance" in busy && busy.maintenance === "compacting"
: "run" in busy;
return valid ? progress : null;
});
const workerPaused = $derived(workerState === "paused");
const composerEditable = $derived(protocolState === "open" && !sending);
const draftHasText = $derived(draft.content.trim().length > 0);
@@ -1907,7 +1919,7 @@
requests={consoleProjection.runActivity.requests}
uploadTokens={consoleProjection.runActivity.uploadTokens}
outputTokens={consoleProjection.runActivity.outputTokens}
compaction={consoleProjection.compaction}
compaction={compactionProgress}
/>
{/if}