fix(ui): gate compaction retry status on success

This commit is contained in:
Josh Lehman
2026-04-01 12:30:55 -07:00
parent a38867b3d8
commit e7e562f982
2 changed files with 49 additions and 4 deletions

View File

@@ -166,7 +166,7 @@ describe("app-tool-stream fallback lifecycle handling", () => {
stream: "compaction",
ts: Date.now(),
sessionKey: "main",
data: { phase: "end", willRetry: true },
data: { phase: "end", willRetry: true, completed: true },
});
expect(host.compactionStatus).toEqual({
@@ -236,7 +236,7 @@ describe("app-tool-stream fallback lifecycle handling", () => {
stream: "compaction",
ts: Date.now(),
sessionKey: "main",
data: { phase: "end", willRetry: true },
data: { phase: "end", willRetry: true, completed: true },
});
expect(host.compactionStatus).toEqual({
@@ -269,4 +269,44 @@ describe("app-tool-stream fallback lifecycle handling", () => {
vi.useRealTimers();
});
it("does not surface retrying or complete when retry compaction failed", () => {
vi.useFakeTimers();
const host = createHost();
handleAgentEvent(host, {
runId: "run-1",
seq: 1,
stream: "compaction",
ts: Date.now(),
sessionKey: "main",
data: { phase: "start" },
});
handleAgentEvent(host, {
runId: "run-1",
seq: 2,
stream: "compaction",
ts: Date.now(),
sessionKey: "main",
data: { phase: "end", willRetry: true, completed: false },
});
expect(host.compactionStatus).toBeNull();
expect(host.compactionClearTimer).toBeNull();
handleAgentEvent(host, {
runId: "run-1",
seq: 3,
stream: "lifecycle",
ts: Date.now(),
sessionKey: "main",
data: { phase: "error", error: "boom" },
});
expect(host.compactionStatus).toBeNull();
expect(host.compactionClearTimer).toBeNull();
vi.useRealTimers();
});
});

View File

@@ -298,6 +298,7 @@ function setCompactionComplete(host: CompactionHost, runId: string) {
export function handleCompactionEvent(host: CompactionHost, payload: AgentEventPayload) {
const data = payload.data ?? {};
const phase = typeof data.phase === "string" ? data.phase : "";
const completed = data.completed === true;
clearCompactionTimer(host);
@@ -311,7 +312,7 @@ export function handleCompactionEvent(host: CompactionHost, payload: AgentEventP
return;
}
if (phase === "end") {
if (data.willRetry === true) {
if (data.willRetry === true && completed) {
// Compaction already succeeded, but the run is still retrying.
// Keep that distinct state until the matching lifecycle end arrives.
host.compactionStatus = {
@@ -322,7 +323,11 @@ export function handleCompactionEvent(host: CompactionHost, payload: AgentEventP
};
return;
}
setCompactionComplete(host, payload.runId);
if (completed) {
setCompactionComplete(host, payload.runId);
return;
}
host.compactionStatus = null;
}
}