From a23aa4320e63db811d3f80ac3f1a2956282d2c53 Mon Sep 17 00:00:00 2001 From: kenyonxu Date: Thu, 11 Jun 2026 13:06:19 +0800 Subject: [PATCH] fix(gateway): move handoff_state index to DEFERRED_INDEX_SQL MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The index references the handoff_state column which is added by _reconcile_columns() on legacy databases. Placing it in SCHEMA_SQL causes 'no such column' errors during schema migration tests because SCHEMA_SQL runs before reconciliation. Move to DEFERRED_INDEX_SQL which runs after _reconcile_columns() — matching the existing pattern used by idx_messages_session_active. Refs: #43504, #40695 (cherry picked from commit 40ecd61d4993754e077a2bdf0c68707cd2add5f4) --- hermes_state.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hermes_state.py b/hermes_state.py index f1015a15b14..2763fb5084e 100644 --- a/hermes_state.py +++ b/hermes_state.py @@ -740,6 +740,8 @@ CREATE INDEX IF NOT EXISTS idx_sessions_session_key ON sessions(session_key, started_at DESC); CREATE INDEX IF NOT EXISTS idx_sessions_gateway_peer ON sessions(source, user_id, chat_id, chat_type, thread_id, started_at DESC); +CREATE INDEX IF NOT EXISTS idx_sessions_handoff_state + ON sessions(handoff_state, started_at); """ FTS_SQL = """