Skip to content

Read every thread once per retention sweep and recheck each group by ID - #7651

Closed
lanjak wants to merge 1 commit into
get-bb:mainfrom
lanjak:fix-7340-retention-sweep
Closed

lanjak wants to merge 1 commit into
get-bb:mainfrom
lanjak:fix-7340-retention-sweep

Conversation

@lanjak

@lanjak lanjak commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Human comments

What was wrong

The storage-retention sweep read every thread (readThreads) again before it acted on each archive, cold storage or delete group. A sweep of up to 50 groups per action read every thread about 150 times (#7340).

What changed

plugins/storage-retention/src/service.ts:

  • The sweep reads every thread once and selects candidates from that snapshot.
  • Before each group it checks only that group again:
    • experimental_listCascade for the root gives the threads core would also archive or delete, including threads created after the snapshot. Cold storage deletes the thread, so it uses the delete cascade.
    • One by-ID read (readThreadsById) gets the root, the group members and the cascade threads. If the fresh root has a parent or source outside that set, a second by-ID read gets them.
    • The fresh rows replace the snapshot rows (a missing row means the thread is gone), and selectCandidates runs again. The group is skipped if it is no longer eligible.
    • Cold storage gets the same updated thread list for its dependent check in coldStorage.store.
  • experimental_listCascade leaves out hidden threads, but core's archive includes them (for example a side chat on the root). A new thread that points at a cold storage candidate as its source is also not in the cascade. So the service listens for thread.created, and the sweep reads every thread again before the next group when a thread was created after the snapshot. It also reads every thread again when the snapshot is 60 s old.

A sweep now makes one full read plus two small calls per group, unless threads are created during the sweep.

No wire, CLI or settings change.

How you verified

New tests in plugins/storage-retention/src/retention.test.ts:

  • 30 archive groups: one full read and 30 by-ID reads. This fails on main (31 full reads).
  • 30 cold storage threads: one full read and 30 by-ID reads. This fails on main (31 full reads).
  • A recent child that only the cascade reports blocks its root.
  • A hidden side chat created during the sweep blocks its source thread, and a fork created during the sweep keeps its source out of cold storage. Both fail without the thread.created refresh.

Existing tests now use a threads.list fake that applies threadIds, and the cold storage sweep tests have a cascade fake. The pinned and unarchived-after-selection test still passes.

pnpm exec turbo run typecheck test lint lint:type-aware --filter=bb-plugin-bb--storage-retention passes (116 tests). oxfmt --check passes.

Fixes #7340

AGENT GENERATED

@lanjak
lanjak force-pushed the fix-7340-retention-sweep branch from ac90674 to ff666fb Compare November 24, 2026 01:03
@github-actions github-actions Bot closed this Dec 1, 2026
@github-actions

github-actions Bot commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

This is an automated message. We have closed this pull request because it has been open for more than two weeks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Storage-retention sweep re-reads every thread before each group it archives or deletes

1 participant