Skip to content

fix(matrix): prune finished fake-indexeddb transactions - #90628

Closed
wyf027 wants to merge 3 commits into
openclaw:mainfrom
wyf027:hermes-auto/issue-90455-matrix-fdb-prune
Closed

wyf027 wants to merge 3 commits into
openclaw:mainfrom
wyf027:hermes-auto/issue-90455-matrix-fdb-prune

Conversation

@wyf027

@wyf027 wyf027 commented Jun 5, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Adds a Matrix-owned fake-indexeddb transaction pruner that is installed immediately after fake-indexeddb/auto in the Matrix crypto runtime.
  • Scopes pruning to Matrix rust-crypto IndexedDB stores whose names end with ::matrix-sdk-crypto, so unrelated fake-indexeddb databases keep their current behavior.
  • Adds a focused regression test covering Matrix crypto-store pruning, unrelated database non-pruning, and raw queue pruning that preserves active/inactive transactions.

Test Plan

  • RED proof: node /tmp/openclaw-auto-90455/proof-red.mjs against unpatched [email protected] failed as expected with 6 retained finished transactions.
  • GREEN proof: ./probe/node_modules/.bin/esbuild proof-green.ts --bundle --platform=node --format=esm --outfile=proof-green.mjs && node proof-green.mjs passed against the patched helper/runtime source.
  • Syntax/source checks: esbuild bundled fake-indexeddb-prune.ts and fake-indexeddb-prune.test.ts successfully in the API-only temp workspace.
  • Whitespace check: git diff --no-index --check main patched reported no whitespace errors.

CI repair follow-up (2026-06-12)

After the draft PR was rechecked, CI reported TypeScript-only failures in extensions/matrix/src/matrix/sdk/fake-indexeddb-prune.ts:

extensions/matrix/src/matrix/sdk/fake-indexeddb-prune.ts(57,24): error TS18046: 'rawDatabase' is of type 'unknown'.
extensions/matrix/src/matrix/sdk/fake-indexeddb-prune.ts(58,51): error TS7006: Parameter 'transaction' implicitly has an 'any' type.
extensions/matrix/src/matrix/sdk/fake-indexeddb-prune.ts(80,3): error TS2322: patched transaction return type was `unknown`, not `IDBTransaction`.

API-only repair commit 264c6fbd2ba6c807fb79b35680aee466b50cd4f8 narrows the raw database before reading transactions, gives the patched prototype the DOM IDBDatabase["transaction"] signature, and returns IDBTransaction & FakeIndexedDbTransaction.

Verification run after the CI repair (temp source-level type probe, no clone):

$ npx -y -p [email protected] tsc -p /tmp/openclaw-pr-90628/tsconfig.fake-indexeddb-prune.json
# exit 0; no TypeScript diagnostics

Real behavior proof

Behavior or issue addressed: Matrix E2EE uses fake-indexeddb for openclaw-matrix-*::matrix-sdk-crypto stores. Current fake-indexeddb 6.2.5 retains every finished transaction in the raw transactions array, which grows without bound during long-running Matrix crypto sync. This patch installs a Matrix-scoped runtime pruner so finished transactions are removed for Matrix crypto stores after completion/abort, without changing unrelated fake-indexeddb databases.

Real environment tested: API-only temp workspace /tmp/openclaw-auto-90455 on macOS runner; Node.js v22.22.1; npm-installed [email protected] and [email protected]; source downloaded from openclaw/openclaw main via gh api (no clone).

Exact steps or command run after this patch:

cd /tmp/openclaw-auto-90455
./probe/node_modules/.bin/esbuild proof-green.ts --bundle --platform=node --format=esm --outfile=proof-green.mjs
node proof-green.mjs
./probe/node_modules/.bin/esbuild patched/extensions/matrix/src/matrix/sdk/fake-indexeddb-prune.ts --bundle --platform=node --format=esm --outfile=/tmp/openclaw-auto-90455/helper-check.mjs
./probe/node_modules/.bin/esbuild patched/extensions/matrix/src/matrix/sdk/fake-indexeddb-prune.test.ts --bundle --platform=node --format=esm --packages=external --outfile=/tmp/openclaw-auto-90455/test-check.mjs
git diff --no-index --check main patched

Evidence before fix (RED, expected failure):

red_status=1
{"databaseName":"openclaw-matrix-proof-red-1780654376777::matrix-sdk-crypto","transactionsAfterFiveSequentialCommits":6,"finishedTransactions":6}
AssertionError [ERR_ASSERTION]: finished Matrix crypto transactions should be pruned
6 !== 0
Node.js v22.22.1

Evidence after fix:

