clawwork-ai / clawwork-ai/ClawWork

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

Open
#404 2 comments 0 reactions 0 assignees View on GitHub
area/core area/ui kind/bug
Dominant language
TypeScript
Stars
532
Forks
75
Avg merge
5h 31m
Merged PRs (30d)
1

Description

## 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`

```typescript
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)

Contributor guide

Open the contributing guide

Research direction

Start in packages/desktop/src/renderer/layouts/Settings/sections/SystemSection.tsx at handleChangeWorkspace, then inspect changeWorkspace, reinitDatabase, the Zustand stores, and the bootstrap flow. Run pnpm check and manually switch to a workspace with a different task list; done means the UI refreshes in place or clearly prompts the user to restart.

Written by the indexing model from the issue text.

Assessment

Tech stack
electron, react, sqlite, typescript
Domain
databases, desktop, frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.