rohitg00/agentmemory · error · Error
Invalid dateFrom: ${filter.dateFrom}
Error message
Invalid dateFrom: ${filter.dateFrom} What it means
queryAudit filters audit entries by an optional dateFrom bound. The value is parsed with new Date(); if parsing yields NaN the filter would silently match nothing, so the library throws this error instead. It is an input-validation error for the audit query API (MCP memory_audit tool / mem::audit function).
Source
Thrown at src/functions/audit.ts:100
filter?: {
operation?: AuditEntry["operation"];
dateFrom?: string;
dateTo?: string;
limit?: number;
},
): Promise<AuditEntry[]> {
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 dateFrom as an ISO 8601 string, e.g. '2024-01-15T00:00:00.000Z'.
- Validate with new Date(value).toString() !== 'Invalid Date' before calling.
- If accepting user input, normalize timezone-less dates explicitly.
- Check for whitespace/encoding corruption in the value being forwarded.
Example fix
// before
await trigger({ function_id: 'mem::audit', payload: { dateFrom: '15/01/2024' } });
// after
await trigger({ function_id: 'mem::audit', payload: { dateFrom: new Date('2024-01-15').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 dateFrom = assertIsoDate(input.dateFrom, 'dateFrom'); 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({ dateFrom, dateTo });
} catch (e) {
if (String(e.message).startsWith('Invalid date')) return { entries: [], hint: 'use ISO 8601 dates' };
throw e;
} Prevention
- Always emit dates with new Date(...).toISOString().
- Validate user-supplied dates at the CLI/UI boundary.
- Avoid locale-formatted date strings in API payloads.
- Unit-test date filter inputs in your integration layer.
When it happens
Trigger: Calling queryAudit (via entries or entriesBefore, or the audit REST/MCP entry points) with filter.dateFrom set to a string that Date cannot parse, e.g. '31/02/2024', 'yesterday', or an empty string.
Common situations: Passing locale-formatted dates (DD/MM/YYYY) instead of ISO 8601; passing a JS Date object serialized poorly; user-supplied --since CLI values forwarded unvalidated.
Related errors
- Invalid dateTo: ${filter.dateTo}
- 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/082a27ce64c41b81.
Report an issue: GitHub.