Skip to content

armgit / Orkas

Public Imported from GitHub
0

Orkas is an open-source (MIT), local-first AI team for your desktop: a Commander turns your goal into to-dos and coordinates 16 built-in specialist agents plus Claude Code, Codex, OpenCode, OpenClaw and Hermes, with projects, scheduled automations and connectors. Free app for macOS & Windows; built-in models or your own keys.

fix(renderer): restore local workspace and cleanup diagnostics

wyt58a82ccc6c6f
diff --git a/src/renderer/modules/task-cleanup.js b/src/renderer/modules/task-cleanup.js
index 5c25118b..beb9f53c 100644
--- a/src/renderer/modules/task-cleanup.js
+++ b/src/renderer/modules/task-cleanup.js
@@ -193,7 +193,7 @@
async function run(retry = false) {
if (busy || loading || owner !== user() || (!retry && !confirming)) return;
busy = true; confirming = false; stopped = false; error = false;
- const operationOwner = owner, retryIds = failed.slice(); failed = [];
+ const operationOwner = owner, startedAt = Date.now(), retryIds = failed.slice(); failed = [];
result = { deleted: 0, skipped: 0, failed: 0, done: 0, total: retry ? retryIds.length : selectedCount() }; render();
try {
let next = 0;
@@ -222,6 +222,11 @@
} catch (_) { error = true; }
finally {
busy = false;
+ if (typeof _logConversationManageResult === 'function') {
+ const failedOperation = error || result.failed;
+ _logConversationManageResult('delete', startedAt, failedOperation ? 'failure' : 'success',
+ failedOperation ? 'delete_failed' : '');
+ }
if (operationOwner === user()) {
window.initRecycleBin?.();
if (typeof loadConversations === 'function') try { await loadConversations({ fresh: true }); } catch (_) { log.warn('cleanup navigation refresh failed'); }
diff --git a/src/renderer/modules/user-workspace.js b/src/renderer/modules/user-workspace.js
index 40eb10ec..a47a9aa1 100644
--- a/src/renderer/modules/user-workspace.js
+++ b/src/renderer/modules/user-workspace.js
@@ -156,6 +156,12 @@ async function _selectAndSetWorkspace(target, dirPath) {
if (!selectedPath) {
const dirResult = await window.orkas.invoke('workspace.selectDirectory', {});
if (!dirResult || dirResult.ok === false) {
+ _wsLog.warn('workspace change failed', {
+ action: 'select',
+ surface: target === 'new-chat' ? 'new_chat'
+ : (target === 'conversation' || target === 'project' ? target : 'unknown'),
+ error_code: 'picker_failed',
+ });
_showWorkspaceSetFailure(t('workspace.set_failed'));
return;
}
diff --git a/test/renderer/task-cleanup.test.ts b/test/renderer/task-cleanup.test.ts
index ab0a9f91..146afccd 100644
--- a/test/renderer/task-cleanup.test.ts
+++ b/test/renderer/task-cleanup.test.ts
@@ -1,10 +1,17 @@
import { readFileSync } from 'node:fs';
import { resolve } from 'node:path';
import vm from 'node:vm';
+import ts from 'typescript';
import { describe, expect, it, vi } from 'vitest';
import { LOCALES } from '../../src/main/i18n';
import { conversationRemovalSource } from './conversation-cache-test-source';
+const conversationSource = readFileSync(resolve(__dirname, '../../src/renderer/modules/conversation.js'), 'utf8');
+const parsedConversation = ts.createSourceFile('conversation.js', conversationSource, ts.ScriptTarget.Latest, true, ts.ScriptKind.JS);
+const manageResultSource = parsedConversation.statements.filter(node =>
+ ts.isFunctionDeclaration(node) && node.name?.text === '_logConversationManageResult')
+ .map(node => node.getText(parsedConversation)).join('\n');
+
function harness() {
const listeners: Record<string, any> = {};
const back = { hidden: true, addEventListener: (_type: string, fn: any) => { listeners.back = fn; } };
@@ -17,8 +24,9 @@ function harness() {
: { ok: true, status: 'deleted' });
const store = new Map<string, string>();
const refresh = vi.fn(); const forgot = vi.fn();
+ const manageLog = { info: vi.fn(), warn: vi.fn() };
const messages = JSON.parse(readFileSync(resolve(__dirname, '../../src/renderer/locales/en.json'), 'utf8'));
- const scope: any = { currentUserId: 'u1', currentCid: '', conversations: [], currentView: 'settings',
+ const scope: any = { _convLog: manageLog, currentUserId: 'u1', currentCid: '', conversations: [], currentView: 'settings',
window: { orkas: { invoke }, TaskUnread: { list: () => [], isUnread: () => false },
addEventListener() {}, initRecycleBin: refresh },
document: { getElementById: (id: string) => id === 'settings-task-cleanup-body' ? body : id === 'chat-cleanup-back' ? back : {},
@@ -35,12 +43,12 @@ function harness() {
let _conversationRemovalRenderPending = false;
const _conversationProjectPages = new Map();
const _unprojectedConversationPage = { total: 0, nextOffset: null };
- ${conversationRemovalSource}\n` + readFileSync(resolve(__dirname, '../../src/renderer/modules/task-cleanup.js'), 'utf8'), scope);
+ ${conversationRemovalSource}\n${manageResultSource}\n` + readFileSync(resolve(__dirname, '../../src/renderer/modules/task-cleanup.js'), 'utf8'), scope);
const click = async (action: string, projectId = '') => listeners.click({ preventDefault: vi.fn(), target: { closest: () => ({ dataset: { cleanupAction: action, cleanupOwner: projectId } }) } });
const check = async (cid: string | null, checked: boolean, projectId = '') => listeners.change({ target: {
checked, getAttribute: (name: string) => name === 'data-cleanup-cid' ? cid : name === 'data-cleanup-project' ? projectId : null, hasAttribute: (name: string) => name === 'data-cleanup-all' && !cid && !projectId,
} });
- return { scope, body, back, invoke, store, picker, refresh, forgot, click, check,
+ return { scope, body, back, invoke, store, picker, refresh, forgot, click, check, manageLog,
show: () => scope.window.initTaskCleanup() };
}
describe('inline history cleanup', () => {
@@ -128,6 +136,46 @@ describe('inline history cleanup', () => {
await h.click('confirm');
expect(h.invoke.mock.calls.filter(([c]) => c.endsWith('remove')).map(([, p]: any) => p.cid)).toEqual(['one']);
});
+ it('logs the aggregate failure while preserving partial success and retry ownership', async () => {
+ const h = harness(); const original = h.invoke.getMockImplementation()!;
+ let fail = true;
+ h.invoke.mockImplementation(async (channel, payload) => {
+ if (channel.endsWith('remove') && payload.cid === 'two' && fail) throw new Error('synthetic-private-cleanup-marker');
+ return original(channel, payload);
+ });
+ await h.show(); await h.check(null, true); await h.click('prepare'); await h.click('confirm');
+ expect(h.body.innerHTML).toContain('Recycled 1 · Skipped 0 · Failed 1');
+ expect(h.forgot.mock.calls.map(([cid]) => cid)).toEqual(['one']);
+ expect(h.manageLog.warn).toHaveBeenCalledExactlyOnceWith('conversation management result', {
+ action: 'delete', result: 'failure', duration_ms: expect.any(Number), error_code: 'delete_failed',
+ });
+ expect(h.manageLog.info).not.toHaveBeenCalled();
+ expect(JSON.stringify(h.manageLog.warn.mock.calls)).not.toContain('synthetic-private-cleanup-marker');
+ fail = false; await h.click('retry');
+ expect(h.invoke.mock.calls.filter(([channel]) => channel.endsWith('remove')).map(([, payload]: any) => payload.cid)).toEqual(['one', 'two', 'two']);
+ expect(h.forgot.mock.calls.map(([cid]) => cid)).toEqual(['one', 'two']);
+ expect(h.manageLog.warn).toHaveBeenCalledTimes(1);
+ expect(h.manageLog.info).toHaveBeenCalledExactlyOnceWith('conversation management result', {
+ action: 'delete', result: 'success', duration_ms: expect.any(Number),
+ });
+ });
+ it('logs a failed cleanup page without attempting removals or exposing its error detail', async () => {
+ const h = harness(); const original = h.invoke.getMockImplementation()!;
+ h.invoke.mockImplementation(async (channel, payload) => {
+ if (channel.endsWith('page')) throw new Error('synthetic-private-page-marker');
+ return original(channel, payload);
+ });
+ await h.show(); await h.check('one', true); await h.click('prepare'); await h.click('confirm');
+ expect(h.invoke.mock.calls.filter(([channel]) => channel.endsWith('remove'))).toHaveLength(0);
+ expect(h.forgot).not.toHaveBeenCalled();
+ expect(h.body.innerHTML).toContain('role="alert"');
+ expect(h.body.innerHTML).toContain('Recycled 0 · Skipped 0 · Failed 0');
+ expect(h.body.innerHTML).not.toContain('synthetic-private-page-marker');
+ expect(h.manageLog.warn).toHaveBeenCalledExactlyOnceWith('conversation management result', {
+ action: 'delete', result: 'failure', duration_ms: expect.any(Number), error_code: 'delete_failed',
+ });
+ expect(h.manageLog.info).not.toHaveBeenCalled();
+ });
it('retries only failed tasks after a partial success', async () => {
const h = harness(); await h.show(); await h.check(null, true);
const original = h.invoke.getMockImplementation()!;
diff --git a/test/renderer/user-workspace.test.ts b/test/renderer/user-workspace.test.ts
index 2ce56889..eba2f762 100644
--- a/test/renderer/user-workspace.test.ts
+++ b/test/renderer/user-workspace.test.ts
@@ -65,7 +65,15 @@ class FakeElement {
this.parentNode = null;
}
- addEventListener() {}
+ listeners = new Map<string, Array<(event: any) => void>>();
+ addEventListener(type: string, handler: (event: any) => void) {
+ const list = this.listeners.get(type) || [];
+ list.push(handler);
+ this.listeners.set(type, list);
+ }
+ click() {
+ for (const handler of this.listeners.get('click') || []) handler({ target: this, stopPropagation() {} });
+ }
contains(target: FakeElement): boolean {
if (target != null && !(target instanceof FakeElement)) {
@@ -391,3 +399,32 @@ describe('user workspace menu placement', () => {
expect(items[1]?.childNodes[0]?.textContent).toBe('logs');
});
});
+
+describe('workspace picker failure diagnostics', () => {
+ beforeEach(() => {
+ delete require.cache[require.resolve('../../src/renderer/modules/user-workspace.js')];
+ });
+
+ it.each([null, { ok: false, error: 'synthetic-private-picker-marker' }])('keeps picker rejection visible and logs its fixed failure code (%j)', async response => {
+ const warn = vi.fn();
+ vi.stubGlobal('createLogger', () => ({ info: vi.fn(), warn, error: vi.fn() }));
+ const toast = vi.fn();
+ vi.stubGlobal('uiToast', toast);
+ const { _showWorkspaceDropdown } = loadUserWorkspace();
+ const invoke = vi.fn().mockResolvedValue(response);
+ (globalThis as any).window.orkas = { invoke };
+ const anchor = new FakeElement('button');
+ _showWorkspaceDropdown(anchor, 'new-chat');
+ const menu = (globalThis as any).document.body.querySelector('.workspace-menu') as FakeElement;
+ const chooseFolder = menu.querySelectorAll('.workspace-menu-item').find(item => item.textContent === 'workspace.pick_folder');
+ expect(chooseFolder).toBeDefined();
+ chooseFolder!.click();
+ await vi.waitFor(() => expect(toast).toHaveBeenCalledOnce());
+ expect(invoke.mock.calls).toEqual([['workspace.selectDirectory', {}]]);
+ expect(toast).toHaveBeenCalledWith('workspace.set_failed', { variant: 'warning', timeoutMs: 6000 });
+ expect(warn).toHaveBeenCalledExactlyOnceWith('workspace change failed', {
+ action: 'select', surface: 'new_chat', error_code: 'picker_failed',
+ });
+ expect(JSON.stringify(warn.mock.calls)).not.toContain('synthetic-private-picker-marker');
+ });
+});