fix: deduplicate compaction terminal failures

This commit is contained in:
2026-10-02 05:30:17 +09:00
parent d0ea9f598d
commit 88338229a1
6 changed files with 616 additions and 133 deletions
@@ -338,6 +338,13 @@ Deno.test("durable compaction failure reconciles live alert and error in both vi
},
},
},
{
eventId: "controller-error",
event: {
event: "error",
data: { code: "internal", message: "summary unavailable" },
},
},
{
eventId: "failed",
event: transition("failed-entry", {
@@ -346,13 +353,6 @@ Deno.test("durable compaction failure reconciles live alert and error in both vi
failure: "compaction",
}),
},
{
eventId: "controller-error",
event: {
event: "error",
data: { code: "internal", message: "summary unavailable" },
},
},
]);
const errors = projection.lines.filter((line) => line.kind === "error");
@@ -362,6 +362,18 @@ Deno.test("durable compaction failure reconciles live alert and error in both vi
assertEquals(errors[0].entryId, "failed-entry");
assertEquals(projectConsoleLines(projection.lines, "normal"), errors);
assertEquals(projectConsoleLines(projection.lines, "overview"), errors);
const history = projectSessionHistoryEntries([{
entry_id: "failed-entry",
timestamp: 10,
provenance: "legacy_unknown",
kind: "run_error",
message,
failure: "compaction",
}], null);
const merged = mergeCommittedHistoryLines(history, projection.lines);
assertEquals(merged.filter((line) => line.kind === "error").length, 1);
assertEquals(merged.find((line) => line.kind === "error")?.entryId, "failed-entry");
});
Deno.test("snapshot restores compaction terminal without reviving transition progress", () => {
@@ -3232,6 +3244,26 @@ Deno.test("committed history reconciles overlapping Read groups before counting
}
});
Deno.test("committed history keeps identical run failures with distinct entry identities", () => {
const message = "the same failure happened again";
const runError = (entryId: string): SessionSnapshotEntry => ({
kind: "run_error",
entry_id: entryId,
timestamp: 1,
provenance: "legacy_unknown",
message,
failure: "compaction",
});
const retained = projectSessionHistoryEntries([runError("run-error-1")], null);
const current = projectSessionHistoryEntries([runError("run-error-2")], null);
const merged = mergeCommittedHistoryLines(retained, current);
assertEquals(merged.map((line) => line.entryId), ["run-error-1", "run-error-2"]);
assertEquals(merged.map((line) => line.body), [message, message]);
assertEquals(projectConsoleLines(merged, "normal").length, 2);
assertEquals(projectConsoleLines(merged, "overview").length, 2);
});
Deno.test("committed history matches tool calls across live and durable result identities", () => {
const retained: ConsoleLine = {
...consoleLine("tool-call-a", "tool"), entryId: "call-entry-a",
@@ -2208,7 +2208,10 @@ function applySessionEntry(
const entryId = stringField(value, "entry_id");
if (entryId) {
for (
let index = Math.max(0, lineCountBefore - 1);
let index = Math.max(
0,
Math.min(lineCountBefore, projection.lines.length - 1),
);
index < projection.lines.length;
index += 1
) {