fix(tui): coalesce busy submit notices (#99879)

* fix(tui): coalesce busy submit notices

* fix(tui): coalesce busy submit notices
This commit is contained in:
Vincent Koc
2026-07-04 04:05:11 -07:00
committed by GitHub
parent 65e2819136
commit e396ff68d8
5 changed files with 35 additions and 8 deletions
+18
View File
@@ -0,0 +1,18 @@
import { describe, expect, it } from "vitest";
import { normalizeTestText } from "../../test/helpers/normalize-text.js";
import { ChatLog } from "./components/chat-log.js";
import { addBlockedChatSubmitNotice, TUI_AGENT_BUSY_MESSAGE } from "./tui-busy-notice.js";
describe("addBlockedChatSubmitNotice", () => {
it("coalesces repeated busy submit notices", () => {
const chatLog = new ChatLog(20);
addBlockedChatSubmitNotice(chatLog);
addBlockedChatSubmitNotice(chatLog);
addBlockedChatSubmitNotice(chatLog);
const rendered = normalizeTestText(chatLog.render(120).join("\n"));
expect(chatLog.children.length).toBe(1);
expect(rendered).toContain(`${TUI_AGENT_BUSY_MESSAGE} x3`);
});
});
+8
View File
@@ -0,0 +1,8 @@
import type { ChatLog } from "./components/chat-log.js";
export const TUI_AGENT_BUSY_MESSAGE =
"agent is busy — press Esc to abort before sending a new message";
export function addBlockedChatSubmitNotice(chatLog: Pick<ChatLog, "addSystem">) {
chatLog.addSystem(TUI_AGENT_BUSY_MESSAGE, { coalesceConsecutive: true });
}
+5 -6
View File
@@ -1122,6 +1122,7 @@ describe("tui command handlers", () => {
expect(addPendingUser).not.toHaveBeenCalled();
expect(addSystem).toHaveBeenCalledWith(
"agent is busy — press Esc to abort before sending a new message",
{ coalesceConsecutive: true },
);
});
@@ -1179,6 +1180,7 @@ describe("tui command handlers", () => {
expect(addUser).not.toHaveBeenCalled();
expect(addSystem).toHaveBeenCalledWith(
"agent is busy — press Esc to abort before sending a new message",
{ coalesceConsecutive: true },
);
});
@@ -1210,6 +1212,7 @@ describe("tui command handlers", () => {
expect(addUser).not.toHaveBeenCalled();
expect(addSystem).toHaveBeenCalledWith(
"agent is busy — press Esc to abort before sending a new message",
{ coalesceConsecutive: true },
);
});
@@ -1465,9 +1468,7 @@ describe("tui command handlers", () => {
await handleCommand("/usage reset");
expect(patchSession).toHaveBeenCalledWith(
expect.objectContaining({ responseUsage: null }),
);
expect(patchSession).toHaveBeenCalledWith(expect.objectContaining({ responseUsage: null }));
expect(addSystem).toHaveBeenCalledWith("usage footer: reset to default");
// Both stale local values must be cleared so the toggle/display is not stale
// until refreshSessionInfo() repopulates the inherited default.
@@ -1492,9 +1493,7 @@ describe("tui command handlers", () => {
await handleCommand("/usage");
expect(patchSession).toHaveBeenCalledWith(
expect.objectContaining({ responseUsage: "full" }),
);
expect(patchSession).toHaveBeenCalledWith(expect.objectContaining({ responseUsage: "full" }));
expect(addSystem).toHaveBeenCalledWith("usage footer: full");
});
});
+2 -1
View File
@@ -26,6 +26,7 @@ import {
createSettingsList,
} from "./components/selectors.js";
import type { TuiBackend, TuiSessionMutationResult } from "./tui-backend.js";
import { addBlockedChatSubmitNotice } from "./tui-busy-notice.js";
import { sanitizeRenderableText } from "./tui-formatters.js";
import {
TUI_RECENT_SESSIONS_ACTIVE_MINUTES,
@@ -782,7 +783,7 @@ export function createCommandHandlers(context: CommandHandlerContext) {
state.pendingOptimisticUserMessage ||
(opts.local !== true && state.activeChatRunId))
) {
chatLog.addSystem("agent is busy — press Esc to abort before sending a new message");
addBlockedChatSubmitNotice(chatLog);
tui.requestRender();
return;
}
+2 -1
View File
@@ -39,6 +39,7 @@ import { CustomEditor } from "./components/custom-editor.js";
import { resolveLocalRunShutdownGraceMs } from "./local-run-shutdown.js";
import { editorTheme, theme } from "./theme/theme.js";
import type { TuiBackend } from "./tui-backend.js";
import { addBlockedChatSubmitNotice } from "./tui-busy-notice.js";
import { createCommandHandlers } from "./tui-command-handlers.js";
import { createEventHandlers } from "./tui-event-handlers.js";
import {
@@ -1434,7 +1435,7 @@ export async function runTui(opts: RunTuiOptions): Promise<TuiResult> {
message,
});
const notifyBlockedChatSubmit = () => {
chatLog.addSystem("agent is busy — press Esc to abort before sending a new message");
addBlockedChatSubmitNotice(chatLog);
tui.requestRender();
};
const submitHandler = createEditorSubmitHandler({