Skip to content

The agent that grows with you

fix(tui): /queue keeps the composer text until the journal write succeeds

Tekniume5bbfcb220a0
diff --git a/ui-tui/src/__tests__/slashAttachmentRenderer.test.tsx b/ui-tui/src/__tests__/slashAttachmentRenderer.test.tsx
index d8fb8ceb3a4..a3554d0d1d9 100644
--- a/ui-tui/src/__tests__/slashAttachmentRenderer.test.tsx
+++ b/ui-tui/src/__tests__/slashAttachmentRenderer.test.tsx
@@ -240,6 +240,24 @@ it('keeps the caption and its image token in the composer when the pending-input
} finally { chmodSync(journal, 0o700); h.close() }
})
+it('keeps `/queue` text in the composer until the pending-input journal holds it', async () => {
+ const h = mount(true)
+ const journal = join(h.home, 'tui-pending-inputs')
+ mkdirSync(journal, { recursive: true })
+
+ try {
+ chmodSync(journal, 0o500)
+ await h.submit('/queue later please')
+ expect(h.composer.state.input).toBe('/queue later please')
+ expect(h.composer.refs.queueRef.current).toEqual([])
+ expect(getUiState().status).toBe('input not saved')
+ chmodSync(journal, 0o700)
+ await h.submit('/queue later please')
+ expect(h.composer.state.input).toBe('')
+ expect(h.composer.refs.queueRef.current.map(item => item.text)).toEqual(['later please'])
+ } finally { chmodSync(journal, 0o700); h.close() }
+})
+
it('a failed attempt write leaves the queue head claimable instead of wedged in flight', async () => {
const h = mount(true)
const journal = join(h.home, 'tui-pending-inputs')
diff --git a/ui-tui/src/app/useSubmission.ts b/ui-tui/src/app/useSubmission.ts
index ec7bab9f16f..c6a33f74782 100644
--- a/ui-tui/src/app/useSubmission.ts
+++ b/ui-tui/src/app/useSubmission.ts
@@ -331,6 +331,23 @@ export function useSubmission(opts: UseSubmissionOptions) {
const submission = prepareSubmission(full, submissionTokens)
const toHistory = submission.text
+ // The composer is the only copy of a draft until the pending-input
+ // journal holds it, so it is cleared after that first durable write and
+ // kept — text and image tokens — when the write fails.
+ const journaled = <T,>(write: () => T): { value: T } | undefined => {
+ try {
+ const value = write()
+ composerActions.clearIn()
+
+ return { value }
+ } catch (error) {
+ sys(`input not saved: ${(error as Error).message} — draft kept`)
+ patchUiState({ status: 'input not saved' })
+
+ return undefined
+ }
+ }
+
if (looksLikeSlashCommand(full)) {
const slash = prepareSlashSubmission(full, submissionTokens)
@@ -342,17 +359,20 @@ export function useSubmission(opts: UseSubmissionOptions) {
const queued =
parsed.name === 'queue' || parsed.name === 'q' ? queueItemFromSlash(slash.display, slash.command) : undefined
- // Attachment commands capture the cleared composer's revision.
- composerActions.clearIn()
-
if (queued) {
// Handled here, before the slash handler, so it is counted here.
reportSlashCommand(gw, parsed.name, getUiState().sid)
- const retained = composerActions.enqueue(queued.text, queued.display, destination)
- if (retained) { retained.attachments = submission.attachments; savePendingInput(retained) }
- sys(`queued: "${queued.display.slice(0, 50)}${queued.display.length > 50 ? '…' : ''}"`)
+ const saved = journaled(() => {
+ const retained = composerActions.enqueue(queued.text, queued.display, destination)
+
+ if (retained) { retained.attachments = submission.attachments; savePendingInput(retained) }
+ })
+
+ if (saved) { sys(`queued: "${queued.display.slice(0, 50)}${queued.display.length > 50 ? '…' : ''}"`) }
} else {
+ // Attachment commands capture the cleared composer's revision.
+ composerActions.clearIn()
// Image tokens are labels in the command; the descriptors and their
// expander ride along so a skill/alias send still carries the image.
slashRef.current(slash.command, { attachments: submission.attachments, expand: expandTokens(submissionTokens) })
@@ -375,23 +395,6 @@ export function useSubmission(opts: UseSubmissionOptions) {
// in that window must not be refused.
const unbound = !live.sid || live.gatewayConnected === false
- // The composer is the only copy of a draft until the pending-input
- // journal holds it, so it is cleared after that first durable write and
- // kept — text and image tokens — when the write fails.
- const journaled = <T,>(write: () => T): { value: T } | undefined => {
- try {
- const value = write()
- composerActions.clearIn()
-
- return { value }
- } catch (error) {
- sys(`input not saved: ${(error as Error).message} — draft kept`)
- patchUiState({ status: 'input not saved' })
-
- return undefined
- }
- }
-
if (unbound) {
composerActions.pushHistory(toHistory)
journaled(() => {