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 (agy): compare timeline date bounds as instants and fix the 0-99 year check

[._.]/ Adam Eivycc99b14c6925
diff --git a/server/lib/memoryValidation.js b/server/lib/memoryValidation.js
index d3412bd401..a1f393f26b 100644
--- a/server/lib/memoryValidation.js
+++ b/server/lib/memoryValidation.js
@@ -111,6 +111,9 @@ const emptyToUndefined = (inner) => z.preprocess(
const isRealCalendarDate = (v) => {
const [year, month, day] = v.split('-').map(Number);
const parsed = new Date(Date.UTC(year, month - 1, day));
+ // Date.UTC maps a 0-99 year onto 1900-1999; re-set it so a year like 0026
+ // compares against itself rather than 1926.
+ parsed.setUTCFullYear(year);
return parsed.getUTCFullYear() === year
&& parsed.getUTCMonth() === month - 1
&& parsed.getUTCDate() === day;
@@ -119,7 +122,9 @@ const isRealCalendarDate = (v) => {
// `startDate`/`endDate` reach Postgres as `created_at >= $n` bind params, so a
// bare calendar date is as usable as a full timestamp — accept either. The
// datetime branch allows a `+HH:MM` offset, not just a `Z` suffix, since either
-// is a legitimate serialization of the same instant.
+// is a legitimate serialization of the same instant. A bare date means midnight
+// at both ends of the range, matching how these bounds have always been read —
+// pass a full timestamp to include part of a day.
const dateBoundary = z.union([
z.string().datetime({ offset: true }),
z.string()
diff --git a/server/services/memory.js b/server/services/memory.js
index a158505a49..7f97fe1da8 100644
--- a/server/services/memory.js
+++ b/server/services/memory.js
@@ -502,12 +502,16 @@ export async function getTimeline(options = {}) {
const index = await loadIndex();
let memories = index.memories.filter(m => m.status === 'active');
- // Filter by date range
- if (options.startDate) {
- memories = memories.filter(m => m.createdAt >= options.startDate);
+ // Filter by date range. Compare instants, not strings — `createdAt` is always
+ // UTC (`…Z`) while a boundary may carry an offset (`…+02:00`) or be a bare
+ // `YYYY-MM-DD`, and those sort lexicographically against each other wrong.
+ const startMs = options.startDate ? Date.parse(options.startDate) : NaN;
+ const endMs = options.endDate ? Date.parse(options.endDate) : NaN;
+ if (!Number.isNaN(startMs)) {
+ memories = memories.filter(m => Date.parse(m.createdAt) >= startMs);
}
- if (options.endDate) {
- memories = memories.filter(m => m.createdAt <= options.endDate);
+ if (!Number.isNaN(endMs)) {
+ memories = memories.filter(m => Date.parse(m.createdAt) <= endMs);
}
// Filter by types
diff --git a/server/services/memory.test.js b/server/services/memory.test.js
index 6b02b33520..b013c58bcb 100644
--- a/server/services/memory.test.js
+++ b/server/services/memory.test.js
@@ -1133,6 +1133,27 @@ describe('memory service', () => {
expect(timeline['2025-01-20']).toBeDefined();
});
+ it('should compare a boundary carrying an offset as an instant, not a string', async () => {
+ const mockIndex = {
+ version: 1, lastUpdated: '', count: 2,
+ memories: [
+ // 03:00Z is BEFORE the 2025-01-15T05:00:00+02:00 boundary (03:00Z)…
+ { id: 'm1', createdAt: '2025-01-15T02:00:00.000Z', status: 'active', sourceAppId: null },
+ // …and 04:00Z is after it, though both sort ahead of it as strings.
+ { id: 'm2', createdAt: '2025-01-15T04:00:00.000Z', status: 'active', sourceAppId: null }
+ ]
+ };
+ readJSONFile.mockImplementation((path, def) => {
+ if (path.includes('index.json')) return Promise.resolve(mockIndex);
+ return Promise.resolve(def);
+ });
+
+ const timeline = await getTimeline({ startDate: '2025-01-15T05:00:00+02:00' });
+
+ expect(timeline['2025-01-15']).toHaveLength(1);
+ expect(timeline['2025-01-15'][0].id).toBe('m2');
+ });
+
it('should filter by types', async () => {
const mockIndex = {
version: 1, lastUpdated: '', count: 2,