graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs
Python
gui: guard chat selection rollback
Pranav P2ce75b722141
diff --git a/gui/src/app/SessionProvider.test.tsx b/gui/src/app/SessionProvider.test.tsxindex a0fed831..0f120440 100644--- a/gui/src/app/SessionProvider.test.tsx+++ b/gui/src/app/SessionProvider.test.tsx@@ -49,12 +49,14 @@ let lastStopPromptInput:function deferred<T>() {let resolve!: (value: T) => void;+ let reject!: (reason?: unknown) => void;- const promise = new Promise<T>((nextResolve) => {+ const promise = new Promise<T>((nextResolve, nextReject) => {resolve = nextResolve;+ reject = nextReject;});- return { promise, resolve };+ return { promise, reject, resolve };}function createSnapshot(@@ -420,6 +422,61 @@ describe("SessionProvider", () => {});});+ test("failed conversation selection does not overwrite newer navigation", async () => {+ sessionStore.getState().setBoardSelection({+ chat: {+ conversationId: "chat-1",+ workspacePath: "/workspace/codegraff-gui",+ },+ kind: "single-chat",+ });+ const selectionRequest = deferred<SessionSnapshot>();+ selectConversationImpl = async () => await selectionRequest.promise;++ 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;+ const selectPromise = actions.selectConversation("/workspace/other", "chat-9");++ expect(sessionStore.getState().selection).toEqual({+ chat: {+ conversationId: "chat-9",+ workspacePath: "/workspace/other",+ },+ kind: "single-chat",+ });++ await actions.startNewChat();++ expect(sessionStore.getState().selection).toEqual({+ kind: "workspace-draft",+ workspacePath: "/workspace/managed-chat",+ });++ selectionRequest.reject(new Error("selection failed"));+ await selectPromise;++ expect(sessionStore.getState().selection).toEqual({+ kind: "workspace-draft",+ workspacePath: "/workspace/managed-chat",+ });+ });+test("stale conversation selection snapshots restore the previous board selection", async () => {sessionStore.getState().setBoardSelection({chat: {diff --git a/gui/src/app/SessionProvider.tsx b/gui/src/app/SessionProvider.tsxindex d6971394..50d7d552 100644--- a/gui/src/app/SessionProvider.tsx+++ b/gui/src/app/SessionProvider.tsx@@ -17,6 +17,7 @@ import {} from "./sessionClientActions";import {beginConversationSelectionRequest,+ areSelectionsEqual,ensureConversationViewLoaded,ensureWorkspacePromptSettingsLoaded,ensureWorkspaceRuntimeStatusLoaded,@@ -421,13 +422,24 @@ export function SessionProvider({ children }: SessionProviderProps) {const previousSelection = sessionStore.getState().selection;const binding = { conversationId, workspacePath } satisfies ChatBinding;+ const optimisticSelection = {+ kind: "single-chat",+ chat: binding,+ } as const;ensureWorkspaceMeta(workspacePath);- sessionStore.getState().setBoardSelection({- kind: "single-chat",- chat: binding,- });+ sessionStore.getState().setBoardSelection(optimisticSelection);++ const revertOptimisticSelection = () => {+ const store = sessionStore.getState();+ if (+ isLatestConversationSelectionRequest(requestId) &&+ areSelectionsEqual(store.selection, optimisticSelection)+ ) {+ store.setBoardSelection(previousSelection);+ }+ };try {const snapshot = await desktopClient.selectConversation(@@ -446,16 +458,14 @@ export function SessionProvider({ children }: SessionProviderProps) {snapshot.activeConversationId === conversationId &&!snapshotHasConversationView(snapshot, binding)) {- sessionStore.getState().setBoardSelection(previousSelection);+ revertOptimisticSelection();return;}applySessionSnapshot(snapshot);ensureWorkspaceMeta(workspacePath, { forceRuntimeStatus: true });} catch {- if (isLatestConversationSelectionRequest(requestId)) {- sessionStore.getState().setBoardSelection(previousSelection);- }+ revertOptimisticSelection();return;}},diff --git a/gui/src/app/sessionStore.ts b/gui/src/app/sessionStore.tsindex d9c0a44b..e5cc941f 100644--- a/gui/src/app/sessionStore.ts+++ b/gui/src/app/sessionStore.ts@@ -235,7 +235,7 @@ function buildConversationSummariesByKey(workspaces: WorkspaceSession[]) {return byKey;}-function areSelectionsEqual(+export function areSelectionsEqual(left: WorkspaceBoardSelection,right: WorkspaceBoardSelection,): boolean {