graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs
Python
gui: revert chat selection when the snapshot has no conversation view
Claude09decd528340
diff --git a/gui/src/app/SessionProvider.test.tsx b/gui/src/app/SessionProvider.test.tsxindex c91959ab..a0fed831 100644--- a/gui/src/app/SessionProvider.test.tsx+++ b/gui/src/app/SessionProvider.test.tsx@@ -31,6 +31,10 @@ let handoffChatImpl: (input: import("../services/desktop/types/contracts").HandoffChatInput,) => Promise<SessionSnapshot>;let openWorkspaceImpl: (workspacePath: string) => Promise<SessionSnapshot>;+let selectConversationImpl: (+ workspacePath: string,+ conversationId: string,+) => Promise<SessionSnapshot>;let renameWorkspaceImpl: (workspacePath: string,displayName: string | null,@@ -170,7 +174,7 @@ mock.module("../services/desktop/client", () => ({},selectConversation: async (workspacePath: string, conversationId: string) => {selectConversationCallCount += 1;- return createSnapshot(workspacePath, conversationId);+ return await selectConversationImpl(workspacePath, conversationId);},sendPrompt: async (input: import("../services/desktop/types/contracts").SendPromptInput,@@ -285,6 +289,10 @@ describe("SessionProvider", () => {);openWorkspaceImpl = async (workspacePath: string) =>createSnapshot(workspacePath, "chat-1");+ selectConversationImpl = async (+ workspacePath: string,+ conversationId: string,+ ) => createSnapshot(workspacePath, conversationId);renameWorkspaceImpl = async (workspacePath: string,displayName: string | null,@@ -370,6 +378,96 @@ describe("SessionProvider", () => {});});+ test("failed conversation selection restores the previous board selection", async () => {+ sessionStore.getState().setBoardSelection({+ chat: {+ conversationId: "chat-1",+ workspacePath: "/workspace/codegraff-gui",+ },+ kind: "single-chat",+ });+ selectConversationImpl = async () => {+ throw new Error("selection failed");+ };++ let capturedActions: SessionActionsContextValue | null = null;++ function CaptureActions() {+ capturedActions = useContext(SessionActionsContext);+ return null;+ }++ renderToStaticMarkup(+ <SessionProvider>+ <CaptureActions />+ </SessionProvider>,+ );++ if (capturedActions == null) {+ throw new Error("Expected session actions to be available");+ }++ const actions = capturedActions as SessionActionsContextValue;++ await actions.selectConversation("/workspace/other", "chat-9");++ expect(sessionStore.getState().selection).toEqual({+ chat: {+ conversationId: "chat-1",+ workspacePath: "/workspace/codegraff-gui",+ },+ kind: "single-chat",+ });+ });++ test("stale conversation selection snapshots restore the previous board selection", async () => {+ sessionStore.getState().setBoardSelection({+ chat: {+ conversationId: "chat-1",+ workspacePath: "/workspace/codegraff-gui",+ },+ kind: "single-chat",+ });+ selectConversationImpl = async (workspacePath, conversationId) =>+ createSnapshot(workspacePath, conversationId, {+ conversationViews: [],+ });++ let capturedActions: SessionActionsContextValue | null = null;++ function CaptureActions() {+ capturedActions = useContext(SessionActionsContext);+ return null;+ }++ renderToStaticMarkup(+ <SessionProvider>+ <CaptureActions />+ </SessionProvider>,+ );++ if (capturedActions == null) {+ throw new Error("Expected session actions to be available");+ }++ const actions = capturedActions as SessionActionsContextValue;++ await actions.selectConversation("/workspace/other", "chat-9");++ expect(sessionStore.getState().selection).toEqual({+ chat: {+ conversationId: "chat-1",+ workspacePath: "/workspace/codegraff-gui",+ },+ kind: "single-chat",+ });+ expect(+ sessionStore.getState().conversationViewsByKey[+ "/workspace/other::chat-9"+ ],+ ).toBeUndefined();+ });+test("stopPrompt targets the active binding", async () => {sessionStore.getState().setBoardSelection({chat: {diff --git a/gui/src/app/SessionProvider.tsx b/gui/src/app/SessionProvider.tsxindex 29f60997..d6971394 100644--- a/gui/src/app/SessionProvider.tsx+++ b/gui/src/app/SessionProvider.tsx@@ -40,6 +40,17 @@ import { appendAttachmentsToPrompt } from "@/components/attachments/attachmentTyimport type { SessionProviderProps } from "./types/app";import { useSessionBootstrap } from "../hooks/useSessionBootstrap";+function snapshotHasConversationView(+ snapshot: SessionSnapshot,+ binding: ChatBinding,+) {+ return snapshot.conversationViews.some(+ (view) =>+ view.workspacePath === binding.workspacePath &&+ view.conversationId === binding.conversationId,+ );+}+export function SessionProvider({ children }: SessionProviderProps) {const activeWorkspacePath = useStore(sessionStore,@@ -407,6 +418,7 @@ export function SessionProvider({ children }: SessionProviderProps) {conversationId: string,) => {const requestId = beginConversationSelectionRequest();+ const previousSelection = sessionStore.getState().selection;const binding = { conversationId, workspacePath } satisfies ChatBinding;@@ -426,9 +438,24 @@ export function SessionProvider({ children }: SessionProviderProps) {return;}+ // The harness can report the target as active without ever sending its+ // conversation view (e.g. a draft that was discarded). Selecting it+ // would leave the board pointing at an empty chat, so revert.+ if (+ snapshot.activeWorkspacePath === workspacePath &&+ snapshot.activeConversationId === conversationId &&+ !snapshotHasConversationView(snapshot, binding)+ ) {+ sessionStore.getState().setBoardSelection(previousSelection);+ return;+ }+applySessionSnapshot(snapshot);ensureWorkspaceMeta(workspacePath, { forceRuntimeStatus: true });} catch {+ if (isLatestConversationSelectionRequest(requestId)) {+ sessionStore.getState().setBoardSelection(previousSelection);+ }return;}},