Skip to content

The agent that grows with you

fix(desktop): preserve fresh draft key on reload

Denis0e6600f3f838
diff --git a/apps/desktop/src/app/session/hooks/use-route-resume.test.tsx b/apps/desktop/src/app/session/hooks/use-route-resume.test.tsx
index 8a5b53a2fc0..cf454267ce7 100644
--- a/apps/desktop/src/app/session/hooks/use-route-resume.test.tsx
+++ b/apps/desktop/src/app/session/hooks/use-route-resume.test.tsx
@@ -29,7 +29,7 @@ interface HarnessProps {
runtimeIdByStoredSessionIdRef: MutableRefObject<Map<string, string>>
selectedStoredSessionId: null | string
selectedStoredSessionIdRef: MutableRefObject<null | string>
- startFreshSessionDraft: (focus: boolean) => unknown
+ startFreshSessionDraft: (options: boolean | { replaceRoute?: boolean; rotateFreshDraftKey?: boolean }) => unknown
}
function RouteResumeHarness({
@@ -86,11 +86,11 @@ describe('useRouteResume', () => {
activeSessionIdRef={activeSessionIdRef}
creatingSessionRef={creatingSessionRef}
currentView="chat"
- freshDraftReady
+ freshDraftReady={false}
gatewayState="open"
- locationPathname="/session-1"
+ locationPathname="/new"
resumeSession={resumeSession}
- routedSessionId="session-1"
+ routedSessionId={null}
runtimeIdByStoredSessionIdRef={runtimeIdByStoredSessionIdRef}
selectedStoredSessionId={null}
selectedStoredSessionIdRef={selectedStoredSessionIdRef}
diff --git a/apps/desktop/src/app/session/hooks/use-route-resume.ts b/apps/desktop/src/app/session/hooks/use-route-resume.ts
index 685576f60ef..9cffa97e724 100644
--- a/apps/desktop/src/app/session/hooks/use-route-resume.ts
+++ b/apps/desktop/src/app/session/hooks/use-route-resume.ts
@@ -30,7 +30,7 @@ interface RouteResumeOptions {
runtimeIdByStoredSessionIdRef: MutableRefObject<Map<string, string>>
selectedStoredSessionId: string | null
selectedStoredSessionIdRef: MutableRefObject<string | null>
- startFreshSessionDraft: (focus: boolean) => unknown
+ startFreshSessionDraft: (options: boolean | { replaceRoute?: boolean; rotateFreshDraftKey?: boolean }) => unknown
}
// Bounded auto-retry for a stranded session window. A resume can fail terminally
@@ -210,7 +210,7 @@ export function useRouteResume({
) {
// A fresh draft is a real navigation — any later resume homes normally.
bootResumeRef.current = false
- startFreshSessionDraft(true)
+ startFreshSessionDraft({ replaceRoute: true, rotateFreshDraftKey: false })
}
}, [
activeSessionId,
diff --git a/apps/desktop/src/app/session/hooks/use-session-actions.test.tsx b/apps/desktop/src/app/session/hooks/use-session-actions.test.tsx
index 6d69e1c9f13..8d422274a93 100644
--- a/apps/desktop/src/app/session/hooks/use-session-actions.test.tsx
+++ b/apps/desktop/src/app/session/hooks/use-session-actions.test.tsx
@@ -51,6 +51,7 @@ import {
$currentModel,
$currentProvider,
$currentReasoningEffort,
+ $freshDraftKey,
$messages,
$messagingSessions,
$newChatWorkspaceTarget,
@@ -5263,6 +5264,7 @@ describe('createBackendSessionForSend workspace target', () => {
expect(params).toMatchObject({ cwd: '/clicked-workspace' })
})
+D
it('does not inherit a stale cwd when Home is the active project scope', async () => {
const params = await createWith(
() => {
@@ -6114,5 +6116,16 @@ describe('routed fresh chat keeps its exact owner across turns', () => {
expect(vi.mocked(requestGatewayForAgent).mock.calls.filter(call => call[2] === 'session.close')).toEqual([])
expect(ambientRequest).not.toHaveBeenCalledWith('session.close', expect.anything())
expect(getSessionOwnerHint(STORED)).toEqual(route)
+
+ it('can preserve the current fresh draft key when explicitly requested', async () => {
+ let handle: HarnessHandle | null = null
+ const requestGateway = vi.fn(async () => ({} as never))
+
+ render(<Harness onReady={h => (handle = h)} requestGateway={requestGateway} />)
+ await waitFor(() => expect(handle).not.toBeNull())
+
+ const before = $freshDraftKey.get()
+ await handle!.startFreshSessionDraft({ replaceRoute: true, rotateFreshDraftKey: false })
+ expect($freshDraftKey.get()).toBe(before)
})
})
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 cc1347711a9..283281427fa 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
@@ -384,6 +384,7 @@ async function desktopSessionCreateParams(
interface FreshSessionDraftOptions {
preserveRoute?: boolean
replaceRoute?: boolean
+ rotateFreshDraftKey?: boolean
workspaceTarget?: NewChatWorkspaceTarget
}
@@ -587,7 +588,10 @@ export function useSessionActions({
? normalizeNewChatWorkspaceTarget(draftOptions.workspaceTarget)
: undefined
- rotateFreshDraftKey()
+ if (draftOptions.rotateFreshDraftKey !== false) {
+ rotateFreshDraftKey()
+ }
+
resetViewSync()
busyRef.current = false
setBusy(false)