Skip to content

fix(stats): ignore requests rejected before routing - #59773

Merged
adamdotdevin merged 1 commit into
devfrom
stats-unrouted-models
Oct 28, 2026
Merged

adamdotdevin merged 1 commit into
devfrom
stats-unrouted-models

Conversation

@opencode-agent

Copy link
Copy Markdown
Contributor

Problem

The stats sync counted every Go/Free generation.completed event, including requests rejected before routing (attempts = 0). Those requests have no route, no endpoint and no usage, but their model_requested string still became a model dimension and got a page on /data.

One rejected request on 2026-09-19 for the nonexistent glm-5.5-flash (HTTP 400, 0 attempts, no workspace) produced /data/zhipuai/glm-5.5-flash. That page is now being shared as evidence of an upcoming model.

Change

  • Add attempts > 0 to the source filter of the usage/geo and retention queries, so only requests that reached an upstream route are counted.

R2 check: across all generation.completed rows since 2026-05-28, every attempts = 0 row has no route, failed, and has null usage, and attempts is never null. The filter therefore drops no tokens or cost.

Effects

  • The lake contains no attempts = 0 events after 2026-09-20 13:44 UTC. For current traffic, this is a guard rather than a behavior change.
  • Inside the display window (2026-09-02 to 2026-09-20), the daily history pass will stop counting pre-routing rejections, mostly Free-tier 429/403s and Go 400s. Request, session, unique-user and error counts for those days drop accordingly. Token and cost totals stay the same.
  • The sync only upserts, so rows that already exist for a dimension no fresh query returns are not deleted. The existing glm-5.5-flash row stays until it leaves the 56-day window (about 2026-11-14) unless it is added to the StatsHiddenModels secret.

Verification

  • bun test src/domain in packages/stats/core: 34 pass, including the new query test
  • bun run typecheck in packages/stats/core
  • oxlint on the changed files: clean

Requested by: @adamdotdevin (Adam via Slack)

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change looks sound. Both lake queries, usage/geo and retention, now share the same attempts > 0 guard, placed next to the existing product filter. A request rejected before routing can no longer create a model dimension or a /data page.

I couldn't run this against the R2 lake: there's no access from the review environment, and the lake schema isn't in the repo. So I couldn't confirm that attempts is a column there, or that rows with attempts = 0 never carry usage. If that holds, token and cost totals are unchanged.

bun test src/domain in packages/stats/core passes (34 tests), and tsc --noEmit is clean. The package's typecheck script (bun check --no-script) fails with "Script not found" on the base branch too, so that's unrelated to this change.

Public API: unchanged.

@adamdotdevin
adamdotdevin merged commit 62ae125 into dev Oct 28, 2026
14 checks passed
@adamdotdevin
adamdotdevin deleted the stats-unrouted-models branch October 28, 2026 09:38
alsuren pushed a commit to alsuren/opencode that referenced this pull request Oct 28, 2026
Co-authored-by: adamdotdevin <2363879+adamdotdevin@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant