Skip to content

refactor(api): build the model pages on climate-ref's filters - #156

Merged
lewisjared merged 8 commits into
mainfrom
refactor/model-queries-on-builders
Oct 25, 2026
Merged

lewisjared merged 8 commits into
mainfrom
refactor/model-queries-on-builders

Conversation

@lewisjared

@lewisjared lewisjared commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Moves the models pages onto climate-ref's query builders and filters. model_run_rows, failed_runs and the ensemble comparison now select through select_execution_group_ids, select_execution_groups and select_scalar_values. They no longer hand-build the latest execution, promoted version and retraction checks, so the models pages count groups the same way as the diagnostics pages.

  • model_run_rows joins the filtered groups once to the model datasets of every era. A select per era looked up every group's latest execution again and made /models 54% slower at full scale.
  • failed_runs is now ExecutionGroupFilter(successful=False, input_datasets=...), ordered by updated_at.
  • The ensemble reads values with MetricValueFilter(latest_only=True, dimensions={"kind": "model"}). A value with no kind now counts as a model value, matching the reader.
  • The ensemble's diagnostic_slug filter moves from Python into SQL.
  • era_group_clauses is gone. Every era scope now comes from era_scope.
  • Bumps climate-ref to 0.20.1, whose synthetic database records each group's source types (fix(testing): record each synthetic group's source types climate-ref#1023). This lets the perf suite time the CMIP6 models pages, which matched nothing before.

Timings at full scale (REF_PERF_SCALE=1), against main with only the 0.20.1 bump so both sides read the same database: models.list 1082 → 594 ms, models.list.cmip6 593 → 542 ms, models.get 1394 → 1088 ms, models.get.cmip6 893 → 362 ms, models.ensemble 1449 → 1715 ms, models.ensemble.cmip6 621 → 650 ms. At scale 0.5 the ensemble was 2% faster, so its full-scale number is likely noise. Every other endpoint was within 15%.

The perf comparison on this PR builds the base's database with climate-ref 0.20.0, which has no group source types, so its numbers for the CMIP6 pages compare against empty results.

Summary by CodeRabbit

  • Improvements
    • Model endpoints now count execution groups consistently with diagnostics, providing clearer model run totals.
    • The models list loads about twice as fast on large databases.
    • Ensemble comparisons now include values without a specified kind as model values.

@coderabbitai

coderabbitai Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 2e5b6e3d-6ba7-4727-a4a9-db8f13b7721f
Commits

Reviewing files that changed from the base of the PR and between 7bd72c1 and 3b5110f.

Files ignored due to path filters: 1
  • backend/uv.lock is excluded by !**/*.lock
Files selected for processing: 6
  • backend/src/ref_backend/core/mip_eras.py
  • backend/src/ref_backend/core/model_ensemble.py
  • backend/src/ref_backend/core/model_runs.py
  • backend/tests/perf/test_endpoints.py
  • backend/tests/test_core/test_model_runs.py
  • changelog/156.improvement.md

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Walkthrough

Model queries now use shared scalar-value and execution-group selection helpers. Model-run aggregation counts distinct execution groups by source, diagnostic and outcome. Ensemble lookup applies era and diagnostic-slug filters during selection. Performance endpoint allowlists and the changelog were updated.

Changes: Model queries

Layer / File(s) Summary
Era-scoped ensemble values
backend/src/ref_backend/core/mip_eras.py, backend/src/ref_backend/core/model_ensemble.py, backend/tests/perf/test_endpoints.py
Ensemble queries now select latest scalar model values with era scoping and optional diagnostic-slug filtering. The performance allowlist includes ensemble endpoints.
Execution-group model runs
backend/src/ref_backend/core/model_runs.py, backend/tests/test_core/test_model_runs.py, backend/tests/perf/test_endpoints.py, changelog/156.improvement.md
Model-run rows now aggregate distinct execution groups by source ID, diagnostic ID and outcome. failed_runs selects groups with a failure filter and returns failed or running labels for rows with executions. Tests and performance allowlists cover the updated query shape and model endpoints; the changelog records the endpoint changes.

Sequence Diagram(s)

sequenceDiagram
  participant model_run_rows
  participant _model_groups
  participant select_execution_group_ids
  model_run_rows->>_model_groups: request model-run rows
  _model_groups->>select_execution_group_ids: select groups with era and execution filters
  select_execution_group_ids-->>_model_groups: return filtered group IDs
  _model_groups-->>model_run_rows: return group and execution rows
  model_run_rows->>model_run_rows: count distinct groups by source, diagnostic, and outcome
Loading

Possibly related PRs

Priority: Normal

Change: Refactor

Merge Risk: Minimal · up to 3b511

The checked ensemble and model-run behavior remains consistent with the intended results. No identified issue blocks merging after normal checks.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 76.92% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 13 functions across 5 files. (1 skipped: … Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly summarises the main change: the model pages now use climate-ref filters and query builders. It is concise, specific, and directly related to the changeset.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 76.92% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 13 functions across 5 files. (1 skipped: 1 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · 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.

lewisjared added a commit that referenced this pull request Oct 24, 2026
@lewisjared
lewisjared marked this pull request as ready for review October 24, 2026 22:50
The model list, model detail and ensemble pages now select through
select_execution_group_ids, select_execution_groups and select_scalar_values.
This drops their hand-built latest execution, promoted version and retraction joins,
so the model pages count groups the same way as the diagnostics pages.
The era scope comes from era_scope, as everywhere else.
The group filter looks up each group's latest execution per group,
so a select per era did that twice and made /models 54% slower at full scale.
Joining once to the model datasets of every era runs in half the time main took.
@lewisjared
lewisjared force-pushed the refactor/model-queries-on-builders branch from e02d46e to 748552c Compare October 24, 2026 23:19
@lewisjared
lewisjared merged commit a40f8ba into main Oct 25, 2026
6 checks passed
@lewisjared
lewisjared deleted the refactor/model-queries-on-builders branch October 25, 2026 22:47
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.

1 participant