Phase 10: hardening and ops
CI / Test (ubuntu-latest) (push) Canceled after 0s
CI / Test (windows-latest) (push) Canceled after 0s
CI / Storage tests on PostgreSQL (push) Canceled after 0s
CI / Complement (federation off) (push) Canceled after 0s
CI / golangci-lint (push) Canceled after 0s
CI / Smoke test the binary (push) Canceled after 0s

Implements PLAN.md Phase 10.

Simplified Sliding Sync (MSC4186) is served at the unstable
org.matrix.simplified_msc3575 endpoint and advertised in /versions. Lists
are sorted by activity and filtered by DM, invite, encryption, room type,
space and tag; room subscriptions, required_state with wildcards, $ME and
$LAZY, and the to_device, e2ee, account_data, receipts and typing
extensions are supported. Per-connection state is kept in memory and an
unknown pos answers M_UNKNOWN_POS.

Threads and relations: m.relates_to is indexed on roomserver_events
(migration 0012), /relations (with recursion) and /threads are served, and
every event a timeline read returns carries its m.thread, m.replace and
m.reference summaries in unsigned.m.relations. Notifications carry a
thread ID (migration 0013): threaded receipts clear only their thread, and
sync reports unread_thread_notifications when the filter asks.

Spaces: /hierarchy walks a space breadth first, asking other servers about
rooms this one is not in through the new federation hierarchy endpoint;
room_summary describes one room. /search runs on FTS5 (sqlite, pocketbase)
or tsvector (postgres), bounded to what each user may see, with context,
profiles, state, grouping and paging.

The PocketBase driver is real: the sqlite schema and store on an embedded
PocketBase app's database, with media in its filesystem, local or S3
(database.pocketbase.s3). It runs the full storage test suite.

Ops: OpenTelemetry tracing over OTLP/HTTP (tracing.*), with server spans
per route, component spans, and trace propagation on federation, push and
application service calls. New metrics for persisted events, waiting
syncs, sliding sync connections and the database pool, with a Grafana
dashboard. deploy/ adds a Compose setup (PostgreSQL, Prometheus, Grafana,
Jaeger) and a Helm chart; cmd/warp-loadtest loads a server and reports
request and delivery latencies.

The load tester found a long-standing bug, fixed here: on a server where
no account data had been written, every incremental /sync re-sent the push
rules and returned at once, and an all-zero token was taken for an initial
sync, so long polls became busy loops.

The PostgreSQL migrations and search dialect compile but were not run
against a live PostgreSQL in this change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
tajniak81andClaude Opus 5.5 committed 2026-10-17 20:21:31 +02:00
1 parent a94794b866
commit 487e0f410b
100 files changed
+10528 -893

No files matched your search

+30 -14
View File
@@ -24,19 +24,17 @@ const (
// ReceiptSet is told about a read receipt a local user set, and clears
// their notifications in the room up to the event it names.
//
// Notifications are not tracked per thread (threads are Phase 10), so a
// receipt counts when it is for the room as a whole or for its main
// timeline, and a receipt inside a thread is left alone: clearing the
// room on it would mark the main timeline read when the user only looked
// at one thread. Thread notifications are cleared when the main receipt
// moves past them.
// Notifications are filed by thread, and a receipt reads the part of the
// room it is for: thread_id "main" the main timeline, a thread root's ID
// that thread, and no thread_id the whole room. Reading one thread leaves
// the main timeline and the other threads unread, and a client that does
// not know about threads sends unthreaded receipts and keeps clearing the
// room as a whole, as before threads.
func (a *API) ReceiptSet(ctx context.Context, userID, roomID, receiptType, threadID, eventID string) {
if receiptType != receiptRead && receiptType != receiptReadPrivate {
return
}
if threadID != "" && threadID != threadMain {
return
}
thread := receiptThread(threadID)
pos, err := a.rooms.EventPosition(ctx, roomID, userID, eventID)
if err != nil {
// A receipt for an event this server does not have — or one the
@@ -47,16 +45,28 @@ func (a *API) ReceiptSet(ctx context.Context, userID, roomID, receiptType, threa
}
return
}
if err := a.markRead(ctx, userID, roomID, pos); err != nil {
if err := a.markRead(ctx, userID, roomID, thread, pos); err != nil {
a.log.Warn("clearing notifications on a receipt failed",
"user_id", userID, "room_id", roomID, "error", err)
}
}
// markRead clears a user's notifications in a room up to a position, and
// wakes their syncs if the counts moved.
func (a *API) markRead(ctx context.Context, userID, roomID string, upTo int64) error {
_, moved, err := a.store.MarkNotificationsRead(ctx, userID, roomID, upTo)
// receiptThread is the part of a room a receipt's thread_id reads, as the
// store names it.
func receiptThread(threadID string) string {
switch threadID {
case "":
return storage.AllThreads
case threadMain:
return storage.ThreadMain
}
return threadID
}
// markRead clears a user's notifications in a room, or in one thread of
// it, up to a position, and wakes their syncs if the counts moved.
func (a *API) markRead(ctx context.Context, userID, roomID, thread string, upTo int64) error {
_, moved, err := a.store.MarkNotificationsRead(ctx, userID, roomID, thread, upTo)
if err != nil {
return err
}
@@ -71,6 +81,12 @@ func (a *API) NotificationCounts(ctx context.Context, userID string, roomIDs []s
return a.store.NotificationCounts(ctx, userID, roomIDs)
}
// ThreadNotificationCounts reads a user's unread counts in the given rooms
// per thread, with the main timeline under storage.ThreadMain.
func (a *API) ThreadNotificationCounts(ctx context.Context, userID string, roomIDs []string) (map[string]map[string]storage.NotificationCounts, error) {
return a.store.ThreadNotificationCounts(ctx, userID, roomIDs)
}
// NotificationCountChanges lists the rooms whose counts for a user moved
// in a window of the notification stream.
func (a *API) NotificationCountChanges(ctx context.Context, userID string, from, to int64) ([]string, error) {
@@ -0,0 +1,22 @@
package pushserver
import (
"testing"
"github.com/dariuszjaniak/warp/server/internal/storage"
)
func TestReceiptThread(t *testing.T) {
for threadID, want := range map[string]string{
// No thread_id: the receipt reads the room as a whole.
"": storage.AllThreads,
// "main" reads the main timeline, which the store files as ''.
"main": storage.ThreadMain,
// Anything else is a thread root, and reads that thread.
"$root:warp.example": "$root:warp.example",
} {
if got := receiptThread(threadID); got != want {
t.Errorf("receiptThread(%q) = %q, want %q", threadID, got, want)
}
}
}
+2 -1
View File
@@ -28,6 +28,7 @@ import (
"github.com/dariuszjaniak/warp/server/internal/pushrules"
"github.com/dariuszjaniak/warp/server/internal/roomserver"
"github.com/dariuszjaniak/warp/server/internal/storage"
"github.com/dariuszjaniak/warp/server/internal/tracing"
)
// Errors callers have to tell apart. The rule-language sentinels are
@@ -174,7 +175,7 @@ func New(opts Options) (*API, error) {
opts.NotificationRetention = DefaultNotificationRetention
}
if opts.HTTPClient == nil {
opts.HTTPClient = &http.Client{Timeout: opts.GatewayTimeout}
opts.HTTPClient = &http.Client{Timeout: opts.GatewayTimeout, Transport: tracing.Transport(nil)}
}
ctx, cancel := context.WithCancel(context.Background())
+3 -1
View File
@@ -104,7 +104,7 @@ func (a *API) process(ctx context.Context, n roomserver.Notification) error {
if target, ok := e.StateKey(); ok && a.isLocal(target) {
switch membership, _ := e.Membership(); membership {
case event.MembershipLeave, event.MembershipBan:
if err := a.markRead(ctx, target, n.RoomID, n.StreamOrdering); err != nil {
if err := a.markRead(ctx, target, n.RoomID, storage.AllThreads, n.StreamOrdering); err != nil {
return err
}
}
@@ -144,6 +144,7 @@ func (a *API) process(ctx context.Context, n roomserver.Notification) error {
var (
notifications []storage.NewNotification
outcomes = map[string]pushrules.Outcome{}
thread = roomserver.ThreadOf(e)
)
now := a.now().UnixMilli()
for _, userID := range candidates {
@@ -179,6 +180,7 @@ func (a *API) process(ctx context.Context, n roomserver.Notification) error {
RoomID: n.RoomID,
EventID: e.EventID(),
EventPos: n.StreamOrdering,
ThreadID: thread,
TimestampMS: now,
Highlight: outcome.Highlight,
Actions: actions,