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.
JavaScript agent-collaborationagent-harnessagent-orchestrationagent-teamagent-workflowai-assistantai-automationai-employeeai-productivityai-teamai-workflowautonomous-agentsclaude-code-guiclaude-coworkdesktop-agentlocal-firstmulti-agentmulti-agent-systemself-evolving-agentstask-automation
fix(projects): reject stale navigation after refresh failure
CloudTianTian1295d245216a
diff --git a/src/renderer/modules/projects.js b/src/renderer/modules/projects.jsindex db3d5069..78ecf17c 100644--- a/src/renderer/modules/projects.js+++ b/src/renderer/modules/projects.js@@ -101,34 +101,36 @@ let _projectsInlineRenameRerendering = false;// ── Public API: cache + render ──────────────────────────────────────────-async function loadProjects(forceRefresh) {+async function loadProjects(forceRefresh, requireFresh = false) {if (_projectsCache && !forceRefresh) {renderProjectsSection();return _projectsCache;}const requestId = ++_projectsLoadRequestId;const previousProjects = Array.isArray(_projectsCache) ? _projectsCache : [];+ let refreshed = false;try {const res = await window.orkas.invoke('projects.list', {});if (requestId !== _projectsLoadRequestId) {- return Array.isArray(_projectsCache) ? _projectsCache : previousProjects;+ return requireFresh ? null : Array.isArray(_projectsCache) ? _projectsCache : previousProjects;}if (res && res.ok && Array.isArray(res.projects)) {_projectsCache = res.projects;+ refreshed = true;} else {_projectsLog.warn('load projects rejected', { error: res && res.error });_projectsCache = previousProjects;}} catch (err) {if (requestId !== _projectsLoadRequestId) {- return Array.isArray(_projectsCache) ? _projectsCache : previousProjects;+ return requireFresh ? null : Array.isArray(_projectsCache) ? _projectsCache : previousProjects;}_projectsLog.warn('load projects failed', err);_projectsCache = previousProjects;}renderProjectsSection();if (typeof window.refreshAutoProjectGroups === 'function') window.refreshAutoProjectGroups();- return _projectsCache;+ return requireFresh && !refreshed ? null : _projectsCache;}/** One-shot: ensure the project owning the active cid is expanded so the@@ -950,7 +952,7 @@ window.openProjectsSurface = async function openProjectsSurface(request) {if (action === 'configure') {const projectId = String(request.target_id || '').trim();if (!projectId) return false;- const projects = await loadProjects(true);+ const projects = await loadProjects(true, true);const exists = Array.isArray(projects)&& projects.some((project) => project && project.project_id === projectId);if (!exists || typeof setView !== 'function') return false;diff --git a/test/main/features/group_chat/app-nav-registry.test.ts b/test/main/features/group_chat/app-nav-registry.test.tsindex 66a694e5..594eeb69 100644--- a/test/main/features/group_chat/app-nav-registry.test.ts+++ b/test/main/features/group_chat/app-nav-registry.test.ts@@ -793,6 +793,7 @@ describe('group_chat app_nav registry', () => {const source = fs.readFileSync(RENDERER_PROJECTS, 'utf8');const fnSource = extractAssignedAsyncFunction(source, 'window.openProjectsSurface =');const calls: string[] = [];+ const lookups: unknown[][] = [];let expanded = false;const toggle = {getAttribute: () => (expanded ? 'true' : 'false'),@@ -806,10 +807,10 @@ describe('group_chat app_nav registry', () => {context._projectsInlineCreate = true;calls.push('create');},- loadProjects: async () => [- { project_id: 'project-1' },- { project_id: 'project-2' },- ],+ loadProjects: async (...args: unknown[]) => {+ lookups.push(args);+ return [{ project_id: 'project-1' }, { project_id: 'project-2' }];+ },setView: (view: string, id: string) => calls.push(`${view}:${id}`),document: { getElementById: () => toggle },};@@ -825,6 +826,39 @@ describe('group_chat app_nav registry', () => {expect(calls.splice(0)).toEqual(['project:project-2']);expect(await openProjects({ action: 'configure', target_id: 'missing' })).toBe(false);expect(calls).toEqual([]);+ expect(lookups).toEqual([[true, true], [true, true]]);+ });++ it('does not use a stale display cache as fresh project existence evidence', async () => {+ const source = fs.readFileSync(RENDERER_PROJECTS, 'utf8');+ const start = source.indexOf('async function loadProjects(');+ const end = source.indexOf('/** One-shot:', start);+ expect(start).toBeGreaterThan(-1);+ expect(end).toBeGreaterThan(start);+ const stale = [{ project_id: 'deleted-project' }];+ const warnings: string[] = [];+ const context: any = {+ _projectsCache: stale,+ _projectsLoadRequestId: 0,+ _projectsLog: { warn: (message: string) => warnings.push(message) },+ renderProjectsSection: () => {},+ window: { orkas: { invoke: async () => ({ ok: false, error: 'offline' }) } },+ };+ const loadProjects = vm.runInNewContext(`(${source.slice(start, end)})`, context) as (+ forceRefresh: boolean, requireFresh?: boolean,+ ) => Promise<Array<{ project_id: string }> | null>;+ expect(await loadProjects(true, true)).toBeNull();+ expect(await loadProjects(true)).toEqual(stale);+ context.window.orkas.invoke = async () => { throw new Error('offline'); };+ expect(await loadProjects(true, true)).toBeNull();+ context.window.orkas.invoke = async () => {+ context._projectsLoadRequestId += 1;+ return { ok: true, projects: stale };+ };+ expect(await loadProjects(true, true)).toBeNull();+ expect(warnings).toEqual([+ 'load projects rejected', 'load projects rejected', 'load projects failed',+ ]);});it('opens the exact automation task through the production helper', async () => {