Skip to content

fix(matrix): retire shared E2EE clients safely - #119570

Merged
vincentkoc merged 4 commits into
mainfrom
fix/qa-matrix-e2e-lifecycle-timeout-20260805
Aug 5, 2026
Merged

vincentkoc merged 4 commits into
mainfrom
fix/qa-matrix-e2e-lifecycle-timeout-20260805

Conversation

@vincentkoc

@vincentkoc vincentkoc commented Aug 5, 2026 •

Copy link
Copy Markdown
Member

Related: #76611

What Problem This Solves

Fixes an issue where encrypted Matrix shutdown could hang or preserve an unsafe sync cursor when monitor work, transient sends or controls, or event decryption was still active.

The exact-main full QA profile exposed the production lifecycle defect as two Matrix E2EE scenarios held until the outer workflow timeout and one sync-state-loss failure:
https://github.com/openclaw/openclaw/actions/runs/30983891496

Why This Change Was Made

Matrix client ownership now lives in one account-keyed shared generation with role-aware monitor and transient leases. Retirement moves through open -> quiescing -> closing: freeze sync-cursor persistence, stop the version-pinned classic matrix-js-sdk sync loop, drain decryptions and monitor tasks, bound transient lease drain, then stop the SDK and persist crypto before marking the sync cursor clean.

If sync cannot quiesce, the generation is poisoned and pending cursor state is discarded rather than persisted or silently reopened. Fully stopped SDK clients are terminal, matching the upstream Rust-crypto contract; later work acquires a fresh generation.

This does not add config, protocol, dependency, release, tag, package-publish, or version changes. Cursor journaling in #110568 and crash-downtime replay in #116934 remain separate concerns.

User Impact

Operators get deterministic Matrix shutdown behavior across monitors and one-off actions. Active work is no longer torn down underneath listeners or decrypt retries, and an uncertain shutdown cannot advance the durable sync cursor.

QA operators get prompt scenario failures with retained workflow evidence instead of workers lingering until the outer Actions timeout.

Evidence

  • Focused exact-head Matrix proof: 209/209 tests passed across five affected suites.
  • Type-aware oxlint on the six final touched files and the max-lines ratchet: passed.
  • Structured P1 autoreview: clean on the lifecycle bundle and final lint extraction.
  • ClawSweeper follow-through: sync now quiesces before decrypt drain; final crypto persistence remains strict and failure-propagating rather than being raced, so the bounded claim is limited to sync, decrypt, task, and transient-lease phases. Repo-native prepare-run passed without rebasing because current-main Matrix files do not overlap.
  • git diff --check: passed.
  • Database-first, media-download-helper, runtime-sidecar-loader, and import-cycle guards: passed.
  • Extension test typing: all branch-owned diagnostics cleared. The linked worktree's shared install still exposes an unrelated terminal-core baseline because installed string-width is 4.2.3 while the lockfile requires 8.2.2; exact-head CI will run with a clean dependency install.
  • Production delta: +901/-445 (net +456). Tests: +2158/-945 (net +1213).
  • No changelog, dependency, or release metadata changes.

Punchcard-Session: silver-valley-valley-dt

Punchcard-Session: silver-valley-valley-dt
@vincentkoc vincentkoc self-assigned this Aug 5, 2026
@vincentkoc
vincentkoc marked this pull request as ready for review August 5, 2026 10:06
Punchcard-Session: silver-valley-valley-dt
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. labels Aug 5, 2026
@clawsweeper

clawsweeper Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Codex review: found issues before merge. Reviewed August 5, 2026, 6:30 AM ET / 10:30 UTC.

ClawSweeper review

What this changes

The PR replaces individual Matrix E2EE QA operation shutdowns with one shared lifecycle intended to bound active work, decrypt draining, and client teardown.

Merge readiness

⚠️ Ready for maintainer review - 4 items remain

Keep open: the proposed lifecycle still permits an unbounded final persistence wait and drains while Matrix sync is active. Likely related people: Peter Steinberger (recent QA cleanup, high confidence) and Dallin Romney (Matrix E2EE feature history, high confidence).

Priority: P2
Reviewed head: 9cbe3a494761d26fdcf0c46f4e860fa9c481e088

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The proposed owner boundary is useful, but two concrete lifecycle gaps prevent the advertised bounded teardown.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored QA reliability PR is exempt from the external-contributor proof gate; exact-head focused and live QA evidence remains valuable validation.
Patch quality 🦐 gold shrimp (3/6) 2 actionable review findings remain.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored QA reliability PR is exempt from the external-contributor proof gate; exact-head focused and live QA evidence remains valuable validation.
Evidence reviewed 5 items Unbounded final persistence: The PR applies the shutdown deadline to active operations and decryption drain but awaits final persistence without a timeout.
Persistence can exceed the lifecycle budget: Matrix stop-and-persist waits for persistence work, and the snapshot lock is intentionally configured to retry for at least 60 seconds.
Sibling shutdown ordering: The production Matrix monitor stops sync before draining decryptions, whereas this lifecycle waits until stop-and-persist to stop sync.
Findings 2 actionable findings [P1] Bound final persistence within the shutdown deadline
[P2] Pause sync before draining decryptions
Security None None.

