fix: resolve workspace teardown race with persistence fence

This commit is contained in:
Hibryda 2026-03-08 20:54:43 +01:00
parent a69022756a
commit dba6a88a28
5 changed files with 39 additions and 10 deletions

View file

@ -1,6 +1,7 @@
import { loadGroups, saveGroups, getCliGroup } from '../adapters/groups-bridge';
import type { GroupsFile, GroupConfig, ProjectConfig } from '../types/groups';
import { clearAllAgentSessions } from '../stores/agents.svelte';
import { waitForPendingPersistence } from '../agent-dispatcher';
export type WorkspaceTab = 'sessions' | 'docs' | 'context' | 'settings';
@ -69,6 +70,9 @@ export function setActiveProject(projectId: string | null): void {
export async function switchGroup(groupId: string): Promise<void> {
if (groupId === activeGroupId) return;
// Wait for any in-flight persistence before clearing state
await waitForPendingPersistence();
// Teardown: clear terminal tabs and agent sessions for the old group
projectTerminals = {};
clearAllAgentSessions();

View file

@ -30,6 +30,10 @@ vi.mock('../stores/agents.svelte', () => ({
clearAllAgentSessions: vi.fn(),
}));
vi.mock('../agent-dispatcher', () => ({
waitForPendingPersistence: vi.fn().mockResolvedValue(undefined),
}));
vi.mock('../adapters/groups-bridge', () => ({
loadGroups: vi.fn().mockImplementation(() => Promise.resolve(mockGroupsData())),
saveGroups: vi.fn().mockResolvedValue(undefined),