Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
132 changes: 132 additions & 0 deletions backend/app/alembic/versions/095_drop_openai_conversation_table.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
"""drop openai_conversation

Revision ID: 095
Revises: 094
Create Date: 2026-12-04 00:00:00.000000

The Responses API and OpenAI Conversations modules were removed, so nothing reads or
writes this table any more. Rows are lost on upgrade; downgrade restores the schema
as it stood at 094 (an empty table) so older code can boot, not the data.
"""

import sqlalchemy as sa
from alembic import op

revision = "095"
down_revision = "094"
branch_labels = None
depends_on = None


def upgrade():
op.drop_table("openai_conversation")

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) During a deploy, admins on still-running old tasks get 500s on every project and organization hard delete. The migration runs before the new image takes over. upgrade() drops openai_conversation while old code still maps it through cascade_delete=True relationships. Fix: split the removal across two releases. Ship the code removal now and drop the table in a later migration, after no running code references it. Otherwise, document that the drop must run only after the old tasks are drained.

Why this was flagged

deploy-staging-ecs.yml runs a one-off task with alembic upgrade head in its "Run database migrations" step. Only after that does "Deploy to ECS and verify rollout" start, with a 15-minute timeout, so base-image tasks keep serving after 095 has run. In the base code, Project.openai_conversations and Organization.openai_conversations were Relationship(..., cascade_delete=True). SQLModel turns that into an ORM delete cascade without passive_deletes. So session.delete(project) in hard_delete_project (crud/project.py:180) and the organization hard delete both SELECT from openai_conversation before deleting. Once 095 has dropped the table, those SELECTs fail with UndefinedTable. Project and org hard deletes then return 500 on old tasks until the rollout finishes. The base branch has no such window. The DB-level ON DELETE CASCADE does not help, because the ORM query runs first. This is a cost beside the PR's purpose of removing the module, not something the purpose requires. Dropping the table in a later release avoids it.

Verification: The migration drops the table outright: op.drop_table("openai_conversation") (095_drop_openai_conversation_table.py:21-22). The base image still maps that table. On an old task, the hard-delete flush issues the collection SELECT against the dropped table. It fails with UndefinedTable / ProgrammingError, so the delete request returns 500. Nothing handles old code running after the upgrade.



def downgrade():
op.create_table(
"openai_conversation",
sa.Column(
"id",
sa.Integer(),
nullable=False,
comment="Unique identifier for the conversation record",
),
sa.Column(
"response_id",
sa.String(),
nullable=False,
comment="OpenAI response identifier",
),
sa.Column(
"ancestor_response_id",
sa.String(),
nullable=False,
comment="Root response ID for conversation threading",
),
sa.Column(
"previous_response_id",
sa.String(),
nullable=True,
comment="Previous response ID in the conversation chain",
),
sa.Column(
"user_question",
sa.String(),
nullable=False,
comment="User's question or input text",
),
sa.Column(
"response",
sa.String(),
nullable=True,
comment="Response generated by OpenAI",
),
sa.Column(
"model",
sa.String(),
nullable=False,
comment="Model used to generate the response",
),
sa.Column(
"assistant_id",
sa.String(),
nullable=True,
comment="OpenAI assistant identifier if used",
),
sa.Column(
"project_id",
sa.Integer(),
nullable=False,
comment="Reference to the project",
),
sa.Column(
"organization_id",
sa.Integer(),
nullable=False,
comment="Reference to the organization",
),
sa.Column(
"inserted_at",
sa.DateTime(),
nullable=False,
comment="Timestamp when the conversation was created",
),
sa.Column(
"updated_at",
sa.DateTime(),
nullable=False,
comment="Timestamp when the conversation was last updated",
),
sa.Column(
"deleted_at",
sa.DateTime(),
nullable=True,
comment="Timestamp when the conversation was deleted",
),
sa.ForeignKeyConstraint(
["organization_id"], ["organization.id"], ondelete="CASCADE"
),
sa.ForeignKeyConstraint(["project_id"], ["project.id"], ondelete="CASCADE"),
sa.PrimaryKeyConstraint("id"),
)
op.create_index(
"ix_openai_conversation_project_id", "openai_conversation", ["project_id"]
)
op.create_index(
"ix_openai_conversation_response_project_active",
"openai_conversation",
["response_id", "project_id"],
postgresql_where=sa.text("deleted_at IS NULL"),
)
op.create_index(
"ix_openai_conversation_ancestor_project_inserted_at_active",
"openai_conversation",
["ancestor_response_id", "project_id", sa.text("inserted_at DESC")],
postgresql_where=sa.text("deleted_at IS NULL"),
)
op.create_index(
"ix_openai_conversation_project_inserted_at_active",
"openai_conversation",
["project_id", sa.text("inserted_at DESC")],
postgresql_where=sa.text("deleted_at IS NULL"),
)
3 changes: 0 additions & 3 deletions backend/app/api/docs/openai_conversation/delete.md

