diff --git a/packages/overlays/matrix-synapse/patches/0001-Add-CVE-IDs-to-changelog-for-1.152.1.-19778.patch b/packages/overlays/matrix-synapse/patches/0001-Add-CVE-IDs-to-changelog-for-1.152.1.-19778.patch
new file mode 100644
index 0000000..adbc9fc
--- /dev/null
+++ b/packages/overlays/matrix-synapse/patches/0001-Add-CVE-IDs-to-changelog-for-1.152.1.-19778.patch
@@ -0,0 +1,29 @@
+From 16c17f3a420242e53088337d48b1fb55a86e3a8f Mon Sep 17 00:00:00 2001
+From: Denis Kasak <dkasak@termina.org.uk>
+Date: Wed, 13 May 2026 17:26:16 +0200
+Subject: [PATCH 01/19] Add CVE IDs to changelog for 1.152.1. (#19778)
+
+Since this is just a change log update, I've removed the entire
+checklist. Please tell me if this is incorrect.
+---
+ CHANGES.md | 4 ++--
+ 1 file changed, 2 insertions(+), 2 deletions(-)
+
+diff --git a/CHANGES.md b/CHANGES.md
+index d9b3f8b2c1..f0488cd68c 100644
+--- a/CHANGES.md
++++ b/CHANGES.md
+@@ -2,8 +2,8 @@
+
+ ## Security Fixes
+
+-- Prevent CPU starvation (Denial of Service) under worker lock contention, additionally capping the `WorkerLock` time out interval to a maximum of 60 seconds. Contributed by Famedly. ([\#19394](https://github.com/element-hq/synapse/issues/19394), ELEMENTSEC-2026-1706, [GHSA-8q93-326v-3m7g](https://github.com/element-hq/synapse/security/advisories/GHSA-8q93-326v-3m7g), CVE pending)
+-- Prevent pagination ending when a page is full of rejected events. (ELEMENTSEC-2025-1636, [GHSA-6qf2-7x63-mm6v](https://github.com/element-hq/synapse/security/advisories/GHSA-6qf2-7x63-mm6v), CVE pending)
++- Prevent CPU starvation (Denial of Service) under worker lock contention, additionally capping the `WorkerLock` time out interval to a maximum of 60 seconds. Contributed by Famedly. ([\#19394](https://github.com/element-hq/synapse/issues/19394), ELEMENTSEC-2026-1706, [GHSA-8q93-326v-3m7g](https://github.com/element-hq/synapse/security/advisories/GHSA-8q93-326v-3m7g), CVE-2026-45078)
++- Prevent pagination ending when a page is full of rejected events. (ELEMENTSEC-2025-1636, [GHSA-6qf2-7x63-mm6v](https://github.com/element-hq/synapse/security/advisories/GHSA-6qf2-7x63-mm6v), CVE-2026-45076)
+
+
+ # Synapse 1.152.0 (2026-04-28)
+--
+2.53.0
+
diff --git a/packages/overlays/matrix-synapse/patches/0001-nix-use-postgres-17.patch b/packages/overlays/matrix-synapse/patches/0002-nix-use-postgres-17.patch
index ae24787..959b903 100644
--- a/packages/overlays/matrix-synapse/patches/0001-nix-use-postgres-17.patch
+++ b/packages/overlays/matrix-synapse/patches/0002-nix-use-postgres-17.patch
@@ -1,7 +1,7 @@
-From 3854baab3efd243cd62f9e30bb1d2edea685cb1f Mon Sep 17 00:00:00 2001
+From e2b5f1ee0eac4b9c84e99fe9eb0d6a59103149a2 Mon Sep 17 00:00:00 2001
From: Rory& <root@rory.gay>
Date: Fri, 25 Jul 2025 08:25:28 +0200
-Subject: [PATCH 01/24] nix: use postgres 17
+Subject: [PATCH 02/19] nix: use postgres 17
Signed-off-by: Rory& <root@rory.gay>
---
diff --git a/packages/overlays/matrix-synapse/patches/0002-nix-fix-flake.patch b/packages/overlays/matrix-synapse/patches/0003-nix-fix-flake.patch
index ea8c622..311bc81 100644
--- a/packages/overlays/matrix-synapse/patches/0002-nix-fix-flake.patch
+++ b/packages/overlays/matrix-synapse/patches/0003-nix-fix-flake.patch
@@ -1,7 +1,7 @@
-From f30af4b3169b497ea54f3e16f7bd188efcd32b4f Mon Sep 17 00:00:00 2001
+From cf9633037f4927bedf4d8c89386cd8fa33984cad Mon Sep 17 00:00:00 2001
From: Rory& <root@rory.gay>
Date: Mon, 9 Jun 2025 17:38:34 +0200
-Subject: [PATCH 02/24] nix: fix flake
+Subject: [PATCH 03/19] nix: fix flake
Signed-off-by: Rory& <root@rory.gay>
---
diff --git a/packages/overlays/matrix-synapse/patches/0003-nix-Update-flake.patch b/packages/overlays/matrix-synapse/patches/0004-nix-Update-flake.patch
index 8f00ff9..36f1e19 100644
--- a/packages/overlays/matrix-synapse/patches/0003-nix-Update-flake.patch
+++ b/packages/overlays/matrix-synapse/patches/0004-nix-Update-flake.patch
@@ -1,7 +1,7 @@
-From 45faeed7e54c334d430141e456253510d2e4abcd Mon Sep 17 00:00:00 2001
+From 33cb357d30e5817bf679fc161a3a333a37579188 Mon Sep 17 00:00:00 2001
From: Rory& <root@rory.gay>
Date: Thu, 13 Nov 2025 13:57:10 +0100
-Subject: [PATCH 03/24] nix: Update flake
+Subject: [PATCH 04/19] nix: Update flake
Signed-off-by: Rory& <root@rory.gay>
---
@@ -44,7 +44,7 @@ index 4e2f01153b..0f2de20b2b 100644
},
"original": {
diff --git a/flake.nix b/flake.nix
-index cc41490a41..5bde1e6c07 100644
+index cc41490a41..50ae70e989 100644
--- a/flake.nix
+++ b/flake.nix
@@ -82,7 +82,7 @@
@@ -52,7 +52,7 @@ index cc41490a41..5bde1e6c07 100644
# NOTE: We currently need to set the Rust version unnecessarily high
# in order to work around https://github.com/matrix-org/synapse/issues/15939
- (rust-bin.stable."1.87.0".default.override {
-+ (rust-bin.stable."1.88.0".default.override {
++ (rust-bin.stable."1.89.0".default.override {
# Additionally install the "rust-src" extension to allow diving into the
# Rust source code in an IDE (rust-analyzer will also make use of it).
extensions = [ "rust-src" ];
diff --git a/packages/overlays/matrix-synapse/patches/0004-nix-Temporarily-disable-go-in-flake.patch b/packages/overlays/matrix-synapse/patches/0005-nix-Temporarily-disable-go-in-flake.patch
index ecfa5e0..3b9e543 100644
--- a/packages/overlays/matrix-synapse/patches/0004-nix-Temporarily-disable-go-in-flake.patch
+++ b/packages/overlays/matrix-synapse/patches/0005-nix-Temporarily-disable-go-in-flake.patch
@@ -1,7 +1,7 @@
-From 13fa20d227a762a848ebd4d522b8e0f10c7404c6 Mon Sep 17 00:00:00 2001
+From cda3b7476e27da235c8304abac8a1cf32ad2c576 Mon Sep 17 00:00:00 2001
From: Rory& <root@rory.gay>
Date: Sat, 16 Aug 2025 20:18:45 +0200
-Subject: [PATCH 04/24] nix: Temporarily disable go in flake
+Subject: [PATCH 05/19] nix: Temporarily disable go in flake
Signed-off-by: Rory& <root@rory.gay>
---
@@ -9,7 +9,7 @@ Signed-off-by: Rory& <root@rory.gay>
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/flake.nix b/flake.nix
-index 5bde1e6c07..cf7a731f51 100644
+index 50ae70e989..ef944747cb 100644
--- a/flake.nix
+++ b/flake.nix
@@ -151,7 +151,7 @@
diff --git a/packages/overlays/matrix-synapse/patches/0005-Add-test-script.patch b/packages/overlays/matrix-synapse/patches/0006-Add-test-script.patch
index 88b3efb..300d132 100644
--- a/packages/overlays/matrix-synapse/patches/0005-Add-test-script.patch
+++ b/packages/overlays/matrix-synapse/patches/0006-Add-test-script.patch
@@ -1,7 +1,7 @@
-From c5168c1e88c635df2ef8b9aaf1921657034c0b35 Mon Sep 17 00:00:00 2001
+From 7218323ec2954bca8af95af70cf9d8d2a064fa3c Mon Sep 17 00:00:00 2001
From: Rory& <root@rory.gay>
Date: Thu, 13 Nov 2025 13:56:59 +0100
-Subject: [PATCH 05/24] Add test script
+Subject: [PATCH 06/19] Add test script
Signed-off-by: Rory& <root@rory.gay>
---
diff --git a/packages/overlays/matrix-synapse/patches/0006-Fix-gitignore-to-ignore-.venv.patch b/packages/overlays/matrix-synapse/patches/0007-Fix-gitignore-to-ignore-.venv.patch
index 8f54a16..2ab29dd 100644
--- a/packages/overlays/matrix-synapse/patches/0006-Fix-gitignore-to-ignore-.venv.patch
+++ b/packages/overlays/matrix-synapse/patches/0007-Fix-gitignore-to-ignore-.venv.patch
@@ -1,7 +1,7 @@
-From 3d2ae2ecffcac03cfa93c206ad8079adf8b206fa Mon Sep 17 00:00:00 2001
+From 527765f8a34f0f4c32973b31909e67f2bcf02035 Mon Sep 17 00:00:00 2001
From: Rory& <root@rory.gay>
Date: Mon, 9 Jun 2025 17:46:10 +0200
-Subject: [PATCH 06/24] Fix gitignore to ignore .venv
+Subject: [PATCH 07/19] Fix gitignore to ignore .venv
Signed-off-by: Rory& <root@rory.gay>
---
diff --git a/packages/overlays/matrix-synapse/patches/0007-Fast-auth-links.patch b/packages/overlays/matrix-synapse/patches/0008-Fast-auth-links.patch
index c57986c..b77ad1b 100644
--- a/packages/overlays/matrix-synapse/patches/0007-Fast-auth-links.patch
+++ b/packages/overlays/matrix-synapse/patches/0008-Fast-auth-links.patch
@@ -1,7 +1,7 @@
-From 9e7ae8bcd370f79a657d44f2d89b641f1abe68e7 Mon Sep 17 00:00:00 2001
+From 064fbcdd10c15eea7f695b693c7ee1ef99b6b606 Mon Sep 17 00:00:00 2001
From: Rory& <root@rory.gay>
Date: Tue, 22 Jul 2025 05:07:01 +0200
-Subject: [PATCH 07/24] Fast auth links
+Subject: [PATCH 08/19] Fast auth links
Signed-off-by: Rory& <root@rory.gay>
---
diff --git a/packages/overlays/matrix-synapse/patches/0008-Add-too-much-logging-to-room-summary-over-federation.patch b/packages/overlays/matrix-synapse/patches/0009-Add-too-much-logging-to-room-summary-over-federation.patch
index 29736d4..ecbeb9f 100644
--- a/packages/overlays/matrix-synapse/patches/0008-Add-too-much-logging-to-room-summary-over-federation.patch
+++ b/packages/overlays/matrix-synapse/patches/0009-Add-too-much-logging-to-room-summary-over-federation.patch
@@ -1,7 +1,7 @@
-From 657c794672e1ae73e2689b576ed55286a6961805 Mon Sep 17 00:00:00 2001
+From e0c0a852c437a5eef52041ec42edfbc6d0b913ca Mon Sep 17 00:00:00 2001
From: Rory& <root@rory.gay>
Date: Wed, 23 Apr 2025 17:53:52 +0200
-Subject: [PATCH 08/24] Add too much logging to room summary over federation
+Subject: [PATCH 09/19] Add too much logging to room summary over federation
Signed-off-by: Rory& <root@rory.gay>
---
diff --git a/packages/overlays/matrix-synapse/patches/0009-Log-entire-room-if-accessibility-check-fails.patch b/packages/overlays/matrix-synapse/patches/0010-Log-entire-room-if-accessibility-check-fails.patch
index 4074550..1d480e4 100644
--- a/packages/overlays/matrix-synapse/patches/0009-Log-entire-room-if-accessibility-check-fails.patch
+++ b/packages/overlays/matrix-synapse/patches/0010-Log-entire-room-if-accessibility-check-fails.patch
@@ -1,7 +1,7 @@
-From 037f114b2a3f49bd6efbba061a6d9d89cd845f05 Mon Sep 17 00:00:00 2001
+From 8f2314ceaf0d459bf11df840ce14918292f5b90d Mon Sep 17 00:00:00 2001
From: Rory& <root@rory.gay>
Date: Wed, 23 Apr 2025 18:24:57 +0200
-Subject: [PATCH 09/24] Log entire room if accessibility check fails
+Subject: [PATCH 10/19] Log entire room if accessibility check fails
Signed-off-by: Rory& <root@rory.gay>
---
diff --git a/packages/overlays/matrix-synapse/patches/0010-Use-parse_boolean-for-unredacted-content.patch b/packages/overlays/matrix-synapse/patches/0011-Use-parse_boolean-for-unredacted-content.patch
index de8b635..f2361c8 100644
--- a/packages/overlays/matrix-synapse/patches/0010-Use-parse_boolean-for-unredacted-content.patch
+++ b/packages/overlays/matrix-synapse/patches/0011-Use-parse_boolean-for-unredacted-content.patch
@@ -1,7 +1,7 @@
-From 6894b8d14cb0b02e8a6fd0120ffd63b0387fbd98 Mon Sep 17 00:00:00 2001
+From c4f5b54b4bc425ff0adc10ef44b1e91cd33fc969 Mon Sep 17 00:00:00 2001
From: Rory& <root@rory.gay>
Date: Tue, 27 May 2025 06:14:26 +0200
-Subject: [PATCH 10/24] Use parse_boolean for unredacted content
+Subject: [PATCH 11/19] Use parse_boolean for unredacted content
Signed-off-by: Rory& <root@rory.gay>
---
diff --git a/packages/overlays/matrix-synapse/patches/0011-Expose-tombstone-in-room-admin-api.patch b/packages/overlays/matrix-synapse/patches/0012-Expose-tombstone-in-room-admin-api.patch
index 37254e3..9c414b8 100644
--- a/packages/overlays/matrix-synapse/patches/0011-Expose-tombstone-in-room-admin-api.patch
+++ b/packages/overlays/matrix-synapse/patches/0012-Expose-tombstone-in-room-admin-api.patch
@@ -1,7 +1,7 @@
-From 95f19ecaa28acb6299ced36ac408af368c200937 Mon Sep 17 00:00:00 2001
+From 4a87e254861c102323b9f3bdab14b792da995069 Mon Sep 17 00:00:00 2001
From: Rory& <root@rory.gay>
Date: Tue, 27 May 2025 06:37:52 +0200
-Subject: [PATCH 11/24] Expose tombstone in room admin api
+Subject: [PATCH 12/19] Expose tombstone in room admin api
Signed-off-by: Rory& <root@rory.gay>
---
diff --git a/packages/overlays/matrix-synapse/patches/0013-Fix-pagination-with-large-gaps-of-rejected-events.patch b/packages/overlays/matrix-synapse/patches/0013-Fix-pagination-with-large-gaps-of-rejected-events.patch
deleted file mode 100644
index 1afd173..0000000
--- a/packages/overlays/matrix-synapse/patches/0013-Fix-pagination-with-large-gaps-of-rejected-events.patch
+++ /dev/null
@@ -1,51 +0,0 @@
-From f502069e368880d4b3129f5a45b41b74869e694e Mon Sep 17 00:00:00 2001
-From: Nicolas Werner <nicolas.werner@hotmail.de>
-Date: Sun, 8 Jun 2025 23:14:31 +0200
-Subject: [PATCH 13/24] Fix pagination with large gaps of rejected events
-
-Signed-off-by: Rory& <root@rory.gay>
----
- synapse/handlers/pagination.py | 13 +++++++++++--
- 1 file changed, 11 insertions(+), 2 deletions(-)
-
-diff --git a/synapse/handlers/pagination.py b/synapse/handlers/pagination.py
-index ab02e3acb8..2a715f1c8b 100644
---- a/synapse/handlers/pagination.py
-+++ b/synapse/handlers/pagination.py
-@@ -566,7 +566,7 @@ class PaginationHandler:
- (
- events,
- next_key,
-- _,
-+ limited,
- ) = await self.store.paginate_room_events_by_topological_ordering(
- room_id=room_id,
- from_key=from_token.room_key,
-@@ -649,7 +649,7 @@ class PaginationHandler:
- (
- events,
- next_key,
-- _,
-+ limited,
- ) = await self.store.paginate_room_events_by_topological_ordering(
- room_id=room_id,
- from_key=from_token.room_key,
-@@ -672,6 +672,15 @@ class PaginationHandler:
-
- next_token = from_token.copy_and_replace(StreamKeyType.ROOM, next_key)
-
-+ # We might have hit some internal filtering first, for example rejected
-+ # events. Ensure we return a pagination token then.
-+ if not events and limited:
-+ return {
-+ "chunk": [],
-+ "start": await from_token.to_string(self.store),
-+ "end": await next_token.to_string(self.store),
-+ }
-+
- # if no events are returned from pagination, that implies
- # we have reached the end of the available events.
- # In that case we do not return end, to tell the client
---
-2.53.0
-
diff --git a/packages/overlays/matrix-synapse/patches/0012-fix-Always-recheck-messages-pagination-data-if-a-bac.patch b/packages/overlays/matrix-synapse/patches/0013-fix-Always-recheck-messages-pagination-data-if-a-bac.patch
index d58c52f..e983a71 100644
--- a/packages/overlays/matrix-synapse/patches/0012-fix-Always-recheck-messages-pagination-data-if-a-bac.patch
+++ b/packages/overlays/matrix-synapse/patches/0013-fix-Always-recheck-messages-pagination-data-if-a-bac.patch
@@ -1,7 +1,7 @@
-From 60cd3178e8d941d32bedd1538f9a84102eed9215 Mon Sep 17 00:00:00 2001
+From 21cd3ad37d016c06494f0ff95c9bfd39fd92c6d4 Mon Sep 17 00:00:00 2001
From: Jason Little <j.little@famedly.com>
Date: Wed, 30 Apr 2025 09:29:42 -0500
-Subject: [PATCH 12/24] fix: Always recheck `/messages` pagination data if a
+Subject: [PATCH 13/19] fix: Always recheck `/messages` pagination data if a
backfill might have been needed (#28)
Signed-off-by: Rory& <root@rory.gay>
@@ -140,7 +140,7 @@ index b3444dd2ef..2d5612fc04 100644
async def send_invite(self, target_host: str, event: EventBase) -> EventBase:
"""Sends the invite to the remote server for signing.
diff --git a/synapse/handlers/pagination.py b/synapse/handlers/pagination.py
-index 8cbe4b63c8..ab02e3acb8 100644
+index 2bc7efeb5e..6d4bde4bbe 100644
--- a/synapse/handlers/pagination.py
+++ b/synapse/handlers/pagination.py
@@ -633,27 +633,31 @@ class PaginationHandler:
@@ -162,7 +162,7 @@ index 8cbe4b63c8..ab02e3acb8 100644
- (
- events,
- next_key,
-- _,
+- limited,
- ) = await self.store.paginate_room_events_by_topological_ordering(
- room_id=room_id,
- from_key=from_token.room_key,
@@ -179,7 +179,7 @@ index 8cbe4b63c8..ab02e3acb8 100644
+ (
+ events,
+ next_key,
-+ _,
++ limited,
+ ) = await self.store.paginate_room_events_by_topological_ordering(
+ room_id=room_id,
+ from_key=from_token.room_key,
diff --git a/packages/overlays/matrix-synapse/patches/0014-Fix-pagination-with-large-gaps-of-rejected-events.patch b/packages/overlays/matrix-synapse/patches/0014-Fix-pagination-with-large-gaps-of-rejected-events.patch
new file mode 100644
index 0000000..deb4522
--- /dev/null
+++ b/packages/overlays/matrix-synapse/patches/0014-Fix-pagination-with-large-gaps-of-rejected-events.patch
@@ -0,0 +1,35 @@
+From aa2cba639cd420a67b9528705187cd8ba21ed93d Mon Sep 17 00:00:00 2001
+From: Nicolas Werner <nicolas.werner@hotmail.de>
+Date: Sun, 8 Jun 2025 23:14:31 +0200
+Subject: [PATCH 14/19] Fix pagination with large gaps of rejected events
+
+Signed-off-by: Rory& <root@rory.gay>
+---
+ synapse/handlers/pagination.py | 11 +++++++++++
+ 1 file changed, 11 insertions(+)
+
+diff --git a/synapse/handlers/pagination.py b/synapse/handlers/pagination.py
+index 6d4bde4bbe..869b476d87 100644
+--- a/synapse/handlers/pagination.py
++++ b/synapse/handlers/pagination.py
+@@ -672,6 +672,17 @@ class PaginationHandler:
+
+ next_token = from_token.copy_and_replace(StreamKeyType.ROOM, next_key)
+
++ # We might have hit some internal filtering first, for example rejected
++ # events. Ensure we return a pagination token then.
++ if not events and limited:
++ return GetMessagesResult(
++ messages_chunk=[],
++ bundled_aggregations={},
++ state=None,
++ start_token=from_token,
++ end_token=next_token,
++ )
++
+ # if no events are returned from pagination (this page is empty)
+ # and there aren't any more pages (not limited),
+ # that implies we have reached the end of the available events.
+--
+2.53.0
+
diff --git a/packages/overlays/matrix-synapse/patches/0014-RequestRatelimiter-expose-can_do_action.patch b/packages/overlays/matrix-synapse/patches/0015-RequestRatelimiter-expose-can_do_action.patch
index a3befc1..d961013 100644
--- a/packages/overlays/matrix-synapse/patches/0014-RequestRatelimiter-expose-can_do_action.patch
+++ b/packages/overlays/matrix-synapse/patches/0015-RequestRatelimiter-expose-can_do_action.patch
@@ -1,7 +1,7 @@
-From ab1b213e5438e6b5c973f0591fc76a22cf24a160 Mon Sep 17 00:00:00 2001
+From b80719e34f34df23c90b69ca60d53d46f955d451 Mon Sep 17 00:00:00 2001
From: Rory& <root@rory.gay>
Date: Fri, 25 Jul 2025 08:26:15 +0200
-Subject: [PATCH 14/24] RequestRatelimiter: expose can_do_action
+Subject: [PATCH 15/19] RequestRatelimiter: expose can_do_action
Signed-off-by: Rory& <root@rory.gay>
---
diff --git a/packages/overlays/matrix-synapse/patches/0015-Clarify-pre_event_ids-assert-in-event-creation-handl.patch b/packages/overlays/matrix-synapse/patches/0016-Clarify-pre_event_ids-assert-in-event-creation-handl.patch
index 1d5de1a..d230cba 100644
--- a/packages/overlays/matrix-synapse/patches/0015-Clarify-pre_event_ids-assert-in-event-creation-handl.patch
+++ b/packages/overlays/matrix-synapse/patches/0016-Clarify-pre_event_ids-assert-in-event-creation-handl.patch
@@ -1,7 +1,7 @@
-From f185b8bbe732e115fede0322da86ab176f68bdd8 Mon Sep 17 00:00:00 2001
+From e221cdbc9fa341f4f375bd4f7e5ed740446bfd68 Mon Sep 17 00:00:00 2001
From: Rory& <root@rory.gay>
Date: Sat, 16 Aug 2025 20:19:08 +0200
-Subject: [PATCH 15/24] Clarify pre_event_ids assert in event creation handler
+Subject: [PATCH 16/19] Clarify pre_event_ids assert in event creation handler
Signed-off-by: Rory& <root@rory.gay>
---
diff --git a/packages/overlays/matrix-synapse/patches/0016-Add-bulk-send-events-endpoint.patch b/packages/overlays/matrix-synapse/patches/0017-Add-bulk-send-events-endpoint.patch
index 5d07d0e..9ed6f9f 100644
--- a/packages/overlays/matrix-synapse/patches/0016-Add-bulk-send-events-endpoint.patch
+++ b/packages/overlays/matrix-synapse/patches/0017-Add-bulk-send-events-endpoint.patch
@@ -1,7 +1,7 @@
-From 6f6e656426f6d1e91aec75b87e28237014fa702e Mon Sep 17 00:00:00 2001
+From 47c6aab82a297f3e9db2df7121c16598f8711ac2 Mon Sep 17 00:00:00 2001
From: Rory& <root@rory.gay>
Date: Sat, 26 Jul 2025 09:50:56 +0200
-Subject: [PATCH 16/24] Add bulk send events endpoint
+Subject: [PATCH 17/19] Add bulk send events endpoint
Try to optimise bulk sending some more
diff --git a/packages/overlays/matrix-synapse/patches/0017-admin-api-send-more-data.patch b/packages/overlays/matrix-synapse/patches/0018-admin-api-send-more-data.patch
index ac2f3b9..2969f7c 100644
--- a/packages/overlays/matrix-synapse/patches/0017-admin-api-send-more-data.patch
+++ b/packages/overlays/matrix-synapse/patches/0018-admin-api-send-more-data.patch
@@ -1,7 +1,7 @@
-From 565b3334daf72a68c01b194d438d36226414973f Mon Sep 17 00:00:00 2001
+From 6cb4af5641c98b0b6149e1201d8c86d72650cab4 Mon Sep 17 00:00:00 2001
From: Rory& <root@rory.gay>
Date: Mon, 27 Oct 2025 19:23:42 +0100
-Subject: [PATCH 17/24] admin api - send more data
+Subject: [PATCH 18/19] admin api - send more data
Signed-off-by: Rory& <root@rory.gay>
---
diff --git a/packages/overlays/matrix-synapse/patches/0018-Allow-overriding-max-background-task-count.patch b/packages/overlays/matrix-synapse/patches/0019-Allow-overriding-max-background-task-count.patch
index 91063ce..bc1c344 100644
--- a/packages/overlays/matrix-synapse/patches/0018-Allow-overriding-max-background-task-count.patch
+++ b/packages/overlays/matrix-synapse/patches/0019-Allow-overriding-max-background-task-count.patch
@@ -1,7 +1,7 @@
-From 8757be9747020372ba76b95e5b36dae24449087a Mon Sep 17 00:00:00 2001
+From 19d1e97075b24788daaf2895da3b46762b461ab3 Mon Sep 17 00:00:00 2001
From: Rory& <root@rory.gay>
Date: Tue, 28 Oct 2025 00:01:45 +0100
-Subject: [PATCH 18/24] Allow overriding max background task count
+Subject: [PATCH 19/19] Allow overriding max background task count
Signed-off-by: Rory& <root@rory.gay>
---
diff --git a/packages/overlays/matrix-synapse/patches/0019-max-and-min-were-probably-switched.-Set-max-to-arbit.patch b/packages/overlays/matrix-synapse/patches/0019-max-and-min-were-probably-switched.-Set-max-to-arbit.patch
deleted file mode 100644
index 43144b3..0000000
--- a/packages/overlays/matrix-synapse/patches/0019-max-and-min-were-probably-switched.-Set-max-to-arbit.patch
+++ /dev/null
@@ -1,39 +0,0 @@
-From 52e5804439f74346972abc9cc0dea28c7e67fa84 Mon Sep 17 00:00:00 2001
-From: Jason Little <j.little@famedly.com>
-Date: Fri, 2 Jan 2026 12:48:22 -0600
-Subject: [PATCH 19/24] max() and min() were probably switched. Set max to
- arbitrary 15 minutes, continue logging at durations greater than 10 minutes
-
----
- synapse/handlers/worker_lock.py | 8 ++++----
- 1 file changed, 4 insertions(+), 4 deletions(-)
-
-diff --git a/synapse/handlers/worker_lock.py b/synapse/handlers/worker_lock.py
-index 1537a18cc0..82dd896d5a 100644
---- a/synapse/handlers/worker_lock.py
-+++ b/synapse/handlers/worker_lock.py
-@@ -275,8 +275,8 @@ class WaitingLock:
-
- def _get_next_retry_interval(self) -> float:
- next = self._retry_interval
-- self._retry_interval = max(5, next * 2)
-- if self._retry_interval > Duration(minutes=10).as_secs(): # >7 iterations
-+ self._retry_interval = min(Duration(minutes=15).as_secs(), next * 2)
-+ if self._retry_interval > Duration(minutes=10).as_secs(): # >12 iterations
- logger.warning(
- "Lock timeout is getting excessive: %ss. There may be a deadlock.",
- self._retry_interval,
-@@ -362,8 +362,8 @@ class WaitingMultiLock:
-
- def _get_next_retry_interval(self) -> float:
- next = self._retry_interval
-- self._retry_interval = max(5, next * 2)
-- if self._retry_interval > Duration(minutes=10).as_secs(): # >7 iterations
-+ self._retry_interval = min(Duration(minutes=15).as_secs(), next * 2)
-+ if self._retry_interval > Duration(minutes=10).as_secs(): # >12 iterations
- logger.warning(
- "Lock timeout is getting excessive: %ss. There may be a deadlock.",
- self._retry_interval,
---
-2.53.0
-
diff --git a/packages/overlays/matrix-synapse/patches/0020-changelog.patch b/packages/overlays/matrix-synapse/patches/0020-changelog.patch
deleted file mode 100644
index 108ed0f..0000000
--- a/packages/overlays/matrix-synapse/patches/0020-changelog.patch
+++ /dev/null
@@ -1,20 +0,0 @@
-From a69c1aff5c261cdc4f239ff9455bd0fe9dcac89e Mon Sep 17 00:00:00 2001
-From: Jason Little <j.little@famedly.com>
-Date: Tue, 20 Jan 2026 06:42:18 -0600
-Subject: [PATCH 20/24] changelog
-
----
- changelog.d/19394.bugfix | 1 +
- 1 file changed, 1 insertion(+)
- create mode 100644 changelog.d/19394.bugfix
-
-diff --git a/changelog.d/19394.bugfix b/changelog.d/19394.bugfix
-new file mode 100644
-index 0000000000..eb93fffe15
---- /dev/null
-+++ b/changelog.d/19394.bugfix
-@@ -0,0 +1 @@
-+Prevent excessively long numbers for the retry interval of `WorkerLock`s. Contributed by Famedly.
---
-2.53.0
-
diff --git a/packages/overlays/matrix-synapse/patches/0021-Update-changelog.d-19394.bugfix.patch b/packages/overlays/matrix-synapse/patches/0021-Update-changelog.d-19394.bugfix.patch
deleted file mode 100644
index 047a782..0000000
--- a/packages/overlays/matrix-synapse/patches/0021-Update-changelog.d-19394.bugfix.patch
+++ /dev/null
@@ -1,20 +0,0 @@
-From 7428f78876be4004a48e63f69cf39818fe3bdc38 Mon Sep 17 00:00:00 2001
-From: Jason Little <j.little@famedly.com>
-Date: Wed, 21 Jan 2026 06:57:34 -0600
-Subject: [PATCH 21/24] Update changelog.d/19394.bugfix
-
-Co-authored-by: Eric Eastwood <madlittlemods@gmail.com>
----
- changelog.d/19394.bugfix | 2 +-
- 1 file changed, 1 insertion(+), 1 deletion(-)
-
-diff --git a/changelog.d/19394.bugfix b/changelog.d/19394.bugfix
-index eb93fffe15..3591c0a745 100644
---- a/changelog.d/19394.bugfix
-+++ b/changelog.d/19394.bugfix
-@@ -1 +1 @@
--Prevent excessively long numbers for the retry interval of `WorkerLock`s. Contributed by Famedly.
-+Capped the `WorkerLock` retry interval to a maximum of 15 minutes to prevent dealing with excessively long numbers. Contributed by Famedly.
---
-2.53.0
-
diff --git a/packages/overlays/matrix-synapse/patches/0022-Adjust-for-the-retry-interval-actually-being-a-timeo.patch b/packages/overlays/matrix-synapse/patches/0022-Adjust-for-the-retry-interval-actually-being-a-timeo.patch
deleted file mode 100644
index 614d4b4..0000000
--- a/packages/overlays/matrix-synapse/patches/0022-Adjust-for-the-retry-interval-actually-being-a-timeo.patch
+++ /dev/null
@@ -1,257 +0,0 @@
-From 5b2cff0cd0284dca13bb05ef943b8d0ccddc1504 Mon Sep 17 00:00:00 2001
-From: Jason Little <j.little@famedly.com>
-Date: Mon, 26 Jan 2026 10:26:38 -0600
-Subject: [PATCH 22/24] Adjust for the retry interval actually being a timeout
- interval, and only increase it when a timeout occurs
-
----
- synapse/handlers/worker_lock.py | 56 +++++++++--------
- tests/handlers/test_worker_lock.py | 99 ++++++++++++++++++++++++++----
- 2 files changed, 120 insertions(+), 35 deletions(-)
-
-diff --git a/synapse/handlers/worker_lock.py b/synapse/handlers/worker_lock.py
-index 82dd896d5a..88ecfd6318 100644
---- a/synapse/handlers/worker_lock.py
-+++ b/synapse/handlers/worker_lock.py
-@@ -208,7 +208,7 @@ class WaitingLock:
- write: bool | None
- deferred: "defer.Deferred[None]" = attr.Factory(defer.Deferred)
- _inner_lock: Lock | None = None
-- _retry_interval: float = 0.1
-+ _timeout_interval: float = 0.1
- _lock_span: "opentracing.Scope" = attr.Factory(
- lambda: start_active_span("WaitingLock.lock")
- )
-@@ -240,19 +240,23 @@ class WaitingLock:
- break
-
- try:
-- # Wait until the we get notified the lock might have been
-+ # Wait until the notification the lock might have been
- # released (by the deferred being resolved). We also
-- # periodically wake up in case the lock was released but we
-+ # periodically wake up in case the lock was released, but we
- # weren't notified.
- with PreserveLoggingContext():
-- timeout = self._get_next_retry_interval()
- await timeout_deferred(
- deferred=self.deferred,
-- timeout=timeout,
-+ timeout=self._timeout_interval,
- clock=self.clock,
- )
-- except Exception:
-- pass
-+ except defer.TimeoutError:
-+ # Only increment the timeout interval if this was an actual timeout
-+ self._timeout_interval = self._increment_timeout_interval()
-+ except Exception as e:
-+ logger.warning(
-+ "Caught an exception while waiting on WaitingLock: %r", e
-+ )
-
- return await self._inner_lock.__aenter__()
-
-@@ -273,13 +277,13 @@ class WaitingLock:
-
- return r
-
-- def _get_next_retry_interval(self) -> float:
-- next = self._retry_interval
-- self._retry_interval = min(Duration(minutes=15).as_secs(), next * 2)
-- if self._retry_interval > Duration(minutes=10).as_secs(): # >12 iterations
-+ def _increment_timeout_interval(self) -> float:
-+ next = self._timeout_interval
-+ next = min(Duration(minutes=15).as_secs(), next * 2)
-+ if next > Duration(minutes=10).as_secs(): # >12 iterations
- logger.warning(
- "Lock timeout is getting excessive: %ss. There may be a deadlock.",
-- self._retry_interval,
-+ next,
- )
- return next * random.uniform(0.9, 1.1)
-
-@@ -297,7 +301,7 @@ class WaitingMultiLock:
- deferred: "defer.Deferred[None]" = attr.Factory(defer.Deferred)
-
- _inner_lock_cm: AsyncContextManager | None = None
-- _retry_interval: float = 0.1
-+ _timeout_interval: float = 0.1
- _lock_span: "opentracing.Scope" = attr.Factory(
- lambda: start_active_span("WaitingLock.lock")
- )
-@@ -324,19 +328,23 @@ class WaitingMultiLock:
- break
-
- try:
-- # Wait until the we get notified the lock might have been
-+ # Wait until the notification the lock might have been
- # released (by the deferred being resolved). We also
-- # periodically wake up in case the lock was released but we
-+ # periodically wake up in case the lock was released, but we
- # weren't notified.
- with PreserveLoggingContext():
-- timeout = self._get_next_retry_interval()
- await timeout_deferred(
- deferred=self.deferred,
-- timeout=timeout,
-+ timeout=self._timeout_interval,
- clock=self.clock,
- )
-- except Exception:
-- pass
-+ except defer.TimeoutError:
-+ # Only increment the timeout interval if this was an actual timeout
-+ self._timeout_interval = self._increment_timeout_interval()
-+ except Exception as e:
-+ logger.warning(
-+ "Caught an exception while waiting on WaitingMultiLock: %r", e
-+ )
-
- assert self._inner_lock_cm
- await self._inner_lock_cm.__aenter__()
-@@ -360,12 +368,12 @@ class WaitingMultiLock:
-
- return r
-
-- def _get_next_retry_interval(self) -> float:
-- next = self._retry_interval
-- self._retry_interval = min(Duration(minutes=15).as_secs(), next * 2)
-- if self._retry_interval > Duration(minutes=10).as_secs(): # >12 iterations
-+ def _increment_timeout_interval(self) -> float:
-+ next = self._timeout_interval
-+ next = min(Duration(minutes=15).as_secs(), next * 2)
-+ if next > Duration(minutes=10).as_secs(): # >12 iterations
- logger.warning(
- "Lock timeout is getting excessive: %ss. There may be a deadlock.",
-- self._retry_interval,
-+ next,
- )
- return next * random.uniform(0.9, 1.1)
-diff --git a/tests/handlers/test_worker_lock.py b/tests/handlers/test_worker_lock.py
-index 61ff51ff92..3ae44d48e2 100644
---- a/tests/handlers/test_worker_lock.py
-+++ b/tests/handlers/test_worker_lock.py
-@@ -21,6 +21,7 @@
-
- import logging
- import platform
-+from unittest.mock import patch
-
- from twisted.internet import defer
- from twisted.internet.testing import MemoryReactor
-@@ -48,13 +49,47 @@ class WorkerLockTestCase(unittest.HomeserverTestCase):
- self.get_success(lock1.__aenter__())
-
- lock2 = self.worker_lock_handler.acquire_lock("name", "key")
-- d2 = defer.ensureDeferred(lock2.__aenter__())
-- self.assertNoResult(d2)
--
-- self.get_success(lock1.__aexit__(None, None, None))
-+ # Wrap the WaitingLock object, so we can detect if the timeouts are being hit
-+ with patch.object(
-+ lock2,
-+ "_increment_timeout_interval",
-+ wraps=lock2._increment_timeout_interval,
-+ ) as wrapped_lock2_increment_timeout_interval_method:
-+ d2 = defer.ensureDeferred(lock2.__aenter__())
-+ self.assertNoResult(d2)
-+
-+ # The lock should not time out here
-+ wrapped_lock2_increment_timeout_interval_method.assert_not_called()
-+ self.get_success(lock1.__aexit__(None, None, None))
-+
-+ self.get_success(d2)
-+ self.get_success(lock2.__aexit__(None, None, None))
-+
-+ def test_timeouts_for_lock_locally(self) -> None:
-+ """Test timeouts are incremented for a lock on a single worker"""
-+ lock1 = self.worker_lock_handler.acquire_lock("name", "key")
-+ self.get_success(lock1.__aenter__())
-
-- self.get_success(d2)
-- self.get_success(lock2.__aexit__(None, None, None))
-+ lock2 = self.worker_lock_handler.acquire_lock("name", "key")
-+ # Wrap the WaitingLock object, so we can detect if the timeouts are being hit
-+ with patch.object(
-+ lock2,
-+ "_increment_timeout_interval",
-+ wraps=lock2._increment_timeout_interval,
-+ ) as wrapped_lock2_increment_timeout_interval_method:
-+ d2 = defer.ensureDeferred(lock2.__aenter__())
-+ self.assertNoResult(d2)
-+
-+ # Recall that pump() will advance time of the given amount 100 times, this
-+ # amounts to about 10 seconds passing
-+ self.pump(10.0)
-+
-+ # Should be timed out 6 times, but do not fail on that exact count
-+ wrapped_lock2_increment_timeout_interval_method.assert_called()
-+ self.get_success(lock1.__aexit__(None, None, None))
-+
-+ self.get_success(d2)
-+ self.get_success(lock2.__aexit__(None, None, None))
-
- def test_lock_contention(self) -> None:
- """Test lock contention when a lot of locks wait on a single worker"""
-@@ -117,10 +152,52 @@ class WorkerLockWorkersTestCase(BaseMultiWorkerStreamTestCase):
- self.get_success(lock1.__aenter__())
-
- lock2 = worker_lock_handler.acquire_lock("name", "key")
-- d2 = defer.ensureDeferred(lock2.__aenter__())
-- self.assertNoResult(d2)
-+ # Wrap the WaitingLock object, so we can detect if the timeouts are being hit
-+ with patch.object(
-+ lock2,
-+ "_increment_timeout_interval",
-+ wraps=lock2._increment_timeout_interval,
-+ ) as wrapped_lock2_increment_timeout_interval_method:
-+ d2 = defer.ensureDeferred(lock2.__aenter__())
-+ self.assertNoResult(d2)
-+
-+ # The lock should not time out here
-+ wrapped_lock2_increment_timeout_interval_method.assert_not_called()
-+ self.get_success(lock1.__aexit__(None, None, None))
-+
-+ self.get_success(d2)
-+ self.get_success(lock2.__aexit__(None, None, None))
-+
-+ def test_timeouts_for_lock_worker(self) -> None:
-+ """Test timeouts are incremented for a lock on another worker"""
-+ worker = self.make_worker_hs(
-+ "synapse.app.generic_worker",
-+ extra_config={
-+ "redis": {"enabled": True},
-+ },
-+ )
-+ worker_lock_handler = worker.get_worker_locks_handler()
-
-- self.get_success(lock1.__aexit__(None, None, None))
-+ lock1 = self.main_worker_lock_handler.acquire_lock("name", "key")
-+ self.get_success(lock1.__aenter__())
-
-- self.get_success(d2)
-- self.get_success(lock2.__aexit__(None, None, None))
-+ lock2 = worker_lock_handler.acquire_lock("name", "key")
-+ # Wrap the WaitingLock object, so we can detect if the timeouts are being hit
-+ with patch.object(
-+ lock2,
-+ "_increment_timeout_interval",
-+ wraps=lock2._increment_timeout_interval,
-+ ) as wrapped_lock2_increment_timeout_interval_method:
-+ d2 = defer.ensureDeferred(lock2.__aenter__())
-+ self.assertNoResult(d2)
-+
-+ # Recall that pump() will advance time of the given amount 100 times, this
-+ # amounts to about 10 seconds passing
-+ self.pump(0.1)
-+
-+ # Should be timed out 6 times, but do not fail on that exact count
-+ wrapped_lock2_increment_timeout_interval_method.assert_called()
-+ self.get_success(lock1.__aexit__(None, None, None))
-+
-+ self.get_success(d2)
-+ self.get_success(lock2.__aexit__(None, None, None))
---
-2.53.0
-
diff --git a/packages/overlays/matrix-synapse/patches/0023-unecessarily-long-pump-in-test-left-over-from-testin.patch b/packages/overlays/matrix-synapse/patches/0023-unecessarily-long-pump-in-test-left-over-from-testin.patch
deleted file mode 100644
index c3b6d9f..0000000
--- a/packages/overlays/matrix-synapse/patches/0023-unecessarily-long-pump-in-test-left-over-from-testin.patch
+++ /dev/null
@@ -1,26 +0,0 @@
-From 2c0e2bb897aa64b79d91f2710058cf31fef9e324 Mon Sep 17 00:00:00 2001
-From: Jason Little <j.little@famedly.com>
-Date: Mon, 26 Jan 2026 11:18:29 -0600
-Subject: [PATCH 23/24] unecessarily long pump() in test, left over from
- testing logging
-
----
- tests/handlers/test_worker_lock.py | 2 +-
- 1 file changed, 1 insertion(+), 1 deletion(-)
-
-diff --git a/tests/handlers/test_worker_lock.py b/tests/handlers/test_worker_lock.py
-index 3ae44d48e2..c5c3ce22ef 100644
---- a/tests/handlers/test_worker_lock.py
-+++ b/tests/handlers/test_worker_lock.py
-@@ -82,7 +82,7 @@ class WorkerLockTestCase(unittest.HomeserverTestCase):
-
- # Recall that pump() will advance time of the given amount 100 times, this
- # amounts to about 10 seconds passing
-- self.pump(10.0)
-+ self.pump(0.1)
-
- # Should be timed out 6 times, but do not fail on that exact count
- wrapped_lock2_increment_timeout_interval_method.assert_called()
---
-2.53.0
-
diff --git a/packages/overlays/matrix-synapse/patches/0024-adjust-changelog-again.patch b/packages/overlays/matrix-synapse/patches/0024-adjust-changelog-again.patch
deleted file mode 100644
index 243014c..0000000
--- a/packages/overlays/matrix-synapse/patches/0024-adjust-changelog-again.patch
+++ /dev/null
@@ -1,19 +0,0 @@
-From 0257cf3bb3d92408654e3e1a1bc9ea58133b1653 Mon Sep 17 00:00:00 2001
-From: Jason Little <j.little@famedly.com>
-Date: Mon, 26 Jan 2026 11:18:38 -0600
-Subject: [PATCH 24/24] adjust changelog(again)
-
----
- changelog.d/19394.bugfix | 2 +-
- 1 file changed, 1 insertion(+), 1 deletion(-)
-
-diff --git a/changelog.d/19394.bugfix b/changelog.d/19394.bugfix
-index 3591c0a745..02131d89ba 100644
---- a/changelog.d/19394.bugfix
-+++ b/changelog.d/19394.bugfix
-@@ -1 +1 @@
--Capped the `WorkerLock` retry interval to a maximum of 15 minutes to prevent dealing with excessively long numbers. Contributed by Famedly.
-+Capped the `WorkerLock` time out interval to a maximum of 15 minutes to prevent dealing with excessively long numbers and prevent logging when the retry is not an actual time out. Contributed by Famedly.
---
-2.53.0
-
|