Skip to content

Open-source AI teammates in Slack, Teams, Discord, Telegram and Mattermost. Self-host it, with any agent harness and any model.

fix(console): treat only the agent DELETE's 404 as already deleted

raullopez-sandbox4da5d94f6b93
diff --git a/console/apps/switch-console-desktop/src/main/core/agents/deleteAgent.test.ts b/console/apps/switch-console-desktop/src/main/core/agents/deleteAgent.test.ts
index d804da2a9..f36c77d61 100644
--- a/console/apps/switch-console-desktop/src/main/core/agents/deleteAgent.test.ts
+++ b/console/apps/switch-console-desktop/src/main/core/agents/deleteAgent.test.ts
@@ -92,8 +92,9 @@ vi.mock('@main/core/switch-servers/gateway-client', () => ({
},
}));
vi.mock('@main/core/workspaces/workspace-session', () => ({
- withWorkspaceSession: (_workspaceId: string, fn: (server: { id: string }) => unknown) =>
- fn({ id: 'srv-1' }),
+ withWorkspaceSession: vi.fn((_workspaceId: string, fn: (server: { id: string }) => unknown) =>
+ fn({ id: 'srv-1' })
+ ),
}));
vi.mock('@main/core/view-state/view-state-service', () => ({
viewStateService: { del: vi.fn(async () => {}) },
@@ -123,6 +124,7 @@ const { stopSharedAgentSessions } = await import('./stop-shared-agent-sessions')
const { deleteAgent: gatewayDeleteAgent, GatewayError } =
await import('@main/core/switch-servers/gateway-client');
const { forgetManagedAgent } = await import('@main/core/agent-migration/managed-agents-store');
+const { withWorkspaceSession } = await import('@main/core/workspaces/workspace-session');
const CREDS = JSON.stringify({
env: { SWITCH_API_ENDPOINT: 'https://s', SWITCH_API_TOKEN: 'tok-123', SWITCH_AGENT_ID: 'sw-1' },
@@ -523,6 +525,18 @@ describe('deleteAgent', () => {
expect(await h.state.fs.exists('.claude/switch-subagents/cc-hoot.settings.json')).toBe(false);
});
+ it('does not take a 404 from reaching the workspace for the agent being gone', async () => {
+ vi.mocked(withWorkspaceSession).mockRejectedValueOnce(
+ new GatewayError('http', '404 Not Found', 404)
+ );
+ await expect(deleteAgent('agent-1', full)).rejects.toThrow('404');
+
+ expect(gatewayDeleteAgent).not.toHaveBeenCalled();
+ expect(autoSessionWatcher.stopForAgent).not.toHaveBeenCalled();
+ expect(h.deleteRow).not.toHaveBeenCalled();
+ expect(await h.state.fs.exists('.claude/switch-subagents/cc-hoot.settings.json')).toBe(true);
+ });
+
it('surfaces any other refusal and leaves the agent, and its controller, untouched', async () => {
vi.mocked(gatewayDeleteAgent).mockRejectedValue(
new GatewayError('http', '500 Internal Server Error', 500)
diff --git a/console/apps/switch-console-desktop/src/main/core/agents/deleteAgent.ts b/console/apps/switch-console-desktop/src/main/core/agents/deleteAgent.ts
index b11cdf6f8..c848a6054 100644
--- a/console/apps/switch-console-desktop/src/main/core/agents/deleteAgent.ts
+++ b/console/apps/switch-console-desktop/src/main/core/agents/deleteAgent.ts
@@ -107,19 +107,21 @@ async function deleteAgentInSwitch(agent: Agent): Promise<void> {
);
}
- try {
- await withWorkspaceSession(workspaceId, (server) => gatewayDeleteAgent(server, switchAgentId));
- } catch (error) {
- // Already gone on the server (an old identity, or a server since reset): the
- // local delete still has to happen, or the agent can never be removed.
- if (!(error instanceof GatewayError && error.kind === 'http' && error.status === 404)) {
- throw error;
+ await withWorkspaceSession(workspaceId, async (server) => {
+ try {
+ await gatewayDeleteAgent(server, switchAgentId);
+ } catch (error) {
+ // Already gone on the server (an old identity, or a server since reset): the
+ // local delete still has to happen, or the agent can never be removed.
+ if (!(error instanceof GatewayError && error.kind === 'http' && error.status === 404)) {
+ throw error;
+ }
+ log.warn('deleteAgent: the Switch identity was already gone', {
+ agentId: agent.id,
+ switchAgentId,
+ });
}
- log.warn('deleteAgent: the Switch identity was already gone', {
- agentId: agent.id,
- switchAgentId,
- });
- }
+ });
}
/**