Skip to content

chore(fine-tuning): Remove Unused fine-tuning module and endpoints - #1429

Open
Ayush8923 wants to merge 1 commit into
chore/remove-doc-transformationfrom
chore/remove-fine-tuning
Open

Ayush8923 wants to merge 1 commit into
chore/remove-doc-transformationfrom
chore/remove-fine-tuning

Conversation

@Ayush8923

@Ayush8923 Ayush8923 commented Dec 4, 2026 •

Copy link
Copy Markdown
Collaborator

Issue

Closes #1382

What Changed

  • Removed 6 endpoints: POST /fine_tuning/fine_tune, GET /fine_tuning/{fine_tuning_id}/refresh, GET /fine_tuning/{document_id}, POST /model_evaluation/evaluate_models, GET /model_evaluation/{document_id}/top_model and GET /model_evaluation/{document_id}.
  • Added migration 097, which drops the model_evaluation and fine_tuning tables and the modelevaluationstatus / finetuningstatus enum types.
  • Removed the FineTuning* and ModelEvaluation* models, their CRUD helpers, core/finetune/ (DataPreprocessor, ModelEvaluator) and the Project.fine_tuning relationship.
  • Removed the "Fine Tuning" and "Model Evaluation" OpenAPI tags and their route docs. Delete docs for document, project and organization no longer list fine-tunings or model evaluations.
  • Deleted 4 test files and the matching fixtures in tests/utils/test_data.py.

Summary

The whole fine-tuning and model-evaluation vertical slice is removed:

 backend/app/
 ├── alembic/versions/
+│   └── 097_drop_fine_tuning_and_model_evaluation_tables.py
 ├── api/
 │   ├── docs/
-│   │   ├── fine_tuning/
-│   │   └── model_evaluation/
 │   └── routes/
-│       ├── fine_tuning.py
-│       └── model_evaluation.py
 ├── core/
-│   └── finetune/            # preprocessing.py, evaluation.py
 ├── crud/
-│   ├── fine_tuning.py
-│   └── model_evaluation.py
 ├── models/
-│   ├── fine_tuning.py
-│   └── model_evaluation.py
 └── tests/
-    ├── api/routes/test_fine_tuning.py, test_model_evaluation.py
-    └── crud/test_fine_tuning.py, test_model_evaluation.py

Migration 097:

upgrade
  drop table model_evaluation    # FK → fine_tuning, so dropped first
  drop table fine_tuning
  drop type modelevaluationstatus, finetuningstatus

downgrade
  recreate both tables + indexes as of 096 (empty; data is not restored)

Evidence

  • Before: api_router included fine_tuning.router and model_evaluation.router. Their tests (test_fine_tuning.py, test_model_evaluation.py, in both api and crud) exercised these routes.
    After: Both routers are unregistered and their tests are deleted. Per the checklist, the app was booted with fastapi run --reload app/main.py / docker compose up and tested manually.

No test-run output is attached.

Merge Danger

Door: one-way

The upgrade drops fine_tuning and model_evaluation along with all their rows. The downgrade recreates only empty tables, so existing jobs and evaluations are permanently lost. Back up these tables first if the data matters.

Reviewers should check that the downgrade's finetuningstatus enum has pending, running, completed, failed. The removed FineTuningStatus model also had cancelled.

