Skip to content

The agent that grows with you

fix(desktop): isolate fresh draft scopes

Denisb976c376e426
diff --git a/apps/desktop/src/app/chat/composer/index.tsx b/apps/desktop/src/app/chat/composer/index.tsx
index aca7952e042..b76279e03a8 100644
--- a/apps/desktop/src/app/chat/composer/index.tsx
+++ b/apps/desktop/src/app/chat/composer/index.tsx
@@ -117,6 +117,7 @@ export function ChatBar({
cwd,
disabled,
focusKey,
+ freshDraftKey,
gateway,
maxRecordingSeconds = 120,
profile,
@@ -203,11 +204,8 @@ export function ChatBar({
// would discard a question the user may want to come back to. The blocking
// prompt owns its own dismissal (Skip, Reject, dialog close).
const awaitingInput = useStore(scope.$awaitingInput)
- // Parked on an approval/sudo/secret prompt: typing can't answer those, so the
- // busy submit routes text to the queue instead of a steer (which would sit
- // undelivered behind the blocked tool batch). Drives the button affordance.
const blockingPrompt = useStore(useMemo(() => sessionBlockingPrompt(sessionId ?? null), [sessionId]))
- const activeQueueSessionKey = queueSessionKey || sessionId || null
+ const activeQueueSessionKey = queueSessionKey || sessionId || freshDraftKey || null
const { collapsed: statusDrawerCollapsed, toggle: toggleStatusDrawer } = useStatusDrawer(activeQueueSessionKey)
const statusDrawerId = useId()
const codingDrawerId = useId()
diff --git a/apps/desktop/src/app/chat/composer/types.ts b/apps/desktop/src/app/chat/composer/types.ts
index bfe81d1345b..b97ccedc7ab 100644
--- a/apps/desktop/src/app/chat/composer/types.ts
+++ b/apps/desktop/src/app/chat/composer/types.ts
@@ -40,6 +40,8 @@ export interface ChatBarProps {
busy: boolean
disabled: boolean
focusKey?: string | null
+ /** Durable scope for the current sessionless new-chat lifecycle. */
+ freshDraftKey?: string
maxRecordingSeconds?: number
state: ChatBarState
gateway?: HermesGateway | null
diff --git a/apps/desktop/src/app/chat/index.tsx b/apps/desktop/src/app/chat/index.tsx
index 51485ae70b6..f85c3ec1f98 100644
--- a/apps/desktop/src/app/chat/index.tsx
+++ b/apps/desktop/src/app/chat/index.tsx
@@ -36,6 +36,7 @@ import { $activeGatewayProfile, $gatewaySwapTarget, $hydrationSyncProfile, $prof
import {
$connection,
$contextSuggestions,
+ $freshDraftKey,
$freshDraftReady,
$gatewayState,
$introPersonality,
@@ -550,6 +551,7 @@ const ChatViewContent = memo(function ChatViewContent({
const petOverlayActive = useStore($petOverlayActive)
const petPresent = petActive || petOverlayActive
const freshDraftReady = useStore($freshDraftReady)
+ const freshDraftKey = useStore($freshDraftKey)
const gatewayState = useStore($gatewayState)
const gatewaySwapTarget = useStore($gatewaySwapTarget)
const hydrationSyncProfile = useStore($hydrationSyncProfile)
@@ -885,6 +887,7 @@ const ChatViewContent = memo(function ChatViewContent({
cwd={currentCwd}
disabled={!gatewayOpen}
focusKey={activeSessionId}
+ freshDraftKey={freshDraftKey}
gateway={gateway}
maxRecordingSeconds={maxVoiceRecordingSeconds}
onAddContextRef={onAddContextRef}
diff --git a/apps/desktop/src/app/session/hooks/use-session-actions/index.ts b/apps/desktop/src/app/session/hooks/use-session-actions/index.ts
index f4696bb950e..cc1347711a9 100644
--- a/apps/desktop/src/app/session/hooks/use-session-actions/index.ts
+++ b/apps/desktop/src/app/session/hooks/use-session-actions/index.ts
@@ -83,6 +83,7 @@ import {
idsShareLineage,
type NewChatWorkspaceTarget,
resolveComposerSessionKey,
+ rotateFreshDraftKey,
sessionPinId,
setActiveSessionId,
setActiveSessionStoredIdRotation,
@@ -586,6 +587,7 @@ export function useSessionActions({
? normalizeNewChatWorkspaceTarget(draftOptions.workspaceTarget)
: undefined
+ rotateFreshDraftKey()
resetViewSync()
busyRef.current = false
setBusy(false)
diff --git a/apps/desktop/src/store/composer.test.ts b/apps/desktop/src/store/composer.test.ts
index 258f1c65c34..244a4dc0e54 100644
--- a/apps/desktop/src/store/composer.test.ts
+++ b/apps/desktop/src/store/composer.test.ts
@@ -284,6 +284,14 @@ describe('session drafts', () => {
expect(takeSessionDraft('session-a').text).toBe('session draft')
})
+ it('keeps separate fresh-chat lifecycle drafts isolated', () => {
+ stashSessionDraft('__new__:first', 'first unsent chat', [])
+ stashSessionDraft('__new__:second', 'second unsent chat', [])
+
+ expect(takeSessionDraft('__new__:first').text).toBe('first unsent chat')
+ expect(takeSessionDraft('__new__:second').text).toBe('second unsent chat')
+ })
+
it('persists draft text (not attachments) to localStorage', () => {
stashSessionDraft('session-a', 'survives reload', [attachment({ id: 'file:a' })])
diff --git a/apps/desktop/src/store/session.test.ts b/apps/desktop/src/store/session.test.ts
index 056481dc014..cf9d4c9aa13 100644
--- a/apps/desktop/src/store/session.test.ts
+++ b/apps/desktop/src/store/session.test.ts
@@ -25,6 +25,7 @@ import {
$currentCwd,
$currentModel,
$currentProvider,
+ $freshDraftKey,
$messagingSessions,
$selectedStoredSessionId,
$sessions,
@@ -52,6 +53,7 @@ import {
mergeSessionPage,
rememberedSessionProfile,
resolveComposerSessionKey,
+ rotateFreshDraftKey,
sessionBelongsToProfile,
sessionMatchesStoredId,
sessionOwnerRouteFromRow,
@@ -329,6 +331,19 @@ describe('knownSessionOwner', () => {
})
})
+describe('fresh draft identity', () => {
+ it('rotates for each new-chat lifecycle and persists the current key', () => {
+ const previous = $freshDraftKey.get()
+ const first = rotateFreshDraftKey()
+ const second = rotateFreshDraftKey()
+
+ expect(first).not.toBe(previous)
+ expect(second).not.toBe(first)
+ expect($freshDraftKey.get()).toBe(second)
+ expect(window.localStorage.getItem('hermes.desktop.freshDraftKey')).toBe(second)
+ })
+})
+
describe('computed $attentionSessionIds', () => {
beforeEach(() => {
clearAllSessionStates()
diff --git a/apps/desktop/src/store/session.ts b/apps/desktop/src/store/session.ts
index d30340823de..d4b65e6319a 100644
--- a/apps/desktop/src/store/session.ts
+++ b/apps/desktop/src/store/session.ts
@@ -325,6 +325,16 @@ export function setRememberedRoute(path: null | string, profile: string): void {
persistString(profileNavigationKey(LAST_ROUTE_KEY, profile), path)
}
+// Stable only for the lifetime of the current sessionless chat. Persisting the
+// key (rather than just its text) lets a reload restore that exact fresh draft;
+// starting another new chat rotates the key so abandoned unsent drafts cannot
+// bleed into the next lifecycle.
+const FRESH_DRAFT_KEY = 'hermes.desktop.freshDraftKey'
+const LEGACY_FRESH_DRAFT_SCOPE = '__new__'
+
+const createFreshDraftKey = (): string =>
+ `__new__:${globalThis.crypto?.randomUUID?.() ?? `${Date.now()}-${Math.random().toString(36).slice(2)}`}`
+
let configuredDefaultProjectDir = ''
function workspaceCwdKey(connection: HermesConnection | null = $connection.get()): string {
@@ -1140,6 +1150,7 @@ export const $messagesEmpty = computed($messages, messages => messages.length ==
export const $lastVisibleMessageIsUser = computed($messages, lastVisibleMessageIsUser)
export const $freshDraftReady = atom(false)
+export const $freshDraftKey = atom(storedString(FRESH_DRAFT_KEY) ?? LEGACY_FRESH_DRAFT_SCOPE)
export const $busy = atom(false)
export const $awaitingResponse = atom(false)
// Stored-session id whose most recent resume FAILED terminally (the gateway RPC
@@ -1583,6 +1594,15 @@ export const markSessionRead = (storedSessionId: string | null | undefined) => {
export const setMessages = (next: Updater<ChatMessage[]>) => updateAtom($messages, next)
export const setFreshDraftReady = (next: Updater<boolean>) => updateAtom($freshDraftReady, next)
+
+export const rotateFreshDraftKey = (): string => {
+ const key = createFreshDraftKey()
+ $freshDraftKey.set(key)
+ persistString(FRESH_DRAFT_KEY, key)
+
+ return key
+}
+
export const setResumeFailedSessionId = (next: Updater<string | null>) => updateAtom($resumeFailedSessionId, next)
export const requestSessionResume = (sessionId: string, ownerRoute?: SessionOwnerRoute) => {