Skip to content

Add GET /runs/trace/{run_id} endpoint#267

Closed
saathviksheerla wants to merge 5 commits intoopenml:mainfrom
saathviksheerla:feat/get-run-trace-endpoint
Closed

Add GET /runs/trace/{run_id} endpoint#267
saathviksheerla wants to merge 5 commits intoopenml:mainfrom
saathviksheerla:feat/get-run-trace-endpoint

Conversation

@saathviksheerla
Copy link
Contributor

Closes #40

Implements the GET /runs/trace/{run_id} endpoint, migrating behavior from the PHP API.

Changes

  • src/database/runs.py — SQL queries for run existence check and trace fetch
  • src/schemas/runs.py — Pydantic models matching PHP response structure
  • src/routers/openml/runs.py — FastAPI endpoint
  • src/main.py — router registration
  • tests/routers/openml/runs_test.py — 6 tests covering happy path, ordering, and error cases

Behavior

  • Returns 571 if run does not exist
  • Returns 572 if run exists but has no trace data
  • Response matches PHP API structure exactly, including string types for all fields

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 8, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

Adds database helpers in src/database/runs.py to fetch a run and its ordered trace iterations. Adds Pydantic schemas in src/schemas/runs.py for trace responses. Introduces a FastAPI router at /runs/trace/{run_id} in src/routers/openml/runs.py that verifies run existence, retrieves ordered trace rows (ordered by repeat, fold, iteration), returns a structured RunTraceResponse on success, and returns HTTP 412 with distinct codes for missing run or missing trace. Registers the router in src/main.py. Adds tests in tests/routers/openml/runs_test.py covering success, ordering, missing run, missing trace, and invalid run_id cases.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: adding a GET endpoint for fetching run traces with a specific run ID path parameter.
Description check ✅ Passed The description is related to the changeset, detailing the files modified, the endpoint behavior, and error handling that matches the implemented code changes.
Linked Issues check ✅ Passed The PR implements the GET /runs/trace/{run_id} endpoint as required by issue #40, with appropriate error codes (571, 572) and response structure matching the PHP API.
Out of Scope Changes check ✅ Passed All changes are in scope: database queries, schemas, router implementation, main.py registration, and comprehensive tests for the endpoint—no extraneous modifications present.
Docstring Coverage ✅ Passed Docstring coverage is 80.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
📝 Coding Plan
  • Generate coding plan for human review comments

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 and usage tips.

Tip

CodeRabbit can enforce grammar and style rules using `languagetool`.

Configure the reviews.tools.languagetool setting to enable/disable rules and categories. Refer to the LanguageTool Community to learn more.

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • The expdb dependency in get_run_trace doesn't need a default of None—dropping the default makes the intent clearer that it must always be provided by FastAPI's dependency injection.
  • In TraceIteration, consider constraining selected to a Literal["true", "false"] to encode the PHP-compatible value space directly in the schema and catch accidental deviations early.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The `expdb` dependency in `get_run_trace` doesn't need a default of `None`—dropping the default makes the intent clearer that it must always be provided by FastAPI's dependency injection.
- In `TraceIteration`, consider constraining `selected` to a `Literal["true", "false"]` to encode the PHP-compatible value space directly in the schema and catch accidental deviations early.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
src/routers/openml/runs.py (1)

35-47: Normalize setup_string, evaluation, and selected to match the explicit type-casting of other fields.

The code explicitly normalizes run_id, repeat, fold, and iteration with str(), but forwards setup_string, evaluation, and selected directly from the SQL row into a schema requiring str. While tests validate these fields are already strings and selected is "true" or "false", this inconsistency creates a fragility point: if the database ever stores a NULL value or non-string type for these fields, Pydantic model construction will fail without a clear error message.

Add str() calls to these three fields at lines 44-46 to match the pattern used for the other iteration fields and ensure consistent defensive programming.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/routers/openml/runs.py` around lines 35 - 47, The TraceIteration
construction in RunTraceResponse currently casts run_id/repeat/fold/iteration to
str but passes setup_string, evaluation, and selected directly; update the
TraceIteration creation (inside RunTraceResponse -> RunTrace -> trace_iteration)
to wrap setup_string, evaluation, and selected with str() as well so all
iteration fields are normalized (e.g., use str(row.setup_string),
str(row.evaluation), str(row.selected)) to avoid Pydantic errors from
NULL/non-string DB values.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/routers/openml/runs.py`:
- Around line 35-47: The TraceIteration construction in RunTraceResponse
currently casts run_id/repeat/fold/iteration to str but passes setup_string,
evaluation, and selected directly; update the TraceIteration creation (inside
RunTraceResponse -> RunTrace -> trace_iteration) to wrap setup_string,
evaluation, and selected with str() as well so all iteration fields are
normalized (e.g., use str(row.setup_string), str(row.evaluation),
str(row.selected)) to avoid Pydantic errors from NULL/non-string DB values.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 7a66e163-c68e-4081-935d-0ad5753181e2

