🙌 OpenHands: AI-Driven Development
Make archived conversations read-only without loading states (#14077)
Rohit Malhotraaef5f9cc8998
diff --git a/AGENTS.md b/AGENTS.mdindex 62fd175ac1..3fca76e185 100644--- a/AGENTS.md+++ b/AGENTS.md@@ -284,6 +284,32 @@ If you are starting a pull request (PR), please follow the template in `.github/These details may or may not be useful for your current task.+### Conversation State Management++#### Agent State and Sandbox Status:+The frontend uses `useAgentState` hook (`frontend/src/hooks/use-agent-state.ts`) to determine the current conversation state. This hook:+- Returns `curAgentState` (AgentState enum) for UI state determination+- Returns `isArchived` flag when `sandbox_status === "MISSING"` (archived conversations)+- Prioritizes live WebSocket execution status over cached API data++#### Archived Conversations (sandbox_status === "MISSING"):+When a conversation's sandbox is no longer available (archived):+- `useAgentState` returns `AgentState.STOPPED` and `isArchived: true`+- Chat input is replaced with an archived banner (`ArchivedBanner` component)+- VS Code tab, Terminal, and Planner show read-only messages instead of loading states+- All interactive elements that require a running sandbox are disabled++#### Testing useAgentState:+When mocking `useAgentState` in tests, always include the `isArchived` property:+```typescript+vi.mock("#/hooks/use-agent-state", () => ({+ useAgentState: () => ({+ curAgentState: AgentState.AWAITING_USER_INPUT,+ isArchived: false,+ }),+}));+```+### MicroagentsMicroagents are specialized prompts that enhance OpenHands with domain-specific knowledge and task-specific workflows. They are Markdown files that can include frontmatter for configuration.diff --git a/frontend/__tests__/components/chat/chat-interface.test.tsx b/frontend/__tests__/components/chat/chat-interface.test.tsxindex db506e9252..ae5ef6152d 100644--- a/frontend/__tests__/components/chat/chat-interface.test.tsx+++ b/frontend/__tests__/components/chat/chat-interface.test.tsx@@ -52,7 +52,7 @@ vi.mock("#/hooks/use-conversation-name-context-menu", () => ({vi.mock("#/hooks/use-agent-state", () => ({useAgentState: vi.fn(() => ({- curAgentState: AgentState.AWAITING_USER_INPUT,+ curAgentState: AgentState.AWAITING_USER_INPUT, isArchived: false,})),}));@@ -275,7 +275,7 @@ describe("ChatInterface - Empty state", () => {describe('ChatInterface - Status Indicator', () => {it("should render ChatStatusIndicator when agent is not awaiting user input / conversation is NOT ready", () => {vi.mocked(useAgentState).mockReturnValue({- curAgentState: AgentState.LOADING,+ curAgentState: AgentState.LOADING, isArchived: false,});renderChatInterfaceWithRouter();@@ -285,7 +285,7 @@ describe('ChatInterface - Status Indicator', () => {it("should NOT render ChatStatusIndicator when agent is awaiting user input / conversation is ready", () => {vi.mocked(useAgentState).mockReturnValue({- curAgentState: AgentState.AWAITING_USER_INPUT,+ curAgentState: AgentState.AWAITING_USER_INPUT, isArchived: false,});renderChatInterfaceWithRouter();diff --git a/frontend/__tests__/components/chat/message-display-continuity.test.tsx b/frontend/__tests__/components/chat/message-display-continuity.test.tsxindex bfece0f37a..75cdd9906f 100644--- a/frontend/__tests__/components/chat/message-display-continuity.test.tsx+++ b/frontend/__tests__/components/chat/message-display-continuity.test.tsx@@ -45,7 +45,7 @@ vi.mock("#/hooks/use-conversation-name-context-menu", () => ({vi.mock("#/hooks/use-agent-state", () => ({useAgentState: vi.fn(() => ({- curAgentState: AgentState.AWAITING_USER_INPUT,+ curAgentState: AgentState.AWAITING_USER_INPUT, isArchived: false,})),}));diff --git a/frontend/__tests__/components/conversation-tab-title.test.tsx b/frontend/__tests__/components/conversation-tab-title.test.tsxindex 3b30c4f3a8..d6793c6d43 100644--- a/frontend/__tests__/components/conversation-tab-title.test.tsx+++ b/frontend/__tests__/components/conversation-tab-title.test.tsx@@ -70,6 +70,7 @@ vi.mock("#/hooks/use-runtime-is-ready", () => ({vi.mock("#/hooks/use-agent-state", () => ({useAgentState: vi.fn(() => ({curAgentState: AgentState.AWAITING_USER_INPUT,+ isArchived: false,})),}));diff --git a/frontend/__tests__/components/features/chat/change-agent-button.test.tsx b/frontend/__tests__/components/features/chat/change-agent-button.test.tsxindex b7d44d1524..c67639f872 100644--- a/frontend/__tests__/components/features/chat/change-agent-button.test.tsx+++ b/frontend/__tests__/components/features/chat/change-agent-button.test.tsx@@ -12,7 +12,7 @@ vi.mock("#/hooks/use-unified-websocket-status", () => ({// Mock agent statevi.mock("#/hooks/use-agent-state", () => ({- useAgentState: () => ({ curAgentState: "IDLE" }),+ useAgentState: () => ({ curAgentState: "IDLE", isArchived: false }),}));// Track invalidateQueries callsdiff --git a/frontend/__tests__/components/features/conversation/agent-status.test.tsx b/frontend/__tests__/components/features/conversation/agent-status.test.tsxindex 3bfb70be24..e9025495d2 100644--- a/frontend/__tests__/components/features/conversation/agent-status.test.tsx+++ b/frontend/__tests__/components/features/conversation/agent-status.test.tsx@@ -36,7 +36,7 @@ const renderAgentStatus = ({describe("AgentStatus - isLoading logic", () => {it("should show loading when curAgentState is INIT", () => {vi.mocked(useAgentState).mockReturnValue({- curAgentState: AgentState.INIT,+ curAgentState: AgentState.INIT, isArchived: false,});renderAgentStatus();@@ -46,7 +46,7 @@ describe("AgentStatus - isLoading logic", () => {it("should show loading when isPausing is true, even if shouldShownAgentLoading is false", () => {vi.mocked(useAgentState).mockReturnValue({- curAgentState: AgentState.AWAITING_USER_INPUT,+ curAgentState: AgentState.AWAITING_USER_INPUT, isArchived: false,});renderAgentStatus({ isPausing: true });@@ -56,7 +56,7 @@ describe("AgentStatus - isLoading logic", () => {it("should NOT update global shouldShownAgentLoading when only isPausing is true", () => {vi.mocked(useAgentState).mockReturnValue({- curAgentState: AgentState.AWAITING_USER_INPUT,+ curAgentState: AgentState.AWAITING_USER_INPUT, isArchived: false,});renderAgentStatus({ isPausing: true });diff --git a/frontend/__tests__/components/features/conversation/archived-conversation-view.test.tsx b/frontend/__tests__/components/features/conversation/archived-conversation-view.test.tsxnew file mode 100644index 0000000000..a4ddb7dcdd--- /dev/null+++ b/frontend/__tests__/components/features/conversation/archived-conversation-view.test.tsx@@ -0,0 +1,261 @@+import { render, screen } from "@testing-library/react";+import { describe, it, expect, vi, beforeEach } from "vitest";+import { QueryClient, QueryClientProvider } from "@tanstack/react-query";+import { MemoryRouter, Route, Routes } from "react-router";+import { I18nextProvider, initReactI18next } from "react-i18next";+import i18n from "i18next";+import { createUserMessageEvent } from "test-utils";+import { useEventStore } from "#/stores/use-event-store";+import { useConversationWebSocket } from "#/contexts/conversation-websocket-context";+import { ArchivedConversationView } from "#/components/features/conversation/archived-conversation-view";++// Initialize i18n for tests+i18n.use(initReactI18next).init({+ lng: "en",+ fallbackLng: "en",+ ns: ["translation"],+ defaultNS: "translation",+ resources: {+ en: {+ translation: {+ CONVERSATION$ARCHIVED_READ_ONLY:+ "This conversation is archived and read-only",+ CONVERSATION$NO_HISTORY_AVAILABLE: "No history available",+ },+ },+ },+ interpolation: {+ escapeValue: false,+ },+});++// Module-level mocks+vi.mock("#/contexts/conversation-websocket-context");++vi.mock("#/hooks/use-agent-state", () => ({+ useAgentState: () => ({ curAgentState: "STOPPED", isArchived: true }),+}));++vi.mock("#/hooks/query/use-active-conversation", () => ({+ useActiveConversation: () => ({+ data: { sandbox_status: "MISSING" },+ }),+}));++vi.mock("#/hooks/query/use-task-polling", () => ({+ useTaskPolling: () => ({+ isTask: false,+ taskStatus: null,+ }),+}));++vi.mock("#/hooks/mutation/use-unified-stop-conversation", () => ({+ useUnifiedPauseConversationSandbox: () => ({+ mutate: vi.fn(),+ }),+}));++vi.mock("#/hooks/mutation/use-unified-start-conversation", () => ({+ useUnifiedResumeConversationSandbox: () => ({+ mutate: vi.fn(),+ }),+}));++vi.mock("#/hooks/use-user-providers", () => ({+ useUserProviders: () => ({+ providers: [],+ }),+}));++vi.mock("#/hooks/use-conversation-name-context-menu", () => ({+ useConversationNameContextMenu: () => ({+ isOpen: false,+ contextMenuRef: { current: null },+ handleContextMenu: vi.fn(),+ handleClose: vi.fn(),+ handleRename: vi.fn(),+ handleDelete: vi.fn(),+ }),+}));++// Mock the V1 Messages component to simplify testing+vi.mock("#/components/v1/chat", () => ({+ Messages: ({ messages }: { messages: unknown[] }) => (+ <div data-testid="v1-messages">+ {messages.map((_, index) => (+ <div key={index} data-testid="v1-message-item" />+ ))}+ </div>+ ),+ shouldRenderEvent: () => true,+ hasUserEvent: () => false,+}));++const createQueryClient = () =>+ new QueryClient({+ defaultOptions: { queries: { retry: false } },+ });++const renderWithProviders = (ui: React.ReactElement) => {+ const queryClient = createQueryClient();+ return render(+ <QueryClientProvider client={queryClient}>+ <I18nextProvider i18n={i18n}>+ <MemoryRouter initialEntries={["/test-conversation-id"]}>+ <Routes>+ <Route path="/:conversationId" element={ui} />+ </Routes>+ </MemoryRouter>+ </I18nextProvider>+ </QueryClientProvider>,+ );+};++describe("ArchivedConversationView", () => {+ beforeEach(() => {+ // Reset event store before each test+ useEventStore.setState({+ events: [],+ uiEvents: [],+ });++ // Default: websocket context with no loading+ vi.mocked(useConversationWebSocket).mockReturnValue({+ isLoadingHistory: false,+ connectionState: "OPEN",+ sendMessage: vi.fn(),+ });+ });++ describe("loading state", () => {+ it("shows loading spinner when loading history and no events exist", () => {+ vi.mocked(useConversationWebSocket).mockReturnValue({+ isLoadingHistory: true,+ connectionState: "OPEN",+ sendMessage: vi.fn(),+ });++ useEventStore.setState({+ events: [],+ uiEvents: [],+ });++ renderWithProviders(<ArchivedConversationView />);++ expect(screen.getByTestId("loading-spinner")).toBeInTheDocument();+ });++ it("does not show loading spinner when events exist", () => {+ vi.mocked(useConversationWebSocket).mockReturnValue({+ isLoadingHistory: true,+ connectionState: "OPEN",+ sendMessage: vi.fn(),+ });++ const userEvent = createUserMessageEvent("evt-1");+ useEventStore.setState({+ events: [userEvent],+ uiEvents: [userEvent],+ });++ renderWithProviders(<ArchivedConversationView />);++ expect(screen.queryByTestId("loading-spinner")).not.toBeInTheDocument();+ });+ });++ describe("archived banner", () => {+ it("renders the archived banner", () => {+ renderWithProviders(<ArchivedConversationView />);++ expect(screen.getByTestId("archived-banner")).toBeInTheDocument();+ // The i18n key is rendered as-is when translations aren't fully loaded+ expect(+ screen.getByText(/ARCHIVED_READ_ONLY|This conversation is archived/i),+ ).toBeInTheDocument();+ });+ });++ describe("messages display", () => {+ it("shows empty state message when no events exist and not loading", () => {+ vi.mocked(useConversationWebSocket).mockReturnValue({+ isLoadingHistory: false,+ connectionState: "OPEN",+ sendMessage: vi.fn(),+ });++ useEventStore.setState({+ events: [],+ uiEvents: [],+ });++ renderWithProviders(<ArchivedConversationView />);++ // The i18n key is rendered as-is when translations aren't fully loaded+ expect(+ screen.getByText(/NO_HISTORY_AVAILABLE|No history available/i),+ ).toBeInTheDocument();+ });++ it("renders V1 messages when events exist", () => {+ const userEvent = createUserMessageEvent("evt-1");+ useEventStore.setState({+ events: [userEvent],+ uiEvents: [userEvent],+ });++ renderWithProviders(<ArchivedConversationView />);++ expect(screen.getByTestId("v1-messages")).toBeInTheDocument();+ expect(screen.getAllByTestId("v1-message-item")).toHaveLength(1);+ });++ it("renders multiple messages correctly", () => {+ const events = [+ createUserMessageEvent("evt-1"),+ createUserMessageEvent("evt-2"),+ createUserMessageEvent("evt-3"),+ ];+ useEventStore.setState({+ events,+ uiEvents: events,+ });++ renderWithProviders(<ArchivedConversationView />);++ expect(screen.getByTestId("v1-messages")).toBeInTheDocument();+ expect(screen.getAllByTestId("v1-message-item")).toHaveLength(3);+ });+ });++ describe("layout structure", () => {+ it("does not show loading spinner when conversation is loaded", () => {+ const userEvent = createUserMessageEvent("evt-1");+ useEventStore.setState({+ events: [userEvent],+ uiEvents: [userEvent],+ });++ renderWithProviders(<ArchivedConversationView />);++ // Should not have any loading spinner in the main view+ expect(screen.queryByTestId("loading-spinner")).not.toBeInTheDocument();+ });++ it("renders the complete layout with header and banner", () => {+ const userEvent = createUserMessageEvent("evt-1");+ useEventStore.setState({+ events: [userEvent],+ uiEvents: [userEvent],+ });++ renderWithProviders(<ArchivedConversationView />);++ // Should have archived banner+ expect(screen.getByTestId("archived-banner")).toBeInTheDocument();++ // Should have messages+ expect(screen.getByTestId("v1-messages")).toBeInTheDocument();+ });+ });+});diff --git a/frontend/__tests__/components/features/conversation/server-status.test.tsx b/frontend/__tests__/components/features/conversation/server-status.test.tsxindex f698589fa7..96392a6e00 100644--- a/frontend/__tests__/components/features/conversation/server-status.test.tsx+++ b/frontend/__tests__/components/features/conversation/server-status.test.tsx@@ -58,7 +58,7 @@ describe("ServerStatus", () => {// Helper function to mock agent state with specific stateconst mockAgentStore = (agentState: AgentState) => {vi.mocked(useAgentState).mockReturnValue({- curAgentState: agentState,+ curAgentState: agentState, isArchived: false,});};@@ -147,7 +147,7 @@ describe("ServerStatusContextMenu", () => {// Helper function to mock agent state with specific stateconst mockAgentStore = (agentState: AgentState) => {vi.mocked(useAgentState).mockReturnValue({- curAgentState: agentState,+ curAgentState: agentState, isArchived: false,});};diff --git a/frontend/__tests__/components/interactive-chat-box.test.tsx b/frontend/__tests__/components/interactive-chat-box.test.tsxindex 884217facb..795aa9a956 100644--- a/frontend/__tests__/components/interactive-chat-box.test.tsx+++ b/frontend/__tests__/components/interactive-chat-box.test.tsx@@ -57,7 +57,7 @@ describe("InteractiveChatBox", () => {const mockStores = (agentState: AgentState = AgentState.INIT) => {vi.mocked(useAgentState).mockReturnValue({- curAgentState: agentState,+ curAgentState: agentState, isArchived: false,});useConversationStore.setState({diff --git a/frontend/__tests__/components/modals/skills/skill-modal.test.tsx b/frontend/__tests__/components/modals/skills/skill-modal.test.tsxindex 2882fd90fc..19dc95ee5e 100644--- a/frontend/__tests__/components/modals/skills/skill-modal.test.tsx+++ b/frontend/__tests__/components/modals/skills/skill-modal.test.tsx@@ -61,7 +61,7 @@ describe("SkillsModal", () => {// Mock the agent state to return a ready statevi.mocked(useAgentState).mockReturnValue({- curAgentState: AgentState.AWAITING_USER_INPUT,+ curAgentState: AgentState.AWAITING_USER_INPUT, isArchived: false,});});diff --git a/frontend/__tests__/components/v1/chat/event-message-plan-preview.test.tsx b/frontend/__tests__/components/v1/chat/event-message-plan-preview.test.tsxindex 60b1dc1cee..e97acd0afe 100644--- a/frontend/__tests__/components/v1/chat/event-message-plan-preview.test.tsx+++ b/frontend/__tests__/components/v1/chat/event-message-plan-preview.test.tsx@@ -49,7 +49,7 @@ describe("EventMessage - PlanPreview rendering", () => {});// Default mock for useAgentStatevi.mocked(useAgentState).mockReturnValue({- curAgentState: AgentState.INIT,+ curAgentState: AgentState.INIT, isArchived: false,});});@@ -183,7 +183,7 @@ describe("EventMessage - PlanPreview rendering", () => {useConversationStore.setState({ planContent });vi.mocked(useAgentState).mockReturnValue({- curAgentState: AgentState.RUNNING,+ curAgentState: AgentState.RUNNING, isArchived: false,});renderWithProviders(@@ -208,7 +208,7 @@ describe("EventMessage - PlanPreview rendering", () => {useConversationStore.setState({ planContent });vi.mocked(useAgentState).mockReturnValue({- curAgentState: AgentState.RUNNING,+ curAgentState: AgentState.RUNNING, isArchived: false,});renderWithProviders(@@ -233,7 +233,7 @@ describe("EventMessage - PlanPreview rendering", () => {useConversationStore.setState({ planContent });vi.mocked(useAgentState).mockReturnValue({- curAgentState: AgentState.AWAITING_USER_INPUT,+ curAgentState: AgentState.AWAITING_USER_INPUT, isArchived: false,});renderWithProviders(@@ -258,7 +258,7 @@ describe("EventMessage - PlanPreview rendering", () => {useConversationStore.setState({ planContent });vi.mocked(useAgentState).mockReturnValue({- curAgentState: AgentState.FINISHED,+ curAgentState: AgentState.FINISHED, isArchived: false,});renderWithProviders(diff --git a/frontend/__tests__/components/v1/chat/event-message-think-action.test.tsx b/frontend/__tests__/components/v1/chat/event-message-think-action.test.tsxindex 0f8ee73383..04c2728712 100644--- a/frontend/__tests__/components/v1/chat/event-message-think-action.test.tsx+++ b/frontend/__tests__/components/v1/chat/event-message-think-action.test.tsx@@ -89,7 +89,7 @@ describe("EventMessage - ThinkAction rendering", () => {beforeEach(() => {vi.clearAllMocks();vi.mocked(useAgentState).mockReturnValue({- curAgentState: AgentState.INIT,+ curAgentState: AgentState.INIT, isArchived: false,});});diff --git a/frontend/__tests__/conversation-websocket-handler.test.tsx b/frontend/__tests__/conversation-websocket-handler.test.tsxindex 7fa7fa2791..c57c9530d5 100644--- a/frontend/__tests__/conversation-websocket-handler.test.tsx+++ b/frontend/__tests__/conversation-websocket-handler.test.tsx@@ -51,6 +51,7 @@ vi.mock("#/hooks/query/use-user-conversation", () => ({status: "RUNNING",},isLoading: false,+ isFetched: true,error: null,})),}));diff --git a/frontend/__tests__/hooks/use-runtime-is-ready.test.tsx b/frontend/__tests__/hooks/use-runtime-is-ready.test.tsxindex 7222cc8f52..ef5c1dc054 100644--- a/frontend/__tests__/hooks/use-runtime-is-ready.test.tsx+++ b/frontend/__tests__/hooks/use-runtime-is-ready.test.tsx@@ -49,7 +49,7 @@ describe("useRuntimeIsReady", () => {it("treats agent errors as not ready by default", () => {vi.mocked(useAgentState).mockReturnValue({- curAgentState: AgentState.ERROR,+ curAgentState: AgentState.ERROR, isArchived: false,});const { result } = renderHook(() => useRuntimeIsReady());@@ -59,7 +59,7 @@ describe("useRuntimeIsReady", () => {it("allows runtime-backed tabs to stay ready when the agent errors", () => {vi.mocked(useAgentState).mockReturnValue({- curAgentState: AgentState.ERROR,+ curAgentState: AgentState.ERROR, isArchived: false,});const { result } = renderHook(() =>diff --git a/frontend/__tests__/routes/changes-tab.test.tsx b/frontend/__tests__/routes/changes-tab.test.tsxindex 1cf2513d18..a39ba556f5 100644--- a/frontend/__tests__/routes/changes-tab.test.tsx+++ b/frontend/__tests__/routes/changes-tab.test.tsx@@ -39,7 +39,7 @@ describe("Changes Tab", () => {refetch: vi.fn(),});vi.mocked(useAgentState).mockReturnValue({- curAgentState: AgentState.RUNNING,+ curAgentState: AgentState.RUNNING, isArchived: false,});render(<GitChanges />, { wrapper });@@ -58,7 +58,7 @@ describe("Changes Tab", () => {refetch: vi.fn(),});vi.mocked(useAgentState).mockReturnValue({- curAgentState: AgentState.RUNNING,+ curAgentState: AgentState.RUNNING, isArchived: false,});render(<GitChanges />, { wrapper });diff --git a/frontend/__tests__/routes/planner-tab.test.tsx b/frontend/__tests__/routes/planner-tab.test.tsxindex 011f8649ed..ce98e15eac 100644--- a/frontend/__tests__/routes/planner-tab.test.tsx+++ b/frontend/__tests__/routes/planner-tab.test.tsx@@ -3,6 +3,7 @@ import { describe, expect, it, vi, beforeEach, afterEach } from "vitest";import PlannerTab from "#/routes/planner-tab";import { renderWithProviders } from "../../test-utils";import { useConversationStore } from "#/stores/conversation-store";+import { AgentState } from "#/types/agent-state";// Mock the handle plan click hookvi.mock("#/hooks/use-handle-plan-click", () => ({@@ -11,6 +12,14 @@ vi.mock("#/hooks/use-handle-plan-click", () => ({}),}));+// Mock the agent state hook+vi.mock("#/hooks/use-agent-state", () => ({+ useAgentState: () => ({+ curAgentState: AgentState.AWAITING_USER_INPUT,+ isArchived: false,+ }),+}));+describe("PlannerTab", () => {const originalRAF = global.requestAnimationFrame;diff --git a/frontend/__tests__/routes/vscode-tab.test.tsx b/frontend/__tests__/routes/vscode-tab.test.tsxindex 8c84678603..e0768ff29b 100644--- a/frontend/__tests__/routes/vscode-tab.test.tsx+++ b/frontend/__tests__/routes/vscode-tab.test.tsx@@ -34,7 +34,7 @@ describe("VSCodeTab", () => {it("keeps VSCode accessible when the agent is in an error state", () => {vi.mocked(useAgentState).mockReturnValue({- curAgentState: AgentState.ERROR,+ curAgentState: AgentState.ERROR, isArchived: false,});mockVSCodeUrlHook({});@@ -51,7 +51,7 @@ describe("VSCodeTab", () => {it("still waits while the runtime is starting", () => {vi.mocked(useAgentState).mockReturnValue({- curAgentState: AgentState.LOADING,+ curAgentState: AgentState.LOADING, isArchived: false,});mockVSCodeUrlHook({});diff --git a/frontend/src/components/features/chat/archived-banner.tsx b/frontend/src/components/features/chat/archived-banner.tsxnew file mode 100644index 0000000000..77c4e49ac4--- /dev/null+++ b/frontend/src/components/features/chat/archived-banner.tsx@@ -0,0 +1,17 @@+import { useTranslation } from "react-i18next";+import { I18nKey } from "#/i18n/declaration";++export function ArchivedBanner() {+ const { t } = useTranslation();++ return (+ <div+ data-testid="archived-banner"+ className="flex items-center justify-center px-4 py-3 rounded-lg bg-neutral-700 border border-neutral-600"+ >+ <span className="text-sm text-neutral-300">+ {t(I18nKey.CONVERSATION$ARCHIVED_READ_ONLY)}+ </span>+ </div>+ );+}diff --git a/frontend/src/components/features/chat/chat-interface.tsx b/frontend/src/components/features/chat/chat-interface.tsxindex f7cb0bcb8c..41ea72edd4 100644--- a/frontend/src/components/features/chat/chat-interface.tsx+++ b/frontend/src/components/features/chat/chat-interface.tsx@@ -35,6 +35,7 @@ import ChatStatusIndicator from "./chat-status-indicator";import { getStatusColor, getStatusText } from "#/utils/utils";import { useNewConversationCommand } from "#/hooks/mutation/use-new-conversation-command";import { I18nKey } from "#/i18n/declaration";+import { ArchivedBanner } from "./archived-banner";function getEntryPoint(hasRepository: boolean | null,@@ -78,7 +79,7 @@ export function ChatInterface() {isPending: isNewConversationPending,} = useNewConversationCommand();- const { curAgentState } = useAgentState();+ const { curAgentState, isArchived } = useAgentState();const { handleBuildPlanClick } = useHandleBuildPlanClick();// Disable Build button while agent is running (streaming)@@ -318,10 +319,14 @@ export function ChatInterface() {/>)}- <InteractiveChatBox- onSubmit={handleSendMessage}- disabled={isNewConversationPending}- />+ {isArchived && <ArchivedBanner />}++ {!isArchived && (+ <InteractiveChatBox+ onSubmit={handleSendMessage}+ disabled={isNewConversationPending}+ />+ )}</div></div></ScrollProvider>diff --git a/frontend/src/components/features/controls/agent-status.tsx b/frontend/src/components/features/controls/agent-status.tsxindex 176bffea23..a3afaefffb 100644--- a/frontend/src/components/features/controls/agent-status.tsx+++ b/frontend/src/components/features/controls/agent-status.tsx@@ -33,7 +33,7 @@ export function AgentStatus({}: AgentStatusProps) {const { t } = useTranslation();const { setShouldShownAgentLoading } = useConversationStore();- const { curAgentState, executionStatus } = useAgentState();+ const { curAgentState, executionStatus, isArchived } = useAgentState();// Trigger browser tab flash and notification sound on state changesuseAgentNotification(curAgentState);@@ -58,12 +58,14 @@ export function AgentStatus({subConversationTaskStatus,);+ // Never show loading state for archived conversations - they are read-onlyconst shouldShownAgentLoading =- curAgentState === AgentState.INIT ||- curAgentState === AgentState.LOADING ||- (webSocketStatus === "CONNECTING" && taskStatus !== "ERROR") ||- isTaskPolling(taskStatus) ||- isTaskPolling(subConversationTaskStatus);+ !isArchived &&+ (curAgentState === AgentState.INIT ||+ curAgentState === AgentState.LOADING ||+ (webSocketStatus === "CONNECTING" && taskStatus !== "ERROR") ||+ isTaskPolling(taskStatus) ||+ isTaskPolling(subConversationTaskStatus));// For UI rendering - includes pause stateconst isLoading = shouldShownAgentLoading || isPausing;diff --git a/frontend/src/components/features/conversation/archived-conversation-view.tsx b/frontend/src/components/features/conversation/archived-conversation-view.tsxnew file mode 100644index 0000000000..2c81ace1ac--- /dev/null+++ b/frontend/src/components/features/conversation/archived-conversation-view.tsx@@ -0,0 +1,75 @@+import React from "react";+import { useTranslation } from "react-i18next";+import { I18nKey } from "#/i18n/declaration";+import { Messages as V1Messages } from "#/components/v1/chat";+import { shouldRenderEvent } from "#/components/v1/chat/event-content-helpers/should-render-event";+import { LoadingSpinner } from "#/components/shared/loading-spinner";+import { handleEventForUI } from "#/utils/handle-event-for-ui";+import { OpenHandsEvent } from "#/types/v1/core";+import { useFilteredEvents } from "#/hooks/use-filtered-events";+import { useConversationWebSocket } from "#/contexts/conversation-websocket-context";+import { ArchivedBanner } from "#/components/features/chat/archived-banner";+import { ConversationNameWithStatus } from "./conversation-name-with-status";++/**+ * A simplified read-only view for archived conversations.+ * Similar to the shared conversation view, it only shows the conversation+ * events without the VS Code tab, Planner, Terminal, and other interactive elements.+ */+export function ArchivedConversationView() {+ const { t } = useTranslation();+ const conversationWebSocket = useConversationWebSocket();+ const { v1FullEvents } = useFilteredEvents();++ // Reconstruct the same UI event stream used in live conversations so+ // completed tool calls render as a single action/observation unit.+ const renderableEvents = React.useMemo(+ () =>+ v1FullEvents+ .reduce<+ OpenHandsEvent[]+ >((uiEvents, event) => handleEventForUI(event, uiEvents), [])+ .filter(shouldRenderEvent),+ [v1FullEvents],+ );++ const isLoading =+ v1FullEvents.length === 0 && conversationWebSocket?.isLoadingHistory;++ if (isLoading) {+ return (+ <div className="flex items-center justify-center h-full">+ <LoadingSpinner size="large" />+ </div>+ );+ }++ return (+ <div className="h-full flex flex-col">+ {/* Header with conversation name */}+ <div className="p-3 md:p-0 pt-2 lg:pt-0">+ <ConversationNameWithStatus />+ </div>++ {/* Archived banner */}+ <div className="px-3 md:px-0 py-2">+ <ArchivedBanner />+ </div>++ {/* Chat panel - read-only */}+ <div className="flex-1 overflow-y-auto custom-scrollbar-always px-3 md:px-0">+ <div className="h-full bg-base rounded-xl border border-tertiary p-4">+ {renderableEvents.length > 0 ? (+ <V1Messages messages={renderableEvents} allEvents={v1FullEvents} />+ ) : (+ <div className="flex items-center justify-center h-full">+ <div className="text-center text-neutral-400 py-8">+ {t(I18nKey.CONVERSATION$NO_HISTORY_AVAILABLE)}+ </div>+ </div>+ )}+ </div>+ </div>+ </div>+ );+}diff --git a/frontend/src/components/features/terminal/terminal.tsx b/frontend/src/components/features/terminal/terminal.tsxindex 33c884ecd3..272dd1f2fa 100644--- a/frontend/src/components/features/terminal/terminal.tsx+++ b/frontend/src/components/features/terminal/terminal.tsx@@ -1,27 +1,41 @@+import { useTranslation } from "react-i18next";import { useTerminal } from "#/hooks/use-terminal";import "@xterm/xterm/css/xterm.css";import { RUNTIME_INACTIVE_STATES } from "#/types/agent-state";import { cn } from "#/utils/utils";import { WaitingForRuntimeMessage } from "../chat/waiting-for-runtime-message";import { useAgentState } from "#/hooks/use-agent-state";+import { I18nKey } from "#/i18n/declaration";function Terminal() {- const { curAgentState } = useAgentState();+ const { t } = useTranslation();+ const { curAgentState, isArchived } = useAgentState();- const isRuntimeInactive = RUNTIME_INACTIVE_STATES.includes(curAgentState);+ // Don't show runtime inactive state for archived conversations+ const isRuntimeInactive =+ !isArchived && RUNTIME_INACTIVE_STATES.includes(curAgentState);const ref = useTerminal();return (<div className="h-full flex flex-col rounded-xl">- {isRuntimeInactive && <WaitingForRuntimeMessage className="pt-16" />}+ {isArchived && (+ <div className="w-full h-full flex items-center text-center justify-center text-2xl text-tertiary-light pt-16">+ {t(I18nKey.CONVERSATION$ARCHIVED_READ_ONLY)}+ </div>+ )}+ {!isArchived && isRuntimeInactive && (+ <WaitingForRuntimeMessage className="pt-16" />+ )}<div className="flex-1 min-h-0 p-4"><divref={ref}className={cn("w-full h-full",- isRuntimeInactive ? "p-0 w-0 h-0 opacity-0 overflow-hidden" : "",+ isRuntimeInactive || isArchived+ ? "p-0 w-0 h-0 opacity-0 overflow-hidden"+ : "",)}/></div>diff --git a/frontend/src/contexts/conversation-websocket-context.tsx b/frontend/src/contexts/conversation-websocket-context.tsxindex 59aa241fc3..d924693666 100644--- a/frontend/src/contexts/conversation-websocket-context.tsx+++ b/frontend/src/contexts/conversation-websocket-context.tsx@@ -337,20 +337,29 @@ export function ConversationWebSocketProvider({latestPlanningFileEventRef.current = null;}, [conversationId]);- const { data: preloadedEvents } = useConversationHistory(conversationId);+ const { data: preloadedEvents, isFetched: isHistoryFetched } =+ useConversationHistory(conversationId);useEffect(() => {+ // Don't do anything until the history query has completed+ // This prevents prematurely setting loading to false before data is available+ if (!isHistoryFetched) {+ return;+ }++ // If no events (empty conversation or query returned empty), just stop loadingif (!preloadedEvents || preloadedEvents.length === 0) {setIsLoadingHistoryMain(false);return;}+ // Add all preloaded events to the storefor (const event of preloadedEvents) {addEvent(event);}setIsLoadingHistoryMain(false);- }, [preloadedEvents, addEvent]);+ }, [preloadedEvents, isHistoryFetched, addEvent]);// Separate message handlers for each connectionconst handleMainMessage = useCallback(diff --git a/frontend/src/hooks/query/use-conversation-history.ts b/frontend/src/hooks/query/use-conversation-history.tsindex 07bda24b29..95cafabf9d 100644--- a/frontend/src/hooks/query/use-conversation-history.ts+++ b/frontend/src/hooks/query/use-conversation-history.ts@@ -3,9 +3,16 @@ import EventService from "#/api/event-service/event-service.api";import { useUserConversation } from "#/hooks/query/use-user-conversation";export const useConversationHistory = (conversationId?: string) => {- const { data: conversation } = useUserConversation(conversationId ?? null);+ const { data: conversation, isFetched: isConversationFetched } =+ useUserConversation(conversationId ?? null);- return useQuery({+ const {+ data,+ isFetched: isQueryFetched,+ isLoading,+ isError,+ error,+ } = useQuery({queryKey: ["conversation-history", conversationId],enabled: !!conversationId && !!conversation,queryFn: async () => {@@ -16,4 +23,15 @@ export const useConversationHistory = (conversationId?: string) => {staleTime: Infinity,gcTime: 30 * 60 * 1000, // 30 minutes — survive navigation away and back (AC5)});++ return {+ data,+ isLoading,+ isError,+ error,+ // Query is considered fetched when:+ // 1. Conversation data is fetched AND history query has run, OR+ // 2. Conversation doesn't exist (isConversationFetched && !conversation)+ isFetched: isQueryFetched || (isConversationFetched && !conversation),+ };};diff --git a/frontend/src/hooks/use-agent-state.test.tsx b/frontend/src/hooks/use-agent-state.test.tsxindex 056d1742a8..df25d9215e 100644--- a/frontend/src/hooks/use-agent-state.test.tsx+++ b/frontend/src/hooks/use-agent-state.test.tsx@@ -27,6 +27,7 @@ describe("useAgentState", () => {mockUseActiveConversation.mockReturnValue({data: {execution_status: V1ExecutionStatus.FINISHED,+ sandbox_status: "RUNNING",},} as ReturnType<typeof useActiveConversation>);@@ -40,12 +41,14 @@ describe("useAgentState", () => {expect(result.current.executionStatus).toBe(V1ExecutionStatus.RUNNING);expect(result.current.curAgentState).toBe(AgentState.RUNNING);+ expect(result.current.isArchived).toBe(false);});it("falls back to cached conversation execution status when live state is empty", () => {mockUseActiveConversation.mockReturnValue({data: {execution_status: V1ExecutionStatus.WAITING_FOR_CONFIRMATION,+ sandbox_status: "RUNNING",},} as ReturnType<typeof useActiveConversation>);@@ -57,5 +60,42 @@ describe("useAgentState", () => {expect(result.current.curAgentState).toBe(AgentState.AWAITING_USER_CONFIRMATION,);+ expect(result.current.isArchived).toBe(false);+ });++ it("returns STOPPED state and isArchived=true for archived conversations (sandbox MISSING)", () => {+ mockUseActiveConversation.mockReturnValue({+ data: {+ execution_status: V1ExecutionStatus.FINISHED,+ sandbox_status: "MISSING",+ },+ } as ReturnType<typeof useActiveConversation>);++ const { result } = renderHook(() => useAgentState());++ expect(result.current.curAgentState).toBe(AgentState.STOPPED);+ expect(result.current.isArchived).toBe(true);+ });++ it("returns STOPPED state for archived conversations even with live execution status", () => {+ mockUseActiveConversation.mockReturnValue({+ data: {+ execution_status: V1ExecutionStatus.IDLE,+ sandbox_status: "MISSING",+ },+ } as ReturnType<typeof useActiveConversation>);++ // Simulate live websocket status (shouldn't happen for archived, but test the priority)+ act(() => {+ useV1ConversationStateStore+ .getState()+ .setExecutionStatus(V1ExecutionStatus.RUNNING);+ });++ const { result } = renderHook(() => useAgentState());++ // sandbox_status === MISSING should take priority+ expect(result.current.curAgentState).toBe(AgentState.STOPPED);+ expect(result.current.isArchived).toBe(true);});});diff --git a/frontend/src/hooks/use-agent-state.ts b/frontend/src/hooks/use-agent-state.tsindex d29695ed50..386b06d008 100644--- a/frontend/src/hooks/use-agent-state.ts+++ b/frontend/src/hooks/use-agent-state.ts@@ -3,11 +3,21 @@ import { useActiveConversation } from "#/hooks/query/use-active-conversation";import { useV1ConversationStateStore } from "#/stores/v1-conversation-state-store";import { AgentState } from "#/types/agent-state";import { V1ExecutionStatus } from "#/types/v1/core/base/common";+import { V1SandboxStatus } from "#/api/sandbox-service/sandbox-service.types";/*** Maps V1 agent status to V0 AgentState*/-function mapV1StatusToV0State(status: V1ExecutionStatus | null): AgentState {+function mapV1StatusToV0State(+ status: V1ExecutionStatus | null,+ sandboxStatus: V1SandboxStatus | undefined,+): AgentState {+ // For archived conversations (sandbox MISSING), return STOPPED to avoid loading states+ // The conversation is read-only and won't resume, so we should not show "starting" indicators+ if (sandboxStatus === "MISSING") {+ return AgentState.STOPPED;+ }+if (!status) {return AgentState.LOADING;}@@ -35,25 +45,30 @@ function mapV1StatusToV0State(status: V1ExecutionStatus | null): AgentState {export interface UseAgentStateResult {curAgentState: AgentState;executionStatus?: V1ExecutionStatus | null;+ isArchived: boolean;}/*** Unified hook that returns the current agent state* - For V0 conversations: Returns state from useAgentStore* - For V1 conversations: Returns mapped state from useV1ConversationStateStore+ * - For archived conversations (sandbox MISSING): Returns STOPPED state*/export function useAgentState(): UseAgentStateResult {const liveExecutionStatus = useV1ConversationStateStore((state) => state.execution_status,);- const fallbackExecutionStatus =- useActiveConversation().data?.execution_status ?? null;+ const conversation = useActiveConversation().data;+ const fallbackExecutionStatus = conversation?.execution_status ?? null;+ const sandboxStatus = conversation?.sandbox_status;const executionStatus = liveExecutionStatus ?? fallbackExecutionStatus;+ const isArchived = sandboxStatus === "MISSING";+const curAgentState = useMemo(- () => mapV1StatusToV0State(executionStatus),- [executionStatus],+ () => mapV1StatusToV0State(executionStatus, sandboxStatus),+ [executionStatus, sandboxStatus],);- return { curAgentState, executionStatus };+ return { curAgentState, executionStatus, isArchived };}diff --git a/frontend/src/i18n/declaration.ts b/frontend/src/i18n/declaration.tsindex 3d7c35dd32..a04ffbba1c 100644--- a/frontend/src/i18n/declaration.ts+++ b/frontend/src/i18n/declaration.ts@@ -1330,6 +1330,7 @@ export enum I18nKey {CONVERSATION$CLEAR_FAILED = "CONVERSATION$CLEAR_FAILED",CONVERSATION$CLEAR_SUCCESS = "CONVERSATION$CLEAR_SUCCESS",CONVERSATION$CLEARING = "CONVERSATION$CLEARING",+ CONVERSATION$ARCHIVED_READ_ONLY = "CONVERSATION$ARCHIVED_READ_ONLY",CTA$ENTERPRISE = "CTA$ENTERPRISE",CTA$ENTERPRISE_DEPLOY = "CTA$ENTERPRISE_DEPLOY",CTA$FEATURE_ON_PREMISES = "CTA$FEATURE_ON_PREMISES",diff --git a/frontend/src/i18n/translation.json b/frontend/src/i18n/translation.jsonindex 2b12a0a4e7..372c4c54cb 100644--- a/frontend/src/i18n/translation.json+++ b/frontend/src/i18n/translation.json@@ -22609,6 +22609,23 @@"uk": "Створення нової розмови...","ca": "S'està creant una nova conversa..."},+ "CONVERSATION$ARCHIVED_READ_ONLY": {+ "en": "This conversation is archived and read-only",+ "ja": "この会話はアーカイブされており、読み取り専用です",+ "zh-CN": "此对话已归档,只读",+ "zh-TW": "此對話已歸檔,只讀",+ "ko-KR": "이 대화는 보관되었으며 읽기 전용입니다",+ "no": "Denne samtalen er arkivert og skrivebeskyttet",+ "it": "Questa conversazione è archiviata e di sola lettura",+ "pt": "Esta conversa está arquivada e é somente leitura",+ "es": "Esta conversación está archivada y es de solo lectura",+ "ar": "هذه المحادثة مؤرشفة وللقراءة فقط",+ "fr": "Cette conversation est archivée et en lecture seule",+ "tr": "Bu konuşma arşivlenmiş ve salt okunurdur",+ "de": "Diese Konversation ist archiviert und schreibgeschützt",+ "uk": "Ця розмова заархівована та доступна лише для читання",+ "ca": "Aquesta conversa està arxivada i és de només lectura"+ },"CTA$ENTERPRISE": {"en": "Enterprise","ja": "エンタープライズ",diff --git a/frontend/src/routes/conversation.tsx b/frontend/src/routes/conversation.tsxindex 27fbdff054..b5f3601ad9 100644--- a/frontend/src/routes/conversation.tsx+++ b/frontend/src/routes/conversation.tsx@@ -20,6 +20,7 @@ import { ConversationSubscriptionsProvider } from "#/context/conversation-subscrimport { ConversationMain } from "#/components/features/conversation/conversation-main/conversation-main";import { ConversationNameWithStatus } from "#/components/features/conversation/conversation-name-with-status";+import { ArchivedConversationView } from "#/components/features/conversation/archived-conversation-view";import { ConversationTabs } from "#/components/features/conversation/conversation-tabs/conversation-tabs";import { WebSocketProviderWrapper } from "#/contexts/websocket-provider-wrapper";@@ -90,6 +91,25 @@ function AppContent() {}}, [conversation, isFetched, isAuthed, navigate, t]);+ // Check if this is an archived conversation (sandbox no longer exists)+ const isArchived = conversation?.sandbox_status === "MISSING";++ // For archived conversations, show a simplified read-only view+ // similar to the shared conversation view+ if (isArchived) {+ return (+ <WebSocketProviderWrapper conversationId={conversationId}>+ <ConversationSubscriptionsProvider>+ <EventHandler>+ <div data-testid="app-route" className="flex flex-col h-full gap-3">+ <ArchivedConversationView />+ </div>+ </EventHandler>+ </ConversationSubscriptionsProvider>+ </WebSocketProviderWrapper>+ );+ }+const content = (<ConversationSubscriptionsProvider><EventHandler>diff --git a/frontend/src/routes/planner-tab.tsx b/frontend/src/routes/planner-tab.tsxindex 3355971136..5f27dc4d72 100644--- a/frontend/src/routes/planner-tab.tsx+++ b/frontend/src/routes/planner-tab.tsx@@ -8,6 +8,7 @@ import { MarkdownRenderer } from "#/components/features/markdown/markdown-renderimport { planComponents } from "#/components/features/markdown/plan-components";import { useHandlePlanClick } from "#/hooks/use-handle-plan-click";import { cn } from "#/utils/utils";+import { useAgentState } from "#/hooks/use-agent-state";function PlannerTab() {const { t } = useTranslation();@@ -20,6 +21,7 @@ function PlannerTab() {} = useScrollToBottom(scrollRef);const { planContent, conversationMode } = useConversationStore();+ const { isArchived } = useAgentState();// Auto-scroll to bottom when plan content changesReact.useEffect(() => {@@ -30,6 +32,9 @@ function PlannerTab() {const isPlanMode = conversationMode === "plan";const { handlePlanClick } = useHandlePlanClick();+ // Disable button for archived conversations or when already in plan mode+ const isButtonDisabled = isPlanMode || isArchived;+if (planContent !== null && planContent !== undefined) {return (<div@@ -53,10 +58,10 @@ function PlannerTab() {<buttontype="button"onClick={handlePlanClick}- disabled={isPlanMode}+ disabled={isButtonDisabled}className={cn("flex w-[164px] h-[40px] p-2 justify-center items-center shrink-0 rounded-lg bg-white overflow-hidden text-black text-ellipsis font-sans text-[16px] not-italic font-normal leading-[20px]",- isPlanMode+ isButtonDisabled? "opacity-50 cursor-not-allowed": "hover:cursor-pointer hover:opacity-80",)}diff --git a/frontend/src/routes/vscode-tab.tsx b/frontend/src/routes/vscode-tab.tsxindex fe60a52dac..7edb546aa2 100644--- a/frontend/src/routes/vscode-tab.tsx+++ b/frontend/src/routes/vscode-tab.tsx@@ -10,8 +10,10 @@ import { WaitingForRuntimeMessage } from "#/components/features/chat/waiting-forfunction VSCodeTab() {const { t } = useTranslation();const { data, isLoading, error } = useUnifiedVSCodeUrl();- const { curAgentState } = useAgentState();- const isRuntimeStarting = RUNTIME_STARTING_STATES.includes(curAgentState);+ const { curAgentState, isArchived } = useAgentState();+ // Don't show starting state for archived conversations+ const isRuntimeStarting =+ !isArchived && RUNTIME_STARTING_STATES.includes(curAgentState);const iframeRef = React.useRef<HTMLIFrameElement>(null);const [isCrossProtocol, setIsCrossProtocol] = useState(false);const [iframeError, setIframeError] = useState<string | null>(null);@@ -39,6 +41,15 @@ function VSCodeTab() {}};+ // For archived conversations, show the archived message instead of loading+ if (isArchived) {+ return (+ <div className="w-full h-full flex items-center text-center justify-center text-2xl text-tertiary-light">+ {t(I18nKey.CONVERSATION$ARCHIVED_READ_ONLY)}+ </div>+ );+ }+if (isRuntimeStarting) {return <WaitingForRuntimeMessage />;}