Skip to content

The agent that grows with you

fix(desktop): recover image/file attach and /compress after a stale session drop

bb3c4f5c521738
diff --git a/apps/desktop/src/app/chat/session-tile-actions.ts b/apps/desktop/src/app/chat/session-tile-actions.ts
index fdaf7126d5c..e5435e4ffe9 100644
--- a/apps/desktop/src/app/chat/session-tile-actions.ts
+++ b/apps/desktop/src/app/chat/session-tile-actions.ts
@@ -367,7 +367,12 @@ export function useSessionTileActions({ runtimeId, scope, storedSessionId }: Ses
// the primary chat so the two can't diverge.
const submitRewind = useCallback(
(text: string, truncateOrdinal: number | undefined, interruptFirst: boolean) =>
- runRewindSubmit(requestGateway, runtimeIdRef.current, text, truncateOrdinal, interruptFirst),
+ runRewindSubmit(requestGateway, runtimeIdRef.current, text, truncateOrdinal, interruptFirst, {
+ storedSessionId: storedIdRef.current,
+ onSessionRecovered: recoveredId => {
+ runtimeIdRef.current = recoveredId
+ }
+ }),
[requestGateway]
)
diff --git a/apps/desktop/src/app/session/hooks/use-prompt-actions/index.ts b/apps/desktop/src/app/session/hooks/use-prompt-actions/index.ts
index fcfe1d78dfb..478c868b0ba 100644
--- a/apps/desktop/src/app/session/hooks/use-prompt-actions/index.ts
+++ b/apps/desktop/src/app/session/hooks/use-prompt-actions/index.ts
@@ -820,8 +820,14 @@ export function usePromptActions({
// response interrupts + retries through the shared busy gate.
const submitRewindPrompt = useCallback(
(sessionId: string, text: string, truncateOrdinal: number | undefined, interruptFirst: boolean) =>
- runRewindSubmit(requestGateway, sessionId, text, truncateOrdinal, interruptFirst),
- [requestGateway]
+ runRewindSubmit(requestGateway, sessionId, text, truncateOrdinal, interruptFirst, {
+ storedSessionId: selectedStoredSessionIdRef.current,
+ onSessionRecovered: recoveredId => {
+ activeSessionIdRef.current = recoveredId
+ setActiveSessionId(recoveredId)
+ }
+ }),
+ [activeSessionIdRef, requestGateway, selectedStoredSessionIdRef]
)
const restoreToMessage = useCallback(
diff --git a/apps/desktop/src/app/session/hooks/use-prompt-actions/slash.ts b/apps/desktop/src/app/session/hooks/use-prompt-actions/slash.ts
index d88d36548ff..b4dff0f95d4 100644
--- a/apps/desktop/src/app/session/hooks/use-prompt-actions/slash.ts
+++ b/apps/desktop/src/app/session/hooks/use-prompt-actions/slash.ts
@@ -29,6 +29,7 @@ import {
$sessions,
$yoloActive,
resolveComposerSessionKey,
+ setActiveSessionId,
setCurrentUsage,
setModelPickerOpen,
setSessionPickerOpen,
@@ -62,7 +63,8 @@ import {
renderCommandsCatalog,
renderRpcResult,
slashStatusText,
- type SubmitTextOptions
+ type SubmitTextOptions,
+ withSessionNotFoundResume
} from './utils'
// Manual compression is LLM-bound and routinely outlives the desktop's 30s
@@ -499,7 +501,8 @@ export function useSlashCommand(deps: SlashCommandDeps) {
return
}
- const { render: renderSlashOutput, sessionId, storedSessionId } = resolved
+ const { render: renderSlashOutput, sessionId: initialSessionId, storedSessionId } = resolved
+ let sessionId = initialSessionId
const focusTopic = ctx.arg.trim()
const noticeId = `session-compress:${sessionId}`
@@ -518,15 +521,41 @@ export function useSlashCommand(deps: SlashCommandDeps) {
})
try {
- const result = await requestGateway<SessionCompressResponse>(
- 'session.compress',
+ // Same stale-runtime recovery as prompt.submit: after sleep/wake a
+ // dead id 404s session.compress while plain chat still works, so
+ // /compress reported "session not found" on a healthy session.
+ // NOT alsoTimeout — compress is legitimately LLM-slow and a
+ // timeout here must not be retried as a dead session.
+ const { result, sessionId: liveSessionId } = await withSessionNotFoundResume(
+ sessionId,
+ storedSessionId,
+ liveId =>
+ requestGateway<SessionCompressResponse>(
+ 'session.compress',
+ {
+ session_id: liveId,
+ ...(focusTopic ? { focus_topic: focusTopic } : {})
+ },
+ SESSION_COMPRESS_TIMEOUT_MS
+ ),
{
- session_id: sessionId,
- ...(focusTopic ? { focus_topic: focusTopic } : {})
- },
- SESSION_COMPRESS_TIMEOUT_MS
+ requestGateway,
+ onRecovered: recoveredId => {
+ // Move the in-flight claim onto the live id so the coalesce
+ // guard releases the right key in `finally`.
+ compressInFlightRef.current.delete(sessionId)
+ compressInFlightRef.current.add(recoveredId)
+
+ if (activeSessionIdRef.current === initialSessionId) {
+ activeSessionIdRef.current = recoveredId
+ setActiveSessionId(recoveredId)
+ }
+ }
+ }
)
+ sessionId = liveSessionId
+
// Replace the transcript with the post-compress history so the
// summarized bubbles actually disappear. `messages` is the same
// shape session.resume returns (_history_to_messages), so