Skip to content

Commit 76a0a37

Browse files
fix: show full-pane Unable to load session for inaccessible sessions
Keep the session URL and replace toast/redirect with EmptyScreen so access failures are visible in the chat and sessions detail panes. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent ecac956 commit 76a0a37

12 files changed

Lines changed: 111 additions & 119 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@truefoundry/trueforge-ui': patch
3+
---
4+
5+
Show a full-pane "Unable to load session" for inaccessible session deep links and sessions-browser details instead of toasting and redirecting away.

‎packages/trueforge-ui/src/atoms/agent-details/AgentSessions.tsx‎

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { useOptionalShellMode } from '../../server/ShellModeContext.js';
1717
import type { Session, SessionEventItem, SessionListEntry } from '../../server/types.js';
1818
import { useSlot } from '../../theme/SlotsProvider.js';
1919
import { drainListPages } from '../../utils/drainListPages.js';
20-
import { reportSessionAccessError } from '../../utils/sessionAccessError.js';
20+
import { getErrorMessage } from '../../utils/getErrorMessage.js';
2121
import { sessionTimeRangeFromCreatedAt } from '../../utils/sessionShareUrl.js';
2222
import { EmptyScreen } from '../EmptyScreen.js';
2323
import { cn } from '../lib/cn.js';
@@ -84,6 +84,7 @@ export function AgentSessions({
8484
const [detailSession, setDetailSession] = useState<Session>();
8585
const [detailLoading, setDetailLoading] = useState(false);
8686
const [detailFailed, setDetailFailed] = useState(false);
87+
const [detailErrorMessage, setDetailErrorMessage] = useState('This session could not be loaded.');
8788
const [pendingDelete, setPendingDelete] = useState<SessionListEntry | null>(null);
8889

8990
const canDeleteSession = typeof chatServer.deleteSession === 'function';
@@ -191,13 +192,15 @@ export function AgentSessions({
191192
setDetailEvents(undefined);
192193
setDetailSession(undefined);
193194
setDetailFailed(false);
195+
setDetailErrorMessage('This session could not be loaded.');
194196
setDetailLoading(false);
195197
return;
196198
}
197199

198200
let cancelled = false;
199201
setDetailLoading(true);
200202
setDetailFailed(false);
203+
setDetailErrorMessage('This session could not be loaded.');
201204
setDetailEvents(undefined);
202205
setDetailSession(undefined);
203206

@@ -219,14 +222,7 @@ export function AgentSessions({
219222
})
220223
.catch((error: unknown) => {
221224
if (cancelled) return;
222-
reportSessionAccessError({
223-
error,
224-
...(toaster != null ? { showError: toaster.showError } : {}),
225-
});
226-
if (detailOnly) {
227-
onCloseDetail?.();
228-
return;
229-
}
225+
setDetailErrorMessage(getErrorMessage(error, 'This session could not be loaded.'));
230226
setDetailFailed(true);
231227
})
232228
.finally(() => {
@@ -236,7 +232,7 @@ export function AgentSessions({
236232
return () => {
237233
cancelled = true;
238234
};
239-
}, [chatServer, detailOnly, onCloseDetail, refreshKey, selectedSessionId, sessionsServer, toaster]);
235+
}, [chatServer, refreshKey, selectedSessionId, sessionsServer]);
240236
useEffect(() => {
241237
onLoadingChange?.(listLoading || detailLoading);
242238
}, [detailLoading, listLoading, onLoadingChange]);
@@ -321,9 +317,7 @@ export function AgentSessions({
321317
Select a session to view details
322318
</div>
323319
) : detailFailed ? (
324-
<div className="flex flex-1 items-center justify-center px-6 text-sm text-text-secondary">
325-
Session details could not be loaded.
326-
</div>
320+
<EmptyScreen title="Unable to load session" description={detailErrorMessage} className="bg-primary-bg" />
327321
) : (
328322
<>
329323
<AgentSessionDetailHeader
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
'use client';
22

3+
import { EmptyScreen } from '../atoms/EmptyScreen.js';
4+
import { useOptionalShellMode } from '../server/ShellModeContext.js';
35
import { ComposerContainer } from './ComposerContainer.js';
46
import { ThreadContainer } from './ThreadContainer.js';
57

68
/** The full assembled thread view: message list + composer. */
79
export function Thread() {
10+
const shell = useOptionalShellMode();
11+
if (shell?.sessionAccessError != null) {
12+
return (
13+
<EmptyScreen title="Unable to load session" description={shell.sessionAccessError} className="bg-primary-bg" />
14+
);
15+
}
816
return <ThreadContainer composer={<ComposerContainer />} />;
917
}

‎packages/trueforge-ui/src/containers/TrueForgeUIShell.tsx‎

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,8 @@ function ChatProviderFromShell({
183183
/** When routing, reports the active thread's remote id up to `ShellRouteSync`. */
184184
onRemoteIdChange?: (id: string | undefined) => void;
185185
} & Omit<TrueForgeChatProviderProps, 'agent' | 'agentName' | 'listSessionsAgentId' | 'children'>) {
186-
const { mode, runtimeKey, historyAgentFilter, listSessionsAgentId, pendingSessionId } = useShellMode();
186+
const { mode, runtimeKey, historyAgentFilter, listSessionsAgentId, pendingSessionId, sessionAccessError } =
187+
useShellMode();
187188

188189
const isCreateAgent = mode.status === 'active' && mode.isMutable && mode.isCreateAgent;
189190

@@ -238,6 +239,13 @@ function ChatProviderFromShell({
238239
defaultAgentSpec: { model: { name: 'openai-main/gpt-4.1' } },
239240
};
240241
}
242+
// Access failures keep a pending id for the URL but must not bind named runtime to it.
243+
if (sessionAccessError != null) {
244+
return {
245+
mode: 'draft',
246+
defaultAgentSpec: draftDefaultAgentSpec,
247+
};
248+
}
241249
// Runtime still uses named|draft; shell mutability maps onto that adapter.
242250
if (!mode.isMutable) {
243251
const agentName = mode.agentName ?? mode.agentId ?? pendingSessionId;
@@ -254,7 +262,7 @@ function ChatProviderFromShell({
254262
mode: 'draft',
255263
defaultAgentSpec: draftDefaultAgentSpec,
256264
};
257-
}, [mode, draftDefaultAgentSpec, pendingSessionId]);
265+
}, [mode, draftDefaultAgentSpec, pendingSessionId, sessionAccessError]);
258266

259267
return (
260268
<DraftCatalogProvider>
@@ -264,7 +272,7 @@ function ChatProviderFromShell({
264272
server={runtimeServer}
265273
agent={agent}
266274
listSessionsAgentId={listSessionsAgentId}
267-
initialSessionId={pendingSessionId ?? hostInitialSessionId}
275+
initialSessionId={sessionAccessError != null ? undefined : (pendingSessionId ?? hostInitialSessionId)}
268276
>
269277
<AgentConfigInstructionsProvider>
270278
<DraftSpecPreferenceBridge />
@@ -324,9 +332,9 @@ export function TrueForgeUIShell(props: TrueForgeUIShellProps) {
324332
const server = resolved.server;
325333
const layoutTree = <LayoutChildren layout={layout} className={className} />;
326334

327-
// Outer toaster so ShellRouteSync (sibling of chat provider) can toast access-denied
328-
// deep links; nested ToasterProvider inside TrueForgeChatProvider stays for hosts
329-
// that mount chat alone. Analytics wraps the same tree so chrome + chat share one sink.
335+
// Outer toaster for sessions browser / chrome; nested ToasterProvider inside
336+
// TrueForgeChatProvider stays for hosts that mount chat alone. Analytics wraps
337+
// the same tree so chrome + chat share one sink.
330338
const shellTree = (
331339
<AnalyticsProvider track={analytics?.track}>
332340
<ToasterProvider>
@@ -338,7 +346,6 @@ export function TrueForgeUIShell(props: TrueForgeUIShellProps) {
338346
routes={resolvedRoutes}
339347
activeRemoteId={activeRemoteId}
340348
initialSettingsOpen={initialSettingsOpen}
341-
onError={onError}
342349
/>
343350
</Suspense>
344351
) : null}

‎packages/trueforge-ui/src/routing/HistorySessionSwitchBridge.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ export function HistorySessionSwitchBridge() {
1313
const pendingSessionEpoch = shell?.pendingSessionEpoch ?? 0;
1414

1515
useEffect(() => {
16-
if (pendingSessionId == null) return;
16+
if (pendingSessionId == null || shell?.sessionAccessError != null) return;
1717
void Promise.resolve(aui.threads().switchToThread(pendingSessionId)).catch(() => undefined);
18-
}, [aui, pendingSessionId, pendingSessionEpoch]);
18+
}, [aui, pendingSessionId, pendingSessionEpoch, shell?.sessionAccessError]);
1919

2020
return null;
2121
}

‎packages/trueforge-ui/src/routing/ShellRouteSync.tsx‎

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { useLocation, useNavigate } from 'react-router-dom';
55

66
import { sessionIsCreateAgent } from '../atoms/lib/sessionCreateAgent.js';
77
import { findAgentByName } from '../atoms/lib/useSearchAgentsList.js';
8-
import { useToasterOptional } from '../containers/ToasterContainer.js';
98
import {
109
useOptionalAgentSessionsServer,
1110
useOptionalCatalogServer,
@@ -17,12 +16,12 @@ import {
1716
} from '../server/ServerContext.js';
1817
import { libraryAgentId, useShellMode } from '../server/ShellModeContext.js';
1918
import { toEffectiveRoutes } from '../server/serverChrome.js';
19+
import { getErrorMessage } from '../utils/getErrorMessage.js';
2020
import {
2121
readHistoryAgentSearch,
2222
updateHistoryAgentSearch,
2323
type HistoryAgentSearch,
2424
} from '../utils/historyAgentSearch.js';
25-
import { reportSessionAccessError } from '../utils/sessionAccessError.js';
2625
import { deriveChatPlace, derivePlace } from './derivePlace.js';
2726
import { buildPath, matchLocation, placesEqual, sanitizeSearchForPlace } from './paths.js';
2827
import type { ResolvedRoutes, RoutePlace, ShellSnapshot } from './types.js';
@@ -44,12 +43,10 @@ export function ShellRouteSync({
4443
routes,
4544
activeRemoteId,
4645
initialSettingsOpen,
47-
onError,
4846
}: {
4947
routes: ResolvedRoutes;
5048
activeRemoteId: string | undefined;
5149
initialSettingsOpen: boolean;
52-
onError?: (error: unknown) => void;
5350
}) {
5451
const shell = useShellMode();
5552
const server = useOptionalServer();
@@ -59,7 +56,6 @@ export function ShellRouteSync({
5956
const sandboxEnvironments = useOptionalSandboxEnvironmentServer();
6057
const capabilities = useServerCapabilities();
6158
const capabilitiesSettled = useServerCapabilitiesSettled();
62-
const toaster = useToasterOptional();
6359
const navigate = useNavigate();
6460
const location = useLocation();
6561
// Same gates as sidebar chrome: missing optional ports unregister their paths.
@@ -116,7 +112,7 @@ export function ShellRouteSync({
116112
* A URL carries only the id, so ask the server whether it names a mutable
117113
* draft or an agent chat; guessing "mutable" opens an agent session as a
118114
* blank draft. `requestedSessionRef` drops replies a later place superseded.
119-
* Access denied / missing session: toast, then New Chat (do not bind the id).
115+
* Access denied / missing session: keep the URL and show a full-pane error.
120116
*/
121117
const goToRoot = useCallback(() => {
122118
shell.setSettingsOpen(false);
@@ -157,18 +153,13 @@ export function ShellRouteSync({
157153
})
158154
.catch((error: unknown) => {
159155
if (requestedSessionRef.current !== sessionId) return;
160-
requestedSessionRef.current = null;
161-
// Drop boot's "wait until place matches URL" so shell→URL can leave /sessions/:id.
162-
bootPlaceRef.current = null;
163-
reportSessionAccessError({
164-
error,
165-
...(onError != null ? { onError } : {}),
166-
...(toaster != null ? { showError: toaster.showError } : {}),
156+
shell.openInaccessibleSession({
157+
sessionId,
158+
message: getErrorMessage(error, 'This session could not be loaded.'),
167159
});
168-
goToRoot();
169160
});
170161
},
171-
[goToRoot, onError, server, shell, toaster],
162+
[server, shell],
172163
);
173164

174165
const applyHistoryAgentSearch = useCallback(

‎packages/trueforge-ui/src/server/ShellModeContext.tsx‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,13 @@ type ShellModeContextValue = {
154154
isMutable?: boolean;
155155
isCreateAgent?: boolean;
156156
}) => void;
157+
/**
158+
* Keep `/sessions/:id` in place and surface a full-pane load failure
159+
* (no toast / redirect). Cleared when opening another session or draft.
160+
*/
161+
openInaccessibleSession: (req: { sessionId: string; message: string }) => void;
162+
/** Backend/access message when the current pending session could not be opened. */
163+
sessionAccessError: string | null;
157164
/** Reset current chat; no-op when idle. */
158165
clearChat: () => void;
159166
/** Return library-only mode to its idle landing; no-op in other modes. */
@@ -278,6 +285,7 @@ export function ShellModeProvider({
278285
const [historyAgentFilter, setHistoryAgentFilter] = useState<HistoryAgentFilter | null>(null);
279286
const [pendingSessionId, setPendingSessionId] = useState<string | undefined>(undefined);
280287
const [pendingSessionEpoch, setPendingSessionEpoch] = useState(0);
288+
const [sessionAccessError, setSessionAccessError] = useState<string | null>(null);
281289
const settingsEnabled = isSettingsChromeEnabled({ catalog, capabilities });
282290
const settingsOpen = settingsEnabled && settingsOpenState;
283291
const sessionsEnabled = isSessionsChromeEnabled({ sessions: sessionsServer });
@@ -491,6 +499,7 @@ export function ShellModeProvider({
491499
setSessionsOpen(false);
492500
setSchedulesOpen(false);
493501
setEnvironmentsOpen(false);
502+
setSessionAccessError(null);
494503
setPendingSessionId(undefined);
495504
const isCreateAgent = resolveMutableIsCreateAgent(req);
496505
const kind: DraftPreferenceKind = isCreateAgent ? 'agent' : 'chat';
@@ -517,6 +526,7 @@ export function ShellModeProvider({
517526
setSessionsOpen(false);
518527
setSchedulesOpen(false);
519528
setEnvironmentsOpen(false);
529+
setSessionAccessError(null);
520530
setPendingSessionId(undefined);
521531
setAgentConfigOpenState(false);
522532
setMode({
@@ -612,6 +622,7 @@ export function ShellModeProvider({
612622
setSessionsOpen(false);
613623
setSchedulesOpen(false);
614624
setEnvironmentsOpen(false);
625+
setSessionAccessError(null);
615626
setAgentConfigOpenState(true);
616627
return;
617628
}
@@ -722,6 +733,7 @@ export function ShellModeProvider({
722733
setSessionsOpen(false);
723734
setSchedulesOpen(false);
724735
setEnvironmentsOpen(false);
736+
setSessionAccessError(null);
725737
setPendingSessionId(sessionId);
726738
setPendingSessionEpoch(n => n + 1);
727739
if (isMutable) {
@@ -757,8 +769,42 @@ export function ShellModeProvider({
757769
],
758770
);
759771

772+
const openInaccessibleSession = useCallback(
773+
({ sessionId, message }: { sessionId: string; message: string }) => {
774+
setSettingsOpen(false);
775+
setLibraryOpenState(false);
776+
setLibraryAgentId(null);
777+
setSessionsOpen(false);
778+
setSchedulesOpen(false);
779+
setEnvironmentsOpen(false);
780+
setAgentConfigOpenState(false);
781+
setSessionAccessError(message);
782+
setPendingSessionId(sessionId);
783+
setPendingSessionEpoch(n => n + 1);
784+
// Keep chrome non-idle so layouts render the thread slot (gated by sessionAccessError).
785+
if (isComposerEnabled) {
786+
setMode({
787+
status: 'active',
788+
isMutable: true,
789+
isCreateAgent: false,
790+
agentSpec: chatSeedRef.current,
791+
locked: false,
792+
});
793+
return;
794+
}
795+
setMode({
796+
status: 'active',
797+
isMutable: false,
798+
isCreateAgent: false,
799+
locked: false,
800+
});
801+
},
802+
[isComposerEnabled, setSettingsOpen, setSessionsOpen, setSchedulesOpen, setEnvironmentsOpen],
803+
);
804+
760805
const clearChat = useCallback(() => {
761806
if (effectiveMode.status === 'idle') return;
807+
setSessionAccessError(null);
762808
setPendingSessionId(undefined);
763809
if (effectiveMode.isMutable) {
764810
// Preserve Edit / builder vs chat intent. New Chat must use the latest
@@ -791,6 +837,7 @@ export function ShellModeProvider({
791837
const openLibraryHome = useCallback(() => {
792838
// Only library-only mode has an idle landing; other modes root via openDraft / clearChat.
793839
if (!isLibraryEnabled || isComposerEnabled) return;
840+
setSessionAccessError(null);
794841
setPendingSessionId(undefined);
795842
setSettingsOpen(false);
796843
setLibraryOpenState(false);
@@ -842,6 +889,8 @@ export function ShellModeProvider({
842889
resetAgentBuilder,
843890
rememberDraftSpec,
844891
openHistorySession,
892+
openInaccessibleSession,
893+
sessionAccessError,
845894
clearChat,
846895
openLibraryHome,
847896
runtimeKey,
@@ -888,6 +937,8 @@ export function ShellModeProvider({
888937
resetAgentBuilder,
889938
rememberDraftSpec,
890939
openHistorySession,
940+
openInaccessibleSession,
941+
sessionAccessError,
891942
clearChat,
892943
openLibraryHome,
893944
runtimeKey,

‎packages/trueforge-ui/src/utils/sessionAccessError.ts‎

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)