Repository navigation
fix(matrix): await persistence shutdown - #129605
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
6081d85 to
c2af2af
Compare
|
@clawsweeper re-review The head changed from |
|
🦞🧹 I asked ClawSweeper to review this item again. |
c2af2af to
251cf2f
Compare
|
Codex review: needs maintainer review before merge. Reviewed August 25, 2026, 5:52 PM ET / 21:52 UTC. ClawSweeper reviewWhat this changesThe PR makes Matrix client retirement await startup, crypto snapshot work, and QA discard cleanup so those tasks cannot outlive a retired generation. Regression provenancePossible regression — suspected (reviewed change). No predecessor PR is attributed. Merge readinessKeep open. The patch addresses real owner-level Matrix shutdown races, but the current head lacks independently verified exact-head proof and direct matrix-js-sdk contract inspection; it is also a member-authored, maintainer-labeled draft. Priority: P2 Review scores
Verification
Live VerificationCommand: Result: PASS (completed) Assertions:
How this fits togetherMatrix client generations own SDK startup and encrypted-state persistence; leases retire a generation before another can replace it. QA Lab uses that lifecycle when exercising encrypted Matrix scenarios. flowchart LR
A[Matrix client lease] --> B[Client generation]
B --> C[SDK startup and crypto setup]
B --> D[Periodic crypto snapshot]
A --> E[Generation retirement]
E --> F[Await owned work]
F --> G[Stop or discard client]
G --> H[Replacement or QA result]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +100, Tests +228. Total +328 across 9 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Retain the owner-boundary repair after direct matrix-js-sdk contract inspection and exact-head focused Matrix/QA validation confirm the shutdown ordering; the production growth is justified only by those distinct asynchronous ownership boundaries. Do we have a high-confidence way to reproduce the issue? No live reproduction was performed; source and focused regressions provide a medium-confidence reproduction path for pending startup, persistence, and discard cleanup. Is this the best way to solve the issue? Unclear: the fix is at the appropriate lifecycle owners, but direct verification of the pinned Matrix SDK contract is still missing. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against e1e2818a6ab0. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Merged via squash.
|
* fix(matrix): await persistence shutdown * fix(matrix): join startup during shutdown * fix(matrix): bound startup retirement * fix(matrix): fence late retirement ownership * fix(matrix): centralize generation retirement
Related: #120168
What Problem This Solves
Fixes Matrix shutdown races where client startup, monitor cleanup, encrypted-state persistence, SDK discard, or QA discard cleanup could outlive the generation that owned them. It also keeps caller-visible shutdown bounded when
matrix-js-sdkcrypto initialization never settles.Why This Change Was Made
Generation retirement had overlapping deletion and late-drain state machines. Late lease release and forced retirement could delete a keyed generation independently of the retirement owner, persistence failure could surface before discard fallback settled, and
stopWithoutPersist()could yield before claiming its shutdown flight.beginGenerationRetirement()is now the sole generation-deletion owner:late-drain, otherwise joins the active owner and never deletes directly;stopWithoutPersist()synchronously single-flights discard-first, persist-first, and mixed concurrent shutdown through the existing stop flight plus one private fallback promise.The existing periodic persistence owner fix, post-abort SDK/persistence fences, and QA asynchronous discard handling remain intact.
User Impact
Matrix shutdown cannot admit a replacement over unresolved startup, monitor work, transient borrowers, or SDK discard. Failed cleanup remains visibly poisoned instead of silently replacing the client. No configuration or workflow changes.
Evidence
81fdd67f5d7d2a9ba2ef892589c1273a3a82b3d1.9295072c2dec01d79e8ae2c875a779abf3b53ff9; no rebase was performed.5ac1b3c558f6826e636203a9b27273801d6f9fae.origin/main:df9b7a5fbe9b94b0ab25dc404db7784797feadca.d2052167ec8088e1bed53d0162b71a149247103b/ fix(matrix): let follow-ups steer active turns #128907 transfers replay-claim ownership inside already tracked Matrix handlers without changing monitor task admission, listener detachment, task waiting, cleanup registration, or this repair's write scope. The subsequentdf9b7a5fbe9bcommit is UI-only. No rebase is required.Owner proof:
extensions/matrix/src/matrix/client/shared.tshas one authoritative retirement flow and onlybeginGenerationRetirement()decides whether the keyed generation can be deleted.extensions/matrix/src/matrix/sdk/client-base.tssynchronously claims one stop flight and awaits any failed-persistence discard fallback.Direct dependency proof from pinned
[email protected]source and types:startClient()starts sync and services without anAbortSignal;initRustCrypto()exposes no cancellation or timeout;stopClient()is synchronous and stops an initialized crypto backend even when startup was incomplete;Validation:
9295072c2decand now cover late-release deletion ownership, repeated forced late-drain retirement, normal discard failure retention, strict persistence fallback joining, failed fallback retention, final-drain discard failure retention, and mixed shutdown single-flight.initRustCrypto()is pending, periodic persistence cancellation/awaiting, and QA deferred discard.git diff --checkpassed.late-drain-stopped,PoisonDisposition,deleteSharedClientStateAfterLateDrain,continueLateGenerationRetirement, andStopOutcome.Live-smoke infeasibility: no authenticated Matrix credentials or accessible E2EE room are available in this execution environment, so a real homeserver/WASM shutdown-restart smoke cannot be performed. Mock lifecycle coverage plus direct
[email protected]source/type contract inspection is the best available proof.Judged LOC
Release Note
Fix Matrix shutdown so unresolved startup, monitor ownership, encrypted-state persistence, and asynchronous discard cleanup cannot outlive or prematurely replace their client generation.