Skip to content

Avoid repeated message-history processing (forward-port of #3539) - #3654

Merged
holmesworcester merged 23 commits into
developfrom
fix/3539-on-develop
Sep 22, 2026
Merged

holmesworcester merged 23 commits into
developfrom
fix/3539-on-develop

Conversation

@holmesworcester

@holmesworcester holmesworcester commented Sep 22, 2026 •

Copy link
Copy Markdown
Collaborator

Forward-port of #3539 "Avoid repeated message-history processing" onto develop for 11.3. This supersedes #3539, which targets 10.0.0.

In one sentence: the index shows every message the old code showed, without redoing the work, and cannot crash the backend. Each arrival is consumed once instead of the whole history being re-consumed on every update; an entry that is unreadable now is shown exactly once as soon as it becomes readable; no path in the update listener can reject or wedge.

What #3539 does

Quiet re-scanned and re-consumed a channel's whole message history on every OrbitDB head update. ChannelStore now keeps an index of the entries it has successfully consumed (hash → message ID, ID → hashes, fully checked ancestry). An update walks only the ancestry the joined head brought in, using the log's own has/get, so one head that imports a whole backlog is processed once. MESSAGE_IDS_STORED announces the delta for ordinary arrivals and a snapshot after a rebuild. Heads a peer announced before the local log joined them wait for local acceptance. The state-manager missingChannelMessages selector uses the entity map instead of scanning the ID array per announced ID. Message signatures and current authorization are still checked on every consume.

What changed in the port

  • git merge origin/fix/ios-qss-processing: 10.0.0 is fully contained in develop, so the merge brings only the PR's nine commits. develop has been merged in since (last: 5c98449, the 11.2.0 back-merge).
  • ChannelStore on develop also serves DM channels (DirectMessagesService, deliveredDmIds); the DM delivery de-dup is kept and a DM ID now counts as delivered only once every listener received it.
  • Avoid repeated message-history processing #3539's e2e changes are dropped: develop removed the sidebar user list; those roster checks live in Community membership. The e2e package is unchanged from develop.
  • CHANGELOG line under Fixes.

Authorization and announcement model (after six audit iterations)

The store serves public, private (role-encrypted) and DM channels and must never index, serve or announce an entry without current authorization, nor lose or repeat a legitimate announcement. The final model:

  • Two clocks. messageIndexEpoch bumps on a change to the local user's own facts or an unknown context (full rebuild). authRevision bumps on every other accepted sigchain update (narrow recheck). Every consume records the revision it started under; a message, push or ID delta is published only while its epoch and revision are current, and every fan-out re-checks that before each registration (a consumer may itself change authorization from inside its callback). Anything not published is handed back to the pending set and re-consumed under the current facts.
  • Narrow rechecks. The store fingerprints every member's keys and roles. An update dirties the members whose facts changed (author → revision); a recheck re-consumes their entries plus the rejected set, announces owed notifications itself, and commits a member only if no later update dirtied them again. Team filter and burst coalescing apply. ID snapshots exclude authors still awaiting a recheck; direct batch fetches restart on an epoch or revision change.
  • Announcements. Delivery is per registration (rawListeners, so once and duplicate registrations keep Node semantics) to the store's own listeners and, via forwardAnnouncementsTo, to ChannelsService's consumers, which no longer re-emit. A throwing consumer neither hides an announcement from later consumers nor gets it repeated to the ones that handled it; the retry (backoff 1 s → 30 s) reaches exactly the consumer that threw. Contract: exactly-once for a consumer that throws before its effect, at-least-once for one that throws after (the state-manager upserts messages by ID); MESSAGE_IDS_STORED failures re-send a full snapshot (IDs are fetch candidates).
  • Unreadable heads. Only an untrusted, unjoined shared-bus root is dropped; a joined or trusted head whose bytes are unreadable stays pending and backs off. Listeners and timers are detached on close/clean.

Auth submodule pin

3rd-party/auth is bumped from develop's 17e0b5bc to auth main at 922f9490a = TryQuiet/auth#39 "Reuse validated cryptographic facts" + TryQuiet/auth#42 "Re-export KeyMap with a relative specifier" (the follow-up that makes auth#39's emitted typings resolve from packages/backend). Audited in iteration 3: reused facts are bound to owned immutable inputs; no cache-reuse bypass found.

