Skip to content

The agent that grows with you

fix(desktop): a prompt the gateway admitted is never reported failed when the journal can't retire it

Teknium3d2b4aca4315
diff --git a/apps/desktop/src/app/session/hooks/use-prompt-actions/index.test.tsx b/apps/desktop/src/app/session/hooks/use-prompt-actions/index.test.tsx
index 0883a4b26e7..dbfa031e5e9 100644
--- a/apps/desktop/src/app/session/hooks/use-prompt-actions/index.test.tsx
+++ b/apps/desktop/src/app/session/hooks/use-prompt-actions/index.test.tsx
@@ -109,6 +109,43 @@ describe('durable submit acknowledgement', () => {
}
})
+ it('a journal retirement that fails after admission still reports the delivered prompt and never reuses its identity', async () => {
+ const entries = new Map<string, string>()
+ const previous = window.hermesDesktop
+ // The private-file journal accepts the preparation write, then the disk fills before retirement.
+ window.hermesDesktop = { ...previous, preparedSubmissions: {
+ read: async () => JSON.stringify(Object.fromEntries([...entries].map(([key, entry]) => [key, JSON.parse(entry)]))),
+ update: async (key, entry) => {
+ if (entry === null) {throw Object.assign(new Error('ENOSPC: no space left on device'), { code: 'ENOSPC' })}
+ entries.set(key, entry)
+ }
+ } }
+ const ids: unknown[] = []
+
+ const requestGateway = vi.fn(async (method: string, params?: Record<string, unknown>) => {
+ if (method !== 'prompt.submit') {return {} as never}
+ ids.push(params?.submission_id)
+
+ return { admission_id: params?.submission_id, status: 'started' } as never
+ })
+
+ try {
+ let handle: HarnessHandle | null = null
+ await actRender(<Harness onReady={h => (handle = h)} rawAdmissionReceipts refreshSessions={async () => undefined} requestGateway={requestGateway} />)
+ const accepted = vi.fn()
+ expect(await handle!.submitText('delivered once', { onAccepted: accepted })).toBe(true)
+ expect(accepted).toHaveBeenCalledTimes(1)
+ expect(handle!.state().messages.some(message => message.error)).toBe(false)
+ // A later identical send is a new turn, never deduplicated into the spent admission.
+ handle!.handleEvent({ type: 'message.complete', session_id: RUNTIME_SESSION_ID, payload: { text: 'done' } } as never)
+ expect(await handle!.submitText('delivered once')).toBe(true)
+ expect(ids).toHaveLength(2)
+ expect(ids[1]).not.toBe(ids[0])
+ } finally {
+ window.hermesDesktop = previous
+ }
+ })
+
it('retains a failed slash kickoff and forwards queued admission intent on retry', async () => {
$sessions.set([])
$connection.set(null)
diff --git a/apps/desktop/src/app/session/hooks/use-prompt-actions/prepared-submissions.ts b/apps/desktop/src/app/session/hooks/use-prompt-actions/prepared-submissions.ts
index c5e802c57df..a939485fc27 100644
--- a/apps/desktop/src/app/session/hooks/use-prompt-actions/prepared-submissions.ts
+++ b/apps/desktop/src/app/session/hooks/use-prompt-actions/prepared-submissions.ts
@@ -16,6 +16,11 @@ export interface PreparedSubmission {
legacyAttempted?: boolean
}
+// Admitted entries whose durable removal failed (ENOSPC/EIO). Their identity is spent: this
+// window never adopts, lists or slots them again, so a later send is never deduplicated
+// into an earlier admission. The entry's Web Lock stays held until the removal lands.
+const retired = new Set<string>()
+
// A journal, not an automatic outbox. Only an explicit retry may reuse an
// uncertain admission. Read storage each time so a remount cannot lose it.
async function readJournal(): Promise<Record<string, PreparedSubmission>> {
@@ -29,6 +34,8 @@ async function readJournal(): Promise<Record<string, PreparedSubmission>> {
throw new Error('Invalid prepared submission journal')
}
+ for (const key of retired) {delete (parsed as Record<string, PreparedSubmission>)[key]}
+
return parsed as Record<string, PreparedSubmission>
}
@@ -133,6 +140,7 @@ export async function writePreparedSubmission(key: string, entry: PreparedSubmis
if (native) {
await native.update(key, JSON.stringify(entry))
+ retired.delete(key)
return
}
@@ -142,10 +150,14 @@ export async function writePreparedSubmission(key: string, entry: PreparedSubmis
// Browser-only clients retain reload recovery, not a process-crash guarantee.
// Native write failures never fall back here: sending requires their ACK.
window.localStorage.setItem(STORAGE_KEY, JSON.stringify(journal))
+ retired.delete(key)
}
+/** Retire an admitted entry. Its identity is spent before the durable write is attempted, so a
+ * failed removal can only leave a stale file entry, never a reusable one. */
export async function removePreparedSubmission(key: string): Promise<void> {
const native = window.hermesDesktop?.preparedSubmissions
+ retired.add(key)
if (native) {
await native.update(key, null)
@@ -155,6 +167,7 @@ export async function removePreparedSubmission(key: string): Promise<void> {
window.localStorage.setItem(STORAGE_KEY, JSON.stringify(journal))
}
+ retired.delete(key)
owned.get(key)?.()
owned.delete(key)
}
diff --git a/apps/desktop/src/app/session/hooks/use-prompt-actions/submit.ts b/apps/desktop/src/app/session/hooks/use-prompt-actions/submit.ts
index 15ad4a8517b..4a046af3c4f 100644
--- a/apps/desktop/src/app/session/hooks/use-prompt-actions/submit.ts
+++ b/apps/desktop/src/app/session/hooks/use-prompt-actions/submit.ts
@@ -1264,7 +1264,9 @@ export function useSubmitPrompt(deps: SubmitPromptDeps) {
throw submitErr
}
- await removePreparedSubmission(retryKey)
+ // The gateway admitted it: a failed journal retirement (ENOSPC/EIO) must not report a
+ // delivered prompt as failed and invite a resend. The identity is retired in memory.
+ await removePreparedSubmission(retryKey).catch(error => console.warn('[prepared-submission-retire]', error))
// The prompt is now accepted. Report the EXACT identity it landed on
// (recovered id included) so a caller that must prove delivery — the