Skip to content

[Bug] changeWorkspace does not refresh renderer stores, leaving UI with stale data #404

@samzong

Description

@samzong

Problem

After SystemSection.handleChangeWorkspace successfully changes the workspace, it updates workspacePath in local state and shows a toast, but the renderer's Zustand stores (task store, message store, agent catalog, etc.) still contain data from the old workspace. The main process has already called reinitDatabase(newPath) and is reading from a different SQLite file, so the renderer's cached task list, messages, and artifacts no longer correspond to anything in the new DB. Users have to manually refresh or relaunch to see the real contents of the new workspace — and the UI gives them no hint that this is needed.

Location

File: packages/desktop/src/renderer/layouts/Settings/sections/SystemSection.tsx:62-78

const handleChangeWorkspace = useCallback(async () => {
  const selected = await window.clawwork.browseWorkspace();
  if (!selected || selected === workspacePath) return;
  const oldPath = workspacePath;
  setChangingWorkspace(true);
  const result = await window.clawwork.changeWorkspace(selected);
  setChangingWorkspace(false);
  if (result.ok) {
    setWorkspacePath(selected);
    toast.success(t('settings.workspaceChanged'), {
      description: t('settings.workspaceOldPathHint', { path: oldPath }),
      duration: 8000,
    });
  }
  // ...
}, [workspacePath, t]);

Fix Approach

Pick one of, in order of increasing invasiveness:

  1. Minimum: change the success toast to clearly state that a restart is required to view the new workspace, and add an "Action: Restart" button that calls window.clawwork.relaunch() (if such an IPC exists, otherwise offer a manual-restart explanation).
  2. Better: emit an IPC event from the main process (e.g. workspace:changed) that the renderer subscribes to; on receipt, clear all Zustand stores and re-run the bootstrap flow.
  3. Best: combine both — cleanly re-hydrate in place, but also toast with a subtle "restart if you see stale data" escape hatch for edge cases.

Verification

  1. Run pnpm check — must pass.
  2. Manual: change workspace to a directory that already has a different task list; confirm either the task list refreshes in place, or the UI clearly prompts the user to restart.

Context

  • WG: UI & Design System (also touches Task & Session Core)
  • Priority: Low
  • Estimated effort: 30-45 minutes (if going for option 2)

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/coreTask & Session Core WGarea/uiUI & Design System WGhelp wantedExtra attention is neededkind/bugCategorizes issue or PR as related to a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions