Skip to content

The agent that grows with you

fix(desktop): clarify preserved session tile recovery

wz-heng319e77eea441
diff --git a/apps/desktop/src/app/chat/session-tile.test.ts b/apps/desktop/src/app/chat/session-tile.test.ts
new file mode 100644
index 00000000000..47cab3b3e7f
--- /dev/null
+++ b/apps/desktop/src/app/chat/session-tile.test.ts
@@ -0,0 +1,17 @@
+import { describe, expect, it } from 'vitest'
+
+import { sessionTileResumeFailure } from './session-tile'
+
+describe('sessionTileResumeFailure', () => {
+ it('keeps a confirmed durable session retryable instead of repeating a stale 404', () => {
+ expect(sessionTileResumeFailure('session not found', true, true)).toBe('Session is still available — retry resuming it.')
+ })
+
+ it('fails safe on an inconclusive durable lookup', () => {
+ expect(sessionTileResumeFailure('404', false, true)).toBe('Session unavailable — you can retry resuming it.')
+ })
+
+ it('does not overwrite a tile that rebound while the lookup was pending', () => {
+ expect(sessionTileResumeFailure('session not found', true, false)).toBeUndefined()
+ })
+})
diff --git a/apps/desktop/src/app/chat/session-tile.tsx b/apps/desktop/src/app/chat/session-tile.tsx
index 9a50589b130..0c9aa9b175f 100644
--- a/apps/desktop/src/app/chat/session-tile.tsx
+++ b/apps/desktop/src/app/chat/session-tile.tsx
@@ -76,6 +76,26 @@ import { ChatView } from '.'
const NO_MESSAGES: ChatMessage[] = []
+export function sessionTileResumeFailure(
+ message: string,
+ durableSessionFound: boolean | undefined,
+ tileStillUnbound: boolean
+): string | undefined {
+ if (!tileStillUnbound) {
+ return undefined
+ }
+
+ if (!/session not found|\b404\b/i.test(message)) {
+ return message
+ }
+
+ if (durableSessionFound) {
+ return 'Session is still available — retry resuming it.'
+ }
+
+ return 'Session unavailable — you can retry resuming it.'
+}
+
/** The tile's SessionView: the same atom shape the primary chat renders
* from, computed from this session's slice of `$sessionStates`. */
function buildTileView(storedSessionId: string): SessionView {
@@ -264,6 +284,7 @@ export function SessionTilePane({ storedSessionId }: { storedSessionId: string }
const delegateRevision = useStore($sessionTileDelegateRevision)
const resumingRef = useRef(false)
const view = useMemo(() => buildTileView(storedSessionId), [storedSessionId])
+
const storedSessionStillExists = useCallback(
() => $sessions.get().some(s => sessionMatchesStoredId(s, storedSessionId)),
[storedSessionId]
@@ -342,6 +363,7 @@ export function SessionTilePane({ storedSessionId }: { storedSessionId: string }
if (!/session not found|\b404\b/i.test(message)) {
patchSessionTile(storedSessionId, { error: message })
+
return
}
@@ -350,10 +372,12 @@ export function SessionTilePane({ storedSessionId }: { storedSessionId: string }
// before releasing this resume attempt, then fail safe: a tile may be
// retried by the user, but must never be deleted on an inconclusive
// reconnect-time lookup.
- await resolveStoredSession(storedSessionId, ownerRoute).catch(() => undefined)
+ const durableSession = await resolveStoredSession(storedSessionId, ownerRoute).catch(() => undefined)
const current = $sessionTiles.get().find(candidate => candidate.storedSessionId === storedSessionId)
- if (current && !current.runtimeId) {
- patchSessionTile(storedSessionId, { error: message })
+ const error = sessionTileResumeFailure(message, Boolean(durableSession), Boolean(current && !current.runtimeId))
+
+ if (error) {
+ patchSessionTile(storedSessionId, { error })
}
})
.finally(() => {