This file was deleted.

3 changes: 0 additions & 3 deletions backend/app/api/docs/openai_conversation/get.md

This file was deleted.

This file was deleted.

This file was deleted.

3 changes: 0 additions & 3 deletions backend/app/api/docs/openai_conversation/list.md

This file was deleted.

5 changes: 0 additions & 5 deletions backend/app/api/docs/openapi_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,6 @@
"Model Evaluation": (
"Evaluate fine-tuned models for a document and find the best-performing one."
),
"OpenAI Conversations": (
"Read and delete stored OpenAI Responses conversations, looked up by id, "
"response id or ancestor response id."
),
"Assistants": (
"[**Deprecated**] OpenAI Assistant creation and management. This "
"feature will be removed in a future version."
Expand Down Expand Up @@ -171,7 +167,6 @@
"Assessment (Experimental)",
"Fine Tuning",
"Model Evaluation",
"OpenAI Conversations",
"Assistants",
"Threads",
],
Expand Down
2 changes: 1 addition & 1 deletion backend/app/api/docs/organization/delete.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ Supports two delete modes, selected by an optional request body:
```

- **`hard_delete: false` (default)** — *Soft delete.* The organization is marked **inactive** and all of its projects are deactivated as well. No data is removed, so the organization can be reactivated later. It simply stops appearing in listings and can no longer be used. Omitting the body entirely also performs a soft delete.
- **`hard_delete: true`** — *Permanent delete.* The organization and everything owned by it — projects, collections, documents, credentials, assistants, fine-tunings, conversations, and user-project mappings — are permanently removed. **This cannot be undone.**
- **`hard_delete: true`** — *Permanent delete.* The organization and everything owned by it — projects, collections, documents, credentials, assistants, fine-tunings, and user-project mappings — are permanently removed. **This cannot be undone.**

In both modes, user **accounts are never deleted** (a user may belong to other organizations). Any user left without an active project afterwards is marked **inactive** and can no longer log in until they are added to an active project again.
2 changes: 1 addition & 1 deletion backend/app/api/docs/projects/delete.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ Supports two delete modes, selected by an optional request body:
```

- **`hard_delete: false` (default)** — *Soft delete.* The project is marked **inactive**. No data is removed, so the project can be reactivated later. It simply stops appearing in listings and can no longer be used. Omitting the body entirely also performs a soft delete.
- **`hard_delete: true`** — *Permanent delete.* The project and everything owned by it — collections, documents, credentials, assistants, fine-tunings, conversations, and user-project mappings — are permanently removed. **This cannot be undone.**
- **`hard_delete: true`** — *Permanent delete.* The project and everything owned by it — collections, documents, credentials, assistants, fine-tunings, and user-project mappings — are permanently removed. **This cannot be undone.**

In both modes, user **accounts are never deleted** (a user may belong to other projects). Any user left without an active project afterwards is marked **inactive** and can no longer log in until they are added to an active project again.
2 changes: 0 additions & 2 deletions backend/app/api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
model_config,
model_evaluation,
onboarding,
openai_conversation,
organization,
project,
threads,
Expand Down Expand Up @@ -71,7 +70,6 @@
api_router.include_router(model_config.router)
api_router.include_router(model_evaluation.router)
api_router.include_router(onboarding.router)
api_router.include_router(openai_conversation.router)
api_router.include_router(organization.router)
api_router.include_router(project.router)
api_router.include_router(threads.router)
Expand Down
163 changes: 0 additions & 163 deletions backend/app/api/routes/openai_conversation.py

This file was deleted.

11 changes: 0 additions & 11 deletions backend/app/crud/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,6 @@
delete_assistant,
)

from .openai_conversation import (
get_ancestor_id_from_response,
get_conversation_by_id,
get_conversation_by_response_id,
get_conversation_by_ancestor_id,
get_conversations_by_project,
get_conversations_count_by_project,
create_conversation,
delete_conversation,
)

from .fine_tuning import (
create_fine_tuning_job,
fetch_by_id,
Expand Down
Loading
Loading