How this fits together

QA Lab creates disposable Matrix E2EE clients for live encrypted-message scenarios. Their operations, decryption retries, and persistence must terminate predictably so a QA worker can release or report an actionable failure.

flowchart LR
  Scenario[Live Matrix QA scenario] --> Client[Disposable E2EE client]
  Client --> Operations[Tracked SDK operations]
  Operations --> Lifecycle[Bounded shutdown lifecycle]
  Lifecycle --> Sync[Stop Matrix sync]
  Sync --> Drain[Drain decryptions]
  Drain --> Persist[Persist or discard state]
  Persist --> Outcome[Scenario result and worker release]
Loading

Before merge

  • Bound final persistence within the shutdown deadline (P1) - stopAndPersist() is awaited after the deadline-controlled phases. Its Matrix implementation waits for IDB and sync-store persistence, while the IDB snapshot lock deliberately retries for at least 60 seconds; a stall here keeps the QA worker alive despite shutdownTimeoutMs. Make final persistence cancellable/bounded within the remaining budget, with a regression for a persist promise that never settles.
  • Pause sync before draining decryptions (P2) - The lifecycle starts drainPendingDecryptions() while the Matrix sync client remains active; sync stops only inside stopAndPersist(). The sibling monitor pauses sync before drain, preventing new encrypted events and retries from extending shutdown. Inject and call the sync-stop operation before drain, then assert that ordering in the lifecycle test.
  • Resolve merge risk (P1) - Merging as written can still hold a QA worker beyond the advertised lifecycle deadline during persistence, and live sync may add decryption work while shutdown is trying to drain it.
  • Complete next step (P2) - This protected maintainer PR has two concrete lifecycle defects that need correction and exact-head review before merge.

Findings

  • [P1] Bound final persistence within the shutdown deadline — extensions/qa-lab/src/live-transports/matrix/substrate/e2ee-client-internals.ts:84
  • [P2] Pause sync before draining decryptions — extensions/qa-lab/src/live-transports/matrix/substrate/e2ee-client-internals.ts:77-84
Agent review details

Security

None.

PR surface

Source +77, Tests +162. Total +239 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 2 103 26 +77
Tests 1 173 11 +162
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 276 37 +239

Review metrics

Metric Value Why it matters
Production versus test delta production +103/-26 (net +77), tests +173/-11 (net +162) The new lifecycle adds material teardown behavior, so coverage must include its final persistence and ordering boundaries.

Merge-risk options

Maintainer options:

  1. Make the entire shutdown enforceably bounded (recommended)
    Pause sync before drain and repair the persistence path so a stalled final persist cannot keep a Matrix QA worker alive beyond the shutdown deadline.

Technical review

Best possible solution:

Pause sync before draining, then make persistence either cancellable within the remaining deadline or explicitly discard state before starting an operation that cannot be bounded.

Do we have a high-confidence way to reproduce the issue?

Yes, from source: a never-settling final persistence promise is awaited outside the lifecycle deadline, and sync remains active during drain. A focused fake-timer regression can demonstrate both paths without a live Matrix account.

Is this the best way to solve the issue?

No: centralizing the lifecycle is the right owner boundary, but it must pause sync before drain and cannot claim bounded shutdown while final persistence is unbounded.

Full review comments:

  • [P1] Bound final persistence within the shutdown deadline — extensions/qa-lab/src/live-transports/matrix/substrate/e2ee-client-internals.ts:84
    stopAndPersist() is awaited after the deadline-controlled phases. Its Matrix implementation waits for IDB and sync-store persistence, while the IDB snapshot lock deliberately retries for at least 60 seconds; a stall here keeps the QA worker alive despite shutdownTimeoutMs. Make final persistence cancellable/bounded within the remaining budget, with a regression for a persist promise that never settles.
    Confidence: 0.98
  • [P2] Pause sync before draining decryptions — extensions/qa-lab/src/live-transports/matrix/substrate/e2ee-client-internals.ts:77-84
    The lifecycle starts drainPendingDecryptions() while the Matrix sync client remains active; sync stops only inside stopAndPersist(). The sibling monitor pauses sync before drain, preventing new encrypted events and retries from extending shutdown. Inject and call the sync-stop operation before drain, then assert that ordering in the lifecycle test.
    Confidence: 0.94

Overall correctness: patch is incorrect
Overall confidence: 0.96

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 637de7d37945.

Labels

Label changes:

  • add P2: The defect affects bounded Matrix QA worker cleanup rather than a confirmed production runtime outage.
  • add merge-risk: 🚨 availability: The new lifecycle owns whether a Matrix QA worker terminates or remains held by decrypt or persistence work.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: This maintainer-authored QA reliability PR is exempt from the external-contributor proof gate; exact-head focused and live QA evidence remains valuable validation.

Label justifications:

  • P2: The defect affects bounded Matrix QA worker cleanup rather than a confirmed production runtime outage.
  • merge-risk: 🚨 availability: The new lifecycle owns whether a Matrix QA worker terminates or remains held by decrypt or persistence work.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: This maintainer-authored QA reliability PR is exempt from the external-contributor proof gate; exact-head focused and live QA evidence remains valuable validation.

Evidence

What I checked:

Likely related people:

  • steipete: Authored the current-main Matrix QA cleanup that introduced the present substrate and teardown path. (role: recent QA transport cleanup contributor; confidence: high; commits: b5d99c1f0675; files: extensions/qa-lab/src/live-transports/matrix/substrate/e2ee-client.ts, extensions/qa-lab/src/live-transports/matrix/substrate/e2ee-client-internals.ts)
  • Dallin Romney: History includes the original Matrix QA E2EE work and bounded-send behavior that this lifecycle refactor replaces. (role: Matrix QA/E2EE feature-history contributor; confidence: high; commits: 56915896; files: extensions/qa-lab/src/live-transports/matrix/substrate/e2ee-client.ts, extensions/qa-lab/src/live-transports/matrix/substrate/e2ee-client-internals.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Pause sync before decrypt draining and add an ordering regression.
  • Ensure final persistence cannot outlive the shutdown deadline, with a pending-persist regression.
  • Rebase and rerun the focused Matrix QA lifecycle proof on the exact head.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

Punchcard-Session: silver-valley-valley-dt
@openclaw-barnacle openclaw-barnacle Bot added channel: matrix Channel integration: matrix size: XL and removed size: M labels Aug 5, 2026
@vincentkoc vincentkoc changed the title fix(qa): stop Matrix E2EE clients within a bounded lifecycle fix(matrix): retire shared E2EE clients safely Aug 5, 2026
Punchcard-Session: silver-valley-valley-dt
@vincentkoc
vincentkoc merged commit a3419d4 into main Aug 5, 2026
132 checks passed
@vincentkoc
vincentkoc deleted the fix/qa-matrix-e2e-lifecycle-timeout-20260805 branch August 5, 2026 17:14
@vincentkoc

Copy link
Copy Markdown
Member Author

Merged via squash.

vincentkoc added a commit to VACInc/openclaw that referenced this pull request Aug 5, 2026
…cope

* origin/main: (70 commits)
  fix(clickclack): preserve MIME extension for unnamed uploads (openclaw#119646)
  fix(memory): keep post-ready RPCs responsive (openclaw#119710)
  fix(browser): preserve locale, timezone, and device overrides (openclaw#119695)
  fix(agents): stop messaging dedupe from dropping final replies that quote a short tool send (openclaw#118178)
  test(agents): batch code mode budget proof (openclaw#119699)
  fix(memory): keep gateway RPCs responsive during startup (openclaw#119676)
  improve(ui): trail transient session status beside row actions (openclaw#119560)
  refactor(msteams): consolidate channel action target resolution (openclaw#119632)
  fix: tail context answers the current user message (openclaw#117364)
  fix(whatsapp): exercise descriptor-safe credential persistence (openclaw#119621)
  fix(diagnostics-otel): route OTLP endpoints by signal (openclaw#101655)
  refactor(skills): consolidate workshop transcript and record normalization (openclaw#119643)
  fix(video): harden DashScope task and media lifecycle (openclaw#117303)
  refactor(transcripts): consolidate persistence and export ownership (openclaw#119634)
  fix: preserve ClickClack discussion state contracts (openclaw#118851)
  fix(matrix): retire shared E2EE clients safely (openclaw#119570)
  refactor(cron): unify catch-up persistence and payload encoding (openclaw#119636)
  refactor(ui): centralize composer attachment and capability controls (openclaw#119650)
  refactor(daemon): consolidate managed service lifecycle ownership (openclaw#119647)
  fix(browser): honor explicit navigation timeouts across browser drivers (openclaw#119654)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 6, 2026
* fix(qa): bound Matrix E2EE client shutdown

Punchcard-Session: silver-valley-valley-dt

* fix(qa): drain Matrix decryptions before SDK shutdown

Punchcard-Session: silver-valley-valley-dt

* fix(matrix): retire shared E2EE clients safely

Punchcard-Session: silver-valley-valley-dt

* fix(matrix): satisfy lifecycle lint gate

Punchcard-Session: silver-valley-valley-dt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: matrix Channel integration: matrix extensions: qa-lab maintainer Maintainer-authored PR merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: XL status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant