Fix date range filter ignoring messages without Timestamp

The filter was using fail-open logic (skipping the date check when
msg.Timestamp was falsy), so messages missing a Timestamp bypassed
the filter entirely. Per-User Report aggregates all filtered messages,
making the bug visible as all-time totals regardless of selected range.

Changed both the message and conversation date filter blocks to
fail-closed: when a date range is active, records without a parseable
timestamp are excluded. Also added a backend warning log to surface
any enriched messages that still lack a Timestamp after the
StartTime fallback (commit 421961a).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Vadym Samoilenko 2026-05-10 14:58:57 +01:00
parent 46ccccc3dd
commit 0165622f3d
2 changed files with 41 additions and 28 deletions

View file

@ -313,6 +313,11 @@ def get_all_data():
if messages_missing_parent > 0:
logger.warning(f"Found {messages_missing_parent} messages that could not be linked to a conversation")
# Log warning if any messages ended up without a Timestamp after enrichment
msg_no_timestamp = sum(1 for m in enriched_messages if not m.get("Timestamp"))
if msg_no_timestamp:
logger.warning(f"Messages missing Timestamp after enrichment: {msg_no_timestamp} / {len(enriched_messages)}")
# Log warning if messages are missing Assistant_ID
msg_has_assistant_id = sum(1 for msg in enriched_messages if msg.get("Assistant_ID"))
msg_no_assistant_id = sum(1 for msg in enriched_messages if not msg.get("Assistant_ID"))

View file

@ -99,22 +99,26 @@ const Dashboard = ({ conversations, messages }) => {
let matches = true;
// Date range filter - only apply if both start and end dates are set
if (filters.dateRange.start && filters.dateRange.end && conv.StartTime) {
try {
const convDate = parseISO(conv.StartTime);
if (isValid(convDate)) {
matches = matches && isWithinInterval(convDate, {
start: filters.dateRange.start,
end: filters.dateRange.end
});
} else {
console.warn("Invalid date in conversation:", conv.StartTime);
// Date range filter - fail-closed: missing/unparseable StartTime is excluded when a range is active
if (filters.dateRange.start && filters.dateRange.end) {
if (!conv.StartTime) {
matches = false;
} else {
try {
const convDate = parseISO(conv.StartTime);
if (!isValid(convDate)) {
console.warn("Invalid date in conversation:", conv.StartTime);
matches = false;
} else {
matches = matches && isWithinInterval(convDate, {
start: filters.dateRange.start,
end: filters.dateRange.end,
});
}
} catch (e) {
console.error("Error parsing conversation date:", e);
matches = false;
}
} catch (e) {
console.error("Error parsing conversation date:", e);
matches = false;
}
}
@ -157,22 +161,26 @@ const Dashboard = ({ conversations, messages }) => {
let matches = true;
// Date range filter - only apply if both start and end dates are set
if (filters.dateRange.start && filters.dateRange.end && msg.Timestamp) {
try {
const msgDate = parseISO(msg.Timestamp);
if (isValid(msgDate)) {
matches = matches && isWithinInterval(msgDate, {
start: filters.dateRange.start,
end: filters.dateRange.end
});
} else {
console.warn("Invalid date in message:", msg.Timestamp);
// Date range filter - fail-closed: missing/unparseable Timestamp is excluded when a range is active
if (filters.dateRange.start && filters.dateRange.end) {
if (!msg.Timestamp) {
matches = false;
} else {
try {
const msgDate = parseISO(msg.Timestamp);
if (!isValid(msgDate)) {
console.warn("Invalid date in message:", msg.Timestamp);
matches = false;
} else {
matches = matches && isWithinInterval(msgDate, {
start: filters.dateRange.start,
end: filters.dateRange.end,
});
}
} catch (e) {
console.error("Error parsing message date:", e);
matches = false;
}
} catch (e) {
console.error("Error parsing message date:", e);
matches = false;
}
}