Skip to content

The agent that grows with you

fix(webapp): each prepared-submission journal entry lives under its own storage key

Adolanium0733c281d6c7
diff --git a/apps/desktop/src/app/session/hooks/use-prompt-actions/index.sleep-wake.test.tsx b/apps/desktop/src/app/session/hooks/use-prompt-actions/index.sleep-wake.test.tsx
index cae41ab9d90..59dbafc15bd 100644
--- a/apps/desktop/src/app/session/hooks/use-prompt-actions/index.sleep-wake.test.tsx
+++ b/apps/desktop/src/app/session/hooks/use-prompt-actions/index.sleep-wake.test.tsx
@@ -8,6 +8,7 @@ import { textPart } from '@/lib/chat-messages'
import { $busy, $messages, $turnStartedAt, setMessages, setSessions } from '@/store/session'
import { actRender, Harness, type HarnessHandle, RUNTIME_SESSION_ID, sessionInfo } from './index-test-utils'
+import { clearStoredJournal } from './prepared-submissions-test-utils'
import { clearSingleFlightSessionResumeState } from './single-flight-resume'
// Suites in this file reuse the same stored-id constants. The module-level
@@ -15,7 +16,7 @@ import { clearSingleFlightSessionResumeState } from './single-flight-resume'
// never-settling in-flight promise from one test into the next.
beforeEach(() => {
clearSingleFlightSessionResumeState()
- window.localStorage.removeItem('hermes.desktop.preparedSubmissions.v1')
+ clearStoredJournal()
// Queue mutations build on the persisted map, not the atom — a queue an
// earlier test left in storage would otherwise sit ahead of this test's send.
window.localStorage.removeItem('hermes.desktop.composerQueue.v1')
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 58e55030794..9f6c2221de3 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
@@ -41,7 +41,7 @@ import { SESSION_COMPRESS_TIMEOUT_MS } from './slash'
// never-settling in-flight promise from one test into the next.
beforeEach(() => {
clearSingleFlightSessionResumeState()
- window.localStorage.removeItem('hermes.desktop.preparedSubmissions.v1')
+ Object.keys(window.localStorage).filter(key => key.startsWith('hermes.desktop.preparedSubmissions.v2:')).forEach(key => window.localStorage.removeItem(key))
// Queue mutations build on the persisted map, not the atom — a queue an
// earlier test left in storage would otherwise sit ahead of this test's send.
window.localStorage.removeItem('hermes.desktop.composerQueue.v1')
@@ -322,7 +322,7 @@ describe('terminal receipt settlement', () => {
try {
expect(await handle!.submitText('next input', { fromQueue: true })).toBe(true)
expect(handle!.state()).toMatchObject({ busy: true, awaitingResponse: true, streamId: 'owner-stream', turnLive: true })
- expect(JSON.parse(window.localStorage.getItem('hermes.desktop.preparedSubmissions.v1')!)).toEqual({})
+ expect(Object.keys(window.localStorage).filter(key => key.startsWith('hermes.desktop.preparedSubmissions.v2:'))).toEqual([])
} finally { $connection.set(null) }
})
diff --git a/apps/desktop/src/app/session/hooks/use-prompt-actions/prepared-submissions-spent.test.ts b/apps/desktop/src/app/session/hooks/use-prompt-actions/prepared-submissions-spent.test.ts
index 8da92d437f5..9d3240a5318 100644
--- a/apps/desktop/src/app/session/hooks/use-prompt-actions/prepared-submissions-spent.test.ts
+++ b/apps/desktop/src/app/session/hooks/use-prompt-actions/prepared-submissions-spent.test.ts
@@ -1,5 +1,7 @@
import { afterEach, expect, test, vi } from 'vitest'
+import { storageView } from './prepared-submissions-test-utils'
+
afterEach(() => { vi.unstubAllGlobals(); vi.resetModules(); localStorage.clear() })
// The native file journal of one origin, shared by every renderer load. Removal fails like
@@ -46,26 +48,6 @@ test('an admitted identity whose journal removal failed stays spent across a rel
expect(journal.file()[intent]).toBeUndefined()
})
-// Chromium gives each renderer its own cached copy of the origin's localStorage and propagates
-// writes asynchronously, last writer wins per key: each window writes against its own view.
-function storageView(shared: Map<string, string>) {
- const local = new Map(shared)
- const written = new Map<string, null | string>()
-
- const storage = {
- get length() { return local.size },
- key: (index: number) => [...local.keys()][index] ?? null,
- getItem: (key: string) => local.get(key) ?? null,
- setItem: (key: string, value: string) => { local.set(key, value); written.set(key, value) },
- removeItem: (key: string) => { local.delete(key); written.set(key, null) },
- clear: () => undefined
- }
-
- const flush = () => { for (const [key, value] of written) { if (value === null) { shared.delete(key) } else { shared.set(key, value) } } }
-
- return { storage, flush }
-}
-
test('two windows retiring different admitted entries keep both tombstones across a reload', async () => {
const realStorage = window.localStorage
const inWindow = (storage: Storage) => Object.defineProperty(window, 'localStorage', { configurable: true, value: storage })
diff --git a/apps/desktop/src/app/session/hooks/use-prompt-actions/prepared-submissions-tabs.test.ts b/apps/desktop/src/app/session/hooks/use-prompt-actions/prepared-submissions-tabs.test.ts
new file mode 100644
index 00000000000..e1f7fbe1897
--- /dev/null
+++ b/apps/desktop/src/app/session/hooks/use-prompt-actions/prepared-submissions-tabs.test.ts
@@ -0,0 +1,114 @@
+import { afterEach, expect, test, vi } from 'vitest'
+
+import { type PreparedSubmission, preparedSubmissionKey } from './prepared-submissions'
+import type * as PreparedSubmissions from './prepared-submissions'
+import { storageView } from './prepared-submissions-test-utils'
+import type { SubmissionDestination } from './submission-destination'
+
+type Journal = typeof PreparedSubmissions
+
+const realStorage = window.localStorage
+const installStorage = (storage: Storage) => Object.defineProperty(window, 'localStorage', { configurable: true, value: storage })
+
+afterEach(() => { installStorage(realStorage); vi.resetModules(); localStorage.clear() })
+
+// The single blob an earlier build kept every browser journal entry in.
+const LEGACY_KEY = 'hermes.desktop.preparedSubmissions.v1'
+const owner = { connectionId: 'local', profile: 'default' }
+const destination = { scopeKey: 'webapp::default' } as SubmissionDestination
+const intent = (text: string) => preparedSubmissionKey('stored', destination, text, [])
+const entry = (id: string, text: string): PreparedSubmission => ({ id, text, attachments: [], params: { submission_id: id }, owner })
+const legacySend = (text: string) => ({ key: intent(text), entry: entry(`${text} id`, text) })
+
+// One browser tab: its own module instance over its own view of the origin's storage, which the
+// other tabs see only once `flush` publishes its writes.
+async function openTab(shared: Map<string, string>) {
+ vi.resetModules()
+ const journal: Journal = await import('./prepared-submissions')
+ const view = storageView(shared)
+
+ const run = <T>(step: (tab: Journal) => Promise<T>) => {
+ installStorage(view.storage as unknown as Storage)
+
+ return step(journal)
+ }
+
+ return { run, flush: view.flush }
+}
+
+// An explicit retry of a retained send: adopt it, journal it again, retire it once acknowledged.
+async function retry(journal: Journal, send: ReturnType<typeof legacySend>, acknowledged: boolean) {
+ const adopted = await journal.adoptPreparedSubmission(send.key, send.entry.id)
+ await journal.writePreparedSubmission(adopted!.key, adopted!.entry)
+
+ if (acknowledged) { await journal.removePreparedSubmission(adopted!.key, adopted!.entry.id) }
+}
+
+test('a tab acting on a stale read of the journal keeps the entry another tab just wrote', async () => {
+ const shared = new Map<string, string>()
+ const read = async (key: string) => (await openTab(shared)).run(journal => journal.readPreparedSubmission(key))
+ // Tab A read the journal before B's write reached it.
+ const a = await openTab(shared)
+ const b = await openTab(shared)
+ await b.run(journal => journal.writePreparedSubmission(intent('from B'), entry('b', 'from B')))
+ b.flush()
+
+ await a.run(journal => journal.writePreparedSubmission(intent('from A'), entry('a', 'from A')))
+ a.flush()
+ expect(await read(intent('from B'))).toEqual(entry('b', 'from B'))
+ expect(await read(intent('from A'))).toEqual(entry('a', 'from A'))
+
+ // A's send is acknowledged: retiring it from the same stale view leaves B's entry alone.
+ await a.run(journal => journal.removePreparedSubmission(intent('from A'), 'a'))
+ a.flush()
+ expect(await read(intent('from B'))).toEqual(entry('b', 'from B'))
+ expect(await read(intent('from A'))).toBeUndefined()
+})
+
+test('an entry an earlier build left in the blob is still offered and adopted, and stays retired once acknowledged', async () => {
+ const image = { id: '/cache/a.png', occurrenceId: 'image-occurrence', kind: 'image', label: 'a.png' } as const
+ const key = preparedSubmissionKey('stored', destination, 'caption', [image])
+ const legacy = { ...entry('legacy', 'caption'), attachments: [image] }
+ localStorage.setItem(LEGACY_KEY, JSON.stringify({ [key]: legacy }))
+ const journal: Journal = await import('./prepared-submissions')
+
+ expect(await journal.listPreparedImageDrafts('stored', destination.scopeKey)).toMatchObject([{ key, id: 'legacy' }])
+ await retry(journal, { key, entry: legacy }, true)
+
+ vi.resetModules()
+ const reloaded: Journal = await import('./prepared-submissions')
+ expect(await reloaded.listPreparedImageDrafts('stored', destination.scopeKey)).toEqual([])
+ expect(await reloaded.adoptPreparedSubmission(key, 'legacy')).toBeUndefined()
+})
+
+test('two tabs upgrading at once: each legacy entry they retire stays retired, every other stays adoptable', async () => {
+ const [untouched, ackedInA, ackedInB, unconfirmedInB] = ['untouched', 'acked in A', 'acked in B', 'unconfirmed in B'].map(legacySend)
+ const legacy = Object.fromEntries([untouched, ackedInA, ackedInB, unconfirmedInB].map(send => [send.key, send.entry]))
+ const shared = new Map([[LEGACY_KEY, JSON.stringify(legacy)]])
+ // Both tabs load the new build over the same blob; neither sees the other's writes until it flushes.
+ const a = await openTab(shared)
+ const b = await openTab(shared)
+ await a.run(journal => retry(journal, ackedInA, true))
+ await b.run(async journal => { await retry(journal, ackedInB, true); await retry(journal, unconfirmedInB, false) })
+ a.flush()
+ b.flush()
+
+ const reloaded = await openTab(shared)
+ const adopt = (send: ReturnType<typeof legacySend>) => reloaded.run(journal => journal.adoptPreparedSubmission(send.key, send.entry.id))
+ expect(await adopt(ackedInA)).toBeUndefined()
+ expect(await adopt(ackedInB)).toBeUndefined()
+ expect(await adopt(untouched)).toEqual(untouched)
+ expect(await adopt(unconfirmedInB)).toEqual(unconfirmedInB)
+})
+
+test('a tab of the earlier build still open keeps a newer entry it writes under a retired legacy key adoptable', async () => {
+ const key = intent('same words')
+ localStorage.setItem(LEGACY_KEY, JSON.stringify({ [key]: entry('first', 'same words') }))
+ const journal: Journal = await import('./prepared-submissions')
+ await journal.removePreparedSubmission(key, 'first')
+ expect(await journal.adoptPreparedSubmission(key, 'first')).toBeUndefined()
+
+ // The earlier build retires 'first' in its blob too, then journals a new send of the same words.
+ localStorage.setItem(LEGACY_KEY, JSON.stringify({ [key]: entry('second', 'same words') }))
+ expect(await journal.adoptPreparedSubmission(key, 'second')).toEqual({ key, entry: entry('second', 'same words') })
+})
diff --git a/apps/desktop/src/app/session/hooks/use-prompt-actions/prepared-submissions-test-utils.ts b/apps/desktop/src/app/session/hooks/use-prompt-actions/prepared-submissions-test-utils.ts
new file mode 100644
index 00000000000..72ceef249d1
--- /dev/null
+++ b/apps/desktop/src/app/session/hooks/use-prompt-actions/prepared-submissions-test-utils.ts
@@ -0,0 +1,44 @@
+import type { PreparedSubmission } from './prepared-submissions'
+
+// The browser journal as localStorage holds it: one key per entry.
+const ENTRY_PREFIX = 'hermes.desktop.preparedSubmissions.v2:'
+
+const storedKeys = () => Array.from({ length: window.localStorage.length }, (_, index) => window.localStorage.key(index)!)
+
+const removeStoredKeys = (remove: (key: string) => boolean) => {
+ for (const key of storedKeys().filter(remove)) { window.localStorage.removeItem(key) }
+}
+
+/** The browser journal's entries, by journal key. */
+export function storedJournal(): Record<string, PreparedSubmission> {
+ return Object.fromEntries(storedKeys()
+ .filter(key => key.startsWith(ENTRY_PREFIX))
+ .map(key => [key.slice(ENTRY_PREFIX.length), JSON.parse(window.localStorage.getItem(key)!)]))
+}
+
+export const clearStoredJournal = () => removeStoredKeys(key => key.startsWith(ENTRY_PREFIX))
+
+export const clearAllButStoredJournal = () => removeStoredKeys(key => !key.startsWith(ENTRY_PREFIX))
+
+// Chromium gives each renderer its own cached copy of the origin's localStorage and propagates
+// writes asynchronously, last writer wins per key: each window writes against its own view.
+export function storageView(shared: Map<string, string>) {
+ const local = new Map(shared)
+ const written = new Map<string, null | string>()
+
+ const storage = {
+ get length() { return local.size },
+ key: (index: number) => [...local.keys()][index] ?? null,
+ getItem: (key: string) => local.get(key) ?? null,
+ setItem: (key: string, value: string) => { local.set(key, value); written.set(key, value) },
+ removeItem: (key: string) => { local.delete(key); written.set(key, null) },
+ clear: () => undefined
+ }
+
+ const flush = () => {
+ for (const [key, value] of written) { if (value === null) { shared.delete(key) } else { shared.set(key, value) } }
+ written.clear()
+ }
+
+ return { storage, flush }
+}
diff --git a/apps/desktop/src/app/session/hooks/use-prompt-actions/prepared-submissions.test.ts b/apps/desktop/src/app/session/hooks/use-prompt-actions/prepared-submissions.test.ts
index 3f787991de9..69ddea5838d 100644
--- a/apps/desktop/src/app/session/hooks/use-prompt-actions/prepared-submissions.test.ts
+++ b/apps/desktop/src/app/session/hooks/use-prompt-actions/prepared-submissions.test.ts
@@ -1,6 +1,7 @@
import { afterEach, expect, test, vi } from 'vitest'
import { listPreparedImageDrafts, type PreparedSubmission, preparedSubmissionKey, readPreparedSubmission, removePreparedSubmission, writePreparedSubmission } from './prepared-submissions'
+import { storedJournal } from './prepared-submissions-test-utils'
import type { SubmissionDestination } from './submission-destination'
afterEach(() => { vi.unstubAllGlobals(); localStorage.clear() })
@@ -16,10 +17,10 @@ test('image recovery never offers expanded slash intent as an ordinary draft and
await writePreparedSubmission(key, { id: key, text, attachments, params: { submission_id: key }, owner: { connectionId: 'local', profile: 'default' } })
}
- const before = localStorage.getItem('hermes.desktop.preparedSubmissions.v1')
+ const before = storedJournal()
expect((await listPreparedImageDrafts('stored', destination.scopeKey)).map(entry => entry.key)).toEqual([ordinary])
expect(await listPreparedImageDrafts('another', destination.scopeKey)).toEqual([])
- expect(localStorage.getItem('hermes.desktop.preparedSubmissions.v1')).toBe(before)
+ expect(storedJournal()).toEqual(before)
expect((await readPreparedSubmission(slash))?.text).toBe('expanded skill instructions')
})
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 9f3a6903ec2..49f3ac86b17 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
@@ -5,6 +5,16 @@ import type { SubmissionDestination } from './submission-destination'
import type { SubmitTextOptions } from './utils'
const STORAGE_KEY = 'hermes.desktop.preparedSubmissions.v1'
+// One localStorage key per browser journal entry. Every tab of the origin shares this storage with
+// last-writer-wins per KEY, so while the journal was one blob under STORAGE_KEY, two tabs rewriting
+// it at once could drop an entry the other had just written or restore one it had just retired.
+// Writing or retiring an entry now touches only keys of its own.
+const ENTRY_PREFIX = 'hermes.desktop.preparedSubmissions.v2:'
+// The blob may still hold an earlier build's uncertain sends. They stay adoptable from it, behind
+// any entry under its own key, and the blob is never rewritten: retiring a key also retires the
+// blob's entry there, recorded under its own key as that entry's id. So no tab can undo another's
+// retirement, and a newer entry that a still-open tab of the earlier build writes stays visible.
+const LEGACY_RETIRED_PREFIX = 'hermes.desktop.preparedSubmissions.v1.retired:'
export interface PreparedSubmission {
id: string
@@ -38,17 +48,22 @@ function readLegacySpent(): Record<string, string> {
return parsed && typeof parsed === 'object' && !Array.isArray(parsed) ? parsed as Record<string, string> : {}
}
-function readSpent(): Record<string, string> {
- const spent = readLegacySpent()
+// Every value stored under a key starting with `prefix`, by the rest of that key.
+function readPrefixed(prefix: string): Record<string, string> {
+ const values: Record<string, string> = {}
for (let index = 0; index < window.localStorage.length; index += 1) {
const key = window.localStorage.key(index)
- const id = key?.startsWith(SPENT_PREFIX) ? window.localStorage.getItem(key) : null
+ const value = key?.startsWith(prefix) ? window.localStorage.getItem(key) : null
- if (key && id) { spent[key.slice(SPENT_PREFIX.length)] = id }
+ if (key && value) { values[key.slice(prefix.length)] = value }
}
- return { ...spent, ...Object.fromEntries(retired) }
+ return values
+}
+
+function readSpent(): Record<string, string> {
+ return { ...readLegacySpent(), ...readPrefixed(SPENT_PREFIX), ...Object.fromEntries(retired) }
}
function writeSpent(key: string, id: string | undefined): void {
@@ -81,7 +96,8 @@ async function readJournal(): Promise<Record<string, PreparedSubmission>> {
throw new Error('Invalid prepared submission journal')
}
- const journal = parsed as Record<string, PreparedSubmission>
+ const stored = parsed as Record<string, PreparedSubmission>
+ const journal = native ? stored : readBrowserJournal(stored)
for (const [key, id] of Object.entries(readSpent())) {
if (journal[key]?.id === id) {
@@ -97,6 +113,17 @@ async function readJournal(): Promise<Record<string, PreparedSubmission>> {
return journal
}
+// The entries under their own keys, over the legacy blob's entries not yet retired.
+function readBrowserJournal(legacy: Record<string, PreparedSubmission>): Record<string, PreparedSubmission> {
+ for (const [key, id] of Object.entries(readPrefixed(LEGACY_RETIRED_PREFIX))) {
+ if (legacy[key]?.id === id) { delete legacy[key] }
+ }
+
+ const entries = Object.entries(readPrefixed(ENTRY_PREFIX)).map(([key, entry]) => [key, JSON.parse(entry)])
+
+ return { ...legacy, ...Object.fromEntries(entries) }
+}
+
function clearSpent(key: string): void {
retired.delete(key)
writeSpent(key, undefined)
@@ -111,9 +138,11 @@ async function retireJournalEntry(key: string): Promise<void> {
return
}
- const journal: Record<string, PreparedSubmission> = JSON.parse(window.localStorage.getItem(STORAGE_KEY) || '{}')
- delete journal[key]
- window.localStorage.setItem(STORAGE_KEY, JSON.stringify(journal))
+ // Remove first: under a full quota, the space this frees can let the marker write succeed.
+ window.localStorage.removeItem(ENTRY_PREFIX + key)
+ const legacy: Record<string, PreparedSubmission> = JSON.parse(window.localStorage.getItem(STORAGE_KEY) || '{}')
+
+ if (legacy[key]) { window.localStorage.setItem(LEGACY_RETIRED_PREFIX + key, legacy[key].id) }
}
export function preparedSubmissionKey(
@@ -251,11 +280,9 @@ export async function writePreparedSubmission(key: string, entry: PreparedSubmis
return
}
- const journal: Record<string, PreparedSubmission> = JSON.parse(window.localStorage.getItem(STORAGE_KEY) || '{}')
- journal[key] = entry
// 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))
+ window.localStorage.setItem(ENTRY_PREFIX + key, JSON.stringify(entry))
clearSpent(key)
}
diff --git a/apps/desktop/src/app/session/hooks/use-prompt-actions/submission-destination.test.tsx b/apps/desktop/src/app/session/hooks/use-prompt-actions/submission-destination.test.tsx
index c3ca2749e50..935c2fa11a2 100644
--- a/apps/desktop/src/app/session/hooks/use-prompt-actions/submission-destination.test.tsx
+++ b/apps/desktop/src/app/session/hooks/use-prompt-actions/submission-destination.test.tsx
@@ -7,6 +7,7 @@ import { $activeGatewayProfile } from '@/store/profile'
import { $connection, $sessions } from '@/store/session'
import { $sessionStates } from '@/store/session-states'
+import { clearAllButStoredJournal, storedJournal } from './prepared-submissions-test-utils'
import { useSlashCommand } from './slash'
import { captureSubmissionDestination } from './submission-destination'
import { useSubmitPrompt } from './submit'
@@ -92,7 +93,7 @@ describe('submission intent destinations', () => {
await act(async () => { expect(await b.result.current('same text')).toBe(true) })
const other = second.requestGateway.mock.calls.find(call => call[0] === 'prompt.submit')![1]!
expect(other.submission_id).not.toBe(original.submission_id)
- const retained = Object.values(JSON.parse(localStorage.getItem('hermes.desktop.preparedSubmissions.v1')!))
+ const retained = Object.values(storedJournal())
expect(retained).toHaveLength(1)
expect(retained[0]).toMatchObject({ id: original.submission_id, params: original })
await act(async () => { expect(await a.result.current('same text', { submission_id: String(original.submission_id) })).toBe(true) })
@@ -137,7 +138,7 @@ describe('submission intent destinations', () => {
await act(async () => { expect(await hook.result.current('image retry', { submission_id: 'image-retry', attachments: [image] })).toBe(true) })
expect(requestGateway.mock.calls.filter(call => call[0] === 'prompt.submit')[1][1]).toEqual(first)
expect(deps.syncAttachmentsForSubmit).toHaveBeenCalledOnce()
- expect(window.localStorage.getItem('hermes.desktop.preparedSubmissions.v1')).not.toContain('image retry')
+ expect(storedJournal()).toEqual({})
})
@@ -194,11 +195,9 @@ describe('submission intent destinations', () => {
await act(async () => {
expect(await hook.result.current('retry me', { submission_id: 'explicit-retry' })).toBe(false)
})
- const journal = window.localStorage.getItem('hermes.desktop.preparedSubmissions.v1')
- expect(journal).toContain('retry me')
+ expect(Object.values(storedJournal())).toMatchObject([{ text: 'retry me' }])
hook.unmount()
- window.localStorage.clear()
- window.localStorage.setItem('hermes.desktop.preparedSubmissions.v1', journal!)
+ clearAllButStoredJournal()
// A same-text send in another profile/session is a different intent; it
// must neither reuse nor retire the original uncertain admission.
$activeGatewayProfile.set('bob')
@@ -305,12 +304,9 @@ describe('submission intent destinations', () => {
await act(async () => {
expect(await hook.result.current(input, { submission_id: 'new-session-retry' })).toBe(false)
})
- const serialized = window.localStorage.getItem('hermes.desktop.preparedSubmissions.v1')
- expect(serialized).toBeTruthy()
- expect(Object.values(JSON.parse(serialized!))[0]).toMatchObject({ owner: { connectionId: 'local', profile: 'default' } })
+ expect(Object.values(storedJournal())).toMatchObject([{ owner: { connectionId: 'local', profile: 'default' } }])
hook.unmount()
- window.localStorage.clear()
- window.localStorage.setItem('hermes.desktop.preparedSubmissions.v1', serialized!)
+ clearAllButStoredJournal()
loseAck = false
hook = mount()
await act(async () => {
diff --git a/apps/desktop/src/app/session/hooks/use-prompt-actions/submit-unknown-receipt.test.tsx b/apps/desktop/src/app/session/hooks/use-prompt-actions/submit-unknown-receipt.test.tsx
index 1a943ab2ae6..10545db7bd6 100644
--- a/apps/desktop/src/app/session/hooks/use-prompt-actions/submit-unknown-receipt.test.tsx
+++ b/apps/desktop/src/app/session/hooks/use-prompt-actions/submit-unknown-receipt.test.tsx
@@ -8,6 +8,7 @@ import { $activeGatewayProfile } from '@/store/profile'
import { $connection, $sessions } from '@/store/session'
import { $sessionStates } from '@/store/session-states'
+import { storedJournal } from './prepared-submissions-test-utils'
import { useSubmitPrompt } from './submit'
import type { GatewayRequest } from './utils'
@@ -76,5 +77,5 @@ it('an exact retry answered `unknown` keeps the bubble, retires the retry identi
expect(state.messages.filter(message => message.role === 'user')).toHaveLength(1)
expect(state.busy).toBe(false)
expect(readPendingSubmissions('stored-a')['lost-1']).toMatchObject({ status: 'unknown', text: 'lost turn' })
- expect(window.localStorage.getItem('hermes.desktop.preparedSubmissions.v1') ?? '').not.toContain('lost turn')
+ expect(storedJournal()).toEqual({})
})
diff --git a/apps/desktop/src/app/session/hooks/use-prompt-actions/submit-voice-stopped.test.tsx b/apps/desktop/src/app/session/hooks/use-prompt-actions/submit-voice-stopped.test.tsx
index b760c1b4577..256ea8bef87 100644
--- a/apps/desktop/src/app/session/hooks/use-prompt-actions/submit-voice-stopped.test.tsx
+++ b/apps/desktop/src/app/session/hooks/use-prompt-actions/submit-voice-stopped.test.tsx
@@ -7,6 +7,7 @@ import { $activeGatewayProfile } from '@/store/profile'
import { $connection, $sessions } from '@/store/session'
import { $sessionStates } from '@/store/session-states'
+import { storedJournal } from './prepared-submissions-test-utils'
import { useSubmitPrompt } from './submit'
import type { GatewayRequest } from './utils'
@@ -69,7 +70,7 @@ it('a voice_stopped receipt settles the send with no turn, no error and no retai
expect(state.messages.some(message => message.error)).toBe(false)
expect(state.busy).toBe(false)
expect(state.awaitingResponse).toBe(false)
- expect(window.localStorage.getItem('hermes.desktop.preparedSubmissions.v1') ?? '').not.toContain('stop-1')
+ expect(storedJournal()).toEqual({})
})
// Greptile on TUI-26: the sidecar refuses `submission_id` (4000, version skew), Desktop retries the