Blast Radius: API consumers

  • Any client still calling /api/v1/fine_tuning/* or /api/v1/model_evaluation/* will stop working.
  • domain-map.md listed the console UI as a consumer of ModelEvaluation. Confirm it no longer calls these routes.
  • This PR is stacked on chore/remove-doc-transformation. Migration 097 revises 096, so merge order matters.

Checklist

Before submitting a pull request, please ensure that you mark these task.

  • Ran fastapi run --reload app/main.py or docker compose up in the repository root and test.
  • If you've fixed a bug or added code that is tested and has test cases.

Notes

Previous PR description

Issue

Closes #1382

Summary

  • Removed the fine-tuning Module and their endpoints which is not used anymore.

Checklist

Before submitting a pull request, please ensure that you mark these task.

  • Ran fastapi run --reload app/main.py or docker compose up in the repository root and test.
  • If you've fixed a bug or added code that is tested and has test cases.

Notes

Remove the /fine_tuning and /model_evaluation endpoints, the
core/finetune preprocessing and evaluator, their CRUD, models, docs,
test fixtures and tests, and the Project relationship. Model evaluation
only scored fine-tuned models, so it goes with fine-tuning.

Migration 097 drops model_evaluation and fine_tuning with their enum
types; the downgrade recreates both empty tables as they stood at 096.
@coderabbitai

coderabbitai Bot commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 37 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between b9453cd and abfe7b2.

Files selected for processing: 33

  • CLAUDE.md
  • backend/app/alembic/versions/097_drop_fine_tuning_and_model_evaluation_tables.py
  • backend/app/api/docs/documents/permanent_delete.md
  • backend/app/api/docs/fine_tuning/create.md
  • backend/app/api/docs/fine_tuning/retrieve.md
  • backend/app/api/docs/model_evaluation/evaluate.md
  • backend/app/api/docs/model_evaluation/examples.py
  • backend/app/api/docs/model_evaluation/get_top_model.md
  • backend/app/api/docs/model_evaluation/list_by_document.md
  • backend/app/api/docs/openapi_config.py
  • backend/app/api/docs/organization/delete.md
  • backend/app/api/docs/projects/delete.md
  • backend/app/api/main.py
  • backend/app/api/routes/fine_tuning.py
  • backend/app/api/routes/model_evaluation.py
  • backend/app/core/finetune/evaluation.py
  • backend/app/core/finetune/preprocessing.py
  • backend/app/crud/__init__.py
  • backend/app/crud/fine_tuning.py
  • backend/app/crud/model_evaluation.py
  • backend/app/crud/organization.py
  • backend/app/crud/project.py
  • backend/app/models/__init__.py
  • backend/app/models/fine_tuning.py
  • backend/app/models/model_evaluation.py
  • backend/app/models/project.py
  • backend/app/tests/api/routes/test_fine_tuning.py
  • backend/app/tests/api/routes/test_model_evaluation.py
  • backend/app/tests/crud/test_fine_tuning.py
  • backend/app/tests/crud/test_model_evaluation.py
  • backend/app/tests/utils/test_data.py
  • docs/architecture/kaapi-knowledge-base-ARCHITECTURE.md
  • docs/wiki/domain-map.md
  • 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

@github-actions github-actions Bot changed the title chore(fine-tuning): Remove the Fine-tuning and Model evaluation modules chore(fine-tuning): Remove modules and endpoints Dec 4, 2026
@Ayush8923
Ayush8923 added this pull request to stack #1432 December 4, 2026 17:34
@Ayush8923
Ayush8923 marked this pull request as ready for review December 4, 2026 17:35

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

Nothing blocking. The comments below are optional suggestions. There is no need to push a fix for them before merging.

Beyond the inline finding, I also looked for leftover references to the removed fine-tuning and model-evaluation code. Outside the alembic migrations, backend/app no longer mentions those modules, models, CRUD, routes or Celery tasks, so I don't expect import or startup errors from the removal.

Extended reasoning...

I searched backend/app (excluding alembic) for fine_tuning, finetune, model_evaluation and the related class names, and nothing matched. The one finding, about old tasks breaking during the migration rollout, is already posted inline.

Comment on lines +24 to +28
def upgrade():
op.drop_table("model_evaluation")
op.drop_table("fine_tuning")
op.execute("DROP TYPE IF EXISTS modelevaluationstatus")
op.execute("DROP TYPE IF EXISTS finetuningstatus")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 (optional) Admins who hard-delete a project or organization during a release rollout get a 500 with "relation fine_tuning does not exist". Migration 097 drops the tables before the ECS rollout replaces the old tasks. Those old tasks still map Project.fine_tuning with cascade_delete=True, so session.delete(project) first SELECTs from fine_tuning. Fix: remove the code in one release and drop the tables in a later one, so no running version still maps them. One way is to merge this change without 097 and add the drop migration afterwards.

Why this was flagged

In .github/workflows/create-release.yml, the "Run database migrations" step runs alembic upgrade head and waits for it to finish. Only then does "Deploy backend service" start the rollout, which has a 15-minute timeout, so old tasks keep serving traffic in that window. On base, backend/app/models/project.py maps fine_tuning: list["FineTuning"] = Relationship(back_populates="project", cascade_delete=True) without passive_deletes. So hard_delete_project (crud/project.py, session.delete(project)) loads that collection, and hard_delete_organization does the same through Organization.project (cascade_delete=True). Once 097 upgrade() has dropped fine_tuning, that load raises ProgrammingError UndefinedTable on old tasks. DELETE requests through api/routes/project.py:253 and api/routes/organization.py:166 then return 500, and the delete is rolled back. The FK ondelete="CASCADE" at the database level does not help, because the ORM issues the SELECT before any DELETE. Before this PR the tables exist, so these deletes work.

Verification: Trigger: an admin hard-deletes a project or organization while old backend tasks are still serving, after migration 097 has run. Old tasks stay in service until the new ones are healthy. In the base crud/project.py (lines 180-181), hard_delete_project calls session.delete(project). The ORM cascade SELECTs from fine_tuning, which migration 097 has dropped, so the request returns a 500.

@Ayush8923 Ayush8923 changed the title chore(fine-tuning): Remove modules and endpoints chore(fine-tuning): Remove fine-tuning module and endpoints Dec 4, 2026
@Ayush8923 Ayush8923 self-assigned this Dec 4, 2026
@codecov

codecov Bot commented Dec 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@Ayush8923 Ayush8923 changed the title chore(fine-tuning): Remove fine-tuning module and endpoints chore(fine-tuning): Remove Unused fine-tuning module and endpoints Dec 4, 2026
@github-actions

github-actions Bot commented Dec 5, 2026

Copy link
Copy Markdown

OpenAPI changes   🔴 18 breaking changes

Caution

Downstream consumers may need an update before merging.

Breaking changes  ·  18
Method Path Change
🔴 GET /api/v1/documents/transformation API path removed without deprecation
🔴 GET /api/v1/documents/transformation/{job_id} API path removed without deprecation
🔴 POST /api/v1/fine_tuning/fine_tune API path removed without deprecation
🔴 GET /api/v1/fine_tuning/{document_id} API path removed without deprecation
🔴 GET /api/v1/fine_tuning/{fine_tuning_id}/refresh API path removed without deprecation
🔴 POST /api/v1/model_evaluation/evaluate_models API path removed without deprecation
🔴 GET /api/v1/model_evaluation/{document_id} API path removed without deprecation
🔴 GET /api/v1/model_evaluation/{document_id}/top_model API path removed without deprecation
🔴 GET /api/v1/openai-conversation API path removed without deprecation
🔴 GET /api/v1/openai-conversation/ancestor/{ancestor_response_id} API path removed without deprecation
🔴 GET /api/v1/openai-conversation/response/{response_id} API path removed without deprecation
🔴 DELETE /api/v1/openai-conversation/{conversation_id} API path removed without deprecation
🔴 GET /api/v1/openai-conversation/{conversation_id} API path removed without deprecation
🔴 POST /api/v1/responses API path removed without deprecation
🔴 POST /api/v1/responses/sync API path removed without deprecation
🔴 POST /api/v1/documents removed the request property callback_url
🔴 POST /api/v1/documents removed the request property target_format
🔴 POST /api/v1/documents removed the request property transformer
Full changelog  ·  45
Method Path Change
🔴 GET /api/v1/documents/transformation API path removed without deprecation
🔴 GET /api/v1/documents/transformation/{job_id} API path removed without deprecation
🔴 POST /api/v1/fine_tuning/fine_tune API path removed without deprecation
🔴 GET /api/v1/fine_tuning/{document_id} API path removed without deprecation
🔴 GET /api/v1/fine_tuning/{fine_tuning_id}/refresh API path removed without deprecation
🔴 POST /api/v1/model_evaluation/evaluate_models API path removed without deprecation
🔴 GET /api/v1/model_evaluation/{document_id} API path removed without deprecation
🔴 GET /api/v1/model_evaluation/{document_id}/top_model API path removed without deprecation
🔴 GET /api/v1/openai-conversation API path removed without deprecation
🔴 GET /api/v1/openai-conversation/ancestor/{ancestor_response_id} API path removed without deprecation
🔴 GET /api/v1/openai-conversation/response/{response_id} API path removed without deprecation
🔴 DELETE /api/v1/openai-conversation/{conversation_id} API path removed without deprecation
🔴 GET /api/v1/openai-conversation/{conversation_id} API path removed without deprecation
🔴 POST /api/v1/responses API path removed without deprecation
🔴 POST /api/v1/responses/sync API path removed without deprecation
🔴 POST /api/v1/documents removed the request property callback_url
🔴 POST /api/v1/documents removed the request property target_format
🔴 POST /api/v1/documents removed the request property transformer
🟢 — — removed the schema APIResponse_CallbackResponse_
🟢 — — removed the schema APIResponse_DocTransformationJobPublic_-Input
🟢 — — removed the schema APIResponse_DocTransformationJobPublic_-Output
🟢 — — removed the schema APIResponse_DocTransformationJobsPublic_
🟢 — — removed the schema APIResponse_FineTuningJobPublic_
🟢 — — removed the schema APIResponse_ModelEvaluationPublic_
🟢 — — removed the schema APIResponse_OpenAIConversationPublic_
🟢 — — removed the schema APIResponse_ResponseJobStatus_
🟢 — — removed the schema APIResponse_list_FineTuningJobPublic__
🟢 — — removed the schema APIResponse_list_ModelEvaluationPublic__
🟢 — — removed the schema APIResponse_list_OpenAIConversationPublic__
🟢 — — removed the schema Body_Fine_Tuning-fine_tune_from_CSV
🟢 — — removed the schema CallbackResponse
🟢 — — removed the schema Diagnostics
🟢 — — removed the schema DocTransformationJobPublic
🟢 — — removed the schema DocTransformationJobsPublic
🟢 — — removed the schema FineTuningJobPublic
🟢 — — removed the schema ModelEvaluationCreate
🟢 — — removed the schema ModelEvaluationPublic
🟢 — — removed the schema ModelEvaluationStatus
🟢 — — removed the schema OpenAIConversationPublic
🟢 — — removed the schema ResponseJobStatus
🟢 — — removed the schema ResponsesAPIRequest
🟢 — — removed the schema ResponsesSyncAPIRequest
🟢 — — removed the schema TransformationJobInfo
🟢 — — removed the schema TransformationStatus
🟢 POST /api/v1/documents removed the optional property data/anyOf[subschema #1: DocumentUploadResponse]/transformation_job from the response with the 200 status

main ↔ 9219c9e8 · generated by oasdiff

@Ayush8923 Ayush8923 added the breaking-change-approved Reviewer-acknowledged API breaking change label Dec 5, 2026

This branch has not been deployed

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

Labels

breaking-change-approved Reviewer-acknowledged API breaking change ready-for-review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cleanup: Remove unused backend modules

1 participant