green_status=0
{
  "matrixResult": {
    "databaseName": "openclaw-matrix-proof-green-1780654737766::matrix-sdk-crypto",
    "transactionsAfterFiveSequentialCommits": 0,
    "finishedTransactions": 0
  },
  "unrelatedResult": {
    "databaseName": "openclaw-nonmatrix-proof-green-1780654737770",
    "transactionsAfterFiveSequentialCommits": 6,
    "finishedTransactions": 6
  },
  "sourceAssertions": "passed"
}
helper_esbuild=ok
test_esbuild=ok
git diff --check: no whitespace errors reported

Observed result after fix: Five sequential writes to a Matrix crypto-store database leave raw.transactions.length === 0 and finishedTransactions === 0; the same probe against an unrelated fake-indexeddb database still retains 6 finished transactions, proving the mitigation is Matrix-scoped.

What was not tested: I did not run the full OpenClaw Vitest suite or a live Matrix gateway/E2EE sync because this cron run must stay API-only without cloning the OpenClaw repository or using a full checkout. The focused proof uses the real fake-indexeddb package and API-downloaded patched source.

Risk/Notes

  • This intentionally avoids the prior closed dependency-patch approach, so it does not change pnpm-lock.yaml, pnpm-workspace.yaml, shrinkwrap files, package versions, or dependency graph policy surfaces.
  • The runtime patch is idempotent and only wraps IDBDatabase.prototype.transaction after fake-indexeddb installs the global IDBDatabase constructor.
  • Pruning only removes transactions whose internal _state is "finished"; active/inactive/waiting transactions remain in the raw queue.

Fixes #90455

@openclaw-barnacle openclaw-barnacle Bot added channel: matrix Channel integration: matrix size: S proof: supplied External PR includes structured after-fix real behavior proof. labels Jun 5, 2026
@clawsweeper

clawsweeper Bot commented Jun 5, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge. Reviewed June 12, 2026, 10:19 AM ET / 14:19 UTC.

Summary
The PR installs a Matrix-local wrapper around fake-indexeddb transaction creation, prunes finished transactions for the primary rust-crypto database, and adds focused regression tests.

PR surface: Source +104, Tests +88. Total +192 across 3 files.

Reproducibility: yes. The supplied real-package probe deterministically shows retained finished transactions, and direct inspection of fake-indexeddb 6.2.5 confirms the persistent backing-array mechanism on current main.

Review metrics: 1 noteworthy metric.

  • Crypto databases covered: 1 of 2. The current exact suffix covers rust-crypto’s main database but excludes its separate metadata database.

Merge readiness
Overall: 🦪 silver shellfish
Proof: 🦞 diamond lobster
Patch quality: 🦪 silver shellfish
Result: blocked by patch quality or review findings.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • Cover ::matrix-sdk-crypto-meta in the predicate and focused regression test.
  • Run the real-package transaction-count probe against both Matrix crypto databases.

Risk before merge

  • [P1] The metadata store remains on fake-indexeddb’s unbounded transaction queue, so this patch does not comprehensively eliminate the reported Matrix E2EE memory-growth mechanism.
  • [P1] The mitigation intentionally relies on private fake-indexeddb fields and prototype behavior, requiring focused compatibility validation whenever that dependency is upgraded.

Maintainer options:

  1. Cover the metadata store (recommended)
    Extend the exact Matrix database predicate and regression proof to include ::matrix-sdk-crypto-meta before merge.
  2. Pause the private workaround
    Pause or close this approach if maintainers prefer to wait for an upstream fake-indexeddb repair instead of owning its private queue contract.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Update the Matrix fake-indexeddb predicate to cover the exact primary and metadata rust-crypto database suffixes, add focused tests and real-package proof for both, preserve unrelated databases and non-finished transactions, and do not change dependencies, config, or lockfiles.

Next step before merge

  • [P2] The blocker is a narrow predicate-and-test repair that can be completed on the existing PR branch without a product or ownership decision.

Security
Cleared: The three-file runtime and test diff introduces no dependency-resolution, workflow, permission, secret, downloaded-code, install, or publishing changes.

Review findings

  • [P1] Prune the rust-crypto metadata database too — extensions/matrix/src/matrix/sdk/fake-indexeddb-prune.ts:46
Review details

Best possible solution:

Match both exact Matrix rust-crypto database suffixes—::matrix-sdk-crypto and ::matrix-sdk-crypto-meta—and prove both queues remain bounded while unrelated databases and unfinished transactions are unchanged.

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

Yes. The supplied real-package probe deterministically shows retained finished transactions, and direct inspection of fake-indexeddb 6.2.5 confirms the persistent backing-array mechanism on current main.

Is this the best way to solve the issue?

No, not as submitted. The Matrix-local ownership and wrapper approach are reasonable, but omitting rust-crypto’s metadata database leaves the same dependency leak active on a sibling store.

