From 9ff286666a5a24f40c9235d66c4765f06468aea9 Mon Sep 17 00:00:00 2001 From: mintaka Date: Fri, 28 Aug 2026 01:41:07 -0400 Subject: [PATCH 1/3] =?UTF-8?q?test(delivery):=20deflake=20TestUnreadableO?= =?UTF-8?q?wedMentionClearedNotReswept=20=E2=80=94=20gate=20on=20waitForOw?= =?UTF-8?q?ed=20not=20post-drain=20owedCount=20(RIG-2920)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The unreadable-owed clear is a side-effect of the start-edge sweep, which runs after waitStartsDrained returns (that helper only proves the edge was dequeued, per introspect_test.go). Asserting owedCount==0 right after it raced the async sweep and flaked red under CI load (owed rows = 1, want 0). Gate on the existing waitForOwed(t, recipient, 0) barrier, which polls until the clear lands and t.Fatalf's at the deadline otherwise — deterministic, strictly stronger. Test-only; no production code touched. Co-authored-by: Matt Wilkinson --- go/internal/delivery/offline_mention_test.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/go/internal/delivery/offline_mention_test.go b/go/internal/delivery/offline_mention_test.go index d40092d6a..edf270a88 100644 --- a/go/internal/delivery/offline_mention_test.go +++ b/go/internal/delivery/offline_mention_test.go @@ -233,14 +233,14 @@ func TestUnreadableOwedMentionClearedNotReswept(t *testing.T) { startConsumer(t, c) c.OnSessionStarted("sess-recip", recipient) - c.waitStartsDrained(t) - + // The sweep's observable effect is the clear (owed -> 0); gate on it. A bare + // waitStartsDrained only proves the start edge was DEQUEUED, not that the + // sweep's ClearOwedMention ran (introspect_test.go), so asserting owedCount + // right after it races the async sweep and flakes red under CI load. + reads.waitForOwed(t, recipient, 0) if got := disp.snapshot(); len(got) != 0 { t.Fatalf("dispatches = %d, want 0 (an unreadable owed message is cleared, not dispatched)", len(got)) } - if n := reads.owedCount(recipient); n != 0 { - t.Fatalf("owed rows for recipient = %d, want 0 (the unreadable row must be cleared)", n) - } // A second start edge finds nothing owed — the row was cleared, so no re-log loop. c.OnSessionStarted("sess-recip", recipient) From ffbfddba54261c41a43173b1f30e59fa21605573 Mon Sep 17 00:00:00 2001 From: mintaka Date: Fri, 28 Aug 2026 01:48:32 -0400 Subject: [PATCH 2/3] test(delivery): broaden waitForOwed doc to cover the sweep-clear call site (RIG-2920) Review low: the helper's doc scoped it to the nil-waker case, but the deflake adds a caller where owed->0 is the sweep's clear side-effect with a dispatcher present. Broaden the doc so it covers both call sites. Co-authored-by: Matt Wilkinson --- go/internal/delivery/helpers_test.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/go/internal/delivery/helpers_test.go b/go/internal/delivery/helpers_test.go index 39ddfc147..c7ad142aa 100644 --- a/go/internal/delivery/helpers_test.go +++ b/go/internal/delivery/helpers_test.go @@ -625,8 +625,9 @@ func (f *fakeReads) seedOwedMention(agent store.AccountID, channel store.Channel } // waitForOwed blocks until agent has exactly n owed-mention rows, or fails at the -// deadline — a polling barrier for the nil-waker case where no dispatch/wake -// signal is available to gate on (the owed row is the only observable effect). +// deadline — a polling barrier for cases where the owed-row count is the only +// observable effect to gate on: a nil-waker record (no dispatch/wake signal), or +// a start-edge sweep's ClearOwedMention (owed -> 0 after the async sweep runs). func (f *fakeReads) waitForOwed(t *testing.T, agent store.AccountID, n int) { t.Helper() deadline := time.After(testTimeout) From cd4125fe3fc19171b5ed7ab8e4b73ee6d8a26e28 Mon Sep 17 00:00:00 2001 From: mintaka Date: Fri, 28 Aug 2026 01:53:53 -0400 Subject: [PATCH 3/3] test(delivery): mark waitForOwed doc call-site list as illustrative (RIG-2920) Round-2 review low: the doc names two representative callers but the helper has four (all the same record -> owed-row shape). Signal the list is an example, not exhaustive; the leading general clause already covers all four. Co-authored-by: Matt Wilkinson --- go/internal/delivery/helpers_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/go/internal/delivery/helpers_test.go b/go/internal/delivery/helpers_test.go index c7ad142aa..00ad44b62 100644 --- a/go/internal/delivery/helpers_test.go +++ b/go/internal/delivery/helpers_test.go @@ -626,8 +626,8 @@ func (f *fakeReads) seedOwedMention(agent store.AccountID, channel store.Channel // waitForOwed blocks until agent has exactly n owed-mention rows, or fails at the // deadline — a polling barrier for cases where the owed-row count is the only -// observable effect to gate on: a nil-waker record (no dispatch/wake signal), or -// a start-edge sweep's ClearOwedMention (owed -> 0 after the async sweep runs). +// observable effect to gate on, e.g. a nil-waker record (no dispatch/wake +// signal) or a start-edge sweep's ClearOwedMention (owed -> 0 after the sweep). func (f *fakeReads) waitForOwed(t *testing.T, agent store.AccountID, n int) { t.Helper() deadline := time.After(testTimeout)