Repository navigation
Avoid repeated message-history processing (forward-port of #3539) - #3654
Conversation
…/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>
Private-channels QSS e2e: develop baseline vs this branchThe PR body left
The seven failures are the identical set on both sides:
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 Also re-ran backend |
…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>
Code review findings and fixesA high-effort review of the backend diff (
Relation to TryQuiet/auth#39: that companion PR caches checked lockbox keys per Team and reuses graph-crypto facts, which makes each 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 Semantics that changed on purpose:
Test results on the fixed branch are in the next comment. |
Test results at 6fdedc7 (the review fixes)
Not run: backend Tor and long-running suites, the other QSS e2e suites, mobile. |
# Conflicts: # CHANGELOG.md
…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>
Security audit iterations 2–6 (Daybreak Blue) → ACCEPT at a85fe17Adversarial 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
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 Results at a85fe17
🤖 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>
Forward-port of #3539 "Avoid repeated message-history processing" onto
developfor 11.3. This supersedes #3539, which targets10.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.
ChannelStorenow 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 ownhas/get, so one head that imports a whole backlog is processed once.MESSAGE_IDS_STOREDannounces 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-managermissingChannelMessagesselector 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.0is fully contained indevelop, so the merge brings only the PR's nine commits.develophas been merged in since (last: 5c98449, the 11.2.0 back-merge).ChannelStoreondevelopalso 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.developremoved the sidebar user list; those roster checks live in Community membership. The e2e package is unchanged fromdevelop.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:
messageIndexEpochbumps on a change to the local user's own facts or an unknown context (full rebuild).authRevisionbumps 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.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.rawListeners, soonceand duplicate registrations keep Node semantics) to the store's own listeners and, viaforwardAnnouncementsTo, toChannelsService'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_STOREDfailures re-send a full snapshot (IDs are fetch candidates).Auth submodule pin
3rd-party/authis bumped from develop's17e0b5bcto authmainat922f9490a= 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 frompackages/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 arepackages/backend/src/nest/auth/services/roles/role.service.ts(revokeMembership→team.removeMemberRole,delete→team.removeRole) andpackages/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.tsremoveMembersis a capability flag; therevokehits inpackages/backend/src/nest/admission/*andlibp2p.service.tsrevoke admission gates, not membership;invite.service.tsrevokes 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 (handleChainUpdateemitsSigchainEvents.UPDATEDon every chain update) and shown exactly once. Covered byliveness: entries become readable once keys or members arriveinchannel.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 duplicateMESSAGES_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}.mdon the build box; each iteration's probes became regression tests that fail against the previous commit.once/duplicate registrations; throw-after-effect contractChannelsServicere-emit stopped at the first throwing consumer and acknowledged the lossTracked 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
getEntriesis not atomic across auth changes;deliveredDmIdsis process-lifetime.Tests at a85fe17 (local; 6fc8eae adds two tests, store spec 81)
test-ci: 103 suites passed, 2 skipped; 1336 tests passed, 6 skipped, 0 failed (channel.store.spec.ts79, of which 32 audit regressions;channels.service.spec.ts47 incl. a throwing-first consumer integration case; replication, DM security and author-impersonation specs included). Backend typecheck, ESLint and Prettier clean.ENVFILE=.env.e2e.qss,Quiet-11.2.0-alpha.0.AppImage, QSS atws://127.0.0.1:3003,--no-sandbox, own Xvfb):multipleClients.qss.test.ts63 passed, 23 skipped, 0 failed.multipleClients.privateChannels.qss.test.ts68 passed, 7 failed: the identical pre-existing setdevelopfails 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