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(tasks): preserve unchanged task records

BlueSkyID66692d5cbe5d878
diff --git a/src/main/features/project_tasks.ts b/src/main/features/project_tasks.ts
index a04159e8..9f114df6 100644
--- a/src/main/features/project_tasks.ts
+++ b/src/main/features/project_tasks.ts
@@ -27,6 +27,7 @@
import * as crypto from 'node:crypto';
import * as fs from 'node:fs';
import * as fsp from 'node:fs/promises';
+import { isDeepStrictEqual } from 'node:util';
import { Mutex } from 'async-mutex';
import * as path from 'node:path';
@@ -547,8 +548,6 @@ export async function updateTask(
if (patch.status !== undefined) {
if (!STATUSES.includes(patch.status)) return { ok: false, error: 'bad_status' };
next.status = patch.status;
- if (patch.status === 'done') next.done_at = nowIso();
- else delete next.done_at;
}
if (patch.owner_agent !== undefined || patch.owner_agent_id !== undefined) {
const owner = await _resolveOwner(uid, pid, patch);
@@ -560,6 +559,13 @@ export async function updateTask(
if (typeof patch.origin_cid === 'string' && patch.origin_cid.trim()) {
next.origin_cid = patch.origin_cid.trim();
}
+ // Validate the whole patch under the task lock before treating it as a
+ // no-op. Reapplying state must not rewrite timestamps or notify listeners.
+ if (isDeepStrictEqual(next, cur)) return { ok: true, task: cur };
+ if (patch.status !== undefined) {
+ if (patch.status === 'done') next.done_at = nowIso();
+ else delete next.done_at;
+ }
next.updated_at = nowIso();
await _writeTask(uid, pid, next);
log.info('updated', { user: maskId(uid), scope: _scopeLog(pid), tid: maskId(tid), status: next.status });
diff --git a/test/e2e/todos_e2e_board.spec.ts b/test/e2e/todos_e2e_board.spec.ts
index bb545364..a11a0e30 100644
--- a/test/e2e/todos_e2e_board.spec.ts
+++ b/test/e2e/todos_e2e_board.spec.ts
@@ -1,5 +1,6 @@
import { openSidebarEntry, expect, test } from './fixtures/orkas';
import path from 'node:path';
+import { readFileSync, statSync } from 'node:fs';
for (const scope of ['global', 'project'] as const) {
test(`gives long ${scope} todo content room while keeping editor actions reachable`, async ({ orkas }, info) => {
@@ -1091,3 +1092,46 @@ test('reaches every to-do and keeps reading positions through background refresh
expect(await board.evaluate(element => element.scrollLeft)).toBeCloseTo(boardLeft, 0);
await page.screenshot({ path: testInfo.outputPath('todo-column-scroll.png') });
});
+
+for (const scope of ['global', 'project'] as const) {
+ test(`preserves unchanged ${scope} todos through IPC and editor saves, then persists a real edit`, async ({ orkas }) => {
+ let page = orkas.page!;
+ await page.evaluate(() => (window as any).setLang('en'));
+ const project = scope === 'project' ? await orkas.invoke<any>('projects.create', { name: 'Unchanged task' }) : null;
+ const projectId = project?.project.project_id || '';
+ const { task } = await orkas.invoke<any>('projects.tasks.create', { projectId, content: 'Preserve this requirement' });
+ const taskId = task.id;
+ const uid = JSON.parse(readFileSync(path.join(orkas.workspaceRoot, 'open-users.json'), 'utf8')).open_current_user_id;
+ const file = path.join(orkas.workspaceRoot, uid, 'cloud', ...(projectId ? ['projects', projectId] : []), 'tasks', taskId + '.json');
+ const bytes = readFileSync(file, 'utf8');
+ const before = statSync(file);
+ const repeated = await orkas.invoke<any>('projects.tasks.update', { projectId, taskId, status: 'todo' });
+ expect(repeated).toMatchObject({ ok: true, task });
+ await openSidebarEntry(page, '#todos-btn');
+ if (projectId) await page.locator(`#todos-content .todo-scope-chip[data-pid="${projectId}"]`).click();
+ const edit = async () => {
+ const card = page.locator(`#todos-content .project-todo-item[data-tid="${taskId}"]`);
+ await card.hover();
+ await card.locator('[data-action="todo-menu"]').click();
+ await page.locator('.context-menu-item').filter({ hasText: /^Edit$/ }).click();
+ await expect(page.locator('#project-todo-input')).toHaveValue('Preserve this requirement');
+ };
+ await edit();
+ await page.locator('#project-todo-save').click();
+ await expect(page.locator('#todo-editor-modal')).not.toHaveClass(/open/);
+ expect(readFileSync(file, 'utf8')).toBe(bytes);
+ expect(statSync(file).mtimeMs).toBe(before.mtimeMs);
+ expect(statSync(file).ino).toBe(before.ino);
+ await edit();
+ await page.locator('#project-todo-input').fill('Authorized revised requirement');
+ await page.locator('#project-todo-save').click();
+ await expect(page.locator('#todo-editor-modal')).not.toHaveClass(/open/);
+ await expect(page.locator(`#todos-content .project-todo-item[data-tid="${taskId}"]`)).toContainText('Authorized revised requirement');
+ page = await orkas.relaunch();
+ const { tasks } = await orkas.invoke<any>('projects.tasks.list', { projectId });
+ expect(tasks.find((item: any) => item.id === taskId)).toMatchObject({ content: 'Authorized revised requirement', status: 'todo' });
+ await openSidebarEntry(page, '#todos-btn');
+ if (projectId) await page.locator(`#todos-content .todo-scope-chip[data-pid="${projectId}"]`).click();
+ await expect(page.locator(`#todos-content .project-todo-item[data-tid="${taskId}"]`)).toContainText('Authorized revised requirement');
+ });
+}
diff --git a/test/main/features/project_tasks.test.ts b/test/main/features/project_tasks.test.ts
index c74e8248..c2f4b667 100644
--- a/test/main/features/project_tasks.test.ts
+++ b/test/main/features/project_tasks.test.ts
@@ -494,6 +494,70 @@ describe('project_tasks › list + progress', () => {
});
describe('project_tasks › update / complete / delete', () => {
+ it.each(['project', 'global'] as const)('keeps repeated %s updates read-only, then persists a real edit with the same status', async (scope) => {
+ const { pt, pid: projectId } = await setup();
+ const pid = scope === 'project' ? projectId : '';
+ const storage = await import('../../../src/main/storage');
+ const clock = vi.spyOn(storage, 'nowIso').mockReturnValue('2026-10-23T16:21:17');
+ try {
+ const created = await pt.createTask(TEST_UID, pid, { content: 'Paused prerequisite' });
+ if (!created.ok) throw new Error('task fixture failed');
+ const id = created.task.id;
+ const file = pid ? taskFile(pid, id) : globalTaskFile(id);
+ const before = await pt.getTask(TEST_UID, pid, id);
+ const bytes = fs.readFileSync(file, 'utf8');
+ const modified = fs.statSync(file).mtimeMs;
+ const events: unknown[] = [];
+ pt.onTasksChanged(event => events.push(event));
+ clock.mockReturnValue('2026-10-23T16:21:58');
+
+ // Historical pause trace: todo_tasks.update sent the existing status.
+ expect(await pt.updateTask(TEST_UID, pid, id, { status: 'todo' })).toEqual({ ok: true, task: before });
+ expect(await pt.updateTask(TEST_UID, pid, id, { content: ' Paused prerequisite ' }))
+ .toEqual({ ok: true, task: before });
+ expect(fs.readFileSync(file, 'utf8')).toBe(bytes);
+ expect(fs.statSync(file).mtimeMs).toBe(modified);
+ expect(events).toEqual([]);
+
+ // Equal status must not conceal a changed requirement or bypass checks.
+ expect(await pt.updateTask(TEST_UID, pid, id, { status: 'todo', content: '' }))
+ .toEqual({ ok: false, error: 'content_empty' });
+ expect(await pt.updateTask(TEST_UID, pid, id, { status: 'todo', owner_agent_id: 'unbound' }))
+ .toEqual({ ok: false, error: 'owner_not_bound' });
+ expect(await pt.updateTask(TEST_UID, pid, id, { status: 'todo' }, { expectedStatus: 'progress' }))
+ .toEqual({ ok: false, error: 'status_conflict' });
+ expect(fs.readFileSync(file, 'utf8')).toBe(bytes);
+ expect(events).toEqual([]);
+ expect(await pt.updateTask(TEST_UID, pid, id, { status: 'todo', content: 'Authorized revised requirement' }))
+ .toMatchObject({ ok: true, task: { content: 'Authorized revised requirement', updated_at: '2026-10-23T16:21:58' } });
+ expect(events).toHaveLength(1);
+ vi.resetModules();
+ const reopened = await import('../../../src/main/features/project_tasks');
+ expect(await reopened.getTask(TEST_UID, pid, id)).toMatchObject({ content: 'Authorized revised requirement', status: 'todo' });
+ } finally { clock.mockRestore(); }
+ });
+
+ it.each(['progress', 'review', 'done'] as const)('does not refresh timestamps when reapplying %s', async status => {
+ const { pt, pid } = await setup();
+ const storage = await import('../../../src/main/storage');
+ const clock = vi.spyOn(storage, 'nowIso').mockReturnValue('2026-10-23T16:21:17');
+ try {
+ const created = await pt.createTask(TEST_UID, pid, { content: 'Existing work' });
+ if (!created.ok) throw new Error('task fixture failed');
+ const changed = await pt.updateTask(TEST_UID, pid, created.task.id, { status });
+ if (!changed.ok) throw new Error('status fixture failed');
+ const bytes = fs.readFileSync(taskFile(pid, created.task.id), 'utf8');
+ const events: unknown[] = [];
+ pt.onTasksChanged(event => events.push(event));
+ clock.mockReturnValue('2026-10-23T16:21:58');
+ const repeated = status === 'done' ? await pt.completeTask(TEST_UID, pid, created.task.id)
+ : await pt.updateTask(TEST_UID, pid, created.task.id, { status });
+ expect(repeated).toEqual(changed);
+ expect(fs.readFileSync(taskFile(pid, created.task.id), 'utf8')).toBe(bytes);
+ expect(events).toEqual([]);
+ } finally { clock.mockRestore(); }
+ });
+
it('rejects a stale status transition without changing the newer result or notifying a false update', async () => {
const { pt, pid } = await setup();
const created = await pt.createTask(TEST_UID, pid, { content: 'Already reviewed' });
diff --git a/test/main/model/core-agent/project-state-tools-integration.test.ts b/test/main/model/core-agent/project-state-tools-integration.test.ts
index 61afa813..aa7e1a9a 100644
--- a/test/main/model/core-agent/project-state-tools-integration.test.ts
+++ b/test/main/model/core-agent/project-state-tools-integration.test.ts
@@ -92,6 +92,31 @@ async function setupProjectStateTools() {
}
describe('project state tools → durable feature stores', () => {
+ it.each(['private', 'global'])('replays the pause-time same-status tool call without mutating %s tasks', async scope => {
+ const { projectTasks, pid: projectId } = await setupProjectStateTools();
+ const pid = scope === 'private' ? projectId : '';
+ const { createProjectTasksHandler } = await import('../../../../src/main/features/project_tasks_tool_handler');
+ const storage = await import('../../../../src/main/storage');
+ const clock = vi.spyOn(storage, 'nowIso').mockReturnValue('2026-10-23T16:21:17');
+ try {
+ const created = await projectTasks.createTask(UID, pid, { content: 'Held dependent task' });
+ if (!created.ok) throw new Error('task fixture failed');
+ const { projectTaskFile, userTaskFile } = await import('../../../../src/main/paths');
+ const file = pid ? projectTaskFile(UID, pid, created.task.id) : userTaskFile(UID, created.task.id);
+ const bytes = fs.readFileSync(file, 'utf8');
+ const events: unknown[] = [];
+ projectTasks.onTasksChanged(event => events.push(event));
+ clock.mockReturnValue('2026-10-23T16:21:58');
+ const tool = createProjectTasksTool(createProjectTasksHandler(UID, pid, 'pause-chat', new Map()), { globalScope: !pid });
+ const result = await tool.execute({ action: 'update', task_id: created.task.id, status: 'todo' }, { state: {} });
+ expect(result.isError).toBe(false);
+ expect(JSON.parse(result.content)).toMatchObject({ ok: true, task: { id: created.task.id, status: 'todo' } });
+ expect(await projectTasks.getTask(UID, pid, created.task.id)).toEqual(created.task);
+ expect(fs.readFileSync(file, 'utf8')).toBe(bytes);
+ expect(events).toEqual([]);
+ } finally { clock.mockRestore(); }
+ });
+
it('resolves global task owners only from the enabled account registry and rejects scope overrides', async () => {
const agents = await import('../../../../src/main/features/agents');
const users = await import('../../../../src/main/features/users');