Authorization is monotonic today; liveness is the property that matters

Premise check (grep of production paths for revoke, removeMember, rotate, role removal, channel-membership removal): no path can make a previously authorized author unauthorized today. The only primitives are packages/backend/src/nest/auth/services/roles/role.service.ts (revokeMembership → team.removeMemberRole, delete → team.removeRole) and packages/backend/src/nest/auth/services/roles/channel.service.ts (revokeMembership → roles.revokeMembership, delete → roles.delete), and neither has a caller outside its own file; packages/types/src/channel.ts removeMembers is a capability flag; the revoke hits in packages/backend/src/nest/admission/* and libp2p.service.ts revoke admission gates, not membership; invite.service.ts revokes invitations, which affects joining, not existing authors; no key rotation call exists. A message that was valid therefore stays valid, and the "consumed under old facts, announced after removal" windows closed in iterations 2–5 are not reachable until removal or rotation exists; the fixes stay in (they are tested and cost nothing on the hot path). The property that is reachable is liveness: an entry rejected for a missing key or an unknown author must be re-consumed as soon as the sigchain update that makes it readable arrives (handleChainUpdate emits SigchainEvents.UPDATED on every chain update) and shown exactly once. Covered by liveness: entries become readable once keys or members arrive in channel.store.spec.ts (6fc8eae) for a new member's admission (narrow recheck) and the local user gaining a private channel's role (full rebuild): one extra consume, one ID announcement, no duplicate MESSAGES_STORED, no retry timer left. Negative controls: the admission case fails when the recheck stops seeding the rejected set; both cases fail when sigchain updates are ignored. #3569's undecryptable-entry sweep covers only the three channel-metadata stores; message entries are retried by the index's rejected set, so the two do not overlap.

Security audit (Daybreak Blue, adversarial, six iterations)

Reports in ~/.cache/quiet-3654-audit/daybreak-3654-iter{1..6}.md on the build box; each iteration's probes became regression tests that fail against the previous commit.

Iter Verdict Findings fixed (commit)
1 REJECT 6fdedc7 (review fixes) then 293d6a2: overlapping rechecks lost dirty authors; joined/trusted unreadable heads were dropped; announcements lost across auth invalidation or a throwing listener
2 REJECT 23c6f17: stale walk published after a narrow author change (no revision); unversioned dirty set lost a second change to the same author; recheck/rebuild ignored publish failures; DM acknowledged before emission; partial-delivery duplicates
3 REJECT 875cdd7: superseded walk still emitted its ID via the epoch-only delta; dispatcher broke once/duplicate registrations; throw-after-effect contract
4 REJECT 114aa9c: ID selected before the community-lookup await (TOCTOU); ChannelsService re-emit stopped at the first throwing consumer and acknowledged the loss
5 REJECT a85fe17: a consumer changing authorization from inside its callback still let later registrations receive the old-facts payload; four service tests faked the store without the new method
6 ACCEPT —

Tracked follow-up (non-blocking per the auditor): every accepted sigchain update rechecks the whole rejected set (O(rejected history)); narrowing it needs a consumer-level rejection taxonomy. Pre-existing, out of scope: the iterator fallback in getEntries is not atomic across auth changes; deliveredDmIds is process-lifetime.

Tests at a85fe17 (local; 6fc8eae adds two tests, store spec 81)

  • Backend test-ci: 103 suites passed, 2 skipped; 1336 tests passed, 6 skipped, 0 failed (channel.store.spec.ts 79, of which 32 audit regressions; channels.service.spec.ts 47 incl. a throwing-first consumer integration case; replication, DM security and author-impersonation specs included). Backend typecheck, ESLint and Prettier clean.
  • State-manager: 71 suites, 313 tests passed. e2e-tests typecheck clean.
  • Desktop QSS e2e against an AppImage packaged from this head (ENVFILE=.env.e2e.qss, Quiet-11.2.0-alpha.0.AppImage, QSS at ws://127.0.0.1:3003, --no-sandbox, own Xvfb): multipleClients.qss.test.ts 63 passed, 23 skipped, 0 failed. multipleClients.privateChannels.qss.test.ts 68 passed, 7 failed: the identical pre-existing set develop fails on this box (sidebar channel-list / channel-link selector timeouts and one join-state check; every message-history assertion passes). Runs on the box's busier periods additionally failed the Tor presence step (owner shown OFFLINE after a failed onion dial), which cascades into later steps; a rerun on the same AppImage returns to the baseline set.

Not run

Backend Tor and long-running suites, the other QSS e2e suites, mobile.

Refs #3539, #3536, #3537, TryQuiet/auth#39, TryQuiet/auth#42.

🤖 Generated with Claude Code

holmesworcester and others added 13 commits September 14, 2026 22:46
…/3539-on-develop

# Conflicts:
#	3rd-party/auth
#	packages/backend/src/nest/storage/channels/channel.store.ts
#	packages/e2e-tests/src/selectors.test.ts
#	packages/e2e-tests/src/selectors.ts
#	packages/e2e-tests/src/tests/multipleClients.privateChannels.qss.test.ts
#	packages/e2e-tests/src/tests/multipleClients.qss.test.ts
…line

ChannelStore on develop takes a DirectMessagesService between the private
messages service and the user profile store; pass a stub in the two specs
#3539 added. Drop a duplicate PushNotificationPayload import the merge produced.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
The mobile-notification and DM fan-out specs fake the OrbitDB store with an
iterator only. The #3539 index reads accepted entries through log.heads/has/get,
so give each fake a log keyed by entry hash, hand a redelivered DM its own entry
as OrbitDB would, and expect an ordinary arrival to announce only the IDs it
added. The #3539 deferred-notification spec now supplies getActiveChain, which
develop consults for the local identity.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@holmesworcester holmesworcester added 11.3 Speculative-reuse caches, design-system alignment and small fixes backend performance labels Sep 22, 2026
@holmesworcester

Copy link
Copy Markdown
Collaborator Author

Private-channels QSS e2e: develop baseline vs this branch

The PR body left multipleClients.privateChannels.qss.test.ts unresolved (60 passed / 15 failed on a busy box, no develop baseline). Ran it twice more on the same box, back to back, same recipe (ENVFILE=.env.e2e.qss AppImage, --no-sandbox, Xvfb + fluxbox, the same QSS stack at ws://127.0.0.1:3003):

AppImage built from passed failed runtime
develop @ d2007b0 (baseline) 68 7 371 s
this branch @ 27fd840 68 7 377 s

The seven failures are the identical set on both sides:

  • Creating Private Channel Before User Joins › First User Doesn't See Private Channel › First user's sidebar is missing private channel
  • Creating Private Channel Before User Joins › User Sees Private Channel When Owner Offline › First user sees private channel in sidebar
  • Creating Private Channel After User Joins › Owner Creates Another Private Channel › Owner creates a second private channel
  • Creating Private Channel After User Joins › Owner Adds User To Second Private Channel › First user's sidebar is missing private channel
  • Creating Private Channel After User Joins › Owner Adds User To Second Private Channel › First user sees second private channel in sidebar
  • Delete private channel › Owner deletes private channel
  • Second User Joins Using QSS Only › Second User Joins › Second user joins through QSS and sees expected state

They are sidebar channel-list / channel-link selector timeouts and one join-state check. Every message-history assertion passes on both sides.

Verdict: pre-existing on develop, not caused by this port. The earlier 15-failure run was the same suite on a more heavily shared box (the extra eight were the same UI steps timing out earlier).

Also re-ran backend test-ci at 27fd840, i.e. after the final develop merge (the PR body's run predated it): 103 suites passed, 2 skipped; 1290 tests passed, 6 skipped, 0 failed.

…arrow its auth invalidation

Review of #3654 found six defects in the incremental message index:

1. A missing or unjoined ancestor threw out of the un-awaited OrbitDB update listener,
   which backendManager answers with a full shutdown, and rejected subscribe(). The walk
   now never throws for unreadable ancestry: the head stays pending and a backoff timer
   retries it; subscribe() and the rebuild survive any read failure.
2. A head that log.heads() reports but the log index does not list yet (append persists
   heads before its index entry) was skipped and the index marked ready. Heads the log
   itself reports are now read from their bytes, as the iterator would show them.
3. MESSAGES_STORED and the mobile push were dropped when a head's walk was superseded by an
   auth rebuild or an earlier queued walk indexed it first. Heads announced by 'update' are
   registered as pending before their walk is queued; whichever walk indexes the entry
   announces it, exactly once.
4. Every SigchainEvents.UPDATED rebuilt the whole index, reintroducing the O(history)
   re-consume the index exists to avoid. The store now fingerprints every member's keys
   and roles when it checks the index. An update that leaves the local user's own facts
   unchanged rechecks only entries by members whose facts changed plus entries rejected so
   far; a change to the local user's own facts (or an unknown context) still rebuilds.
5. Direct fetch by hash only served single-ID reads. A batch whose IDs each map to one
   log entry is now fetched by hash; the iterator is kept for ambiguous IDs.
6. The 'update' listener on the shared OrbitDbService events bus was never removed.
   close() and clean() detach it and stop the retry timer.

Notifications are emitted after a walk returns, outside the index queue, so a username
lookup no longer blocks indexing.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@holmesworcester

Copy link
Copy Markdown
Collaborator Author

Code review findings and fixes

A high-effort review of the backend diff (channel.store.ts and its specs) found six blocking defects in the incremental message index. All six are fixed in commit 6fdedc7, each with a test that reproduces the failure mode first.

# Finding Fix Test
1 indexJoinedAncestry threw (not joined / Missing channel log entry) inside the un-awaited 'update' listener. That is an unhandledRejection, which backendManager answers with initiateShutdown; the same throw rejected subscribe(), so the channel was never marked subscribed. The walk never throws for unreadable ancestry. The head stays in a pending set and a backoff timer (1 s doubling to 30 s, unref) re-walks only pending heads. refreshMessageIds / the rebuild log and retry instead of rejecting subscribe(). Other read failures in the listener are caught and retried the same way. does not treat an unavailable or unjoined ancestor as completed ancestry (now asserts the listener resolves), retries an unreadable ancestor in the background…, subscribes when the initial rebuild cannot read an ancestor…, never rejects the shared update listener when a log read fails…
2 The rebuild continued over a head present in log.heads() but absent from the log index (append persists heads before the index entry; a kill in between leaves exactly that) and marked the index ready, so the message stayed invisible. Heads the log itself reports (trusted) are read from their entry bytes when has() denies them, matching what the iterator would show. Heads announced over the shared bus keep the strict has() gate (no bytes fetched for unjoined entries). indexes a head the log reports from its bytes when the log index lags behind heads(); defers a snapshot head… adjusted for the one extra read
3 MESSAGES_STORED and the mobile push were dropped when a head's walk was superseded by an auth rebuild, or when an earlier queued walk had already indexed it. Heads are registered as pending (notify: true) synchronously in the listener, before the walk is queued. Whichever walk indexes the entry (its own, an earlier head's, or the rebuild) announces it, exactly once; pending entries survive a full invalidation. announces an arrival exactly once when an auth update interrupts its walk, announces each concurrent head once even when an earlier walk indexed it, existing emits a deferred mobile notification… cases
4 Every SigchainEvents.UPDATED discarded the whole index and re-consumed every message of every channel, reintroducing the O(history) scan the PR exists to remove. The store fingerprints each member's keys and roles (team.members()) when it checks the index. An update that leaves the local user's own facts unchanged bumps the epoch (discarding in-flight walks, which re-run from the pending set) and rechecks only entries authored by members whose facts changed plus entries rejected so far; a change to the local user's own facts, or an unavailable context, still rebuilds everything. keeps checked consumes when a sigchain update only admits a new member (50 messages, 0 re-consumes), rechecks only the messages of a member whose keys or roles changed, retries rejected entries on a sigchain update without rewalking accepted history, rebuilds the whole index when the local user's own authorization changes
5 The direct-fetch fast path fired only for exactly one ID; the frontend's batch getMessages({ ids }) after a multi-entry import fell through to a full log scan. When the index is ready and every requested ID maps to exactly one log entry, each is fetched by hash and re-consumed under the current epoch. Unknown IDs are skipped; any ID with several entries keeps the ordered iterator. fetches a batch of announced IDs directly without rescanning history (3 hash reads, 0 iterations)
6 The 'update' listener on the shared static OrbitDbService.events bus was never removed in close() / clean(): a leak plus dead-store callbacks across leave/rejoin. The listener is kept and detached in close() and clean() (like the auth listener); subscribe() detaches a previous one first; the retry timer is cleared too. detaches its update listener from the shared events bus on close / on clean

Relation to TryQuiet/auth#39: that companion PR caches checked lockbox keys per Team and reuses graph-crypto facts, which makes each onConsume cheaper; it does not change how many entries are re-consumed, since message signatures and current authorization are still checked per message. Finding 4 is the scope half of the same problem: quiet keeps nothing about keys or lockboxes, only the per-entry consume outcome and a fingerprint of each member's public keys and roles, so the two compose without overlap.

Also done (the review's optional items): notifications and the username lookup now run after a walk returns, outside the index queue, so they no longer serialize indexing (7); the hash → id and hash → author maps are one indexedEntries map (8).

Semantics that changed on purpose:

  • Ancestors are consumed before their descendants (unchanged), so an arrival whose ancestor is unreadable announces nothing until the retry completes; the entries it did consume are indexed and announced immediately.
  • On a sigchain update that does not touch the local user, removed IDs are communicated by the reconciliation snapshot as before; the frontend still treats IDs as candidates, not an authoritative list.

Test results on the fixed branch are in the next comment.

@holmesworcester

Copy link
Copy Markdown
Collaborator Author

Test results at 6fdedc7 (the review fixes)

  • Backend test-ci: 103 suites passed, 2 skipped; 1303 tests passed, 6 skipped, 0 failed (13 new tests in channel.store.spec.ts, now 48). channel.store.replication.spec.ts, direct-messages.security.spec.ts, author-impersonation.spec.ts, channels.service.spec.ts included. ESLint and Prettier clean on the changed files.
  • Desktop QSS e2e against an AppImage packaged from 6fdedc7 (ENVFILE=.env.e2e.qss, same QSS stack and recipe as the baseline comment above):
    • multipleClients.qss.test.ts: 63 passed, 23 skipped, 0 failed.
    • multipleClients.privateChannels.qss.test.ts: 68 passed, 7 failed. The 7 are the identical pre-existing set that develop fails on this box (see the baseline comment); every message-history assertion passes.

Not run: backend Tor and long-running suites, the other QSS e2e suites, mobile.

holmesworcester and others added 8 commits September 22, 2026 09:30
…ve overlap and failure

Daybreak Blue iteration 1 of #3654 rejected the index on three state-machine defects:

M-1 Overlapping sigchain updates diffed each new fingerprint against the one just
    published, so a second update could drop an author the first, still running, recheck
    had not finished; a recheck that failed on a log read was retried as pending-head work.
    Dirty authors now accumulate across updates and are diffed against the last committed
    facts; a recheck commits its authors only after every selected entry was consumed under
    them, and a failed recheck is repeated by the retry timer with the same dirty set. The
    narrow path no longer bumps the epoch: in-flight walks stay valid and the queued recheck
    re-examines whatever they index. Updates for other teams are ignored and a burst of
    updates coalesces into one queued recheck.
M-2 A head the log had joined (or reported) whose bytes were momentarily unreadable was
    dropped as complete. Only an unjoined, untrusted shared-bus head is dropped now; any
    other unreadable entry keeps its head pending and is retried with backoff.
M-3 Walk completion acknowledged a head's announcement before it was published, so an auth
    change or a throwing listener in that window lost MESSAGES_STORED and the push for good.
    Announcements are acknowledged one by one after they are emitted under the epoch they
    were consumed in; anything not emitted returns to the pending set and is consumed again
    under the current facts before it is announced. MESSAGES_STORED and the push are emitted
    together after the username lookup, and a DM is marked delivered only then.
L-3 A non-Error rejection in the rebuild no longer escapes as an unhandled rejection.
L-2 Batch reads return request order; documented and tested.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Picks up "Reuse validated cryptographic facts" and the KeyMap re-export fix
that makes its emitted typings resolve from packages/backend.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…s per listener

Daybreak iteration 2 (M-1, M-2, L-2):

- M-1: every accepted sigchain update bumps an authorization revision. A
  consume records the revision it started under; its announcement is only
  made while that revision is current, otherwise it is handed back and
  reconsumed under the current facts. Dirty members are versioned by the
  revision that dirtied them, so a recheck commits only members no later
  update dirtied again; a member already queued under the same facts is not
  re-dirtied. The recheck announces owed notifications itself, so a stale
  walk costs exactly one current reconsume. Direct batch fetches restart
  when the revision changes mid-batch.
- M-2: recheckAuthorization and the rebuild act on publishNotifications'
  result and schedule a retry; a DM ID counts as delivered only after every
  listener received it.
- L-2: announcements are handed to listeners one by one and the pending
  entry records which listeners already received them, so a retry after a
  throwing listener reaches only the listeners still owed the message and
  no listener sees it twice; the push notification is tracked separately
  from MESSAGES_STORED.

Nine regression tests reproduce the audit's probes (stale-walk publication
for a rejected and an accepted current result, a second change to the same
author during their recheck, DM loss after a throwing first listener,
stranded announcements on the recheck and rebuild paths, partial delivery,
a failing push listener, and a batch fetch spanning an auth change); all
nine fail against the previous commit.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…egistration

Daybreak iteration 3 (M-1, L-1, L-2):

- M-1: a walk result carries the authorization revision it started under and
  refreshMessageIds announces its ID delta only while that revision (and the
  epoch) is still current; otherwise, and for every reconciliation snapshot,
  it announces the indexed IDs of members not awaiting a recheck, so the
  ID of an entry consumed under superseded facts never escapes before the
  current recheck decides it.
- L-1: announcements are delivered per registration via rawListeners, so a
  once() listener is unregistered after its first delivery and a listener
  registered twice receives each announcement twice, also across a retry.
- L-2: ChannelsService forwards store announcements without throwing back
  into the store, so a failing downstream consumer cannot make the store
  announce the same message again to consumers that already handled it.
  The store's delivery contract is documented: exactly-once for a listener
  that throws before its effect, at-least-once for one that throws after.

Tests: the stale-walk cases now pause the current recheck and assert that
no MESSAGE_IDS_STORED delta or snapshot names the entry meanwhile; once()
and duplicate-registration delivery; a throw-after-effect contract test; and
a ChannelsService test that a throwing consumer does not cause redelivery
to healthy consumers. All but the contract test fail against the previous
commit.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…s consumers per registration

Daybreak iteration 4 (M-1, M-2):

- M-1: refreshMessageIds awaits the community lookup first and only then,
  with no await left before emission, decides whether the walk's delta is
  still current (epoch and authorization revision) or which indexed IDs a
  snapshot may name (authors not awaiting a recheck). A narrow sigchain
  update during the lookup can no longer let an already selected stale ID
  escape.
- M-2: ChannelsService no longer re-emits store announcements. The store
  keeps a list of announcement targets (itself and, via
  forwardAnnouncementsTo, the service) and delivers MESSAGES_STORED,
  SEND_PUSH_NOTIFICATION and MESSAGE_IDS_STORED to every registration of
  every target one by one, so a throwing consumer neither hides an
  announcement from the consumers registered after it nor gets it repeated
  to the ones that already handled it, and the retry reaches exactly the
  consumer that threw. A failed MESSAGE_IDS_STORED delivery flags a
  snapshot resend on the retry timer (IDs are fetch candidates, so a
  repeated snapshot is harmless).

Tests: delta and snapshot cases that pause the community lookup, change the
author's facts meanwhile and pause the recheck; a throwing first
MESSAGE_IDS_STORED consumer; throwing-first consumers on a forwarding
emitter for MESSAGES_STORED and the push; and the ChannelsService test now
registers the throwing consumer first and expects both consumers to see
each message exactly once. All fail against the previous commit.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Daybreak iteration 5 (M-1, M-2, I-3):

- M-1: a consumer may itself change authorization (or close the store)
  from inside its callback. deliver() now asks a currentness predicate
  before every registration and stops the fan-out once it fails: message
  and push delivery use the consumed epoch and authorization revision, ID
  delivery the epoch and the revision the IDs were decided under. Earlier
  registrations keep their delivery record, so the announcement made again
  under the current facts reaches exactly the consumers still owed it.
- M-2: the four ChannelsService tests that fake a store with a bare
  EventEmitter now give it forwardAnnouncementsTo; the whole spec passes.
- I-3: idsResendNeeded is cleared by a fully delivered snapshot and by
  index invalidation.

Tests: consumers that emit a narrow (accepted and rejected) or a full
sigchain update from inside MESSAGES_STORED, SEND_PUSH_NOTIFICATION and
MESSAGE_IDS_STORED callbacks; later registrations only ever receive the
result consumed under the facts that consumer established. All five fail
against the previous commit.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@holmesworcester

Copy link
Copy Markdown
Collaborator Author

Security audit iterations 2–6 (Daybreak Blue) → ACCEPT at a85fe17

Adversarial re-audits of the incremental message index, one per fix commit; each iteration's probes were converted into regression tests that fail against the previous commit. Head a85fe17 also bumps 3rd-party/auth to 922f9490a (TryQuiet/auth#39 + TryQuiet/auth#42) and merges develop at 5c98449.

Iter Verdict Blocking findings Fix
2 REJECT A walk paused in onConsume under an author's old keys could publish after the author's keys rotated (narrow updates changed no epoch); a second change to the same author during their running recheck was erased by the unversioned dirty set; recheckAuthorization/rebuild ignored a failed publication; a DM was marked delivered before emission; partial fan-out duplicated 23c6f17: authRevision versions every consume and its announcement; dirtyAuthors is author → revision; publish failures schedule a retry on every path; DM marked delivered only after all listeners; delivery per listener with retry
3 REJECT The superseded walk still emitted its ID through the epoch-only MESSAGE_IDS_STORED delta; dispatcher broke once/duplicate registrations; throw-after-effect duplication 875cdd7: ID delta gated on epoch + revision, snapshots exclude authors awaiting a recheck; delivery per registration via rawListeners; contract documented
4 REJECT refreshMessageIds selected IDs and then awaited the community lookup (TOCTOU); ChannelsService re-emitted with emit, which stops at the first throwing consumer and acknowledged the loss 114aa9c: IDs decided after the last await; the store delivers to the service's consumers registration by registration (forwardAnnouncementsTo), ID failures re-send a snapshot
5 REJECT A consumer changing authorization from inside its callback still let later registrations receive the old-facts payload; four service tests faked the store without the new method a85fe17: currentness re-checked before every registration; doubles fixed
6 ACCEPT none —

Non-blocking follow-up kept by the auditor across iterations: every accepted sigchain update rechecks the whole rejected set (O(rejected history)); narrowing it needs a consumer-level rejection taxonomy. Pre-existing and out of scope: the iterator fallback in getEntries is not atomic across auth changes; deliveredDmIds is process-lifetime.

Results at a85fe17

  • Backend test-ci: 103 suites passed, 2 skipped; 1336 tests passed, 6 skipped, 0 failed. channel.store.spec.ts 79 (32 audit regressions), channels.service.spec.ts 47. Typecheck, ESLint, Prettier clean.
  • State-manager 313 passed; e2e-tests typecheck clean.
  • Desktop QSS e2e from an AppImage packaged at this head: multipleClients.qss 63 passed / 0 failed; multipleClients.privateChannels.qss 68 passed / 7 failed, the identical develop baseline set. Two runs during heavy box load failed the Tor presence step first (owner OFFLINE after a failed onion dial) and cascaded; the rerun returned to the baseline set.

🤖 Generated with Claude Code

…ers arrive

Authorization is monotonic in Quiet today (no member removal, no key
rotation), so the property the index must keep is liveness: an entry
rejected for a missing key or an unknown author is re-consumed once the
sigchain update that makes it readable arrives and announced exactly once.
Covered for a new member's admission (narrow recheck) and for the local
user gaining the channel's role (full rebuild).

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

11.3 Speculative-reuse caches, design-system alignment and small fixes backend performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant