Skip to content

fix(evi): reject a spend-report window that ends in the future - #793

Open
evlogai[bot] wants to merge 1 commit into
mainfrom
fix/evi-report-window-guard
Open

evlogai[bot] wants to merge 1 commit into
mainfrom
fix/evi-report-window-guard

Conversation

@evlogai

@evlogai evlogai Bot commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

Problem

ai_gateway__report accepts any YYYY-MM-DD window, including one that ends after today. The gateway answers an out-of-range window with zero rows, and the empty-scope receipt then says "empty results usually mean traffic predates evi:env tagging": a wrong diagnosis that sent today's cost investigation chasing a tagging bug that did not exist. The actual cause was a window dated in 2027.

This hit in practice on 2026-10-08: three report calls with future end dates returned empty scopes, and the note pointed at the wrong layer.

Change

Window validation moves up front, in apps/evi/agent/lib/gateway.ts:

+export function reportWindowProblem(
+  startDate: string,
+  endDate: string,
+  today = todayUtc(),
+): { field: 'startDate' | 'endDate', message: string } | undefined {
+  if (startDate > endDate) return { field: 'startDate', message: 'startDate must not be later than endDate' }
+  if (endDate > today) {
+    return {
+      field: 'endDate',
+      message: `endDate is in the future: the window ends ${endDate} but today is ${today} (UTC), and the gateway has no data for dates that have not happened yet`,
+    }
+  }
+  return undefined
+}

ai_gateway__report's input schema now runs it via superRefine, so a future-dated window is rejected at the tool boundary with the offending field named, instead of returning a plausible-looking empty report:

-          }).refine(({ startDate, endDate }) => startDate <= endDate, {
-            message: 'startDate must not be later than endDate',
-            path: ['startDate'],
-          }),
+          }).superRefine(({ startDate, endDate }, ctx) => {
+            const problem = reportWindowProblem(startDate, endDate)
+            if (problem) ctx.addIssue({ code: 'custom', message: problem.message, path: [problem.field] })
+          }),

A caller that asks for 2026-02-07 to 2027-03-07 when today is 2026-10-08 now gets: "endDate is in the future: the window ends 2027-03-07 but today is 2026-10-08 (UTC), and the gateway has no data for dates that have not happened yet", and can correct the dates in the same turn.

Checks

Run at be37147 off main (59a105f), cold:

  • apps/evi: tsc clean.
  • vitest run agent/lib/gateway.test.ts: 23 passed, including 4 new: window ending today accepted, future endDate rejected with the field and message, inverted window rejected, and todayUtc returning the UTC calendar date across a local-midnight boundary under fake timers.
  • pnpm run lint: exit 0.

No changeset: the change is confined to apps/evi.

ELI5

When someone asks the spending report for dates that have not happened yet, the gateway quietly answers "nothing here" and the message blames a configuration problem that is not the real cause. This change makes the report say "that date is in the future" instead, so nobody goes looking in the wrong place.

@evlogai
evlogai Bot requested a review from HugoRCD October 8, 2026 08:11
@vercel

vercel Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
evi Ready Ready Preview Oct 8, 2026 8:12am UTC
4 Skipped Deployments
Project Deployment Actions Updated
evlog-docs Skipped Skipped v0 Oct 8, 2026 8:12am UTC
evlog-render-lab Skipped Skipped Oct 8, 2026 8:12am UTC
evlog-telemetry Skipped Skipped Oct 8, 2026 8:12am UTC
just-use-evlog Skipped Skipped Oct 8, 2026 8:12am UTC

Request Review

@coderabbitai

coderabbitai Bot commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d4e19055-c311-4244-9bdf-e57e2de0657e

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added the bug Something isn't working label Oct 8, 2026
@github-actions

github-actions Bot commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

Thank you for following the naming conventions! 🙏

@pkg-pr-new

pkg-pr-new Bot commented Oct 8, 2026

Copy link
Copy Markdown
@evlog/cli

npm i https://pkg.pr.new/@evlog/cli@793

evlog

npm i https://pkg.pr.new/evlog@793

@evlog/nuxthub

npm i https://pkg.pr.new/@evlog/nuxthub@793

@evlog/signals

npm i https://pkg.pr.new/@evlog/signals@793

@evlog/telemetry

npm i https://pkg.pr.new/@evlog/telemetry@793

commit: be37147

This branch was successfully deployed

1 active and 4 inactive deployments
Preview – evi — be371474 Deployed Oct 8, 2026 by vercel[bot]
Preview – just-use-evlog — be371474 Deployed Oct 8, 2026 by vercel[bot]
Preview – evlog-telemetry — be371474 Deployed Oct 8, 2026 by vercel[bot]
Preview – evlog-docs — be371474 Deployed Oct 8, 2026 by vercel[bot]
Preview – evlog-render-lab — be371474 Deployed Oct 8, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants