Skip to content

refactor(intake): complete ClickHouse repository migration - #941

Merged
BrianNewsom merged 10 commits into
mainfrom
clickhouse-complete-repository-migration/brnewsom
Jul 28, 2026
Merged

refactor(intake): complete ClickHouse repository migration#941
BrianNewsom merged 10 commits into
mainfrom
clickhouse-complete-repository-migration/brnewsom

Conversation

@BrianNewsom

@BrianNewsom BrianNewsom commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Summary

  • add domain-facing interfaces and ClickHouse adapters for annotations, evaluator results, spans, and traces
  • add typed registered-table inserts and typed external-data queries to the ClickHouse executor
  • inject repository interfaces through the Intake spans service instead of raw ClickHouse-backed classes
  • remove all remaining direct runtime repository access to the raw ClickHouse client

Stack

Validation

  • Ruff format and lint across Intake: passed
  • targeted ty across repositories, service wiring, and repository tests: passed
  • Intake unit suite: 214 passed
  • complete Intake integration suite on ClickHouse 26.3: 148 passed

Summary by CodeRabbit

  • New Features
    • Added repository support for storing, retrieving, filtering, paginating, and soft-deleting annotations, spans, traces, and evaluator results.
    • Added consistent ClickHouse data access for queries, inserts, pagination, and external data.
  • Bug Fixes
    • Improved handling of empty query results and insert failures with clearer error behavior.
  • Refactor
    • Standardized data access across Intake repositories, improving consistency and maintainability.
  • Tests
    • Expanded coverage for ClickHouse queries, inserts, external data, pagination, and repository behavior.

Signed-off-by: Brian Newsom <brnewsom@nvidia.com>
Signed-off-by: Brian Newsom <brnewsom@nvidia.com>
Signed-off-by: Brian Newsom <brnewsom@nvidia.com>
Signed-off-by: Brian Newsom <brnewsom@nvidia.com>
Signed-off-by: Brian Newsom <brnewsom@nvidia.com>
Signed-off-by: Brian Newsom <brnewsom@nvidia.com>
Signed-off-by: Brian Newsom <brnewsom@nvidia.com>
Base automatically changed from clickhouse-evaluation-read-service/brnewsom to main July 28, 2026 18:03
Signed-off-by: Brian Newsom <brnewsom@nvidia.com>
Signed-off-by: Brian Newsom <brnewsom@nvidia.com>
@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Introduces domain repository interfaces, migrates ClickHouse repositories from the raw client to ClickHouseExecutor, adds typed external-data and insert handling, updates dependency wiring, and adapts architecture and repository tests.

Changes

Intake repository migration

