From 0650e5c8bd4ff6c229f5388c19a458eba12274be Mon Sep 17 00:00:00 2001 From: Eric Eastwood Date: Thu, 16 Jul 2026 17:39:59 -0500 Subject: [PATCH 1/2] Fix `check_consistency` using stale value after auto-repair --- synapse/storage/util/sequence.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/synapse/storage/util/sequence.py b/synapse/storage/util/sequence.py index 5bee3cf34f6..18d3cbeafe2 100644 --- a/synapse/storage/util/sequence.py +++ b/synapse/storage/util/sequence.py @@ -184,6 +184,16 @@ def check_consistency( """ txn.execute(sql) + # Since we just auto-repaired, update `last_value` with the new value + # (otherwise we'd make stale comparisons below) + # + # `setval` returns the value the sequence was set to, and marks the sequence + # as `is_called` (i.e. the next `nextval` will return a value strictly + # greater than it), so this is now the true "last value". + row = txn.fetchone() + assert row is not None + (last_value,) = row + txn.close() # If we have values in the stream positions table then they have to be From ba9ac9d7faacf814a52d4e0327c245fe665192be Mon Sep 17 00:00:00 2001 From: Eric Eastwood Date: Thu, 16 Jul 2026 17:45:41 -0500 Subject: [PATCH 2/2] Add changelog --- changelog.d/19973.bugfix | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/19973.bugfix diff --git a/changelog.d/19973.bugfix b/changelog.d/19973.bugfix new file mode 100644 index 00000000000..1c63f00cc49 --- /dev/null +++ b/changelog.d/19973.bugfix @@ -0,0 +1 @@ +Fix bug where Synapse could refuse to start with an `IncorrectDatabaseSetup` error about `stream_positions` being inconsistent with a stream sequence, even though the sequence had just been automatically repaired.