Skip to content

The agent that grows with you

fix(desktop): Enter while busy steers the live turn instead of parking it in the queue

Brooklyn Nicholsona3936ae0c683
diff --git a/apps/desktop/src/app/chat/composer/hooks/use-composer-queue.test.tsx b/apps/desktop/src/app/chat/composer/hooks/use-composer-queue.test.tsx
index 8a2894e650d..5052ad69882 100644
--- a/apps/desktop/src/app/chat/composer/hooks/use-composer-queue.test.tsx
+++ b/apps/desktop/src/app/chat/composer/hooks/use-composer-queue.test.tsx
@@ -288,4 +288,77 @@ describe('useComposerQueue park integration', () => {
await waitFor(() => expect(onSubmit).toHaveBeenCalledTimes(1))
expect(getQueuedPrompts(SESSION_KEY)).toHaveLength(0)
})
+
+ describe('deliverQueuedNow (double-Enter while busy)', () => {
+ it('steers a text entry into the live turn instead of interrupting it', async () => {
+ const entry = enqueueQueuedPrompt(SESSION_KEY, { attachments: [], text: 'fix the header too' })!
+ const onSteer = vi.fn(async () => true)
+ const { hook, onCancel, onSubmit } = renderQueueHook({ busy: true, onSteer })
+
+ await act(async () => {
+ expect(await hook.result.current.deliverQueuedNow(entry.id)).toBe(true)
+ })
+
+ expect(onSteer).toHaveBeenCalledWith('fix the header too')
+ expect(onCancel).not.toHaveBeenCalled()
+ expect(onSubmit).not.toHaveBeenCalled()
+ expect(getQueuedPrompts(SESSION_KEY)).toHaveLength(0)
+ })
+
+ it('falls back to send-now (interrupt) when the live turn refuses the steer', async () => {
+ const other = enqueueQueuedPrompt(SESSION_KEY, { attachments: [], text: 'older' })!
+ const entry = enqueueQueuedPrompt(SESSION_KEY, { attachments: [], text: 'refused' })!
+ const onSteer = vi.fn(async () => false)
+ const { hook, onCancel } = renderQueueHook({ busy: true, onSteer })
+
+ await act(async () => {
+ await hook.result.current.deliverQueuedNow(entry.id)
+ })
+
+ expect(onSteer).toHaveBeenCalledTimes(1)
+ expect(onCancel).toHaveBeenCalledTimes(1)
+ expect(getQueuedPrompts(SESSION_KEY).map(e => e.id)).toEqual([entry.id, other.id])
+ })
+
+ it('interrupts directly for a payload a steer cannot carry', async () => {
+ const entry = enqueueQueuedPrompt(SESSION_KEY, {
+ attachments: [{ id: 'shot', kind: 'image', label: 'shot.png' }],
+ text: 'look at this'
+ })!
+
+ const onSteer = vi.fn(async () => true)
+ const { hook, onCancel } = renderQueueHook({ busy: true, onSteer })
+
+ await act(async () => {
+ await hook.result.current.deliverQueuedNow(entry.id)
+ })
+
+ expect(onSteer).not.toHaveBeenCalled()
+ expect(onCancel).toHaveBeenCalledTimes(1)
+ })
+
+ it('a repeat Enter while the steer is in flight never escalates to an interrupt', async () => {
+ const entry = enqueueQueuedPrompt(SESSION_KEY, { attachments: [], text: 'once' })!
+
+ let accept: (value: boolean) => void = () => {}
+
+ const onSteer = vi.fn(() => new Promise<boolean>(resolve => (accept = resolve)))
+ const { hook, onCancel } = renderQueueHook({ busy: true, onSteer })
+
+ let first: Promise<unknown> = Promise.resolve()
+
+ await act(async () => {
+ first = hook.result.current.deliverQueuedNow(entry.id)
+ expect(await hook.result.current.deliverQueuedNow(entry.id)).toBe(true)
+ })
+
+ await act(async () => {
+ accept(true)
+ await first
+ })
+
+ expect(onSteer).toHaveBeenCalledTimes(1)
+ expect(onCancel).not.toHaveBeenCalled()
+ })
+ })
})
diff --git a/apps/desktop/src/app/chat/composer/hooks/use-composer-queue.ts b/apps/desktop/src/app/chat/composer/hooks/use-composer-queue.ts
index ad8edfb8b22..dd4376c344d 100644
--- a/apps/desktop/src/app/chat/composer/hooks/use-composer-queue.ts
+++ b/apps/desktop/src/app/chat/composer/hooks/use-composer-queue.ts
@@ -343,6 +343,40 @@ export function useComposerQueue({
[activeQueueSessionKey, busy, onSteer, queueEditRef]
)
+ // Double-Enter while busy. The entry usually sits in the queue because the
+ // first Enter's steer didn't land, so retry that: the words join the live
+ // turn as a bubble, with no interrupt and no settle wait. A payload a steer
+ // can't carry (attachments, hidden notes, expanded skills) or a refused
+ // steer falls back to send-now's interrupt.
+ const busyRef = useRef(busy)
+ busyRef.current = busy
+ const steeringIdsRef = useRef(new Set<string>())
+
+ const deliverQueuedNow = useCallback(
+ async (id: string) => {
+ const entry = activeQueueSessionKey ? getQueuedPrompts(activeQueueSessionKey).find(e => e.id === id) : undefined
+
+ if (!busy || !entry || entry.displayKind || entry.displayText || !isSteerableEntry(entry)) {
+ return sendQueuedNow(id)
+ }
+
+ // A repeat Enter mid-steer must not interrupt the turn about to take it.
+ if (steeringIdsRef.current.has(id)) {
+ return true
+ }
+
+ steeringIdsRef.current.add(id)
+ const steered = await steerQueuedNow(id).finally(() => steeringIdsRef.current.delete(id))
+
+ // Settled while we asked: the idle auto-drain already owns the entry.
+ return (
+ steered ||
+ (busyRef.current && getQueuedPrompts(activeQueueSessionKey!).some(e => e.id === id) && sendQueuedNow(id))
+ )
+ },
+ [activeQueueSessionKey, busy, sendQueuedNow, steerQueuedNow]
+ )
+
// Edge-independent auto-drain: send the head whenever the session is idle and
// the queue is non-empty, bounding retries so a thrown/rejected onSubmit (e.g.
// a stale-session 404) can't strand the entry permanently nor spin-loop. The
@@ -454,6 +488,7 @@ export function useComposerQueue({
return {
beginQueuedEdit,
+ deliverQueuedNow,
drainNextQueued,
editingQueuedPrompt,
exitQueuedEdit,
diff --git a/apps/desktop/src/app/chat/composer/hooks/use-composer-submit.restore-scoping.test.tsx b/apps/desktop/src/app/chat/composer/hooks/use-composer-submit.restore-scoping.test.tsx
index e1b461139e5..fcdd2c8df4b 100644
--- a/apps/desktop/src/app/chat/composer/hooks/use-composer-submit.restore-scoping.test.tsx
+++ b/apps/desktop/src/app/chat/composer/hooks/use-composer-submit.restore-scoping.test.tsx
@@ -182,7 +182,6 @@ function Harness({ pendingScope, suspend, onSubmit }: HarnessProps) {
activeQueueSessionKey,
attachments,
busy: false,
- compacting: false,
disabled: false,
inputDisabled: false,
drainNextQueued: async () => false,
diff --git a/apps/desktop/src/app/chat/composer/hooks/use-composer-submit.test.tsx b/apps/desktop/src/app/chat/composer/hooks/use-composer-submit.test.tsx
index 89e0e559bc6..cf84770f6c6 100644
--- a/apps/desktop/src/app/chat/composer/hooks/use-composer-submit.test.tsx
+++ b/apps/desktop/src/app/chat/composer/hooks/use-composer-submit.test.tsx
@@ -26,7 +26,6 @@ import { useComposerSubmit } from './use-composer-submit'
interface SubmitHarnessOptions {
attachments?: ComposerAttachment[]
busy?: boolean
- compacting?: boolean
inputDisabled?: boolean
scopeTarget?: ComposerTarget
sessionKey?: string | null
@@ -41,7 +40,6 @@ let surfaceSequence = 0
function renderSubmitHook({
attachments = [],
busy = false,
- compacting = false,
inputDisabled = false,
scopeTarget = 'main',
sessionKey = 'stored-session',
@@ -105,7 +103,6 @@ function renderSubmitHook({
activeQueueSessionKeyRef: { current: sessionKey },
attachments,
busy,
- compacting,
clearDraft,
disabled: false,
draftScopeRef,
@@ -388,23 +385,6 @@ describe('useComposerSubmit busy-turn routing', () => {
clearQueuedPrompts('stored-session')
})
- it('queues a plain-text follow-up while the active turn is compacting', () => {
- const { hook, onCancel, onSteer, onSubmit, queueCurrentDraft } = renderSubmitHook({
- busy: true,
- compacting: true,
- text: 'wait for the summary'
- })
-
- act(() => {
- hook.result.current.submitDraft()
- })
-
- expect(queueCurrentDraft).toHaveBeenCalledTimes(1)
- expect(onSteer).not.toHaveBeenCalled()
- expect(onSubmit).not.toHaveBeenCalled()
- expect(onCancel).not.toHaveBeenCalled()
- })
-
it('runs slash commands immediately while busy', async () => {
const { clearDraft, hook, onCancel, onSteer, onSubmit, queueCurrentDraft } = renderSubmitHook({
busy: true,
diff --git a/apps/desktop/src/app/chat/composer/hooks/use-composer-submit.ts b/apps/desktop/src/app/chat/composer/hooks/use-composer-submit.ts
index 2304fac0f8a..f0a8457495d 100644
--- a/apps/desktop/src/app/chat/composer/hooks/use-composer-submit.ts
+++ b/apps/desktop/src/app/chat/composer/hooks/use-composer-submit.ts
@@ -23,7 +23,6 @@ interface UseComposerSubmitArgs {
activeQueueSessionKeyRef: RefObject<string | null>
attachments: ComposerAttachment[]
busy: boolean
- compacting: boolean
clearDraft: () => void
disabled: boolean
draftScopeRef: RefObject<string | null>
@@ -60,7 +59,6 @@ export function useComposerSubmit({
activeQueueSessionKeyRef,
attachments,
busy,
- compacting,
clearDraft,
disabled,
draftScopeRef,
@@ -147,8 +145,8 @@ export function useComposerSubmit({
// if the turn has already ended, or a steer is not possible, queue it so it
// runs next. This holds for hidden setup notes and for visible messages a
// button sends on the user's behalf alike.
- const externalSubmitRef = useRef({ busy, compacting, dispatchSubmit, onSteer, onSteerHidden })
- externalSubmitRef.current = { busy, compacting, dispatchSubmit, onSteer, onSteerHidden }
+ const externalSubmitRef = useRef({ busy, dispatchSubmit, onSteer, onSteerHidden })
+ externalSubmitRef.current = { busy, dispatchSubmit, onSteer, onSteerHidden }
useLayoutEffect(
() =>
@@ -194,7 +192,6 @@ export function useComposerSubmit({
if (
current.onSteer &&
- !current.compacting &&
!hasBlockingPromptRequest(sessionId) &&
text.trim() &&
!SLASH_COMMAND_RE.test(text.trim())
@@ -293,10 +290,12 @@ export function useComposerSubmit({
triggerHaptic('submit')
clearDraft()
dispatchSubmit(text)
- } else if (!compacting && !blockingPrompt && !attachments.length && text.trim()) {
+ } else if (!blockingPrompt && !attachments.length && text.trim()) {
// Cursor-style stop-and-correct: interrupt the live turn and redirect
// it with this text. redirect() preserves the shown reasoning/work; if
// the turn already ended, steerDraft re-queues so nothing is lost.
+ // Compaction is the gateway's call: it answers `queued` under the
+ // compression lock. The client flag can outlive an aborted compaction.
steerDraft()
} else if (payloadPresent) {
// Attachments can't ride a redirect (no tool-result image carriage) —
diff --git a/apps/desktop/src/app/chat/composer/index.tsx b/apps/desktop/src/app/chat/composer/index.tsx
index b76279e03a8..2431cdd6a09 100644
--- a/apps/desktop/src/app/chat/composer/index.tsx
+++ b/apps/desktop/src/app/chat/composer/index.tsx
@@ -362,6 +362,7 @@ export function ChatBar({
// and bounded auto-drain. Consumes the draft API and writes `queueEditRef`.
const {
beginQueuedEdit,
+ deliverQueuedNow,
drainNextQueued,
editingQueuedPrompt,
exitQueuedEdit,
@@ -419,7 +420,8 @@ export function ChatBar({
// into a tool result) and never for a slash command (those execute inline).
// A blocking prompt (approval/sudo/secret) also rules it out: the tool batch
// is parked on the user, so a steer can't reach the model — text queues.
- const canSteer = busy && !compacting && !blockingPrompt && !!onSteer && attachments.length === 0 && isSteerableText
+ // Compaction does not: the gateway holds the correction until it finishes.
+ const canSteer = busy && !blockingPrompt && !!onSteer && attachments.length === 0 && isSteerableText
// While busy: text redirects the live turn (Cursor-style stop-and-correct),
// attachments queue for the next turn, an empty composer stops.
@@ -436,7 +438,6 @@ export function ChatBar({
activeQueueSessionKeyRef,
attachments,
busy,
- compacting,
clearDraft,
disabled,
draftScopeRef,
@@ -1021,8 +1022,9 @@ export function ChatBar({
}
// Empty Enter while busy. With prompts queued this is the double-send:
- // the first Enter put the words in the queue, a second sends them now
- // (promote + interrupt + drain on settle), mirroring the idle empty-Enter
+ // the first Enter put the words in the queue, a second delivers them
+ // now — steered into the live turn when a steer can carry them, else
+ // promote + interrupt + drain on settle — mirroring the idle empty-Enter
// drain above. With nothing queued it stays a no-op — interrupting is
// explicit (Stop/Esc), never a stray Enter after sending. Gate on the live
// DOM payload (not the render-lagged composer state) so a message typed
@@ -1032,7 +1034,7 @@ export function ChatBar({
const head = queuedPrompts.find(entry => entry.id !== queueEdit?.entryId)
if (head) {
- sendQueuedNow(head.id)
+ void deliverQueuedNow(head.id)
}
return