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: reject non-day report dates and derive report durations through the shared clamp (#3501)
[._.]/ Adam Eivy948b5466d4bd
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex 6b3f202196..6f9112cb1c 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -122,4 +122,4 @@- **[issue-3508] The "N missing · Embed" badge on the Brain graph no longer reads your entire Brain off disk to compute a number.** Checking embedding coverage means counting live records and asking which of them have a vector yet — but it was answering that by loading and parsing every person, project, idea, admin item, memory entry and daily log entry in full, across every store, then throwing all of it away except each record's id. On a Brain with a few thousand records that is a few thousand file reads and JSON parses to render two integers. The tally now works from an id index instead: which record ids exist is re-read from the directory listing every time (cheap, and it is the honest source of truth for records added or hard-pruned), while whether a given record is archived or tombstoned — the part that requires opening the file — is resolved once per record and then remembered. Changes that keep a record's id, an archive flip or a delete writing a tombstone over it, drop just that one id from the index so the next count re-reads exactly one file; records arriving from a sync peer, which land deliberately silent so they cannot echo back around the network, ride the same local-only signal the search projection already uses, so an archive performed on another machine is not invisible here. The daily-log walk also loses a cap nobody meant as a policy: it used to ask for the first 10,000 days and would simply have stopped counting after that.-- **[issue-3501] Daily agent reports for past dates read as all-zero, and the dashboard's activity card re-scanned every agent you have ever run.** Both the daily report and the "today" activity card worked out which agents finished on a given date by walking the entire in-memory agent dictionary and string-matching each record's completion timestamp — so the cost grew with your whole agent history rather than with the day being asked about, and once the housekeeping sweep had evicted a day's finished agents out of live state (it keeps roughly a day), asking for that date's report returned zeros even though every one of those runs was still sitting on disk. Both now consult the date-bucket index that already maps each archived agent to its day: the index is a small in-memory id-to-date map, so a date whose agents are all still live costs no disk reads at all, and a date that has been swept out resolves from the archive instead of reporting nothing. Live records still win over their archived copies, since the archive is written at completion time and the live one carries anything recorded since. The "while you were away" card is built on the same lookup now, which also stops it re-reading up to thirty days of archives on every poll for agents it already had in hand.+- **[issue-3501] Daily agent reports for past dates read as all-zero, and the dashboard's activity card re-scanned every agent you have ever run.** Both the daily report and the "today" activity card worked out which agents finished on a given date by walking the entire in-memory agent dictionary and string-matching each record's completion timestamp — so the cost grew with your whole agent history rather than with the day being asked about, and once the housekeeping sweep had evicted a day's finished agents out of live state (it keeps roughly a day), asking for that date's report returned zeros even though every one of those runs was still sitting on disk. Both now consult the date-bucket index that already maps each archived agent to its day: the index is a small in-memory id-to-date map, so a date whose agents are all still live costs no disk reads at all, and a date that has been swept out resolves from the archive instead of reporting nothing. Live records still win over their archived copies, since the archive is written at completion time and the live one carries anything recorded since. The "while you were away" card is built on the same lookup now, which also stops it re-reading up to thirty days of archives on every poll for agents it already had in hand. Asking for a report by anything other than a plain calendar day is now rejected outright rather than quietly writing an empty report under a filename nothing can read back, and a report row's duration is derived the same way every other view derives it, so a clock-skewed run can no longer show negative time.diff --git a/server/routes/cos.test.js b/server/routes/cos.test.jsindex 780142e251..55a0b05a8b 100644--- a/server/routes/cos.test.js+++ b/server/routes/cos.test.js@@ -1360,6 +1360,17 @@ describe('CoS Routes', () => {expect(response.status).toBe(200);expect(cos.generateReport).toHaveBeenCalledWith('2026-02-25');});++ it('should reject a date that is not a bare YYYY-MM-DD day', async () => {+ // A full ISO timestamp matches no date bucket and no completedAt prefix,+ // so it would write an all-zero report under an unreadable filename.+ const response = await request(app)+ .post('/api/cos/reports/generate')+ .send({ date: '2026-02-25T00:00:00.000Z' });++ expect(response.status).toBe(400);+ expect(cos.generateReport).not.toHaveBeenCalled();+ });});describe('GET /api/cos/briefings', () => {diff --git a/server/routes/cosReportRoutes.js b/server/routes/cosReportRoutes.jsindex 4b90459e26..14a07537c6 100644--- a/server/routes/cosReportRoutes.js+++ b/server/routes/cosReportRoutes.js@@ -13,8 +13,12 @@ import { validateRequest } from '../lib/validation.js';const router = Router();+// The date is both a date-bucket key and the report's filename, so it must be a+// bare YYYY-MM-DD day. A full ISO timestamp would match no bucket (and no+// agent's `completedAt` prefix), silently writing an all-zero report under a+// filename `listReports`/`getReport` can never round-trip.const generateReportSchema = z.object({- date: z.string().optional(),+ date: z.string().regex(/^\d{4}-\d{2}-\d{2}$/, 'date must be YYYY-MM-DD').optional(),});// `since` is the client's last-visit marker (ISO-8601). Optional and tolerant:diff --git a/server/services/cosReports.js b/server/services/cosReports.jsindex da75997d35..c3f367f857 100644--- a/server/services/cosReports.js+++ b/server/services/cosReports.js@@ -77,9 +77,7 @@ export async function generateReport(date = null) {id: a.id,taskId: a.taskId,success: a.result?.success || false,- duration: a.completedAt && a.startedAt- ? new Date(a.completedAt) - new Date(a.startedAt)- : 0+ duration: agentDurationMs(a)}))};