📥 Commits

Reviewing files that changed from the base of the PR and between 72989df and 64ee6c2.

📒 Files selected for processing (5)
  • src/database/runs.py
  • src/main.py
  • src/routers/openml/runs.py
  • src/schemas/runs.py
  • tests/routers/openml/runs_test.py

@codecov
Copy link

codecov bot commented Mar 8, 2026

Codecov Report

❌ Patch coverage is 70.00000% with 9 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (main@f94808c). Learn more about missing BASE report.

Files with missing lines Patch % Lines
src/routers/openml/runs.py 62.50% 6 Missing ⚠️
src/database/runs.py 71.42% 2 Missing ⚠️
src/main.py 50.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #267   +/-   ##
=======================================
  Coverage        ?   55.04%           
=======================================
  Files           ?       37           
  Lines           ?     1477           
  Branches        ?      118           
=======================================
  Hits            ?      813           
  Misses          ?      662           
  Partials        ?        2           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/routers/openml/runs.py`:
- Around line 40-47: Convert the `selected` value to a string when constructing
the TraceIteration so it matches the other iteration fields and the Pydantic
schema: change the construction in the TraceIteration call that currently passes
selected=row.selected to use selected=str(row.selected) (locate the
TraceIteration instantiation that sets repeat=str(row.repeat),
fold=str(row.fold), iteration=str(row.iteration)) so `selected` becomes a string
literal "true"/"false" as expected by the model.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: b3a49664-e599-42cd-b1f4-f36558498629

📥 Commits

Reviewing files that changed from the base of the PR and between 64ee6c2 and 257c444.

📒 Files selected for processing (2)
  • src/routers/openml/runs.py
  • src/schemas/runs.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/schemas/runs.py

@saathviksheerla
Copy link
Contributor Author

@coderabbitai review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 8, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/routers/openml/runs.py`:
- Line 51: Normalize the selected value explicitly instead of relying on
truthiness: replace the ternary that uses row.selected (the selected key in the
serialized output) with an explicit normalization check that handles booleans,
integers, enums, and strings (for example, treat values as true only if they
match True, 1, "1", "true", "t", or "yes" case-insensitively); update the
serialization that sets selected="true"/"false" to use that normalization logic
(or a small helper like normalize_selected(value)) so string values like "false"
no longer serialize as "true".

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 1415a658-924d-4dbd-a450-2656165973f4

📥 Commits

Reviewing files that changed from the base of the PR and between 257c444 and ae1f456.

📒 Files selected for processing (1)
  • src/routers/openml/runs.py

@saathviksheerla
Copy link
Contributor Author

@coderabbitai review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 8, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/routers/openml/runs.py`:
- Around line 45-51: When constructing the TraceIteration instance, explicitly
cast the database value for evaluation to a string instead of forwarding the raw
value; update the TraceIteration(...) call (the evaluation argument alongside
repeat, fold, iteration) to use str(row.evaluation) so TraceIteration.evaluation
is always a string and matches the model/tests.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 0101722f-6ed4-4983-a863-5d2df0d9f22d

📥 Commits

Reviewing files that changed from the base of the PR and between ae1f456 and 6b876f3.

📒 Files selected for processing (1)
  • src/routers/openml/runs.py

@saathviksheerla
Copy link
Contributor Author

@PGijsbers ready for your review.
All local tests pass (144 passed).
The failing CI check is test_estimation_procedure_list in evaluationmeasures_test.py — it's a pre-existing failure on main unrelated to this PR (extra 'percentage': None field in the response diff).

@saathviksheerla saathviksheerla force-pushed the feat/get-run-trace-endpoint branch from 53a1e33 to 6b876f3 Compare March 13, 2026 13:37
@saathviksheerla saathviksheerla deleted the feat/get-run-trace-endpoint branch March 13, 2026 13:53
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.

GET /run/trace/{id}

1 participant