Full review comments:

  • [P1] Prune the rust-crypto metadata database too — extensions/matrix/src/matrix/sdk/fake-indexeddb-prune.ts:46
    The pinned rust-crypto implementation also opens <prefix>::matrix-sdk-crypto-meta, but this exact suffix check excludes it. Finished transactions for that database therefore remain retained by fake-indexeddb, leaving a second unbounded queue; cover both exact suffixes and add a metadata-store regression case.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.99

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 0fc5a57a3440.

Label changes

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR provides red/green terminal output against real fake-indexeddb 6.2.5 and the patched source, directly measuring the primary transaction queue with an unrelated-database control.
  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦞 diamond lobster and patch quality is 🦪 silver shellfish.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Sufficient (terminal): The PR provides red/green terminal output against real fake-indexeddb 6.2.5 and the patched source, directly measuring the primary transaction queue with an unrelated-database control.
  • remove rating: 🌊 off-meta tidepool: Current PR rating is rating: 🦪 silver shellfish, so this older rating label is no longer current.

Label justifications:

  • P1: The linked Matrix E2EE bug causes recurring whole-gateway OOM outages in affected deployments.
  • merge-risk: 🚨 compatibility: The implementation wraps a dependency prototype and mutates undocumented fake-indexeddb transaction state.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦞 diamond lobster and patch quality is 🦪 silver shellfish.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Sufficient (terminal): The PR provides red/green terminal output against real fake-indexeddb 6.2.5 and the patched source, directly measuring the primary transaction queue with an unrelated-database control.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR provides red/green terminal output against real fake-indexeddb 6.2.5 and the patched source, directly measuring the primary transaction queue with an unrelated-database control.
Evidence reviewed

PR surface:

Source +104, Tests +88. Total +192 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 2 104 0 +104
Tests 1 88 0 +88
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 192 0 +192

Acceptance criteria:

  • [P1] node scripts/run-vitest.mjs extensions/matrix/src/matrix/sdk/fake-indexeddb-prune.test.ts.
  • [P1] Real [email protected] probe for ::matrix-sdk-crypto, ::matrix-sdk-crypto-meta, and an unrelated database.
  • [P1] git diff --check.

What I checked:

Likely related people:

  • gumadeiras: Introduced the replacement Matrix implementation and authored several subsequent E2EE bootstrap, persistence, and verification changes around this runtime. (role: Matrix E2EE feature owner; confidence: high; commits: 94693f7ff036, 78a842d05519, 94081d886336; files: extensions/matrix/src/matrix/sdk.ts, extensions/matrix/src/matrix/sdk/idb-persistence.ts)
  • steipete: Recently changed Matrix crypto persistence and has the largest recent history across the central SDK and persistence files. (role: recent Matrix persistence contributor; confidence: high; commits: 0566b9692742, e8348c0dc840, 5f3bb537888d; files: extensions/matrix/src/matrix/sdk.ts, extensions/matrix/src/matrix/sdk/idb-persistence.ts)
  • vincentkoc: Introduced the lazy Matrix crypto runtime boundary where the proposed pruner is installed and later maintained adjacent Matrix plugin code. (role: runtime-boundary contributor; confidence: medium; commits: d4c7ef3778ce, e6df924a34eb; files: extensions/matrix/src/matrix/sdk/crypto-runtime.ts, extensions/matrix/src/matrix/sdk/idb-persistence.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

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.

How this review workflow works
  • 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.

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. P1 High-priority user-facing bug, regression, or broken workflow. labels Jun 5, 2026
@wyf027
wyf027 marked this pull request as ready for review June 5, 2026 11:09
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Jun 5, 2026
@wyf027
wyf027 marked this pull request as draft June 12, 2026 13:18
@clawsweeper clawsweeper Bot added rating: 🌊 off-meta tidepool PR readiness rating does not apply to this item. and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Jun 12, 2026
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed rating: 🌊 off-meta tidepool PR readiness rating does not apply to this item. labels Jun 12, 2026
@clawsweeper clawsweeper Bot removed proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Jun 13, 2026
@clawsweeper clawsweeper Bot added rating: 🌊 off-meta tidepool PR readiness rating does not apply to this item. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. rating: 🌊 off-meta tidepool PR readiness rating does not apply to this item. labels Jun 13, 2026
@wyf027

wyf027 commented Jun 18, 2026

Copy link
Copy Markdown
Contributor Author

Closing this stale draft PR because it has been open for a long time without merge. I can reopen or resubmit if needed.

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

Labels

channel: matrix Channel integration: matrix merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. proof: supplied External PR includes structured after-fix real behavior proof. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: M 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.

[Bug]: Matrix E2EE heap grows unbounded → OOM — fake-indexeddb never clears finished transactions (@openclaw/matrix)

1 participant