Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: preserve committed task responses when action logging fails
Adam Eivyfa8d834fa80f
diff --git a/server/routes/cosTaskRoutes.js b/server/routes/cosTaskRoutes.jsindex 1c607efb15..0c90cccb2d 100644--- a/server/routes/cosTaskRoutes.js+++ b/server/routes/cosTaskRoutes.js@@ -67,8 +67,14 @@ const pickDefined = (source, fields) => Object.fromEntries(fields.filter((field) => source?.[field] !== undefined).map((field) => [field, source[field]]),);+// The task change has committed before these diagnostic ledger writes. A ledger+// outage must not turn it into a failed request that encourages another mutation.+const recordCommittedTaskAction = (action) => recordUserAction(action).catch((err) => {+ console.error(`❌ Failed to record ${action.type} after task mutation: ${err.message}`);+});+async function logTaskCreated(req, task, taskData) {- await recordUserAction({+ await recordCommittedTaskAction({type: 'cos.task.create',target: task.id,targetName: task.description,@@ -535,7 +541,7 @@ router.put('/tasks/:id', asyncHandler(async (req, res) => {// An edit is not an idempotent retry — two saves of the same field are two// distinct operator actions — so the timestamp is part of the dedupe key.const happenedAt = new Date().toISOString();- await recordUserAction({+ await recordCommittedTaskAction({type: 'cos.task.update',target: id,targetName: result?.description,@@ -563,7 +569,7 @@ router.delete('/tasks/:id', asyncHandler(async (req, res) => {throw new ServerError(result.error, { status: 404, code: 'NOT_FOUND' });}- await recordUserAction({+ await recordCommittedTaskAction({type: 'cos.task.delete',target: id,targetName: doomed?.description,@@ -584,7 +590,7 @@ router.post('/tasks/:id/approve', asyncHandler(async (req, res) => {throw new ServerError(result.error, { status: 400, code: 'BAD_REQUEST' });}- await recordUserAction({+ await recordCommittedTaskAction({type: 'cos.task.approve',target: id,targetName: result?.description,@@ -673,7 +679,7 @@ router.post('/tasks/:id/spawn', asyncHandler(async (req, res) => {// Force-spawn is repeatable (spawn, it fails, spawn again), so each press is// its own row — hence the timestamp in the dedupe key.const happenedAt = new Date().toISOString();- await recordUserAction({+ await recordCommittedTaskAction({type: 'cos.task.spawn',target: req.params.id,summary: `Force-spawned CoS task ${req.params.id}`,diff --git a/server/routes/cosTaskRoutes.test.js b/server/routes/cosTaskRoutes.test.jsindex f329320fb9..b85d9e10dc 100644--- a/server/routes/cosTaskRoutes.test.js+++ b/server/routes/cosTaskRoutes.test.js@@ -14,7 +14,7 @@import { describe, it, expect, vi, beforeEach, afterEach, afterAll } from 'vitest';import express from 'express';-import { rmSync } from 'node:fs';+import { mkdirSync, rmSync } from 'node:fs';import { join } from 'node:path';import { request } from '../lib/testHelper.js';import { errorMiddleware } from '../lib/errorHandler.js';@@ -145,6 +145,28 @@ describe('CoS task collection selectors', () => {});});+describe('CoS task responses after action-ledger failures', () => {+ it.each(['post', 'delete'])('keeps a committed %s successful when the ledger cannot write', async (method) => {+ const ledgerPath = join(tempRoot, 'user-action-events.json');+ mkdirSync(ledgerPath);+ const log = vi.spyOn(console, 'error').mockImplementation(() => {});+ cos.getTaskById.mockResolvedValue({ id: 'task-1', description: 'Example task' });+ cos.deleteTask.mockResolvedValue({ success: true, taskId: 'task-1' });++ try {+ const url = method === 'post' ? '/api/cos/tasks' : '/api/cos/tasks/task-1';+ const res = await request(buildApp())[method](url).send(method === 'post' ? { description: 'Example task' } : undefined);++ expect(res.status).toBe(200);+ expect(res.body).toMatchObject(method === 'post' ? { id: 'task-1', description: 'Example task' } : { success: true, taskId: 'task-1' });+ expect(log).toHaveBeenCalledWith(expect.stringContaining(`Failed to record cos.task.${method === 'post' ? 'create' : 'delete'}`));+ } finally {+ rmSync(ledgerPath, { recursive: true, force: true });+ log.mockRestore();+ }+ });+});+describe('POST /api/cos/tasks — targetInstanceId (#4520)', () => {it('passes a registry-known pin through to addTask', async () => {const res = await request(buildApp())