Skip to content

A local-first multi-agent app development platform, built on PenguinHarness

A retry ladder is one line in the transcript (#528)

Yaowei Zheng3101c4cf874a
diff --git a/changelog/unreleased/2026-08-28-retry-line-collapse.md b/changelog/unreleased/2026-08-28-retry-line-collapse.md
new file mode 100644
index 00000000..156d391e
--- /dev/null
+++ b/changelog/unreleased/2026-08-28-retry-line-collapse.md
@@ -0,0 +1,48 @@
+# A retry ladder is one line in the transcript, not one per attempt
+
+- **Date:** 2026-08-28
+- **Type:** fix
+- **Scope:** `web`
+- **PR:** [#528](https://github.com/Prism-Shadow/penguin-harness/pull/528)
+
+[中文版](2026-08-28-retry-line-collapse.zh.md)
+
+Every retryable request end added its own line, so a request that retried four times left four
+of them stacked in the conversation:
+
+```
+[Retry] Connection timed out; retry #1 sent
+[Retry] Connection timed out; retry #2 sent
+[Retry] Network or service temporarily unavailable; retry #3 sent
+[Retry] Connection timed out; retry #4 sent
+```
+
+A later attempt now replaces the one before it, so the ladder reads as one line that counts up
+to `retry #4 sent`. The count was always in the line, so nothing about how many attempts ran is
+lost from the transcript.
+
+## Details
+
+- The collapse is in the chat page's view model (`lib/omni/stream-model.ts`) and nothing else.
+ **The Trace is untouched**: it still records every attempt as its own event, and the Trace
+ panel builds from those raw events rather than from this model, so the full ladder is still
+ readable there. The engine's retry behaviour is unchanged.
+- A ladder whose failed attempts produced no output collapses; one whose attempts had already
+ streamed thinking or text does not, because that content sits between the rungs. Those ladders
+ render one line per attempt exactly as before.
+- A new incident opens its own line rather than overwriting the previous ladder's: attempts
+ climb within one incident and restart at 1 in the next.
+- **A ladder that gave up keeps its line.** It carries the final failure and its detail, which is
+ the one retry line worth keeping on screen; a later incident opens its own.
+- The superseded item's id is kept through the replacement, so the rendered row updates instead
+ of remounting and replaying its entry animation as though it were a new failure. The line's
+ per-attempt state is reset alongside it, so "retry now" and "give up" stay usable on every
+ countdown in the ladder.
+- Traces written before the attempt ordinal existed read as attempt 1 throughout, so they never
+ collapse and replay exactly as they always did.
+
+## What the collapse costs
+
+A superseded attempt's *cause* leaves the transcript with it: a ladder whose attempts failed for
+different reasons — a timeout, then a network error — shows only the reason it is currently on.
+The attempt count survives, and the per-attempt causes remain in the Trace.
diff --git a/changelog/unreleased/2026-08-28-retry-line-collapse.zh.md b/changelog/unreleased/2026-08-28-retry-line-collapse.zh.md
new file mode 100644
index 00000000..460b884d
--- /dev/null
+++ b/changelog/unreleased/2026-08-28-retry-line-collapse.zh.md
@@ -0,0 +1,32 @@
+# 一轮重试在对话里只占一行,而不是每次一行
+
+- **Date:** 2026-08-28
+- **Type:** fix
+- **Scope:** `web`
+- **PR:** [#528](https://github.com/Prism-Shadow/penguin-harness/pull/528)
+
+[English](2026-08-28-retry-line-collapse.md)
+
+每一次可重试的请求结束都会新增一行,于是一个重试了四次的请求在对话里留下四行:
+
+```
+[重试]连接超时或网络中断,已发起第 1 次重试
+[重试]连接超时或网络中断,已发起第 2 次重试
+[重试]网络或服务暂时不可用,已发起第 3 次重试
+[重试]连接超时或网络中断,已发起第 4 次重试
+```
+
+现在后一次重试会覆盖前一次,这一轮只显示一行,并一直数到「已发起第 4 次重试」。次数本来就写在这一行里,因此「一共重试了几次」并没有从对话中丢失。
+
+## 细节
+
+- 合并只发生在对话页的视图模型(`lib/omni/stream-model.ts`)里。**Trace 不受影响**:每一次尝试仍作为独立事件被记录,而 Trace 面板是基于原始事件而非该模型构建的,因此完整的重试过程在那里依然可读。引擎的重试行为没有任何改动。
+- 失败的尝试若没有产出任何内容,该轮重试会合并为一行;若某次尝试在中断前已经流出思考或正文,这些内容会插在两次之间,该轮便不合并,仍与以往一样每次一行。
+- 新的一次故障另起一行,不会覆盖上一轮:同一次事件内的尝试序号递增,下一次事件则从第 1 次重新开始。
+- **已放弃的那一轮会保留自己的行。** 它承载着最终失败及其详情,是最值得留在屏幕上的一行;之后的事件另起一行。
+- 被覆盖的 item 的 id 会被保留,因此渲染出来的那一行是就地更新,而不是重新挂载、重放入场动画——后者看起来像是又出了一次新故障。该行中属于单次尝试的状态会随之重置,因此「立即重试」与「放弃」在这一轮的每次倒计时上都可用。
+- 早于「尝试序号」字段的 Trace 全程读作第 1 次,因此永远不会发生合并,回放效果与以往完全一致。
+
+## 这次合并的代价
+
+被覆盖的那次尝试的**原因**也随之离开对话:一轮中各次失败原因不同时(先超时、后网络错误),只会显示当前所处的那个原因。次数得以保留,逐次的原因仍在 Trace 中。
diff --git a/packages/web/e2e/llm-errors.spec.mjs b/packages/web/e2e/llm-errors.spec.mjs
index 2a43de3a..3888d4cc 100644
--- a/packages/web/e2e/llm-errors.spec.mjs
+++ b/packages/web/e2e/llm-errors.spec.mjs
@@ -61,12 +61,14 @@ test("a quota-403 retries with a live countdown; 'retry now' skips the wait and
await page.getByPlaceholder(/输入消息/).fill("quota retry test");
await page.getByRole("button", { name: "发送" }).click();
- // Early retries flip fast (250/500ms waits — below the 2s countdown floor they keep the
- // plain waiting/retried text).
- await expect(page.locator("p.text-amber-600", { hasText: "已发起第 1 次重试" })).toBeVisible({
- timeout: 20000,
- });
- await expect(page.locator("p.text-amber-600", { hasText: "已发起第 2 次重试" })).toBeVisible();
+ // One line for the whole ladder, advancing through the ordinals rather than stacking: the
+ // early retries flip fast (250/500ms waits — below the 2s countdown floor they keep the plain
+ // waiting/retried text), so asserting any single early ordinal is a race against the stream
+ // model's commit throttle. What is stable is that there is exactly ONE retry line, and that it
+ // has reached at least attempt 2 by the time the countdown below appears.
+ const ladder = page.locator("p.text-amber-600", { hasText: "[重试]" });
+ await expect(ladder).toHaveCount(1, { timeout: 20000 });
+ await expect(ladder).toHaveText(/第 [2-9] 次重试/, { timeout: 20000 });
// The 4s wait before retry #5: a live countdown (whole seconds, ticking down).
const countdown = page.locator("p.text-amber-600", { hasText: /第 5 次重试,\d+ 秒后发起/ });
diff --git a/packages/web/src/features/chat/message-item.tsx b/packages/web/src/features/chat/message-item.tsx
index 8b6a25b2..01b51db6 100644
--- a/packages/web/src/features/chat/message-item.tsx
+++ b/packages/web/src/features/chat/message-item.tsx
@@ -111,6 +111,15 @@ function ReconnectLine({ item, ctx }: { item: ReconnectItem; ctx: StreamRenderCo
: null;
const [now, setNow] = useState(() => Date.now());
const [acted, setActed] = useState(false);
+ // Both pieces of state belong to ONE attempt, and a ladder now reuses this component across
+ // all of them: the item keeps its id through the collapse (see stream-model's continuedLadder),
+ // so React keeps the instance rather than remounting it. Without this reset, one click on
+ // "retry now" would leave both controls disabled for every later attempt of the same ladder,
+ // and the first paint of each new countdown would render against the previous attempt's `now`.
+ useEffect(() => {
+ setActed(false);
+ setNow(Date.now());
+ }, [item.attempt]);
useEffect(() => {
if (target === null || Date.now() >= target) return;
const timer = setInterval(() => {
@@ -119,7 +128,10 @@ function ReconnectLine({ item, ctx }: { item: ReconnectItem; ctx: StreamRenderCo
}, 250);
return () => clearInterval(timer);
}, [target]);
- const remainingMs = target !== null ? target - now : 0;
+ // Clamped to the wait the engine actually announced. The reset above runs after the commit,
+ // so the frame that first paints a superseded attempt still holds the previous one's `now` —
+ // unclamped that renders a countdown longer than any backoff this ladder can plan.
+ const remainingMs = target !== null ? Math.min(target - now, item.plannedDelayMs ?? 0) : 0;
const live = target !== null && remainingMs > 0;
const seconds = live ? Math.ceil(remainingMs / 1000) : undefined;
const showControls =
diff --git a/packages/web/src/lib/omni/stream-model.ts b/packages/web/src/lib/omni/stream-model.ts
index 6c747285..ea9d867c 100644
--- a/packages/web/src/lib/omni/stream-model.ts
+++ b/packages/web/src/lib/omni/stream-model.ts
@@ -1725,7 +1725,20 @@ function handleEvent(model: StreamModel, p: EventPayload, tsMs?: number, nowMs?:
// and their exhaustion is marked by the abort event instead.
item.gaveUp = true;
}
- model.items.push(item);
+ // One line per LADDER, not per attempt: a later attempt replaces the one before it, so
+ // a request that retries four times reads 已发起第 4 次重试 / "retry #4 sent" on a single
+ // line instead of stacking four. The count is already in the line, so nothing is lost
+ // from the transcript — and the Trace is untouched, keeping every attempt as its own
+ // event for the Trace panel, which builds from the raw events rather than from this model.
+ const continues = continuedLadder(model, item);
+ if (continues !== null) {
+ // The previous item's id is kept so the rendered line UPDATES rather than being
+ // replaced: a new key would remount the row and replay its entry animation, which
+ // reads as a new failure rather than the same one progressing.
+ model.items[model.items.length - 1] = { ...item, id: continues.id };
+ } else {
+ model.items.push(item);
+ }
}
return;
}
@@ -1784,6 +1797,37 @@ function isWrapUpCompaction(model: StreamModel): boolean {
return model.items[model.items.length - 1]?.kind === "assistant_text";
}
+/**
+ * The reconnect item this one supersedes, or null when it opens a new line.
+ *
+ * A ladder's attempts climb (1, 2, 3, …), and they are adjacent WHEN THE FAILED ATTEMPTS
+ * PRODUCED NOTHING — the `request_begin` that resends only marks the waiting item, so nothing
+ * is pushed between two such rungs. An attempt cut off after it had already streamed thinking
+ * or text pushes that content in between, and the ladder simply does not collapse: it renders
+ * one line per attempt, exactly as it did before. That is the conservative direction, and the
+ * reason this looks only at the tail rather than scanning back the way
+ * {@link findLastWaitingReconnect} does — a scan would have to decide where the replacement
+ * belongs among the content it skipped over.
+ *
+ * So the last item being a reconnect is necessary but NOT sufficient: a request that succeeded
+ * pushes nothing, so the next failure's item is adjacent to the previous ladder's last one
+ * while belonging to a different incident. That one restarts at attempt 1, which is what
+ * separates the two cases.
+ *
+ * A ladder that gave up is closed and is never superseded: its line carries the final failure
+ * and its detail, which is the one retry line worth keeping on screen.
+ *
+ * Traces written before the attempt ordinal existed read as attempt 1 throughout, so they never
+ * collapse and render exactly as they always did — the safe direction for a record this cannot
+ * re-derive.
+ */
+function continuedLadder(model: StreamModel, next: ReconnectItem): ReconnectItem | null {
+ const last = model.items[model.items.length - 1];
+ if (last === undefined || last.kind !== "reconnect") return null;
+ if (last.gaveUp === true) return null;
+ return next.attempt > last.attempt ? last : null;
+}
+
function findLastWaitingReconnect(model: StreamModel): ReconnectItem | null {
for (let i = model.items.length - 1; i >= 0; i--) {
const item = model.items[i]!;
diff --git a/packages/web/test/stream-model.test.ts b/packages/web/test/stream-model.test.ts
index 679014c2..c00d5138 100644
--- a/packages/web/test/stream-model.test.ts
+++ b/packages/web/test/stream-model.test.ts
@@ -687,21 +687,84 @@ describe("approvals and events", () => {
// Retry request sent: the notice is marked as retrying.
pushMessage(m, requestBegin());
expect(retry.retrying).toBe(true);
- // Retry fails again: a second notice, carrying the next ordinal.
+ // Retry fails again: the SAME line advances rather than a second one appearing — one line
+ // per ladder, carrying the latest ordinal (see continuedLadder).
pushMessage(m, requestEnd("retryable", { attempt: 2, retryInMs: 4000 }));
- const retry2 = items(m)[1] as ReconnectItem;
- expect(retry2).toMatchObject({ kind: "reconnect", status: "retryable", attempt: 2 });
- // Retry succeeds: no new entry; the next round's failure carries attempt 1 again.
+ expect(items(m)).toHaveLength(1);
+ expect(items(m)[0]).toMatchObject({ kind: "reconnect", status: "retryable", attempt: 2 });
+ // The id is kept through the replacement, so the rendered row updates instead of
+ // remounting and replaying its entry animation as if it were a new failure.
+ expect((items(m)[0] as ReconnectItem).id).toBe(retry.id);
+ // Retry succeeds: no new entry. The next round's failure restarts at attempt 1, which is
+ // what tells it apart from a continuation — it opens its own line even though the previous
+ // ladder's line is still the last item, nothing having been pushed in between.
pushMessage(m, requestBegin());
pushMessage(m, requestEnd("completed"));
+ expect(items(m)).toHaveLength(1);
+ pushMessage(m, requestBegin());
+ pushMessage(m, requestEnd("retryable", { attempt: 1, retryInMs: 2000 }));
expect(items(m)).toHaveLength(2);
+ expect((items(m)[1] as ReconnectItem).attempt).toBe(1);
+ // A Trace written before the field existed lacks it: rendered as attempt 1. The line above
+ // is still waiting rather than gave-up, so it is the ORDINAL that decides here — 1 does not
+ // climb past 1, so nothing is superseded and the replay is exactly what it always was.
pushMessage(m, requestBegin());
- pushMessage(m, requestEnd("retryable", { attempt: 1 }));
+ pushMessage(m, requestEnd("retryable", { retryInMs: 2000 }));
+ expect(items(m)).toHaveLength(3);
expect((items(m)[2] as ReconnectItem).attempt).toBe(1);
- // A Trace written before the field existed lacks it: rendered as attempt 1.
+ });
+
+ it("a ladder with no attempt ordinal at all never collapses: one line per attempt, as before", () => {
+ // "Written before the ordinal existed" means the field is ABSENT, not that it is 1. Every
+ // rung then reads as attempt 1, the ordinal never climbs, and nothing is ever superseded —
+ // the safe direction for a record this model cannot re-derive.
+ const legacyEnd = (status: string) => requestEnd(status as Parameters<typeof requestEnd>[0]);
+ const m = createStreamModel();
+ for (const status of ["timeout", "failed", "malformed"]) {
+ pushMessage(m, requestBegin());
+ pushMessage(m, legacyEnd(status));
+ }
+ expect((items(m) as ReconnectItem[]).map((i) => [i.status, i.attempt])).toEqual([
+ ["timeout", 1],
+ ["failed", 1],
+ ["malformed", 1],
+ ]);
+ });
+
+ it("an attempt that already streamed output breaks the ladder's adjacency, so it does not collapse", () => {
+ // The collapse only ever supersedes the item directly before it. An attempt cut off after it
+ // had produced text leaves that text between the rungs, so the ladder renders one line per
+ // attempt exactly as it did before — the conservative direction, since deciding where a
+ // replacement belongs among the content it skipped is a question this model cannot answer.
+ const m = createStreamModel();
+ for (const attempt of [1, 2]) {
+ pushMessage(m, requestBegin());
+ pushMessage(m, partialText("start"));
+ pushMessage(m, partialText("delta", "Let me "));
+ pushMessage(m, partialText("stop"));
+ pushMessage(m, assistantText("Let me "));
+ pushMessage(m, requestEnd("retryable", { attempt, retryInMs: 2000 }));
+ }
+ expect(items(m).map((i) => i.kind)).toEqual([
+ "assistant_text",
+ "reconnect",
+ "assistant_text",
+ "reconnect",
+ ]);
+ });
+
+ it("a ladder that gave up keeps its line: the next failure opens a new one", () => {
+ // The gave-up line carries the final failure and its detail, which is the one retry line
+ // worth keeping on screen — a later incident must not overwrite it.
+ const m = createStreamModel();
pushMessage(m, requestBegin());
- pushMessage(m, requestEnd("retryable"));
- expect((items(m)[3] as ReconnectItem).attempt).toBe(1);
+ pushMessage(m, requestEnd("retryable", { attempt: 4, errorMessage: "socket hang up" }));
+ expect(items(m)).toHaveLength(1);
+ expect(items(m)[0]).toMatchObject({ gaveUp: true, attempt: 4 });
+ pushMessage(m, requestBegin());
+ pushMessage(m, requestEnd("retryable", { attempt: 5, retryInMs: 2000 }));
+ expect(items(m)).toHaveLength(2);
+ expect((items(m)[0] as ReconnectItem).errorMessage).toBe("socket hang up");
});
it("a terminal retryable (no retry planned) settles as gave-up at creation, detail attached", () => {
@@ -765,17 +828,20 @@ describe("approvals and events", () => {
pushMessage(m, legacyEnd("failed", { errorMessage: "502 bad gateway", attempt: 2 }));
pushMessage(m, requestBegin());
pushMessage(m, legacyEnd("malformed", { attempt: 3 }));
+ // One ladder, one line, carrying the latest attempt and ITS spelling. The finer
+ // pre-convergence statuses still render — the line shows whichever one the ladder is on —
+ // but a superseded attempt's cause leaves the transcript with it. That is the trade the
+ // collapse makes, and the attempt count is what survives it.
expect((items(m) as ReconnectItem[]).map((i) => [i.status, i.attempt])).toEqual([
- ["timeout", 1],
- ["failed", 2],
["malformed", 3],
]);
- // After a normal finish the next run's first failure is stamped #1 again.
+ // After a normal finish the next run's first failure is stamped #1 again, so it opens its
+ // own line rather than continuing the ladder above.
pushMessage(m, requestBegin());
pushMessage(m, requestEnd("completed"));
pushMessage(m, requestBegin());
pushMessage(m, legacyEnd("failed", { attempt: 1 }));
- expect((items(m)[3] as ReconnectItem).attempt).toBe(1);
+ expect((items(m)[1] as ReconnectItem).attempt).toBe(1);
});
it("request_end(fatal) stays out of the ladder: terminal, so no retry notice", () => {