Skip to content

Add Phase 14 admin schemas for endpoints and presets - #442

Closed
hedhoud wants to merge 7 commits into
linagora:refactor/hexagonalfrom
hedhoud:refactor/phase14-B
Closed

Add Phase 14 admin schemas for endpoints and presets#442
hedhoud wants to merge 7 commits into
linagora:refactor/hexagonalfrom
hedhoud:refactor/phase14-B

Conversation

@hedhoud

@hedhoud hedhoud commented Jun 2, 2026

Copy link
Copy Markdown
Collaborator

Context: Phase 14 introduces model endpoint and pipeline preset management, and Person B needs stable admin API contracts before wiring routers and runtime behavior.\n\nThis PR adds the dependency-light admin schemas for model endpoints, presets, and partition preset assignment. The goal is to make the API contract reviewable early while Person A finishes the backing services and database work.\n\nValidation: Ruff, layer guard, and the full unit suite pass locally.

Summary by CodeRabbit

  • New Features

    • Admin APIs to manage model endpoints (create/list/get/update/delete/promote/validate) with input normalization and sensible defaults.
    • Admin APIs to manage partitions including config read/update endpoints and preset assignment/validation.
    • Admin APIs to create/update/list/get/delete presets and to fetch preset option lists.
    • App wiring: model-endpoints and presets routers are mounted and exposed in OpenAPI tags.
  • Tests

    • Unit tests for schema validation, payload normalization/defaults, router behavior, partition config flows, optional provider resolution, and router mounting.

@coderabbitai

coderabbitai Bot commented Jun 2, 2026

Copy link
Copy Markdown

Review Change Stack

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

Walkthrough

Adds Phase 14 admin Pydantic schemas (model endpoints, partitions, presets), admin routers for model endpoints and presets, DI providers for optional Phase‑14 services, extends admin package exports, and adds unit tests covering normalization, defaults, explicit-null rejection, and update payload requirements.

Changes

Phase 14 Admin Schemas & Routers

Layer / File(s) Summary
Model Endpoint Schemas
openrag/api/schemas/admin/model_endpoint_schemas.py
ModelEndpointType (embedder,reranker,llm,vlm), _normalize_* helpers, CreateModelEndpointRequest and UpdateModelEndpointRequest with name/endpoint normalization and update non-empty check, ModelEndpointResponse, and ValidateEndpointResponse; exported.
Partition schemas
openrag/api/schemas/admin/partition_schemas.py
CreatePartitionRequest and UpdatePartitionRequest with name normalization, default preset/embedder references ("default"), explicit-null rejection, and PartitionDetailResponse.
Preset schemas
openrag/api/schemas/admin/preset_schemas.py
PresetType (indexation,retrieval), CreatePresetRequest and UpdatePresetRequest with name normalization and explicit-null rejection, plus PresetResponse and PresetOptionsResponse.
Admin package re-export
openrag/api/schemas/admin/__init__.py
Extend __all__ to re-export the new model endpoint, partition, and preset schema symbols.
Admin router: model_endpoints
openrag/api/routers/admin/model_endpoints.py
Admin-protected router exposing CRUD, set-default, and validate endpoints for model endpoints; delegates to get_model_endpoint_service.
Admin router: presets
openrag/api/routers/admin/presets.py
Admin-protected router exposing preset options and CRUD endpoints; delegates to get_preset_service and applies registry fallbacks for options.
Admin router: partitions (config)
openrag/api/routers/admin/partitions.py
Adds _require_service_method and admin endpoints PATCH /{partition} and GET /{partition}/config delegating to PartitionService methods and returning PartitionDetailResponse.
DI providers
openrag/di/providers.py
Add _get_optional_service and dependency getters get_model_endpoint_service and get_preset_service; export them via __all__.
Unit tests: schemas
tests/unit/api/schemas/admin/test_phase14_schemas.py
Tests for endpoint URL/name normalization, defaults and constraints, explicit-null rejection, and requiring at least one field on update for model endpoints, presets, and partitions.
Unit tests: admin routers
tests/unit/api/routers/admin/test_phase14_admin_routers.py
FastAPI tests using fake services and admin override verifying normalized payloads and that update routes forward only provided fields.
Unit tests: partition routes
tests/unit/api/routers/admin/test_phase14_partition_routes.py
Async tests for partition config endpoints, including 503 behavior when service methods are absent.
Router import test
tests/unit/api/routers/test_router_imports.py
Add admin router modules to import/has-router assertion list.
DI container tests
tests/unit/di/test_container.py
Mark Phase 14 providers optional in tests, adjust provider wiring assertions, and add tests verifying optional providers resolve or raise HTTP 503 when missing.

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant AdminRouter
  participant ModelEndpointService
  participant ModelEndpointStore
  Client->>AdminRouter: POST/PUT/GET /model-endpoints...
  AdminRouter->>ModelEndpointService: create/update/get/validate (payload/model_type,name)
  ModelEndpointService->>ModelEndpointStore: persist/read/set-default/validate
  ModelEndpointStore-->>ModelEndpointService: record/validation result
  ModelEndpointService-->>AdminRouter: ModelEndpointResponse / ValidateEndpointResponse
  AdminRouter-->>Client: HTTP response (201/200/204)
Loading
classDiagram
  class CreatePartitionRequest {
    string name
    string embedder_name = "default"
    string indexation_preset = "default"
    string retrieval_preset = "default"
    int chat_history_depth = 0
  }
  class UpdatePartitionRequest {
    string|None name
    string|None indexation_preset
    string|None retrieval_preset
    string|None description
    int|None chat_history_depth
  }
  class CreatePresetRequest {
    string name
    PresetType preset_type
    dict config = {}
  }
  class UpdatePresetRequest {
    string|None name
    dict|None config
  }
  class PresetResponse {
    string name
    PresetType preset_type
    dict config
    datetime created_at
    datetime updated_at
  }
  CreatePartitionRequest --|> UpdatePartitionRequest
  CreatePresetRequest --|> UpdatePresetRequest
  UpdatePresetRequest --|> PresetResponse
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • paultranvan

