Budibase/budibase · error · HTTPError

startDate query must be before endDate query

Error message

startDate query must be before endDate query

What it means

This error is thrown when sanitizing the startDate/endDate query parameters for fetching agent log sessions: after both dates are validated, their comparable values are compared and if the start date is chronologically after the end date the request is rejected with 400. The library enforces a forward-looking date range.

Source

Thrown at packages/server/src/api/controllers/ai/agentLogs.ts:116

}

export async function fetchAgentLogs(
  ctx: UserCtx<void, FetchAgentLogsResponse>
) {
  const { agentId } = ctx.params
  const { startDate, endDate, bookmark, limit, statusFilter, triggerFilter } =
    ctx.query as Record<string, string>
  const defaults = getDefaultLogRange()
  const sanitizedStartDate =
    sanitizeDateQuery(startDate, "startDate") || defaults.startDate
  const sanitizedEndDate =
    sanitizeDateQuery(endDate, "endDate") || defaults.endDate

  if (
    getComparableDate(sanitizedStartDate, "start") >
    getComparableDate(sanitizedEndDate, "end")
  ) {
    throw new HTTPError("startDate query must be before endDate query", 400)
  }
  ctx.body = await sdk.ai.agentLogs.fetchSessions(
    agentId,
    sanitizedStartDate,
    sanitizedEndDate,
    sanitizeBookmarkQuery(bookmark),
    sanitizeLimitQuery(limit),
    statusFilter,
    triggerFilter
  )
}

export async function fetchAgentLogSession(
  ctx: UserCtx<void, AgentLogSession | null>
) {
  const { agentId } = ctx.params
  const { sessionId, environment } = ctx.query as Record<string, string>
  ctx.body = await sdk.ai.agentLogs.fetchSessionDetail(

View on GitHub (pinned to a81a902e9a)

Solutions

  1. Swap the values so startDate is earlier than or equal to endDate
  2. Verify the caller's date computation (e.g. duration subtraction) is not inverted
  3. Ensure both dates use consistent timezone/format (ISO 8601)
  4. Validate the range in the UI before issuing the request

Example fix

// before
?startDate=2026-05-01&endDate=2026-04-01
// after
?startDate=2026-04-01&endDate=2026-05-01
Defensive patterns

Strategy: validation

Validate before calling

function validateDateRange(startDate, endDate) {
  if (new Date(startDate).getTime() > new Date(endDate).getTime()) {
    throw new Error("startDate must be before or equal to endDate")
  }
  return { startDate, endDate }
}
validateDateRange(params.startDate, params.endDate)

Try / catch

try {
  const sessions = await fetchAgentLogs(agentId, { startDate, endDate })
} catch (err) {
  if (err.status === 400 && /startDate query/.test(err.message)) {
    [startDate, endDate] = [endDate, startDate]
    return fetchAgentLogs(agentId, { startDate, endDate })
  }
  throw err
}

Prevention

When it happens

Trigger: Calling fetchAgentLogs with ?startDate=2026-05-01&endDate=2026-04-01 (reversed range), or with time-of-day values that invert the range (startDate=2026-04-02T10:00 vs endDate=2026-04-02T09:00). Date-only values are expanded to start-of-day/end-of-day before comparison.

Common situations: UI date-range pickers that allow inverted selections; timezone mixups where one date is UTC and the other local; programmatic callers computing startDate = endDate - duration with sign errors; millisecond vs ISO string inconsistencies.

Related errors


AI-assisted analysis of Budibase/budibase@a81a902e9a (2026-08-29). Data as JSON: /api/errors/8d9d89806f72cd17. Report an issue: GitHub.