Skip to content

Commit 2aa2808

Browse files
tulsi-builderBasilBotclaude
committed
fix(inbox): bound thread discovery to 30 days and end at the cap quietly
Ordinary lifetime history exhausted the discovery budget and became a permanent "Retry inbox" error that retry could not fix. - Read only the last 30 days for authored seeds, follows, replies and Solo discovery. - Reaching the request/byte/seed/retained cap is bounded completion: admitted rows stay, the feed is ready, no error. - Skip archived and metadata-pending channels. - Read replies for a batch of roots across channels in one walk instead of per channel. - Share one edit/deletion settlement closure between addressed and thread history. Co-authored-by: BasilBot <399581b6165ab01343e3a1324774b1024d76942aea563468f93c975e5ee5193c@buzz.block.builderlab.xyz> Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: tulsi <[email protected]>
1 parent 38f190a commit 2aa2808

6 files changed

Lines changed: 228 additions & 95 deletions

File tree

‎docs/buzz-help.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ the interface unless an available tool actually supports that action.
6868
- **Inbox** collects DMs, ordinary responses in Solo chats, mentions of you, and replies in threads you started,
6969
replied in, or follow. Solo chats appear under All and DMs; their nested threads stay separate. Agent-only coordination stays out. Its sidebar entry shows how many of
7070
those conversations are unread, not counting ones you archived. When opened, it also looks for
71-
older mentions and replies in your older threads, which then join that count. History
71+
older mentions and for replies in threads from the last 30 days, which then join that count. History
7272
is bounded; a loading error means some older conversations may still be missing.
7373
- **Communities** have their own channels, people, and agents. Switching
7474
communities changes the available context. A channel reopens where you

‎docs/inbox.md‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,18 +162,19 @@ event, the finite attempt stays failed/incomplete rather than treating the filte
162162
page as exhausted history. Explicit Retry can settle it once existing shared
163163
readers have admitted the missing reference; Inbox adds no reference-resolution loop.
164164
Thread discovery separately pages viewer-authored posts/replies and explicit
165-
follow choices, then batches up to 100 candidate roots per channel for targeted
166-
reply reads. Seeds stay outside unread retention until a thread has incoming
165+
follow choices in current, unarchived channels, then batches up to 100
166+
candidate roots across channels for targeted reply reads. Every discovery read,
167+
Solo included, stays within the last 30 days. Seeds stay outside unread retention until a thread has incoming
167168
activity. The existing unread projection decides relevance and survival after
168169
edit/delete closure; a root leaves the pending query only once incoming evidence
169170
survives that fold. Self-only or deleted pages continue with the composite
170171
`until`/`before_id` cursor. Explicit unfollows are excluded, and changing follow
171172
choices invalidates an already-demanded feed. Completed exact IDs clear their
172173
incomplete flags before other discovery batches finish, so later failures leave
173174
usable rows visible. Discovery caps one attempt at 256 raw requests, 4 MiB,
174-
2,000 authored seeds and 2,000 admitted events; hitting a cap shows an error,
175-
not complete history. Retrying starts a fresh bounded attempt and does not
176-
extend those limits.
175+
2,000 authored seeds and 2,000 admitted events. Hitting a cap ends discovery
176+
as bounded completion: admitted rows stay and Inbox shows no error, because a
177+
retry would repeat the same walk. A non-advancing page is still an error.
177178

178179
Auxiliary reads cap retained results at 2,000 events / 4 MiB per stage; the shared reader
179180
keeps its existing per-request deadline and cancellation. Missing roots,

‎src/features/relay/inbox-feed.test.ts‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import type { RelayEvent, ReadFilter } from "./events";
99
import type { LiveCallbacks } from "./live";
1010
import { byteSize } from "./budget";
1111
import { createInboxFeed } from "./inbox-feed";
12+
import { INBOX_THREAD_WINDOW_SECONDS } from "./inbox-thread-history";
1213

1314
// General #e reads return an empty terminal page. The ordinary #p response is
1415
// still explicitly gated by each test; no incidental timer orders admission.
@@ -18,6 +19,14 @@ afterEach(() => {
1819
vi.useRealTimers();
1920
vi.unstubAllGlobals();
2021
});
22+
/** Fixture timestamps are small; place "now" so they fall inside the thread
23+
* discovery window (plus `later` seconds). */
24+
function threadWindowNow(later = 0) {
25+
vi.useFakeTimers({
26+
toFake: ["Date"],
27+
now: (INBOX_THREAD_WINDOW_SECONDS + later) * 1000,
28+
});
29+
}
2130
function deferred<T>() {
2231
let resolve!: (value: T) => void;
2332
let reject!: (error: Error) => void;
@@ -1613,6 +1622,7 @@ it.each(["edit", "delete"] as const)(
16131622
);
16141623

16151624
it("discovers ordinary replies to an old authored thread outside channel catch-up", async () => {
1625+
threadWindowNow();
16161626
const h = setup();
16171627
h.admit([h.viewer.pubkey, h.alice.pubkey]);
16181628
const root = message(h.viewer, "room", "old own thread", 20);
@@ -1639,7 +1649,32 @@ it("discovers ordinary replies to an old authored thread outside channel catch-u
16391649
});
16401650
});
16411651