Layer / File(s) Summary
Repository contracts
services/intake/src/nmp/intake/repository/*.py
Adds abstract interfaces for annotations, evaluator results, spans, and traces with typed asynchronous persistence and retrieval methods.
Executor query and insert primitives
services/intake/src/nmp/intake/repository/clickhouse/executor.py
Adds typed external-data queries, structured inserts, insert validation, error translation, and insert logging to ClickHouseExecutor.
Executor-backed repositories
services/intake/src/nmp/intake/repository/clickhouse/*.py
Migrates annotation, evaluator-result, span, and trace repositories to executor-based queries and inserts while preserving filtering, sorting, pagination, and row mapping.
Dependency wiring and validation
services/intake/src/nmp/intake/spans/api/dependencies.py, services/intake/src/nmp/intake/spans/service.py, services/intake/tests/*
Injects ClickHouseExecutor into repositories, updates repository imports, adjusts the architecture allowlist, and updates executor and repository test doubles and assertions.

Sequence Diagram(s)

sequenceDiagram
  participant IntakeSpansService
  participant ClickHouseTraceRepository
  participant ClickHouseExecutor
  participant ClickHouseSpanClient
  IntakeSpansService->>ClickHouseTraceRepository: list traces
  ClickHouseTraceRepository->>ClickHouseExecutor: fetch_scalar and fetch_all
  ClickHouseExecutor->>ClickHouseSpanClient: execute ClickHouseQuery
  ClickHouseSpanClient-->>ClickHouseExecutor: count and row results
  ClickHouseExecutor-->>ClickHouseTraceRepository: normalized rows
  ClickHouseTraceRepository-->>IntakeSpansService: PaginatedResult
Loading

Possibly related PRs

Suggested reviewers: shanaiabuggy, mckornfield, callingmedic911

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 3.70% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ 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 matches the main change: completing the Intake ClickHouse repository migration.
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.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch clickhouse-complete-repository-migration/brnewsom

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (5)
services/intake/src/nmp/intake/repository/clickhouse/trace.py (1)

101-113: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Duplicate total_results pattern. Same as annotations.py; see consolidated comment.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@services/intake/src/nmp/intake/repository/clickhouse/trace.py` around lines
101 - 113, Update the total_results calculation in the trace repository to use
the same consolidated helper or shared pattern established for annotations.py,
instead of duplicating the fetch_scalar, count query, and fallback logic.
Preserve the existing traces.list.count query parameters and zero-result
behavior.
services/intake/src/nmp/intake/repository/clickhouse/annotations.py (1)

86-111: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Duplicate fetch_scalar+or 0+int() pattern for total_results.

Same total_results computation is repeated verbatim across annotations.py, evaluator_results.py, span.py (x2), and trace.py. See consolidated comment.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@services/intake/src/nmp/intake/repository/clickhouse/annotations.py` around
lines 86 - 111, Extract the repeated total_results computation into a shared
helper and reuse it from the annotation listing flow around
_executor.fetch_scalar and the equivalent listing methods in
evaluator_results.py, span.py, and trace.py. Preserve the existing count query,
parameters, and fallback behavior while removing the duplicated fetch_scalar/or
0/int pattern.
services/intake/src/nmp/intake/repository/clickhouse/span.py (2)

160-169: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Duplicate total_results pattern (second occurrence in this file). See consolidated comment.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@services/intake/src/nmp/intake/repository/clickhouse/span.py` around lines
160 - 169, Remove the duplicate total_results calculation in the spans
repository and reuse the consolidated total-results value or shared pattern
already established elsewhere in the file. Update the surrounding list-groups
flow without changing its query or fallback behavior.

94-104: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Duplicate total_results pattern. Same as annotations.py; see consolidated comment.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@services/intake/src/nmp/intake/repository/clickhouse/span.py` around lines 94
- 104, Remove the duplicated total_results count logic from the spans repository
method and reuse the shared pagination/count helper established for
annotations.py. Update the flow around
self._executor.table(ClickHouseTable.SPANS) and the spans.list.count query while
preserving the existing filters and zero-result behavior.
services/intake/src/nmp/intake/repository/clickhouse/evaluator_results.py (1)

83-108: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Duplicate total_results pattern. Same as annotations.py; see consolidated comment.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@services/intake/src/nmp/intake/repository/clickhouse/evaluator_results.py`
around lines 83 - 108, Replace the duplicated total_results count-query pattern
in the evaluator-results listing flow with the consolidated pagination/count
approach already used by annotations.py. Update the code around the
evaluator-results repository method while preserving its table, filters, and
parameters, and keep the existing row pagination behavior unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@services/intake/src/nmp/intake/repository/clickhouse/annotations.py`:
- Around line 86-111: Extract the repeated total_results computation into a
shared helper and reuse it from the annotation listing flow around
_executor.fetch_scalar and the equivalent listing methods in
evaluator_results.py, span.py, and trace.py. Preserve the existing count query,
parameters, and fallback behavior while removing the duplicated fetch_scalar/or
0/int pattern.

In `@services/intake/src/nmp/intake/repository/clickhouse/evaluator_results.py`:
- Around line 83-108: Replace the duplicated total_results count-query pattern
in the evaluator-results listing flow with the consolidated pagination/count
approach already used by annotations.py. Update the code around the
evaluator-results repository method while preserving its table, filters, and
parameters, and keep the existing row pagination behavior unchanged.

In `@services/intake/src/nmp/intake/repository/clickhouse/span.py`:
- Around line 160-169: Remove the duplicate total_results calculation in the
spans repository and reuse the consolidated total-results value or shared
pattern already established elsewhere in the file. Update the surrounding
list-groups flow without changing its query or fallback behavior.
- Around line 94-104: Remove the duplicated total_results count logic from the
spans repository method and reuse the shared pagination/count helper established
for annotations.py. Update the flow around
self._executor.table(ClickHouseTable.SPANS) and the spans.list.count query while
preserving the existing filters and zero-result behavior.

In `@services/intake/src/nmp/intake/repository/clickhouse/trace.py`:
- Around line 101-113: Update the total_results calculation in the trace
repository to use the same consolidated helper or shared pattern established for
annotations.py, instead of duplicating the fetch_scalar, count query, and
fallback logic. Preserve the existing traces.list.count query parameters and
zero-result behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 5944027d-9a2a-4d65-a6d5-7e67a4307221

📥 Commits

Reviewing files that changed from the base of the PR and between 48a2614 and b6f6ffc.

📒 Files selected for processing (16)
  • services/intake/src/nmp/intake/repository/annotations.py
  • services/intake/src/nmp/intake/repository/clickhouse/annotations.py
  • services/intake/src/nmp/intake/repository/clickhouse/evaluation_session.py
  • services/intake/src/nmp/intake/repository/clickhouse/evaluator_results.py
  • services/intake/src/nmp/intake/repository/clickhouse/executor.py
  • services/intake/src/nmp/intake/repository/clickhouse/span.py
  • services/intake/src/nmp/intake/repository/clickhouse/trace.py
  • services/intake/src/nmp/intake/repository/evaluator_results.py
  • services/intake/src/nmp/intake/repository/span.py
  • services/intake/src/nmp/intake/repository/trace.py
  • services/intake/src/nmp/intake/spans/api/dependencies.py
  • services/intake/src/nmp/intake/spans/service.py
  • services/intake/tests/test_clickhouse_architecture.py
  • services/intake/tests/test_clickhouse_executor.py
  • services/intake/tests/test_spans_clickhouse_repository.py
  • services/intake/tests/test_traces_clickhouse_repository.py
💤 Files with no reviewable changes (1)
  • services/intake/tests/test_clickhouse_architecture.py

@github-actions

github-actions Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor
Suite Lines Covered Line Rate Branch Rate
Unit Tests 27559/35314 78.0% 62.5%
Integration Tests 16094/34032 47.3% 19.8%

@BrianNewsom
BrianNewsom added this pull request to the merge queue Jul 28, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jul 28, 2026
@BrianNewsom
BrianNewsom added this pull request to the merge queue Jul 28, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jul 28, 2026
@BrianNewsom
BrianNewsom added this pull request to the merge queue Jul 28, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jul 28, 2026
Signed-off-by: Brian Newsom <brnewsom@nvidia.com>
@BrianNewsom
BrianNewsom added this pull request to the merge queue Jul 28, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jul 28, 2026
@BrianNewsom
BrianNewsom added this pull request to the merge queue Jul 28, 2026
Merged via the queue into main with commit 64cce8d Jul 28, 2026
58 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants