Skip to content

The agent that grows with you

test(desktop,tui): busy /undo and /retry show main's stop-first or wait-for-compress text on both clients (currently failing)

yoniebans9f36385cb9f6
diff --git a/apps/desktop/src/app/session/hooks/use-prompt-actions/slash-session-commands.test.tsx b/apps/desktop/src/app/session/hooks/use-prompt-actions/slash-session-commands.test.tsx
index 3e974f81145..4ab63895a18 100644
--- a/apps/desktop/src/app/session/hooks/use-prompt-actions/slash-session-commands.test.tsx
+++ b/apps/desktop/src/app/session/hooks/use-prompt-actions/slash-session-commands.test.tsx
@@ -78,6 +78,12 @@ const canonical = () => $connection.set({ mode: 'local', wsUrl: 'ws://localhost/
// The shared owner's typed refusal of a rewind while a turn runs, as the wire delivers it.
const BUSY = new JsonRpcGatewayError('session_busy', { code: 4001, data: { reason: 'session_busy' } })
+// The same refusal while another writer holds the compression lock: Stop does not end it.
+const COMPRESSING = new JsonRpcGatewayError('session_busy', {
+ code: 4001,
+ data: { field: 'compression', reason: 'session_busy' }
+})
+
beforeEach(() => {
clearSingleFlightSessionResumeState()
window.localStorage.removeItem('hermes.desktop.composerQueue.v1')
@@ -253,6 +259,32 @@ describe('/retry on a canonical session', () => {
})
})
+describe('/undo and /retry while a compression holds the session', () => {
+ beforeEach(canonical)
+
+ for (const command of ['undo', 'retry'] as const) {
+ it(`/${command} says to wait for the compression instead of pressing Stop`, async () => {
+ const requestGateway = gateway(method => {
+ if (method === 'session.resume') {
+ return SNAPSHOT
+ }
+
+ if (method === 'session.rewind') {
+ throw COMPRESSING
+ }
+ })
+
+ const handle = await mount(requestGateway)
+ await handle.submitText(`/${command}`)
+
+ expect(renderedText(handle)).toContain(`a /compress is running; run /${command} when it finishes`)
+ expect(renderedText(handle)).not.toContain('Stop the current reply first')
+ expect(callsOf(requestGateway, 'session.interrupt')).toEqual([])
+ expect(callsOf(requestGateway, 'prompt.submit')).toEqual([])
+ })
+ }
+})
+
describe('/steer', () => {
it('steers the running turn through session.steer', async () => {
publishSessionState(RUNTIME_SESSION_ID, { ...createClientSessionState(RUNTIME_SESSION_ID), busy: true })
diff --git a/ui-tui/src/__tests__/canonicalSlashCommands.test.ts b/ui-tui/src/__tests__/canonicalSlashCommands.test.ts
index 2e384623a01..73f28a14ac5 100644
--- a/ui-tui/src/__tests__/canonicalSlashCommands.test.ts
+++ b/ui-tui/src/__tests__/canonicalSlashCommands.test.ts
@@ -1,3 +1,4 @@
+import { JsonRpcGatewayError } from '@hermes/shared/json-rpc-channel'
import { beforeEach, expect, it, vi } from 'vitest'
import { createSlashHandler } from '../app/createSlashHandler.js'
@@ -11,7 +12,7 @@ import { getUiState, patchUiState, resetUiState } from '../app/uiStore.js'
const flush = () => new Promise(resolve => setImmediate(resolve))
const LEGACY = ['session.title', 'session.undo', 'session.usage', 'slash.exec', 'tools.configure']
-function harness() {
+function harness(rewindRefusal?: Error) {
let voiceMode = 'off'
// T9/T10 owner verbs, one answer per method (kept out of the request ladder below).
@@ -43,7 +44,7 @@ function harness() {
{ role: 'assistant', content: 'a2', row_id: 14 }
]
- const request = vi.fn(async (method: string, params: any) => {
+ const reply = async (method: string, params: any) => {
if (method === 'session.resume') {
return { session_id: 'owner', revision: 7, execution_generation: 3, messages }
}
@@ -112,7 +113,14 @@ function harness() {
}
throw new Error(`unknown_method: ${method}`)
- })
+ }
+
+ // A refused rewind (the owner's typed busy refusal) replaces only the rewind reply.
+ const request = vi.fn(async (method: string, params: any) =>
+ rewindRefusal && method === 'session.mutate' && params.operation === 'rewind'
+ ? Promise.reject(rewindRefusal)
+ : reply(method, params)
+ )
const sys = vi.fn()
const send = vi.fn()
@@ -201,6 +209,39 @@ it('/title renames and /undo, /retry rewind through session.mutate with the snap
expect(request.mock.calls.some(([method]) => LEGACY.includes(method))).toBe(false)
})
+it('/undo and /retry while a turn runs print main\'s stop-first text, not the bare reason code', async () => {
+ const busy = new JsonRpcGatewayError('session_busy', { code: 4001, data: { reason: 'session_busy' } })
+ const { send, slash, sys } = harness(busy)
+
+ for (const command of ['undo', 'retry']) {
+ slash(`/${command}`)
+ await flush()
+ expect(sys).toHaveBeenLastCalledWith(
+ `session busy — Hermes is still replying. Stop the current reply first (Stop button, or Ctrl+C in a terminal), then run /${command}.`
+ )
+ }
+
+ expect(sys.mock.calls.some(([line]) => String(line).includes('error: session_busy'))).toBe(false)
+ expect(send).not.toHaveBeenCalled()
+})
+
+it('/undo and /retry while a compression holds the session say to wait for it', async () => {
+ const compressing = new JsonRpcGatewayError('session_busy', {
+ code: 4001,
+ data: { field: 'compression', reason: 'session_busy' }
+ })
+
+ const { send, slash, sys } = harness(compressing)
+
+ for (const command of ['undo', 'retry']) {
+ slash(`/${command}`)
+ await flush()
+ expect(sys).toHaveBeenLastCalledWith(`session busy — a /compress is running; run /${command} when it finishes.`)
+ }
+
+ expect(send).not.toHaveBeenCalled()
+})
+
it("/usage renders main's session totals from session.stats and /tools lists the owner's tools.show", async () => {
const { page, panel, request, slash, sys } = harness()