Skip to content

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

fix(web): offer Stop while a compaction is running (#347)

Yaowei Zhengd41f9a678414
diff --git a/changelog/unreleased/2026-08-19-stop-during-compaction.md b/changelog/unreleased/2026-08-19-stop-during-compaction.md
new file mode 100644
index 00000000..625b3366
--- /dev/null
+++ b/changelog/unreleased/2026-08-19-stop-during-compaction.md
@@ -0,0 +1,19 @@
+# The composer can interrupt a compaction again
+
+- **Date:** 2026-08-19
+- **Type:** fix
+- **Scope:** `web`
+- **PR:** [#347](https://github.com/Prism-Shadow/penguin-harness/pull/347)
+
+[中文版](2026-08-19-stop-during-compaction.zh.md)
+
+The chat composer's single action button offers Stop while a compaction is running, so a compaction can be interrupted from the Web App again.
+
+## Details
+
+The button asked `running && midRunAction(...) === "stop"` to decide whether it wore the Stop face, but a compacting Session's status is `compacting`, not `running`. It therefore fell through to the Send branch — which `canSend` disables for the whole compaction — leaving a dead button exactly where the only available action belonged.
+
+- The decision moved into `isStopAction` alongside `midRunAction` in `composer-send.ts`, which already exists to stop this class of mistake being repeated: a state where nothing can be sent must leave Stop, never a disabled Send. Compacting is unconditionally such a state — neither the steering nor the follow-up channel is offered while a compaction runs — so the button is Stop there whatever the composer holds.
+- Nothing changed for the states that already worked: an idle Session never offers Stop, and a running one offers it exactly where the draft has no send channel.
+
+The server and core were never part of this: the abort route accepts an interrupt in any non-idle state, and core stops the compaction request on the signal, settling the pair as `aborted` with the original context kept — the same well-defined outcome a compaction interrupted by quitting reaches. Both halves are now pinned by tests.
diff --git a/changelog/unreleased/2026-08-19-stop-during-compaction.zh.md b/changelog/unreleased/2026-08-19-stop-during-compaction.zh.md
new file mode 100644
index 00000000..0534d01a
--- /dev/null
+++ b/changelog/unreleased/2026-08-19-stop-during-compaction.zh.md
@@ -0,0 +1,19 @@
+# 输入区重新可以打断压缩
+
+- **Date:** 2026-08-19
+- **Type:** fix
+- **Scope:** `web`
+- **PR:** [#347](https://github.com/Prism-Shadow/penguin-harness/pull/347)
+
+[English](2026-08-19-stop-during-compaction.md)
+
+压缩进行期间,聊天输入区那颗唯一的操作按钮会显示为「停止」,压缩因此重新可以从 Web App 打断。
+
+## 详情
+
+按钮此前用 `running && midRunAction(...) === "stop"` 判断自己是否该是「停止」,但压缩中的 Session 状态是 `compacting` 而不是 `running`,于是落进了「发送」分支——而 `canSend` 在整个压缩期间都把它禁用,结果就是本该出现唯一可用操作的位置上摆着一颗死按钮。
+
+- 该判断移入 `composer-send.ts` 中与 `midRunAction` 并列的 `isStopAction`:这个模块本就是为了终结同一类错误而拆出来的——凡是发不出任何东西的状态,都必须留下「停止」,而不是一颗禁用的「发送」。压缩中无条件属于这种状态:插话与排队两条通道在压缩期间都不开放,因此无论输入区里有什么,按钮都是「停止」。
+- 原本正常的状态一切照旧:空闲的 Session 从不显示「停止」,运行中的 Session 也仍然只在草稿无处可发时显示它。
+
+服务端与核心自始至终都不在问题范围内:abort 路由接受任何非空闲状态下的打断,核心也会依信号中止压缩请求,让成对事件以 `aborted` 收束并保留原上下文——与用户退出程序导致压缩中断时抵达的,是同一个定义明确的终态。两侧现在都有测试钉住。
diff --git a/packages/server/test/abort-compaction.test.ts b/packages/server/test/abort-compaction.test.ts
new file mode 100644
index 00000000..0a48059d
--- /dev/null
+++ b/packages/server/test/abort-compaction.test.ts
@@ -0,0 +1,114 @@
+/**
+ * POST /api/sessions/:id/abort while a **compaction** is in flight.
+ *
+ * The composer's Stop button used to be gated on the Session being `running`, so a
+ * compacting Session showed a disabled Send instead and a compaction could not be
+ * interrupted from the Web App. The button was the whole of that bug — this file pins the
+ * half underneath it, so a future change cannot quietly make the server the problem too:
+ * the abort route does not care which non-idle state the Session is in, and the signal it
+ * fires reaches the compaction (the runtime's `compact` generator sees it and finishes),
+ * returning the Session to idle.
+ */
+import { afterEach, beforeEach, describe, expect, it } from "vitest";
+import { compactionBegin, compactionEnd } from "@prismshadow/penguin-core";
+import type { OmniMessage } from "@prismshadow/penguin-core";
+import type { SessionRow } from "../src/db/repos/sessions.js";
+import type { RuntimeSession } from "../src/runtime/session-manager.js";
+import { apiClient, createTestApp, provisionUser, waitFor } from "./helpers.js";
+import type { TestApp } from "./helpers.js";
+
+const SID = "session-2026-08-19-10-00-00-aabb0003";
+
+/** Records what the compaction saw of the abort signal. */
+interface CompactionProbe {
+ started: boolean;
+ sawAbort: boolean;
+ /** The terminal status the compaction settled on (mirrors core: an interrupted one ends `aborted`). */
+ endStatus: string | null;
+}
+
+/**
+ * Fake Session whose compaction parks until the signal fires — the shape of a real one, whose
+ * compaction request is a full LLM round trip against the largest context of the session and
+ * therefore the thing a user most wants to be able to stop.
+ */
+function compactingFakeSession(sessionId: string, probe: CompactionProbe): RuntimeSession {
+ return {
+ sessionId,
+ toolPermission: () => "rw",
+ generateTitle: async () => ({ title: null, usage: null }),
+ compactability: () => "ok" as const,
+ steer: () => false,
+ skipReconnectWait: () => false,
+ // eslint-disable-next-line require-yield
+ async *run() {},
+ async *compact(opts: { signal: AbortSignal }): AsyncGenerator<OmniMessage> {
+ probe.started = true;
+ yield compactionBegin({ reason: "manual", mode: "summarize", context: 1000, turns: 3 });
+ await new Promise<void>((resolve) => {
+ if (opts.signal.aborted) {
+ resolve();
+ return;
+ }
+ opts.signal.addEventListener("abort", () => resolve(), { once: true });
+ });
+ probe.sawAbort = opts.signal.aborted;
+ // Core's own interrupted-compaction outcome: the pair closes `aborted`, the original
+ // context is kept, and the half-written summary is discarded.
+ probe.endStatus = "aborted";
+ yield compactionEnd({ reason: "manual", mode: "summarize", status: "aborted" });
+ },
+ };
+}
+
+describe("abort during compaction", () => {
+ let t: TestApp;
+ let api: ReturnType<typeof apiClient>;
+ let probe: CompactionProbe;
+
+ beforeEach(async () => {
+ t = await createTestApp();
+ const { cookie } = await provisionUser(t.app, "compactstopper");
+ api = apiClient(t.app, cookie);
+ const row: SessionRow = {
+ sessionId: SID,
+ projectId: "compactstopper-default_project",
+ agentId: "default_agent",
+ modelId: "m1",
+ provider: "custom",
+ workspace: "/tmp/w",
+ approvalMode: "always-ask",
+ title: null,
+ createdAt: new Date().toISOString(),
+ lastActiveAt: new Date().toISOString(),
+ };
+ t.deps.sessionsRepo.insert(row);
+ probe = { started: false, sawAbort: false, endStatus: null };
+ t.deps.manager.adopt(row, compactingFakeSession(SID, probe));
+ });
+ afterEach(async () => {
+ await t.cleanup();
+ });
+
+ it("takes the abort while compacting: 202, the signal reaches the compaction, the Session goes idle", async () => {
+ await t.deps.manager.startCompact(SID);
+ await waitFor(() => probe.started && t.deps.manager.statusOf(SID) === "compacting");
+
+ const res = await api.post(`/api/sessions/${SID}/abort`, {});
+ // 202 = an interrupt was triggered (204 would mean "nothing in progress" — the answer
+ // this route would give if it only recognized `running` as interruptible).
+ expect(res.status).toBe(202);
+
+ await waitFor(() => t.deps.manager.statusOf(SID) === "idle");
+ expect(probe.sawAbort).toBe(true);
+ // The interrupted compaction settles in the same well-defined state a crash-interrupted
+ // one does: aborted, with the original context kept.
+ expect(probe.endStatus).toBe("aborted");
+ });
+
+ it("an idle Session reports 204: there is no compaction to stop", async () => {
+ const res = await api.post(`/api/sessions/${SID}/abort`, {});
+ expect(res.status).toBe(204);
+ expect(probe.started).toBe(false);
+ });
+});
diff --git a/packages/web/src/features/chat/chat-input.tsx b/packages/web/src/features/chat/chat-input.tsx
index fc6564f6..8a6807e8 100644
--- a/packages/web/src/features/chat/chat-input.tsx
+++ b/packages/web/src/features/chat/chat-input.tsx
@@ -112,7 +112,7 @@ import {
historyStepForward,
} from "./input-history";
import type { HistoryStep } from "./input-history";
-import { midRunAction } from "./composer-send";
+import { isStopAction, midRunAction } from "./composer-send";
import { PAPERCLIP_ICON } from "./attached-files-banner";
import { FileDropZone } from "./drop-zone";
import { splitDroppedFiles } from "../../lib/file-drop";
@@ -1339,7 +1339,8 @@ export function ChatInput({
// Which of the two channels this draft can use, or Stop when neither will take it — the whole
// decision lives in midRunAction so it can be reasoned about and tested on its own, and so
// that Stop stays the fallthrough rather than a case somebody has to remember to widen. Only
- // meaningful while running; idle/compacting is always Send, gated by canSend above.
+ // meaningful while running: an idle Session is always Send (gated by canSend above) and a
+ // compacting one is always Stop (see isStopAction).
const midRun = midRunAction({
sending: busy,
goalOn,
@@ -1359,7 +1360,7 @@ export function ChatInput({
const queueAction = running && midRun === "queue";
const canMidRunSend = steerAction || queueAction;
const midRunSendLabel = midRun === "queue" ? S.chat.followUpSend : S.chat.steerSend;
- const stopAction = running && midRun === "stop";
+ const stopAction = isStopAction(status, midRun);
// Queued hint: shown after a successful steer until the message shows up in the stream
// (steeringDeliveredCount increases past the baseline captured at queue time) or the run
// stops being observable (task no longer running).
@@ -2757,8 +2758,10 @@ export function ChatInput({
{/* One action button, never two: while running an empty composer means "Stop"
(abort), and typing turns the very same button into "Send" — which, mid-run,
steers or queues per the remembered send mode (the "+" menu's settings row).
- Idle/compacting keeps the ordinary send button (disabled while compacting via
- canSend). Merging the pair keeps the running-state row within a 320px viewport. */}
+ While COMPACTING it is always Stop: a compaction is abortable, and neither send
+ channel is open then, so the alternative was a permanently disabled Send sitting
+ where the only available action belonged. Idle keeps the ordinary send button.
+ Merging the pair keeps the running-state row within a 320px viewport. */}
<button
type="button"
title={stopAction ? S.chat.stop : running ? midRunSendLabel : S.chat.send}
diff --git a/packages/web/src/features/chat/composer-send.ts b/packages/web/src/features/chat/composer-send.ts
index f88ed108..c80b3927 100644
--- a/packages/web/src/features/chat/composer-send.ts
+++ b/packages/web/src/features/chat/composer-send.ts
@@ -57,7 +57,8 @@ export interface MidRunComposerState {
/**
* The button's mode while a Task runs. Idle and compacting are not this function's business:
- * the button is always Send there, gated by the ordinary `canSend`.
+ * a compacting Session takes its face from `isStopAction` below, and an idle one is always
+ * Send, gated by the ordinary `canSend`.
*
* Steering is preferred over the queue when both could carry the draft, since it reaches the
* turn already under way; the queue picks up what steering cannot — a skills-only draft, a
@@ -81,3 +82,26 @@ export function midRunAction(s: MidRunComposerState): MidRunAction {
// because the two put the message in different places. Stop, as with anything unsendable.
return "stop";
}
+
+/**
+ * Whether the single action button wears its Stop face, for **every** session state.
+ *
+ * Compaction is abortable — the server takes an abort while a compaction is in flight and
+ * core stops the compaction request on the signal — but the button used to ask only
+ * `running && midRunAction(...) === "stop"`, and a compacting Session is not `running`. It
+ * therefore fell through to the Send branch, which `canSend` disables while compacting: a
+ * dead button exactly where Stop belonged, and no way to interrupt a compaction from the
+ * composer at all.
+ *
+ * That is the same mistake this module was extracted to stop repeating (see the header): a
+ * state where nothing can be sent must leave Stop, never a disabled Send. Compacting is
+ * unconditionally that state — neither send channel is offered while a compaction runs, so
+ * there is no draft the button could carry instead, whatever the composer holds.
+ */
+export function isStopAction(
+ status: "idle" | "running" | "compacting",
+ midRun: MidRunAction,
+): boolean {
+ if (status === "compacting") return true;
+ return status === "running" && midRun === "stop";
+}
diff --git a/packages/web/test/composer-send.test.ts b/packages/web/test/composer-send.test.ts
index 28cd21dd..4d574c81 100644
--- a/packages/web/test/composer-send.test.ts
+++ b/packages/web/test/composer-send.test.ts
@@ -8,7 +8,7 @@
* to delete what you had typed.
*/
import { describe, expect, it } from "vitest";
-import { midRunAction } from "../src/features/chat/composer-send";
+import { isStopAction, midRunAction } from "../src/features/chat/composer-send";
import type { MidRunComposerState } from "../src/features/chat/composer-send";
/** An active session with both channels wired, steer mode, and a one-line text draft. */
@@ -109,3 +109,32 @@ describe("midRunAction — a send already in flight", () => {
expect(act({ sending: true, goalOn: true })).toBe("disabled");
});
});
+
+describe("isStopAction — which session states offer Stop at all", () => {
+ it("offers Stop for the whole of a compaction, whatever the composer holds", () => {
+ // The regression this pins: a compacting Session is not `running`, so a gate written as
+ // `running && midRun === "stop"` fell through to the Send branch — which canSend disables
+ // while compacting. The result was a dead button where Stop belonged and no way to
+ // interrupt a compaction from the composer (the server has always accepted the abort).
+ expect(isStopAction("compacting", "stop")).toBe(true);
+ // A draft does not buy the button back: neither send channel is open while compacting,
+ // so every mid-run face still resolves to Stop.
+ expect(isStopAction("compacting", "steer")).toBe(true);
+ expect(isStopAction("compacting", "queue")).toBe(true);
+ expect(isStopAction("compacting", "disabled")).toBe(true);
+ });
+
+ it("keeps the running rules exactly as they were: Stop only where the draft has nowhere to go", () => {
+ expect(isStopAction("running", "stop")).toBe(true);
+ expect(isStopAction("running", "steer")).toBe(false);
+ expect(isStopAction("running", "queue")).toBe(false);
+ // A send in flight must not turn into an abort on the next click.
+ expect(isStopAction("running", "disabled")).toBe(false);
+ });
+
+ it("never offers Stop when idle: there is nothing to stop", () => {
+ expect(isStopAction("idle", "stop")).toBe(false);
+ expect(isStopAction("idle", "steer")).toBe(false);
+ expect(isStopAction("idle", "disabled")).toBe(false);
+ });
+});