1652+
it("does not read threads older than the discovery window", async () => {
1653+
threadWindowNow(100);
1654+
const h = setup();
1655+
h.admit([h.viewer.pubkey, h.alice.pubkey]);
1656+
const root = message(h.viewer, "room", "months-old own thread", 20);
1657+
const reply = message(h.alice, "room", "months-old reply", 21, [
1658+
["e", root.id, "", "reply"],
1659+
]);
1660+
const { matchesEvent } = await import("./projection");
1661+
h.query.mockImplementation(async (filters) =>
1662+
[root, reply].filter((event) =>
1663+
filters.some((filter) => matchesEvent(event, filter)),
1664+
),
1665+
);
1666+
await h.session.inboxFeed.ensure();
1667+
expect(h.session.inboxFeed.snapshot().status).toBe("ready");
1668+
expect(rows(h)).toEqual([]);
1669+
expect(
1670+
h.query.mock.calls.some(([filters]) =>
1671+
filters.some((filter) => filter.authors && filter.since === 100),
1672+
),
1673+
).toBe(true);
1674+
});
1675+
16421676
it("keeps completed thread rows usable when later discovery fails", async () => {
1677+
threadWindowNow();
16431678
const h = setup();
16441679
h.admit([h.viewer.pubkey, h.alice.pubkey]);
16451680
const root = message(h.viewer, "room", "own root", 20);
@@ -1663,6 +1698,7 @@ it("keeps completed thread rows usable when later discovery fails", async () =>
16631698
});
16641699

16651700
it("discovers participation in someone else's thread without a mention", async () => {
1701+
threadWindowNow();
16661702
const h = setup();
16671703
h.admit([h.viewer.pubkey, h.alice.pubkey]);
16681704
const root = message(h.alice, "room", "root", 10);
@@ -1680,6 +1716,7 @@ it("discovers participation in someone else's thread without a mention", async (
16801716
});
16811717

16821718
it("discovers an explicit follow added after the feed settled", async () => {
1719+
threadWindowNow();
16831720
vi.stubGlobal("localStorage", { getItem: () => null, setItem: vi.fn() });
16841721
const h = setup();
16851722
h.admit([h.viewer.pubkey, h.alice.pubkey]);
@@ -1700,6 +1737,7 @@ it("discovers an explicit follow added after the feed settled", async () => {
17001737
});
17011738

17021739
it("pages past deleted recent replies to find surviving thread activity", async () => {
1740+
threadWindowNow();
17031741
const h = setup();
17041742
h.admit([h.viewer.pubkey, h.alice.pubkey]);
17051743
const root = message(h.viewer, "room", "root", 1);
@@ -1771,6 +1809,7 @@ it.each(["clear", "revoke", "unfollow"] as const)(
17711809
);
17721810

17731811
it("discovers ordinary Solo activity outside catch-up without self or agent-only messages", async () => {
1812+
threadWindowNow();
17741813
const h = setup();
17751814
h.admit([h.viewer.pubkey, h.alice.pubkey]);
17761815
h.live.receive([
@@ -1807,6 +1846,7 @@ it("discovers ordinary Solo activity outside catch-up without self or agent-only
18071846
});
18081847

18091848
it("pages past a Solo root belonging to a nested row to discover older flat activity", async () => {
1849+
threadWindowNow();
18101850
const h = setup();
18111851
h.admit([h.viewer.pubkey, h.alice.pubkey]);
18121852
h.live.receive([

‎src/features/relay/inbox-feed.ts‎

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import { discoverInboxThreads } from "./inbox-thread-history";
1+
import {
2+
discoverInboxThreads,
3+
INBOX_THREAD_WINDOW_SECONDS,
4+
} from "./inbox-thread-history";
25
import type { ThreadFollows } from "./thread-follows";
36
import { byteSize } from "./budget";
47
import type { ChannelQueries } from "./contracts";
@@ -144,6 +147,23 @@ export function createInboxFeed({
144147
// Authorized responses can have short pages. Only empty ends the walk.
145148
}
146149
}
150+
/** One closure governs admission for addressed and thread history: stored
151+
* edits and deletions of the targets, then deletions of their edits. */
152+
async function settle(ids: readonly string[], signal: AbortSignal) {
153+
const updates = await overlays(ids, [40003, 5, 9005], signal);
154+
await overlays(
155+
[
156+
...new Set([
157+
...retainedEditIds(ids),
158+
...updates
159+
.filter((event) => event.kind === 40003)
160+
.map((event) => event.id),
161+
]),
162+
],
163+
[5, 9005],
164+
signal,
165+
);
166+
}
147167
async function refresh() {
148168
if (closed) return;
149169
if (work) return work;
@@ -184,18 +204,7 @@ export function createInboxFeed({
184204
...project(mentions, true).map((event) => event.id),
185205
]),
186206
];
187-
const updates = await overlays(targets, [40003, 5, 9005], owned.signal);
188-
const edits = updates.filter((event) => event.kind === 40003);
189-
await overlays(
190-
[
191-
...new Set([
192-
...retainedEditIds(targets),
193-
...edits.map((event) => event.id),
194-
]),
195-
],
196-
[5, 9005],
197-
owned.signal,
198-
);
207+
await settle(targets, owned.signal);
199208
if (closed || generation !== epoch) return;
200209
publish({ incomplete: [] });
201210
if (threadHistory)
@@ -207,6 +216,8 @@ export function createInboxFeed({
207216
(channel) =>
208217
!channel.huddle &&
209218
!channel.cached &&
219+
!channel.archived &&
220+
!channel.metadataPending &&
210221
channel.members?.includes(viewer),
211222
)
212223
.map((channel) => channel.id)
@@ -225,6 +236,7 @@ export function createInboxFeed({
225236
.map((channel) => channel.id)
226237
.sort(),
227238
choices: threadHistory.choices(),
239+
since: Math.floor(Date.now() / 1000) - INBOX_THREAD_WINDOW_SECONDS,
228240
read: threadHistory.read,
229241
signal: owned.signal,
230242
admit: async (events, signal, flatOnly) => {
@@ -241,19 +253,7 @@ export function createInboxFeed({
241253
},
242254
);
243255
const ids = project(admitted).map((event) => event.id);
244-
const updates = await overlays(ids, [40003, 5, 9005], signal);
245-
await overlays(
246-
[
247-
...new Set([
248-
...retainedEditIds(ids),
249-
...updates
250-
.filter((event) => event.kind === 40003)
251-
.map((event) => event.id),
252-
]),
253-
],
254-
[5, 9005],
255-
signal,
256-
);
256+
await settle(ids, signal);
257257
if (closed || generation !== epoch || signal.aborted) return [];
258258
const settled = new Set(ids);
259259
publish({

‎src/features/relay/inbox-thread-history.test.ts‎

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,3 +197,63 @@ it("finds quiet Solo activity after a busy Solo settles and skips deleted or age
197197
),
198198
).toBe(true);
199199
});
200+
201+
it("ends a lifetime of authored posts as bounded completion, not an error", async () => {
202+
const viewer = keypair();
203+
const post = message(viewer, "room", "post", 1);
204+
// Already-verified clones; signatures are irrelevant to the walk.
205+
const f = fixture(
206+
Array.from({ length: 2001 }, (_, i) => ({
207+
...post,
208+
id: (i + 1).toString(16).padStart(64, "0"),
209+
created_at: 1 + i,
210+
})),
211+
);
212+
await expect(
213+
discoverInboxThreads({
214+
...f,
215+
viewer: viewer.pubkey,
216+
channelIds: ["room"],
217+
choices: new Map(),
218+
signal: new AbortController().signal,
219+
}),
220+
).resolves.toEqual({ complete: false });
221+
});
222+
223+
it("reads replies for many channels together and stays in the window", async () => {
224+
const viewer = keypair(),
225+
other = keypair();
226+
const channelIds = Array.from({ length: 20 }, (_, i) => `room-${i}`);
227+
const post = message(viewer, "room-0", "post", 1);
228+
const posts = Array.from({ length: 1300 }, (_, i) => ({
229+
...post,
230+
id: (i + 1).toString(16).padStart(64, "0"),
231+
created_at: 100 + i,
232+
tags: [["h", `room-${i % 20}`]],
233+
}));
234+
// Post 650 (room-10) gets the only incoming reply.
235+
const root = posts[650];
236+
if (!root) throw new Error("missing fixture post");
237+
const reply = message(other, "room-10", "reply", 5000, [
238+
["e", root.id, "", "reply"],
239+
]);
240+
const stale = message(viewer, "room-0", "outside the window", 50);
241+
const f = fixture([...posts, reply, stale]);
242+
await expect(
243+
discoverInboxThreads({
244+
...f,
245+
viewer: viewer.pubkey,
246+
channelIds,
247+
choices: new Map(),
248+
since: 100,
249+
signal: new AbortController().signal,
250+
}),
251+
).resolves.toEqual({ complete: true });
252+
expect(
253+
f.admit.mock.calls.flatMap(([events]) => events).map((event) => event.id),
254+
).toEqual(expect.arrayContaining([root.id, reply.id]));
255+
expect(f.read.mock.calls.every(([filter]) => filter.since === 100)).toBe(
256+
true,
257+
);
258+
expect(f.read.mock.calls.length).toBeLessThan(40);
259+
});

0 commit comments

Comments
 (0)