Skip to content

πŸ™Œ OpenHands: AI-Driven Development

PLTF-2895: event_callback index β€” use plain CREATE INDEX (#14651)

aivong-openhands57b0da3df607
diff --git a/enterprise/migrations/versions/117_add_event_callback_composite_index.py b/enterprise/migrations/versions/117_add_event_callback_composite_index.py
index eeb6dd1b9b..9350fea582 100644
--- a/enterprise/migrations/versions/117_add_event_callback_composite_index.py
+++ b/enterprise/migrations/versions/117_add_event_callback_composite_index.py
@@ -5,14 +5,18 @@ but none of these columns were indexed, causing full sequential scans on the
event_callback table for every event dispatch (INC-95). This composite index
directly covers that query.
-The equivalent index is defined for the OSS app_server alembic chain in
-openhands/app_server/app_lifespan/alembic/versions/010.py. That chain is only
-run by OssAppLifespanService; the SaaS deployment applies DB migrations solely
-through this enterprise chain, so the index must also be created here. Both use
-IF NOT EXISTS so they are safe to coexist.
-
-CREATE INDEX CONCURRENTLY is used (inside an autocommit block) to avoid locking
-the table during deployment.
+Implementation note: this migration runs through the enterprise alembic harness
+(migrations/env.py), which acquires a session-level pg_advisory_lock on the
+migration connection before opening the migration transaction. That pre-opened
+transaction makes alembic's autocommit_block() (required for CREATE INDEX
+CONCURRENTLY) raise an AssertionError, so a CONCURRENTLY build is not possible
+here. event_callback is small, so a plain transactional CREATE INDEX completes
+in well under a second; the brief lock on writes during the build is acceptable
+and is consistent with every other migration in this chain.
+
+The OSS app_server chain creates the equivalent index in
+openhands/app_server/app_lifespan/alembic/versions/010.py. Both use IF NOT
+EXISTS so they are safe to coexist across deployment modes.
Revision ID: 117
Revises: 116
@@ -30,21 +34,17 @@ depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
- with op.get_context().autocommit_block():
- op.create_index(
- 'ix_event_callback_conversation_id_status_event_kind',
- 'event_callback',
- ['conversation_id', 'status', 'event_kind'],
- postgresql_concurrently=True,
- if_not_exists=True,
- )
+ op.create_index(
+ 'ix_event_callback_conversation_id_status_event_kind',
+ 'event_callback',
+ ['conversation_id', 'status', 'event_kind'],
+ if_not_exists=True,
+ )
def downgrade() -> None:
- with op.get_context().autocommit_block():
- op.drop_index(
- 'ix_event_callback_conversation_id_status_event_kind',
- table_name='event_callback',
- postgresql_concurrently=True,
- if_exists=True,
- )
+ op.drop_index(
+ 'ix_event_callback_conversation_id_status_event_kind',
+ table_name='event_callback',
+ if_exists=True,
+ )