Skip to content

The agent that grows with you

feat(tui): admit busy queue-mode input to the authority FIFO immediately

Teknium829ad086e6f0
diff --git a/ui-tui/src/__tests__/busyQueueAdmission.test.tsx b/ui-tui/src/__tests__/busyQueueAdmission.test.tsx
new file mode 100644
index 00000000000..701b38cfecb
--- /dev/null
+++ b/ui-tui/src/__tests__/busyQueueAdmission.test.tsx
@@ -0,0 +1,137 @@
+import { mkdtempSync, rmSync } from 'node:fs'
+import { tmpdir } from 'node:os'
+import { join } from 'node:path'
+import { PassThrough } from 'node:stream'
+
+import { renderSync, Text } from '@hermes/ink'
+import { useStore } from '@nanostores/react'
+import React from 'react'
+import { expect, it, vi } from 'vitest'
+
+import { createGatewayEventHandler } from '../app/createGatewayEventHandler.js'
+import { turnController } from '../app/turnController.js'
+import { $uiState, patchUiState, resetUiState } from '../app/uiStore.js'
+import { useSubmission } from '../app/useSubmission.js'
+import { canonicalEvent, canonicalResult } from '../canonicalGateway.js'
+import { useQueue } from '../hooks/useQueue.js'
+
+// Canonical authority rows: `pending` carries the server-issued admission_id,
+// the client's input_id and the public text under `ref` destination fields.
+const row = (admission_id: string, input_id: string, text: string, status = 'queued') => ({
+ admission_id, input_id, text, status, sequence: 1, outcome: null, authority_epoch: 1, execution_generation: null,
+ ref: { profile_id: '/tmp/profile', session_id: 'stored-owner' }
+})
+
+function mount(busyInputMode: 'queue' | 'interrupt' = 'queue') {
+ const home = mkdtempSync(join(tmpdir(), 'ink-busy-admit-'))
+ vi.stubEnv('HERMES_HOME', home)
+ resetUiState()
+ const info = { model: 'test', skills: {}, tools: {}, profile_name: 'default',
+ stored_session_id: 'stored-owner', execution_epoch: '1', execution_generation: 1, running: true }
+ patchUiState({ sid: 'owner', info, busy: true, status: 'running…', busyInputMode })
+ const calls: Array<{ method: string; params: any }> = []
+ const request = vi.fn((method: string, params: any) => {
+ calls.push({ method, params })
+ if (method === 'input.detect_drop') { return Promise.resolve({ matched: false }) }
+ if (method === 'prompt.submit') {
+ return Promise.resolve({ admission_id: `adm-${params.submission_id}`, input_id: params.submission_id,
+ target_session_id: 'stored-owner', target_profile_home: home, status: 'queued' })
+ }
+ if (method === 'prompt.cancel') { return Promise.resolve({ admission_id: params.admission_id, status: 'terminal', outcome: 'cancelled' }) }
+ throw new Error(`unexpected RPC: ${method}`)
+ })
+ const gw = { request, isCanonical: true } as any
+ let queue!: ReturnType<typeof useQueue>
+ let submission!: ReturnType<typeof useSubmission>
+ const noop = () => {}
+ const onEvent = createGatewayEventHandler({
+ composer: { dequeue: () => undefined, queueEditRef: { current: null }, sendQueued: noop, setInput: noop },
+ gateway: { gw, rpc: async () => null },
+ session: { STARTUP_RESUME_ID: '', colsRef: { current: 80 }, newSession: noop, resetSession: noop, resumeById: noop, setCatalog: noop },
+ submission: { submitRef: { current: noop } }, system: { bellOnComplete: false, sys: noop },
+ transcript: { appendMessage: noop, panel: noop, setHistoryItems: noop },
+ voice: { setProcessing: noop, setRecording: noop, setVoiceEnabled: noop }
+ } as any)
+ // The wire shape the gateway fans out; the client translates it exactly once.
+ const fanout = (pending: any[]) => onEvent(canonicalEvent({ type: 'session.info', session_id: 'owner',
+ payload: { stored_session_id: 'stored-owner', pending, running: true, execution_generation: 1, revision: 3,
+ execution_epoch: '1' } } as any) as any)
+
+ function Harness() {
+ const ui = useStore($uiState)
+ queue = useQueue(gw)
+ submission = useSubmission({
+ appendMessage: noop,
+ composerActions: { ...queue, prependQueue: queue.prependQ, takeQueue: queue.takeQ, removeQueue: queue.removeQ,
+ pushHistory: noop, clearIn: noop } as any,
+ composerRefs: { queueRef: queue.queueRef, queueEditRef: queue.queueEditRef, tokensRef: { current: [] } } as any,
+ composerState: { input: '', inputBuf: [], completions: [] } as any,
+ gw, setLastUserMsg: noop, slashRef: { current: () => true },
+ submitRef: { current: noop }, sys: noop
+ })
+
+ return <Text>{ui.status} {queue.queuedDisplay.join('|')}</Text>
+ }
+ const instance = renderSync(<Harness />, {
+ stdin: new PassThrough() as any,
+ stdout: Object.assign(new PassThrough(), { columns: 80, rows: 20, isTTY: false }) as any,
+ stderr: new PassThrough() as any, patchConsole: false
+ })
+
+ return {
+ calls, request, fanout,
+ get queue() { return queue }, get submission() { return submission },
+ cleanup() { instance.unmount(); turnController.fullReset(); resetUiState(); vi.unstubAllEnvs(); rmSync(home, { recursive: true, force: true }) }
+ }
+}
+
+it('admits busy queue-mode input to the authority immediately with a stable input_id instead of holding it locally', async () => {
+ const h = mount('queue')
+ try {
+ h.submission.dispatchSubmission('follower while busy')
+ await expect.poll(() => h.calls.filter(c => c.method === 'prompt.submit').length).toBe(1)
+ const submit = h.calls.find(c => c.method === 'prompt.submit')!.params
+ expect(submit).toMatchObject({ session_id: 'owner', text: 'follower while busy', queued: true })
+ expect(typeof submit.submission_id).toBe('string')
+ expect(submit.submission_id.length).toBeGreaterThan(8)
+ // The receipt settles the local staging row; the durable FIFO now owns it.
+ await expect.poll(() => h.queue.queueRef.current.length).toBe(0)
+ // The in-flight turn's streaming buffer and busy latch are untouched.
+ expect($uiState.get()).toMatchObject({ busy: true, status: 'running…' })
+ } finally { h.cleanup() }
+})
+
+it('renders the queue from the session.info pending fanout, excluding the started row, and clears it when the fanout empties', async () => {
+ const h = mount('queue')
+ try {
+ h.fanout([row('adm-1', 'in-1', 'currently running', 'started'), row('adm-2', 'in-2', 'second in line')])
+ await expect.poll(() => h.queue.queuedDisplay).toEqual(['[queued] second in line'])
+ h.fanout([row('adm-1', 'in-1', 'currently running', 'started')])
+ await expect.poll(() => h.queue.queuedDisplay).toEqual([])
+ } finally { h.cleanup() }
+})
+
+it('deletes a server-queued row through prompt.cancel rather than local removal', async () => {
+ const h = mount('queue')
+ try {
+ h.fanout([row('adm-9', 'in-9', 'cancel me')])
+ await expect.poll(() => h.queue.queuedDisplay).toEqual(['[queued] cancel me'])
+ h.queue.removeQ(0)
+ await expect.poll(() => h.calls.filter(c => c.method === 'prompt.cancel').length).toBe(1)
+ expect(h.calls.find(c => c.method === 'prompt.cancel')!.params).toEqual({ session_id: 'owner', admission_id: 'adm-9' })
+ // Only the authority's next fanout retires the row.
+ expect(h.queue.queuedDisplay).toEqual(['[queued] cancel me'])
+ h.fanout([])
+ await expect.poll(() => h.queue.queuedDisplay).toEqual([])
+ } finally { h.cleanup() }
+})
+
+it('projects canonical pending rows onto the legacy pending_submissions shape for resume snapshots and fanout', () => {
+ const pending = [row('adm-3', 'in-3', 'hello')]
+ const snapshot = canonicalResult('session.resume', { session_id: 'sid', stored_session_id: 'sid', authority_epoch: 1,
+ execution_generation: 2, running: true, messages: [], pending }, {})
+ expect(snapshot.info.pending_submissions).toEqual([expect.objectContaining({ admission_id: 'adm-3', input_id: 'in-3', user: 'hello',
+ status: 'queued', target_session_id: 'stored-owner', target_profile_home: '/tmp/profile' })])
+ const ev = canonicalEvent({ type: 'session.info', session_id: 'sid', payload: { pending } } as any)
+ expect((ev.payload as any).pending_submissions[0]).toMatchObject({ admission_id: 'adm-3', user: 'hello' })
+})
diff --git a/ui-tui/src/app/createGatewayEventHandler.ts b/ui-tui/src/app/createGatewayEventHandler.ts
index e5f444a03be..d77fa0ce2a9 100644
--- a/ui-tui/src/app/createGatewayEventHandler.ts
+++ b/ui-tui/src/app/createGatewayEventHandler.ts
@@ -28,6 +28,7 @@ import type { Msg, SubagentProgress, SubagentStatus, Usage } from '../types.js'
import { applyDelegationStatus, getDelegationState } from './delegationStore.js'
import type { GatewayEventHandlerContext } from './interfaces.js'
import { getOverlayState, patchOverlayState } from './overlayStore.js'
+import { markBubbleShown, newlyStartedRows } from './pendingBubbles.js'
import { flashGoodVibes, flashPet } from './petFlashStore.js'
import { captureDestination, isCurrentDestination } from './submissionDestination.js'
import { turnController } from './turnController.js'
@@ -825,6 +826,13 @@ export function createGatewayEventHandler(ctx: GatewayEventHandlerContext): (ev:
const info = { ...current, ...incoming }
+ // A busy-time admission painted no bubble at submit; paint it when the
+ // authority starts it, so it lands after the previous assistant reply.
+ for (const started of newlyStartedRows(current?.pending_submissions, incoming.pending_submissions)) {
+ markBubbleShown(started.input_id)
+ appendMessage({ role: 'user', text: started.user })
+ }
+
// A replayed snapshot can be the only terminal signal after reconnect.
// Missing running on older gateways must not clear a live turn.
if (incoming.running === true) {
diff --git a/ui-tui/src/app/interfaces.ts b/ui-tui/src/app/interfaces.ts
index f61f7621cb1..c41cdb3c217 100644
--- a/ui-tui/src/app/interfaces.ts
+++ b/ui-tui/src/app/interfaces.ts
@@ -389,6 +389,8 @@ export interface ComposerActions {
openEditor: () => Promise<void>
prependQueue: (item: QueueItem, destination?: SubmissionDestination) => void
pushHistory: (text: string) => void
+ /** Composer text for queue-edit slot `index` (local items first, then server-queued rows). */
+ queueDraft: (index: number) => string
removeQueue: (index: number) => void
setCompIdx: StateSetter<number>
setComposerTokens: StateSetter<ComposerToken[]>
diff --git a/ui-tui/src/app/pendingBubbles.ts b/ui-tui/src/app/pendingBubbles.ts
new file mode 100644
index 00000000000..25948a9b061
--- /dev/null
+++ b/ui-tui/src/app/pendingBubbles.ts
@@ -0,0 +1,22 @@
+import type { SessionInfo } from '../types.js'
+
+export type PendingRow = NonNullable<SessionInfo['pending_submissions']>[number]
+
+// Inputs whose transcript bubble this client already painted at submit time.
+// A busy-time admission defers its bubble until the authority starts it, so
+// the bubble lands after the in-flight assistant reply instead of inside it.
+const shown = new Set<string>()
+
+export const markBubbleShown = (inputId?: string) => { if (inputId) { shown.add(inputId) } }
+export const resetBubbleLedger = () => shown.clear()
+
+// Rows the authority just moved queued → started whose bubble nobody painted.
+// Only a transition observed by THIS client counts: a resume snapshot's started
+// row already lives in the replayed history.
+export function newlyStartedRows(previous: PendingRow[] | undefined, incoming: PendingRow[] | undefined): PendingRow[] {
+ if (!previous || !incoming) { return [] }
+ const wasQueued = new Set(previous.filter(row => row.status === 'queued').map(row => row.admission_id))
+ return incoming.filter(row => row.status === 'started' && wasQueued.has(row.admission_id) && !(row.input_id && shown.has(row.input_id)))
+}
+
+export const isServerQueued = (row: PendingRow) => row.status === 'queued' || row.status === 'unknown'
diff --git a/ui-tui/src/app/submissionCore.ts b/ui-tui/src/app/submissionCore.ts
index d1e53d3bb76..a0017971fa0 100644
--- a/ui-tui/src/app/submissionCore.ts
+++ b/ui-tui/src/app/submissionCore.ts
@@ -4,6 +4,7 @@ import type { QueueItem } from '../hooks/useQueue.js'
import { pendingInputOwner, savePendingInput } from '../lib/pendingInputs.js'
import type { Msg } from '../types.js'
+import { markBubbleShown } from './pendingBubbles.js'
import { captureDestination, isCurrentDestination, type SubmissionDestination } from './submissionDestination.js'
import { turnController } from './turnController.js'
import { getUiState, patchUiState } from './uiStore.js'
@@ -53,12 +54,16 @@ export function submitPrompt(
deps: SubmitPromptDeps,
showUserMessage = true,
displayOverride?: string,
- opts: { skipDetectDrop?: boolean; destination?: SubmissionDestination; queueItem?: QueueItem } = {}
+ opts: { skipDetectDrop?: boolean; destination?: SubmissionDestination; queueItem?: QueueItem; behindTurn?: boolean } = {}
): void {
const destination = opts.destination ?? captureDestination()
const owner = pendingInputOwner(opts.queueItem?.ownerDestination ?? destination)
const { sid } = owner
const focused = () => isCurrentDestination(owner)
+ // A busy-time admission joins the authority FIFO behind the running turn:
+ // it must not touch the in-flight stream buffer, status or transcript. Its
+ // user bubble is painted when the fanout reports the row started.
+ const ownsTurn = () => focused() && !opts.behindTurn
if (!sid) {
return deps.sys('session not ready yet')
@@ -77,12 +82,12 @@ export function submitPrompt(
}
// Close the async-busy gap up front, before the detect_drop round-trip.
- if (focused()) {
+ if (ownsTurn()) {
markSubmitting()
}
const startSubmit = (displayText: string, submitText: string, show = true) => {
- if (focused()) {
+ if (ownsTurn()) {
turnController.clearStatusTimer()
deps.setLastUserMsg(text)
@@ -99,6 +104,8 @@ export function submitPrompt(
if (item) {
item.preparedText ??= submitText
+ if (opts.behindTurn) { item.queued = true }
+ if (ownsTurn() && show) { markBubbleShown(item.submissionId) }
savePendingInput(item)
}
diff --git a/ui-tui/src/app/useComposerState.ts b/ui-tui/src/app/useComposerState.ts
index 177b72b34a5..16c520f05e6 100644
--- a/ui-tui/src/app/useComposerState.ts
+++ b/ui-tui/src/app/useComposerState.ts
@@ -139,6 +139,7 @@ export function useComposerState({ gw, submitRef, sys }: UseComposerStateOptions
stage,
queueRef,
queueEditRef,
+ queueDraft,
queuedDisplay,
queueEditIdx,
enqueue,
@@ -147,7 +148,7 @@ export function useComposerState({ gw, submitRef, sys }: UseComposerStateOptions
removeQ,
setQueueEdit,
takeQ
- } = useQueue()
+ } = useQueue(gw)
const { historyRef, historyIdx, setHistoryIdx, historyDraftRef, pushHistory } = useInputHistory()
const { completions, compIdx, setCompIdx, compReplace } = useCompletion(input, isBlocked, gw)
@@ -515,6 +516,7 @@ export function useComposerState({ gw, submitRef, sys }: UseComposerStateOptions
openEditor,
prependQueue: prependQ,
pushHistory,
+ queueDraft,
removeQueue: removeQ,
setCompIdx,
setComposerTokens,
@@ -536,6 +538,7 @@ export function useComposerState({ gw, submitRef, sys }: UseComposerStateOptions
openEditor,
prependQ,
pushHistory,
+ queueDraft,
removeQ,
setCompIdx,
setComposerTokens,
diff --git a/ui-tui/src/app/useInputHandlers.ts b/ui-tui/src/app/useInputHandlers.ts
index f9857f6f560..48c9459cf6f 100644
--- a/ui-tui/src/app/useInputHandlers.ts
+++ b/ui-tui/src/app/useInputHandlers.ts
@@ -275,7 +275,7 @@ export function useInputHandlers(ctx: InputHandlerContext): InputHandlerResult {
}
const cycleQueue = (dir: 1 | -1) => {
- const len = cRefs.queueRef.current.length
+ const len = cState.queuedDisplay.length
if (!len) {
return false
@@ -285,7 +285,7 @@ export function useInputHandlers(ctx: InputHandlerContext): InputHandlerResult {
cActions.setQueueEdit(index)
cActions.setHistoryIdx(null)
- cActions.setInput(cRefs.queueRef.current[index]?.display ?? '')
+ cActions.setInput(cActions.queueDraft(index))
return true
}
diff --git a/ui-tui/src/app/useSubmission.ts b/ui-tui/src/app/useSubmission.ts
index 2697d9859d1..73c7d4ae1d6 100644
--- a/ui-tui/src/app/useSubmission.ts
+++ b/ui-tui/src/app/useSubmission.ts
@@ -103,7 +103,7 @@ export function useSubmission(opts: UseSubmissionOptions) {
showUserMessage = true,
displayText?: string,
expandOverride?: (value: string) => string,
- submitOpts: { skipDetectDrop?: boolean; destination?: SubmissionDestination; queueItem?: QueueItem } = {}
+ submitOpts: { skipDetectDrop?: boolean; destination?: SubmissionDestination; queueItem?: QueueItem; behindTurn?: boolean } = {}
) => {
// Read tokens off the ref, not render state: a paste immediately followed
// by Enter submits before React has re-rendered with the new token.
@@ -253,6 +253,14 @@ export function useSubmission(opts: UseSubmissionOptions) {
}
if (mode === 'queue') {
+ // Canonical authority: admit now so the input is crash-durable and in
+ // every viewer's pending list; the server FIFO orders it behind the
+ // running turn. Legacy gateways keep the renderer-side queue.
+ if (gw.isCanonical) {
+ return send(item.text, true, item.display, value => value, {
+ destination, behindTurn: true, queueItem: item.settle ? item : undefined })
+ }
+
return enqueueText()
}
@@ -266,7 +274,7 @@ export function useSubmission(opts: UseSubmissionOptions) {
// and file-drop interpolation exactly once.
send(item.text, true, item.display, value => value, { destination, queueItem: item.settle ? item : undefined })
},
- [composerActions, send]
+ [composerActions, gw, send]
)
const dispatchSubmission = useCallback(
@@ -345,7 +353,7 @@ export function useSubmission(opts: UseSubmissionOptions) {
// 'interrupt' / 'steer' should reach the live turn instead of
// silently going back to the queue. handleBusyInput resolves
// mode-specific behavior (interrupt-and-send, steer, or queue).
- if (getUiState().busyInputMode === 'queue') {
+ if (getUiState().busyInputMode === 'queue' && !gw.isCanonical) {
return composerActions.prependQueue(picked)
}
diff --git a/ui-tui/src/canonicalGateway.ts b/ui-tui/src/canonicalGateway.ts
index b683c836b58..19377b64e2e 100644
--- a/ui-tui/src/canonicalGateway.ts
+++ b/ui-tui/src/canonicalGateway.ts
@@ -44,11 +44,25 @@ export function canonicalResult(method: string, value: any, request: Record<stri
: row) : value.messages
return { ...value, messages, info: { ...value.info, stored_session_id: value.stored_session_id,
execution_epoch: String(value.authority_epoch), execution_generation: value.execution_generation,
- running: value.running } }
+ running: value.running, pending_submissions: pendingSubmissions(value.pending) } }
}
return value
}
+// The authority's durable FIFO rows (`pending` on snapshots and session.info
+// fanout) projected onto the client's receipt shape: one translation, so the
+// queue panel, the receipt matcher and Desktop all read the same list.
+export function pendingSubmissions(pending: unknown) {
+ if (!Array.isArray(pending)) { return undefined }
+ return pending.filter(row => row && typeof row === 'object').map(row => ({
+ ...row, user: row.text, target_profile_home: row.ref?.profile_id, target_session_id: row.ref?.session_id }))
+}
+
+export function canonicalEvent<T extends { type: string; payload?: any }>(event: T): T {
+ const pending = pendingSubmissions(event.payload?.pending)
+ return pending ? { ...event, payload: { ...event.payload, pending_submissions: pending } } : event
+}
+
export function localCreationOptions(env = process.env): Record<string, unknown> {
const fields: Record<string, string | undefined> = {
model: env.HERMES_MODEL, provider: env.HERMES_TUI_PROVIDER, cwd: env.HERMES_CWD,
diff --git a/ui-tui/src/gatewayClient.ts b/ui-tui/src/gatewayClient.ts
index 80d49b4b98b..90579ac5406 100644
--- a/ui-tui/src/gatewayClient.ts
+++ b/ui-tui/src/gatewayClient.ts
@@ -6,7 +6,7 @@ import { promisify } from 'node:util'
import { WebSocket as UndiciWebSocket } from 'undici'
-import { canonicalRequest, canonicalResult, type CreationContract } from './canonicalGateway.js'
+import { canonicalEvent, canonicalRequest, canonicalResult, type CreationContract } from './canonicalGateway.js'
import type { GatewayEvent } from './gatewayTypes.js'
import { CircularBuffer } from './lib/circularBuffer.js'
@@ -670,7 +670,7 @@ export class GatewayClient extends EventEmitter {
if (this.isCanonical && ev.type === 'gateway.ready') { return }
if (this.isCanonical) {
const shared = ev as GatewayEvent & { authority_epoch?: number; execution_generation?: number }
- ev.payload = { ...ev.payload, execution_epoch: String(shared.authority_epoch),
+ ev.payload = { ...canonicalEvent(ev).payload, execution_epoch: String(shared.authority_epoch),
execution_generation: shared.execution_generation } as any
}
this.publish(ev)
diff --git a/ui-tui/src/hooks/useQueue.ts b/ui-tui/src/hooks/useQueue.ts
index 04ddfe65611..273caaa5998 100644
--- a/ui-tui/src/hooks/useQueue.ts
+++ b/ui-tui/src/hooks/useQueue.ts
@@ -3,6 +3,7 @@ import { randomUUID } from 'node:crypto'
import { useStore } from '@nanostores/react'
import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
+import { isServerQueued } from '../app/pendingBubbles.js'
import { captureDestination, type SubmissionDestination } from '../app/submissionDestination.js'
import { $uiState, getUiState } from '../app/uiStore.js'
import {
@@ -70,7 +71,10 @@ interface PendingQueue {
items: QueueItem[]
}
-export function useQueue() {
+// `gw` owns server-queued rows: the authority's pending fanout is rendered
+// after this client's unconfirmed local items, and deleting/editing one goes
+// through `prompt.cancel` — the next fanout, not a local splice, retires it.
+export function useQueue(gw?: { request: (method: string, params: Record<string, unknown>) => Promise<unknown> }) {
const ui = useStore($uiState)
const queues = useRef(new Map<string, PendingQueue>())
const unbound = useRef<PendingQueue>({ edit: null, items: [] })
@@ -175,11 +179,36 @@ export function useQueue() {
[getQueue]
)
+ const serverRows = (ui.info?.pending_submissions ?? []).filter(isServerQueued)
+
const queuedDisplay = [
...queueRef.current.map(item => `${item.failed ? '[unconfirmed · Alt+K retry] ' : ''}${item.display}`),
- ...(ui.info?.pending_submissions ?? []).map(item => `[${item.status} · ${item.admission_id}] ${item.user}`)
+ ...serverRows.map(row => `[${row.status}] ${row.user}`)
]
+ // Indexes past the local items address server rows (read live, not from
+ // render state: key handlers run between renders).
+ const serverRowAt = useCallback(
+ (index: number) => {
+ const local = queueRef.current.length
+
+ return index >= local ? (getUiState().info?.pending_submissions ?? []).filter(isServerQueued)[index - local] : undefined
+ },
+ [queueRef]
+ )
+
+ const queueDraft = useCallback(
+ (index: number) => serverRowAt(index)?.user ?? queueRef.current[index]?.display ?? '',
+ [queueRef, serverRowAt]
+ )
+
+ const cancelServerRow = useCallback(
+ (row: { admission_id: string }) => {
+ void gw?.request('prompt.cancel', { session_id: getUiState().sid, admission_id: row.admission_id }).catch(() => {})
+ },
+ [gw]
+ )
+
const queueEditIdx = queueEditRef.current
const syncQueue = useCallback(() => refresh(version => version + 1), [])
@@ -277,7 +306,7 @@ export function useQueue() {
for (const receipt of getUiState().info?.pending_submissions ?? []) {
const item = queue.items.find(
item =>
- item.submissionId === receipt.admission_id &&
+ item.submissionId === (receipt.input_id ?? receipt.admission_id) &&
Boolean(item.destination?.storedSid) &&
item.destination?.storedSid === receipt.target_session_id &&
item.destination?.profileHome === receipt.target_profile_home
@@ -324,6 +353,17 @@ export function useQueue() {
const takeQ = useCallback(
(i: number, editedDisplay?: string) => {
const queue = getQueue()
+ const server = serverRowAt(i)
+
+ // Editing a durable row re-admits the edited text as a new input; the
+ // authority retires the original.
+ if (server) {
+ cancelServerRow(server)
+ const item = queueItem(editedDisplay ?? server.user)
+ queue.items.push(item)
+
+ return claim(queue, item)
+ }
if (queue.items[i]?.inFlight) {
return undefined
@@ -344,11 +384,17 @@ export function useQueue() {
return claim(queue, item)
},
- [getQueue, claim]
+ [getQueue, claim, cancelServerRow, serverRowAt]
)
const removeQ = useCallback(
(i: number) => {
+ const server = serverRowAt(i)
+
+ if (server) {
+ return cancelServerRow(server)
+ }
+
if (queueRef.current[i]?.inFlight) {
return
}
@@ -362,7 +408,7 @@ export function useQueue() {
removeAtInPlace(queueRef.current, i)
syncQueue()
},
- [queueRef, syncQueue]
+ [queueRef, syncQueue, cancelServerRow, serverRowAt]
)
return {
@@ -370,6 +416,7 @@ export function useQueue() {
stage,
enqueue,
prependQ,
+ queueDraft,
queueEditIdx,
queueEditRef,
queueRef,
diff --git a/ui-tui/src/types.ts b/ui-tui/src/types.ts
index 9a300641b45..e7860d16c6f 100644
--- a/ui-tui/src/types.ts
+++ b/ui-tui/src/types.ts
@@ -202,6 +202,7 @@ export interface SessionInfo {
reasoning_effort?: string
pending_submissions?: Array<{
admission_id: string
+ input_id?: string
target_session_id: string
target_profile_home: string
status: string