The open-source agent harness - the runtime layer that turns an LLM into a working agent.
fix: hide running turns for shared-session viewers (AGE-2569) (#1113)
Govinda Vashishtha4dc8aeb0e067
diff --git a/.changeset/hide-running-turns-shared-session.md b/.changeset/hide-running-turns-shared-session.mdnew file mode 100644index 000000000..b7750decd--- /dev/null+++ b/.changeset/hide-running-turns-shared-session.md@@ -0,0 +1,5 @@+---+'@truefoundry/trueforge-ui': patch+---++Route shared-session viewers to the read-only session view and hide in-flight turns.diff --git a/packages/trueforge-ui/src/containers/AgentSessionTimelineContainer.tsx b/packages/trueforge-ui/src/containers/AgentSessionTimelineContainer.tsxindex e22bca00e..b767e2fe4 100644--- a/packages/trueforge-ui/src/containers/AgentSessionTimelineContainer.tsx+++ b/packages/trueforge-ui/src/containers/AgentSessionTimelineContainer.tsx@@ -261,7 +261,9 @@ export function AgentSessionTimelineContainer({);}- if (messages.length === 0 && renderableTurnViews.length === 0) {+ // Running tips are omitted from listEvents (and thus from turn views). Orphan+ // projected content with no section to attach to must not blank the pane.+ if (renderableTurnViews.length === 0) {return (<div className="flex flex-1 items-center justify-center px-6 text-sm text-text-secondary">This session has no messages yet.diff --git a/packages/trueforge-ui/src/routing/ShellRouteSync.tsx b/packages/trueforge-ui/src/routing/ShellRouteSync.tsxindex fb67f7cea..a2c79fd74 100644--- a/packages/trueforge-ui/src/routing/ShellRouteSync.tsx+++ b/packages/trueforge-ui/src/routing/ShellRouteSync.tsx@@ -8,6 +8,7 @@ import { findAgentByName } from '../atoms/lib/useSearchAgentsList.js';import {useOptionalAgentSessionsServer,useOptionalCatalogServer,+ useOptionalPermissionsServer,useOptionalSandboxEnvironmentServer,useOptionalScheduleServer,useOptionalServer,@@ -52,6 +53,7 @@ export function ShellRouteSync({const server = useOptionalServer();const catalog = useOptionalCatalogServer();const sessions = useOptionalAgentSessionsServer();+ const permissions = useOptionalPermissionsServer();const schedules = useOptionalScheduleServer();const sandboxEnvironments = useOptionalSandboxEnvironmentServer();const capabilities = useServerCapabilities();@@ -158,13 +160,28 @@ export function ShellRouteSync({return;}const requestedChatIdentity = chatIdentityRef.current;- void server- .getSession({ sessionId })- .then(session => {+ // Shared viewers can read a session but cannot subscribe/send. Prefer the+ // read-only share surface when MANAGE is missing and that route exists.+ const canManagePromise =+ permissions == null || sessions == null+ ? Promise.resolve(true)+ : permissions+ .listPermissions({ resourceType: 'session', resourceIds: [sessionId] })+ .then(response => (response.data.permissions[sessionId] ?? []).includes('MANAGE'))+ .catch(() => true);++ void Promise.all([server.getSession({ sessionId }), canManagePromise])+ .then(([session, canManage]) => {if (requestedSessionRef.current !== sessionId) {releaseAbandonedBootSession(sessionId);return;}+ if (!canManage) {+ // Leave the /sessions/:id boot wait so shell→URL can rewrite to share.+ releaseAbandonedBootSession(sessionId);+ shell.openSharedSession(sessionId);+ return;+ }shell.openHistorySession({sessionId,isMutable: session.isMutable,@@ -188,7 +205,7 @@ export function ShellRouteSync({});});},- [releaseAbandonedBootSession, server, shell],+ [permissions, releaseAbandonedBootSession, server, sessions, shell],);const applyHistoryAgentSearch = useCallback(diff --git a/packages/trueforge-ui/test/containers/AgentSessionTimelineContainer.test.tsx b/packages/trueforge-ui/test/containers/AgentSessionTimelineContainer.test.tsxindex 92c09d26d..678a1b1cc 100644--- a/packages/trueforge-ui/test/containers/AgentSessionTimelineContainer.test.tsx+++ b/packages/trueforge-ui/test/containers/AgentSessionTimelineContainer.test.tsx@@ -192,6 +192,52 @@ describe('AgentSessionTimelineContainer', () => {});});+ it('shows the empty state when the only turn is still running', async () => {+ render(+ <SlotsProvider overrides={{ AgentSessionEventTimeline: () => null }}>+ <ServerProvider+ server={createMockAgentUIServer({+ listTurns: async () => ({+ data: [+ {+ id: 'turn-running',+ sessionId: 'sess-1',+ state: { status: 'running' as const },+ createdAt: '2026-01-01T00:00:00.000Z',+ input: [{ type: 'user.message' as const, content: 'in flight' }],+ },+ ],+ }),+ getTurn: async () => ({+ id: 'turn-running',+ sessionId: 'sess-1',+ state: { status: 'running' as const },+ createdAt: '2026-01-01T00:00:00.000Z',+ input: [{ type: 'user.message' as const, content: 'in flight' }],+ }),+ listTurnEvents: async () => ({+ data: [+ {+ type: 'model.message' as const,+ id: 'm1',+ threadId: 'main',+ content: 'partial assistant text',+ createdAt: '2026-01-01T00:00:01.000Z',+ },+ ],+ }),+ })}+ >+ <AgentSessionTimelineContainer sessionId="sess-1" events={[]} />+ </ServerProvider>+ </SlotsProvider>,+ );++ expect(await screen.findByText('This session has no messages yet.')).toBeInTheDocument();+ expect(screen.queryByText('in flight')).not.toBeInTheDocument();+ expect(screen.queryByText('partial assistant text')).not.toBeInTheDocument();+ });+it('keeps responses in their backend turns and renders terminal failures', async () => {let timelineTitles: string[] = [];render(diff --git a/packages/trueforge-ui/test/routing/ShellRouteSync.test.tsx b/packages/trueforge-ui/test/routing/ShellRouteSync.test.tsxindex 30fe54c5b..235aabaf1 100644--- a/packages/trueforge-ui/test/routing/ShellRouteSync.test.tsx+++ b/packages/trueforge-ui/test/routing/ShellRouteSync.test.tsx@@ -2,12 +2,13 @@import { act, render, waitFor } from '@testing-library/react';import { StrictMode, useEffect, useState, type ReactNode } from 'react';import { MemoryRouter, useLocation, useNavigate, type NavigateFunction } from 'react-router-dom';-import { describe, expect, it } from 'vitest';+import { describe, expect, it, vi } from 'vitest';import { resolveRoutesConfig } from '@/routing/paths.js';import { ShellRouteSync } from '@/routing/ShellRouteSync.js';import { ServerProvider } from '@/server/ServerContext.js';import { ShellModeProvider, useShellMode, type AgentConfig } from '@/server/ShellModeContext.js';+import type { ListPermissionsResponse, PermissionsServer } from '@/server/types.js';import {createMockAgentSessionsServer,createMockAgentUIServer,@@ -53,6 +54,7 @@ function SettingsCatalogProvider({includeSchedules = false,includeEnvironments = false,getSession,+ permissions,}: {children: ReactNode;settingsEnabled?: boolean;@@ -69,12 +71,14 @@ function SettingsCatalogProvider({updatedAt: string;agentName?: string;}>;+ permissions?: PermissionsServer;}) {const server = createMockAgentUIServer({...(includeCatalog ? { catalog: createMockCatalog() } : {}),...(includeSessions ? { sessions: createMockAgentSessionsServer() } : {}),...(includeSchedules ? { schedules: createMockScheduleServer() } : {}),...(includeEnvironments ? { sandboxEnvironments: createMockSandboxEnvironmentServer() } : {}),+ ...(permissions == null ? {} : { permissions }),getCapabilities: async () => {if (capabilitiesFail) throw new Error('Unavailable');return {@@ -111,6 +115,7 @@ function Harness({includeSchedules = false,includeEnvironments = false,getSession,+ permissions,}: {agentConfig?: AgentConfig;initialRemoteId?: string;@@ -129,6 +134,7 @@ function Harness({updatedAt: string;agentName?: string;}>;+ permissions?: PermissionsServer;}) {const [remoteId, setId] = useState<string | undefined>(initialRemoteId);setRemoteId = setId;@@ -141,6 +147,7 @@ function Harness({includeSchedules={includeSchedules}includeEnvironments={includeEnvironments}getSession={getSession}+ permissions={permissions}><ShellModeProvider agentConfig={agentConfig} initialSettingsOpen={initialSettingsOpen}><CaptureShell />@@ -170,6 +177,7 @@ function renderSync(opts: {updatedAt: string;agentName?: string;}>;+ permissions?: PermissionsServer;strict?: boolean;}) {const tree = (@@ -185,6 +193,7 @@ function renderSync(opts: {includeSchedules={opts.includeSchedules}includeEnvironments={opts.includeEnvironments}getSession={opts.getSession}+ permissions={opts.permissions}/></MemoryRouter>);@@ -198,6 +207,37 @@ describe('ShellRouteSync', () => {expect(pathname).toBe('/sessions/abc');});+ it('rewrites a non-manager session deep link to the shared read-only view', async () => {+ renderSync({+ initialEntries: ['/sessions/shared-by-other'],+ permissions: {+ listPermissions: vi.fn(async (): Promise<ListPermissionsResponse> => ({+ data: { type: 'session', permissions: { 'shared-by-other': [] } },+ })),+ },+ });++ await waitFor(() => expect(shell.sharedSessionId).toBe('shared-by-other'));+ expect(shell.sessionsOpen).toBe(true);+ expect(shell.pendingSessionId).toBeUndefined();+ await waitFor(() => expect(pathname).toBe('/sessions/share/shared-by-other'));+ });++ it('keeps a manager session deep link on the live chat route', async () => {+ renderSync({+ initialEntries: ['/sessions/owned'],+ permissions: {+ listPermissions: vi.fn(async (): Promise<ListPermissionsResponse> => ({+ data: { type: 'session', permissions: { owned: ['MANAGE'] } },+ })),+ },+ });++ await waitFor(() => expect(shell.pendingSessionId).toBe('owned'));+ expect(shell.sharedSessionId).toBeNull();+ expect(pathname).toBe('/sessions/owned');+ });+it('keeps the session URL and surfaces a pane error when a deep link is forbidden', async () => {const forbidden = Object.assign(new Error('Only the session creator can access this session'), {statusCode: 403,