rohitg00/agentmemory · error · Error
Invalid dateTo: ${filter.dateTo}
Error message
Invalid dateTo: ${filter.dateTo} What it means
queryAudit filters audit entries by an optional dateTo bound. If the value cannot be parsed by new Date() (NaN result), the library throws instead of silently returning wrong results. Same validation family as the dateFrom error, but for the upper bound of the time range.
Source
Thrown at src/functions/audit.ts:107
const all = await kv.list<AuditEntry>(KV.audit);
let entries = [...all].sort(
(a, b) => new Date(b.timestamp).getTime() - new Date(a.timestamp).getTime(),
);
if (filter?.operation) {
entries = entries.filter((e) => e.operation === filter.operation);
}
if (filter?.dateFrom) {
const from = new Date(filter.dateFrom).getTime();
if (Number.isNaN(from)) {
throw new Error(`Invalid dateFrom: ${filter.dateFrom}`);
}
entries = entries.filter((e) => new Date(e.timestamp).getTime() >= from);
}
if (filter?.dateTo) {
const to = new Date(filter.dateTo).getTime();
if (Number.isNaN(to)) {
throw new Error(`Invalid dateTo: ${filter.dateTo}`);
}
entries = entries.filter((e) => new Date(e.timestamp).getTime() <= to);
}
return entries.slice(0, filter?.limit || 100);
}
View on GitHub (pinned to e04ba88819)
Solutions
- Pass dateTo as an ISO 8601 string, e.g. '2024-01-31T23:59:59.999Z'.
- Validate parseability with new Date(value) before the call.
- For 'now' bounds, generate the value with new Date().toISOString() on the caller side.
- Log the raw value to spot silent corruption (empty string, undefined stringified).
Example fix
// before
{ dateTo: String(endMs) }
// after
{ dateTo: new Date(endMs).toISOString() } Defensive patterns
Strategy: validation
Validate before calling
function assertIsoDate(v: string, label: string): string {
const t = new Date(v).getTime();
if (Number.isNaN(t)) throw new Error(`${label} is not a valid date: ${v}`);
return new Date(t).toISOString();
}
const dateTo = assertIsoDate(input.dateTo, 'dateTo'); Type guard
function isParseableDate(v: unknown): v is string {
return typeof v === 'string' && !Number.isNaN(new Date(v).getTime());
} Try / catch
try {
return await queryAudit({ dateTo });
} catch (e) {
if (String(e.message).startsWith('Invalid date')) return { entries: [], hint: 'use ISO 8601 dates' };
throw e;
} Prevention
- Use Date.prototype.toISOString() for all API date fields.
- Validate both range bounds together before calling.
- Reject empty strings early — they parse as Invalid Date for range use.
- Keep date normalization in one shared helper.
When it happens
Trigger: Calling queryAudit (via entries/entriesBefore or the audit MCP/REST surface) with filter.dateTo set to an unparseable string like 'tomorrow', '2024-13-01', or a locale-formatted date.
Common situations: Constructing ranges from user CLI input without validation; passing millisecond timestamps as numbers coerced to weird strings; i18n formatting of dates before sending.
Related errors
- Invalid dateFrom: ${filter.dateFrom}
- Refusing to read image outside managed store: ${data.raw.ima
- mem::context: AGENTMEMORY_AGENT_SCOPE=isolated is set but no
- mem::search: query must be a non-empty string
- mem::search: limit must be a positive integer
AI-assisted analysis of rohitg00/agentmemory@e04ba88819 (2026-08-30).
Data as JSON: /api/errors/ffe596fd743f43c2.
Report an issue: GitHub.