Skip to content

The agent that grows with you

fix(quick-entry): reconcile a late relay outcome in the capture window

LeonardoLGDS692126b80d89
diff --git a/apps/desktop/electron/preload.ts b/apps/desktop/electron/preload.ts
index 45f59999866..a15713b3ff7 100644
--- a/apps/desktop/electron/preload.ts
+++ b/apps/desktop/electron/preload.ts
@@ -258,6 +258,15 @@ contextBridge.exposeInMainWorld('hermesDesktop', {
ipcRenderer.on('hermes:quick-entry:shown', listener)
return () => ipcRenderer.removeListener('hermes:quick-entry:shown', listener)
+ },
+ // Main → quick window: the outcome of a submit whose relay already timed
+ // out. Delivery is now KNOWN — reconcile the unknown state instead of
+ // leaving the user to resend a prompt that may already be delivered.
+ onLateResult: callback => {
+ const listener = (_event, payload) => callback(payload)
+ ipcRenderer.on('hermes:quick-entry:late-result', listener)
+
+ return () => ipcRenderer.removeListener('hermes:quick-entry:late-result', listener)
}
},
getBootProgress: () => ipcRenderer.invoke('hermes:boot-progress:get'),
diff --git a/apps/desktop/src/app/quick-entry/quick-entry-app.tsx b/apps/desktop/src/app/quick-entry/quick-entry-app.tsx
index dc563558b02..34a16cd5467 100644
--- a/apps/desktop/src/app/quick-entry/quick-entry-app.tsx
+++ b/apps/desktop/src/app/quick-entry/quick-entry-app.tsx
@@ -80,11 +80,20 @@ export function QuickEntryApp() {
})
})
+ const offLateResult = api?.onLateResult(payload => {
+ dispatch({
+ message: payload?.result?.message ?? 'Hermes could not deliver the prompt.',
+ ok: payload?.result?.ok === true,
+ type: 'late-result'
+ })
+ })
+
inputRef.current?.focus()
return () => {
offShown?.()
offState?.()
+ offLateResult?.()
}
}, [])
diff --git a/apps/desktop/src/global.d.ts b/apps/desktop/src/global.d.ts
index ee0bc3ae14a..dda32a9d1b0 100644
--- a/apps/desktop/src/global.d.ts
+++ b/apps/desktop/src/global.d.ts
@@ -206,6 +206,11 @@ declare global {
// Quick window subscribes to "you were just summoned" so it can reset
// its draft and re-focus the input on every open.
onShown: (callback: () => void) => () => void
+ // Quick window subscribes to the outcome of a submit whose relay timed
+ // out (delivery is unknown until this arrives).
+ onLateResult: (
+ callback: (payload: { correlationId: string; result: QuickEntrySubmitResult }) => void
+ ) => () => void
}
getBootProgress: () => Promise<DesktopBootProgress>
getConnectionConfig: (profile?: null | string) => Promise<DesktopConnectionConfig>
diff --git a/apps/desktop/src/store/quick-entry.test.ts b/apps/desktop/src/store/quick-entry.test.ts
index a50fbc55ea9..32615ade9c0 100644
--- a/apps/desktop/src/store/quick-entry.test.ts
+++ b/apps/desktop/src/store/quick-entry.test.ts
@@ -336,6 +336,47 @@ describe('quickComposerReducer', () => {
expect(retried.state.unknownSubmitId).toBe(7)
})
+ it('a late success clears an unknown outcome', () => {
+ const { state } = run([
+ connect,
+ { draft: 'pending prompt', type: 'edit' },
+ { submitId: 7, type: 'submit' },
+ { message: 'may still be delivered', submitId: 7, type: 'submit-unknown' },
+ { message: 'accepted', ok: true, type: 'late-result' }
+ ])
+
+ expect(state.draft).toBe('')
+ expect(state.visible).toBe(false)
+ expect(state.unknownSubmitId).toBeNull()
+ expect(state.error).toBeNull()
+ })
+
+ it('a late failure proves non-acceptance and keeps the text', () => {
+ const { state } = run([
+ connect,
+ { draft: 'pending prompt', type: 'edit' },
+ { submitId: 7, type: 'submit' },
+ { message: 'may still be delivered', submitId: 7, type: 'submit-unknown' },
+ { message: 'gateway down', ok: false, type: 'late-result' }
+ ])
+
+ expect(state.unknownSubmitId).toBeNull()
+ expect(state.error).toBe('gateway down')
+ expect(state.draft).toBe('pending prompt')
+ expect(state.visible).toBe(true)
+ })
+
+ it('a late result without an unknown submit changes nothing', () => {
+ const { state } = run([
+ connect,
+ { draft: 'fresh draft', type: 'edit' },
+ { message: 'accepted', ok: true, type: 'late-result' }
+ ])
+
+ expect(state.draft).toBe('fresh draft')
+ expect(state.visible).toBe(true)
+ })
+
it('a late success reconciles the unknown outcome', () => {
const unknown = run([
connect,
diff --git a/apps/desktop/src/store/quick-entry.ts b/apps/desktop/src/store/quick-entry.ts
index c9ebf0d05bb..cae2ef4c1ce 100644
--- a/apps/desktop/src/store/quick-entry.ts
+++ b/apps/desktop/src/store/quick-entry.ts
@@ -181,6 +181,7 @@ export type QuickComposerEvent =
| { type: 'submit'; submitId?: number }
| { type: 'submit-error'; message: string; submitId: number }
| { message: string; submitId: number; type: 'submit-unknown' }
+ | { message: string; ok: boolean; type: 'late-result' }
| { type: 'submit-ok'; submitId: number }
| { type: 'target'; target: string }
@@ -386,6 +387,38 @@ export function quickComposerReducer(state: QuickComposerState, event: QuickComp
}
}
+ case 'late-result': {
+ // A late outcome only reconciles a submit the window still holds as
+ // UNKNOWN. Without one it must not clobber a fresh draft.
+ if (state.unknownSubmitId === null) {
+ return { send: null, state }
+ }
+
+ return event.ok
+ ? {
+ send: null,
+ state: {
+ ...state,
+ draft: '',
+ error: null,
+ lastSubmitText: '',
+ orphanedFailure: null,
+ unknownSubmitId: null,
+ visible: false
+ }
+ }
+ : {
+ send: null,
+ state: {
+ ...state,
+ error: event.message,
+ lastSubmitText: '',
+ unknownSubmitId: null,
+ visible: true
+ }
+ }
+ }
+
case 'submit-error': {
if (event.submitId > 0 && state.pendingSubmitId === event.submitId) {
return {