Poem

🐰 I hopped through schemas, tidy and neat,
Trimmed names and endpoints, defaults complete.
Presets, partitions, routers in a line,
DI and tests all passing fine.
A little rabbit cheers this merge — so divine!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 64.58% 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 PR title directly and concisely summarizes the main change: adding Phase 14 admin schemas for two key registry features (model endpoints and presets).
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.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@coderabbitai coderabbitai 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.

Actionable comments posted: 3

🤖 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.

Inline comments:
In `@openrag/api/schemas/admin/model_endpoint_schemas.py`:
- Around line 37-43: The current validate_endpoint field_validator trims
whitespace but checks non-emptiness before removing trailing slashes, so inputs
like "/" or "///" pass then normalize to an empty string; update
validate_endpoint to first strip whitespace, then compute a normalized value =
value.rstrip("/") (or similar) and validate that normalized is non-empty,
raising ValueError("endpoint must be non-empty") if it is empty, and finally
return the normalized value; ensure you update the classmethod validate_endpoint
accordingly so callers get the sanitized, non-empty endpoint.

In `@openrag/api/schemas/admin/partition_schemas.py`:
- Around line 38-54: UpdatePartitionRequest currently accepts explicit nulls for
fields that should not be cleared; add validators to reject None when the client
explicitly sets embedder, indexation_preset, retrieval_preset, description, or
chat_history_depth. Concretely, update or add field validators (e.g.,
on_validate for "embedder", "indexation_preset", "retrieval_preset",
"description", "chat_history_depth") that raise a ValueError if the incoming
value is None (but allow omission), keep using _normalize_name for non-empty
strings in validate_non_empty_name, and leave require_at_least_one_update and
model_fields_set logic intact so clients must provide at least one non-null
update.

In `@openrag/api/schemas/admin/preset_schemas.py`:
- Around line 36-48: Update UpdatePresetRequest so PATCH payloads with explicit
nulls are rejected: add field validators for "name" and "config" that raise when
value is None (so UpdatePresetRequest(name=None) / (config=None) are invalid),
and change the existing model_validator require_at_least_one_update to check
that at least one of the updatable fields is both present and not None (e.g.,
use self.model_fields_set plus a check like any(getattr(self, f) is not None for
f in ("name","config"))). Reference UpdatePresetRequest, the
validate_name/_normalize_name flow, and require_at_least_one_update when making
these changes.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: fbba401e-ec47-4ef6-8e30-d4c2e7abc1ce

📥 Commits

Reviewing files that changed from the base of the PR and between e207d64 and 35e2346.

📒 Files selected for processing (5)
  • openrag/api/schemas/admin/__init__.py
  • openrag/api/schemas/admin/model_endpoint_schemas.py
  • openrag/api/schemas/admin/partition_schemas.py
  • openrag/api/schemas/admin/preset_schemas.py
  • tests/unit/api/schemas/admin/test_phase14_schemas.py

Comment thread openrag/api/schemas/admin/model_endpoint_schemas.py Outdated
Comment thread openrag/api/schemas/admin/partition_schemas.py
Comment thread openrag/api/schemas/admin/preset_schemas.py
@hedhoud hedhoud changed the title phase14-B Add Phase 14 admin schemas for endpoints and presets Jun 2, 2026
@coderabbitai coderabbitai Bot added the feat Add a new feature label Jun 2, 2026
@coderabbitai coderabbitai Bot added the refactor label Jun 2, 2026

@coderabbitai coderabbitai 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.

🧹 Nitpick comments (1)
openrag/api/routers/admin/partitions.py (1)

36-43: 💤 Low value

503 vs 501 for an unimplemented method.

HTTP_503_SERVICE_UNAVAILABLE signals a transient/overloaded condition and may trigger client/proxy retries with backoff. Since this guard reflects a method that isn't wired yet (phased rollout), 501 Not Implemented communicates "permanently unavailable in this build" more accurately and avoids retry storms. If the tests intentionally pin 503 as the contract, feel free to disregard.

🤖 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 `@openrag/api/routers/admin/partitions.py` around lines 36 - 43, The guard
function _require_service_method currently raises HTTPException with
status.HTTP_503_SERVICE_UNAVAILABLE when a service method is not present; change
it to use status.HTTP_501_NOT_IMPLEMENTED so missing/unimplemented methods
return 501 instead of 503. Locate _require_service_method and update the
status_code value in the HTTPException construction (keeping the detail message
and callable check intact), and run/adjust any tests that assert the previous
503 behavior to expect 501.
🤖 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 `@openrag/api/routers/admin/partitions.py`:
- Around line 36-43: The guard function _require_service_method currently raises
HTTPException with status.HTTP_503_SERVICE_UNAVAILABLE when a service method is
not present; change it to use status.HTTP_501_NOT_IMPLEMENTED so
missing/unimplemented methods return 501 instead of 503. Locate
_require_service_method and update the status_code value in the HTTPException
construction (keeping the detail message and callable check intact), and
run/adjust any tests that assert the previous 503 behavior to expect 501.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: ba6338c4-e5bc-41ee-9b46-923efb8082ab

📥 Commits

Reviewing files that changed from the base of the PR and between d177ffb and 6206c86.

📒 Files selected for processing (2)
  • openrag/api/routers/admin/partitions.py
  • tests/unit/api/routers/admin/test_phase14_partition_routes.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feat Add a new feature refactor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant