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: keep the cached CoS working set bounded across writes
Adam Eivy73fb93b9da24
diff --git a/docs/plans/2026-10-20-cos-task-queue-to-postgres.md b/docs/plans/2026-10-20-cos-task-queue-to-postgres.mdindex 6d8e47beeb..898182bc1d 100644--- a/docs/plans/2026-10-20-cos-task-queue-to-postgres.md+++ b/docs/plans/2026-10-20-cos-task-queue-to-postgres.md@@ -61,8 +61,10 @@ Data standards are updated by migration, not carried as runtime fallbacks:`<name>.imported` (the recovery copy) and drops the retired config keys.- `data.reference/` no longer ships the two files.-Rolling back to a release that reads the Markdown files finds no files; restore-them from `*.imported` first.+There is no reverse migration. `*.imported` is only the pre-migration snapshot:+tasks written afterwards, and the history folded in from `cos_task_archive`, live+only in `cos_tasks`. To return to a release that reads the Markdown files, take a+`pg_dump` of `cos_tasks`/`cos_task_lists` first and regenerate the files from it.## Follow-ups (not in this change)diff --git a/scripts/seed-readme-demo-data.mjs b/scripts/seed-readme-demo-data.mjsindex b4354b3c0f..10770650d9 100644--- a/scripts/seed-readme-demo-data.mjs+++ b/scripts/seed-readme-demo-data.mjs@@ -8,6 +8,10 @@* empty directory, then overlays fake records that make the public UI pages* useful to inspect without exposing a real install.*+ * The demo's tasks are Markdown files that db-migration 018 imports, so the demo+ * server must start against a database that has not yet run it (a fresh,+ * disposable one). An already-migrated database ignores them.+ ** Usage:* node scripts/seed-readme-demo-data.mjs --root /tmp/portos-readme-demo*/diff --git a/server/lib/cosTaskRows.js b/server/lib/cosTaskRows.jsindex b86ce25b70..6e90df88fe 100644--- a/server/lib/cosTaskRows.js+++ b/server/lib/cosTaskRows.js@@ -64,7 +64,7 @@ export function rowColumns(task) {const byId = (a, b) => (a.id < b.id ? -1 : a.id > b.id ? 1 : 0);/** Queue order for `{ task, position }` rows. */-export function compareRows(a, b) {+function compareRows(a, b) {return statusRank(a.task.status) - statusRank(b.task.status)|| (b.task.priorityValue ?? 2) - (a.task.priorityValue ?? 2)|| a.position - b.positiondiff --git a/server/lib/cosTaskRows.test.js b/server/lib/cosTaskRows.test.jsindex 0e6890476c..a0f2873f25 100644--- a/server/lib/cosTaskRows.test.js+++ b/server/lib/cosTaskRows.test.js@@ -1,7 +1,7 @@import { describe, expect, it } from 'vitest';import {POSITION_STEP, WORKING_SET_COMPLETED_WINDOW_MS, WORKING_SET_KEEP_COMPLETED,- assignPositions, compareRows, completionStamp, planListSave, rowColumns, selectWorkingSet, storedForm,+ assignPositions, completionStamp, planListSave, rowColumns, selectWorkingSet, storedForm,} from './cosTaskRows.js';const NOW = Date.parse('2026-10-20T12:00:00Z');@@ -50,7 +50,7 @@ describe('queue order', () => {{ task: task('d', { priorityValue: 3 }), position: 1 },{ task: task('e', { status: 'in_progress' }), position: 0 },];- expect(rows.sort(compareRows).map((row) => row.task.id)).toEqual(['d', 'a', 'b', 'e', 'c']);+ expect(selectWorkingSet(rows).map((row) => row.task.id)).toEqual(['d', 'a', 'b', 'e', 'c']);});});diff --git a/server/services/cosTaskStore.js b/server/services/cosTaskStore.jsindex 3daccc698b..ecebc3b176 100644--- a/server/services/cosTaskStore.js+++ b/server/services/cosTaskStore.js@@ -36,7 +36,7 @@ import { cosEvents } from './cosEvents.js';import { CLAIM_METADATA_KEYS } from './cosTaskClaim.js';import { mergeTaskLists } from './cosTaskMerge.js';import { applyTaskListSave, countCompletedTasks, deleteStoredTask, getCompletedTaskIds, getStoredTask, loadTaskWorkingSet, pageCompletedTasks, readTaskListVersion } from './cosTaskRepository.js';-import { compareRows, planListSave } from '../lib/cosTaskRows.js';+import { planListSave, selectWorkingSet } from '../lib/cosTaskRows.js';import { buildQueuedTask } from './cosTaskIntake.js';import { canChallenge, getChallengeCount, buildChallengePatch, buildChallengeResolutionPatch, classifyRecheckOutcome, MAX_CHALLENGES_PER_TASK } from './cosChallenge.js';import { runLocalCodeReview, getCodeReviewDefaults } from './codeReview.js';@@ -225,7 +225,8 @@ async function writeTaskList(source, tasks) {const positions = new Map(snapshot.rows.map((row) => [row.task.id, row.position]));for (const { task, position } of plan.upserts) positions.set(task.id, position);if (cached?.snapshot === snapshot && version === cached.version + 1) {- const rows = plan.saved.map((task) => ({ task, position: positions.get(task.id) })).sort(compareRows);+ // Same bound as a reload, so completions never accumulate in the cache.+ const rows = selectWorkingSet(plan.saved.map((task) => ({ task, position: positions.get(task.id) })));snapshotCache.set(source, { version, snapshot: { rows, tasks: rows.map((row) => row.task) } });} else {snapshotCache.delete(source);diff --git a/server/services/cosTaskStore.test.js b/server/services/cosTaskStore.test.jsindex f01ceb2de0..356295c344 100644--- a/server/services/cosTaskStore.test.js+++ b/server/services/cosTaskStore.test.js@@ -2907,6 +2907,16 @@ describe('cosTaskStore completed history older than the working set', () => {expect(await getTaskById(id(999))).toBeNull();});+ it('keeps the cached working set bounded when a write completes another task', async () => {+ await seedHistory();+ await getUserTasks();+ await updateTask(id(900), { status: 'completed' }, 'user', { now: CLOCK });+ const completed = (await getUserTasks()).tasks.filter((task) => task.status === 'completed');+ expect(completed).toHaveLength(100);+ expect(await inWorkingSet(id(6))).toBe(false);+ expect(await getTaskById(id(6))).toMatchObject({ id: id(6), status: 'completed' });+ });+it('reopens an old completed task in place: the edit applies, it joins the working set, no second row appears', async () => {await seedHistory();const result = await updateTask(id(1), { status: 'pending', description: 'Reopened task' }, 'user', { now: CLOCK });