Skip to content

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

address review (claude): make the write-side cache invalidation test non-vacuous

[._.]/ Adam Eivy402371cc67fb
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index 966dd95a3e..d027db2144 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -84,4 +84,4 @@
## Internal
-- **[issue-3497] The Chief of Staff stops re-reading and re-parsing its task lists dozens of times a minute.** Every daemon evaluation tick, scheduler sweep, and agent status update read both task files off disk and parsed them from scratch — work that grows with the task list and was already the single busiest thing the idle daemon did. Parsed tasks are now kept in memory and reused while the file on disk is unchanged, so an unchanged list costs a file-timestamp check instead of a full re-parse. Edits made outside PortOS (a text editor, a restore, a sync peer) are still picked up, because the check keys on both the file's timestamp and its size, and every write PortOS makes drops the remembered copy outright rather than trusting a timestamp that some filesystems only record to the nearest second.
+- **[issue-3497] The Chief of Staff no longer re-reads and re-parses its task lists on every scheduler tick** — an unchanged list is served from memory instead, which matters most on installs whose task history has grown large. Edits made outside PortOS (a text editor, a restore, a sync peer) are still picked up immediately.
diff --git a/server/services/cosTaskStore.test.js b/server/services/cosTaskStore.test.js
index 4380736a74..f577f75f73 100644
--- a/server/services/cosTaskStore.test.js
+++ b/server/services/cosTaskStore.test.js
@@ -213,23 +213,33 @@ describe('cosTaskStore parsed-task cache (#3497)', () => {
expect(after.tasks[0].description).toBe('edited outside the store');
});
- it('re-parses after a write through the store even when mtime has not moved', async () => {
+ it('re-parses after a write through the store even when the stamp has not moved', async () => {
await addTask({ description: 'original' }, 'user');
- await getUserTasks();
+ const created = (await getUserTasks()).tasks[0]; // primes the cache
+
+ // Snapshot the EXACT stamp the cache is now holding, so it can be restored
+ // byte-for-byte after the write below.
+ const cachedContent = mock.files.get(USER_FILE);
+ const cachedMtime = mock.mtimes.get(USER_FILE);
- // Freeze mtime+size across the update: a coarse-granularity filesystem can
- // report an identical stamp for a same-second, same-length rewrite, so the
- // write path must drop the entry itself rather than trust the stamp.
- const frozenMtime = mock.mtimes.get(USER_FILE);
- const created = (await getUserTasks()).tasks[0];
await updateTask(created.id, { description: 'original' }, 'user');
- mock.mtimes.set(USER_FILE, frozenMtime);
- mock.files.set(USER_FILE, mock.files.get(USER_FILE).replace('original', 'rewritten'));
+
+ // Put back content of the identical LENGTH ('original' and 'REWRITTN' are
+ // both 8 chars) at the identical mtime, so `mtimeMs:size` is bit-for-bit
+ // what the cached entry carries. The stamp check therefore cannot save this
+ // read — only writeTaskFile having dropped the entry itself can. Restoring
+ // a different-length string instead would move `size`, the stamp would
+ // differ anyway, and this test would pass with the write-side invalidation
+ // deleted. That matters because the length-neutral rewrite is the COMMON
+ // production case (a status flip, an `updatedAt` restamp), and on a
+ // coarse-mtime filesystem two writes inside one tick stamp identically.
+ mock.files.set(USER_FILE, cachedContent.replace('original', 'REWRITTN'));
+ mock.mtimes.set(USER_FILE, cachedMtime);
mock.parseCalls = 0;
const after = await getUserTasks();
expect(mock.parseCalls).toBe(1);
- expect(after.tasks[0].description).toBe('rewritten');
+ expect(after.tasks[0].description).toBe('REWRITTN');
});
it('invalidates on deleteTask so the removed task never comes back cached', async () => {