Skip to content

Incremental model provider stats computation#6290

Merged
virajmehta merged 1 commit intomainfrom
sl/incremental-model-provider-stats
Feb 13, 2026
Merged

Incremental model provider stats computation#6290
virajmehta merged 1 commit intomainfrom
sl/incremental-model-provider-stats

Conversation

@shuyangli
Copy link
Member

@shuyangli shuyangli commented Feb 11, 2026

This adds a way to incrementally refresh model provider stats, and schedules a pgcron job every 5 minutes to refresh the last 10 minutes of data. Also adds a way to do a full refresh (we use this in our tests). We will need to figure out the right way to schedule this job for existing users, but it's sufficient for new users.

Can get merged independently of the model inference table split, because it only touches the metadata columns.

A step towards #5691.

Note

Medium Risk
Touches Postgres migration logic and scheduled refresh behavior for production aggregates; correctness depends on the incremental window/watermark and could lead to stale or incorrect stats if misconfigured.

Overview
Switches model_provider_statistics from a materialized view to a regular table that is maintained via new PL/pgSQL refresh functions and a persisted watermark, avoiding full refreshes on large datasets.

Updates pg_cron setup to run refresh_model_provider_statistics_incremental every 5 minutes (with a 10-minute lookback), adjusts e2e tests to assert this job is scheduled exactly once, and changes the Postgres fixture loader to call a full backfill function instead of REFRESH MATERIALIZED VIEW.

Written by Cursor Bugbot for commit 9cac4cf. This will update automatically on new commits. Configure here.

@shuyangli shuyangli force-pushed the sl/incremental-model-provider-stats branch 3 times, most recently from d3a38c6 to 9cac4cf Compare February 11, 2026 23:19
@shuyangli
Copy link
Member Author

@BugBot review

@shuyangli
Copy link
Member Author

/merge-queue

@github-actions
Copy link
Contributor

🚀 Merge queue workflow triggered!

View the run: https://github.com/tensorzero/tensorzero/actions/runs/21927347534

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

@shuyangli shuyangli marked this pull request as ready for review February 12, 2026 00:14
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9cac4cfb5b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@shuyangli shuyangli force-pushed the sl/incremental-model-provider-stats branch 3 times, most recently from 0aa3538 to de24a8c Compare February 12, 2026 15:04
virajmehta
virajmehta previously approved these changes Feb 12, 2026
Copy link
Member

@virajmehta virajmehta left a comment

Choose a reason for hiding this comment

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

this makes sense but please add a bit more documentation

@virajmehta
Copy link
Member

seems like one of the PG tests is failing too:

stderr ───

thread 'db::model_provider_statistics_queries::test_model_usage_timeseries_monthly_basic_postgres' (21580) panicked at tensorzero-core/tests/e2e/db/model_provider_statistics_queries.rs:34:13:
Input tokens should be positive for model: openai::gpt-4o-mini-2024-07-18
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Cancelling due to test failure: 3 tests still running
PASS [ 1.556s] (350/409) tensorzero-core::e2e db::postgres::pooled_inference_writes::test_flush_on_timeout
────────────
Summary [ 33.684s] 350/409 tests run: 349 passed, 1 failed, 5932 skipped
TRY 3 FAIL [ 0.054s] (349/409) tensorzero-core::e2e db::model_provider_statistics_queries::test_model_usage_timeseries_monthly_basic_postgres

Copy link
Member Author

The failing PG test was because I tried to be clever and coalesce null values to 0, but we actually expect null values, I think

@shuyangli shuyangli force-pushed the sl/incremental-model-provider-stats branch from 9aced72 to 108658f Compare February 13, 2026 01:03
@shuyangli shuyangli requested a review from virajmehta February 13, 2026 01:03
@virajmehta virajmehta added this pull request to the merge queue Feb 13, 2026
Merged via the queue into main with commit c60a9d0 Feb 13, 2026
62 checks passed
@virajmehta virajmehta deleted the sl/incremental-model-provider-stats branch February 13, 2026 03:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments