Skip to content

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

Closed
sahibzada-allahyar wants to merge 1 commit into
openclaw:mainfrom
sahibzada-allahyar:fastino-90455-matrix-idb-prune-c
Closed

sahibzada-allahyar wants to merge 1 commit into
openclaw:mainfrom
sahibzada-allahyar:fastino-90455-matrix-idb-prune-c

Conversation

@sahibzada-allahyar

Copy link
Copy Markdown
Contributor

Fixes #90455.

What Changed

  • Adds a pnpm patch for [email protected] so finished transactions are pruned at the start of processTransactions().
  • Covers both completed and aborted transaction cleanup in a focused Matrix fake-indexeddb regression test.
  • Wires the patch through pnpm-workspace.yaml and the lockfile.

Real Behavior Proof

Behavior addressed: Matrix E2EE usage with fake-indexeddb can retain finished IndexedDB transactions in the internal transaction array, causing unbounded heap growth over time.

Setup:

  • Repository: OpenClaw checkout.
  • Base checkout: /Users/allahyar/Documents/fastino-tasks/openclaw.
  • Patched checkout: /Users/allahyar/Documents/fastino-tasks/openclaw-tui-90455c.
  • Proof script: imports fake-indexeddb/auto, creates a real IndexedDB database, runs five sequential readwrite transactions, then inspects fake-indexeddb's internal _rawDatabase.transactions.length.

Before, on current main:

$ node -e 'async function main(){await import("fake-indexeddb/auto"); const name="openclaw-proof-90455-main-"+Date.now(); await new Promise((resolve,reject)=>{const req=indexedDB.open(name,1); req.onupgradeneeded=()=>req.result.createObjectStore("test"); req.onsuccess=()=>resolve(req.result); req.onerror=()=>reject(req.error)}).then(async db=>{const raw=db._rawDatabase; for(let i=0;i<5;i++){await new Promise((resolve,reject)=>{const tx=db.transaction("test","readwrite"); tx.objectStore("test").put({val:i},"key-"+i); tx.oncomplete=()=>resolve(); tx.onerror=()=>reject(tx.error);});} console.log(JSON.stringify({transactionsAfterFiveSequentialCommits:raw.transactions.length})); db.close(); await new Promise(resolve=>{const del=indexedDB.deleteDatabase(name); del.onsuccess=()=>resolve(); del.onerror=()=>resolve();});});} main().catch(err=>{console.error(err); process.exit(1);})'
{"transactionsAfterFiveSequentialCommits":6}

After, on this branch:

$ node -e 'async function main(){await import("fake-indexeddb/auto"); const name="openclaw-proof-90455-branch-"+Date.now(); await new Promise((resolve,reject)=>{const req=indexedDB.open(name,1); req.onupgradeneeded=()=>req.result.createObjectStore("test"); req.onsuccess=()=>resolve(req.result); req.onerror=()=>reject(req.error)}).then(async db=>{const raw=db._rawDatabase; for(let i=0;i<5;i++){await new Promise((resolve,reject)=>{const tx=db.transaction("test","readwrite"); tx.objectStore("test").put({val:i},"key-"+i); tx.oncomplete=()=>resolve(); tx.onerror=()=>reject(tx.error);});} console.log(JSON.stringify({transactionsAfterFiveSequentialCommits:raw.transactions.length})); db.close(); await new Promise(resolve=>{const del=indexedDB.deleteDatabase(name); del.onsuccess=()=>resolve(); del.onerror=()=>resolve();});});} main().catch(err=>{console.error(err); process.exit(1);})'
{"transactionsAfterFiveSequentialCommits":0}

Observed result after fix: finished fake-indexeddb transactions no longer remain in the internal transaction array after sequential Matrix-style IndexedDB work.

Verification

$ node scripts/run-vitest.mjs extensions/matrix/src/matrix/sdk/fake-indexeddb-transaction-cleanup.test.ts extensions/matrix/src/matrix/sdk/idb-persistence.test.ts
[test] starting test/vitest/vitest.extension-matrix.config.ts

 RUN  v4.1.7 /Users/allahyar/Documents/fastino-tasks/openclaw-tui-90455c


 Test Files  2 passed (2)
      Tests  9 passed (9)
   Start at  03:37:16
   Duration  1.86s (transform 1.11s, setup 128ms, import 1.52s, tests 103ms, environment 0ms)

[test] passed 1 Vitest shard in 4.51s
$ git diff --check origin/main...HEAD
# no output
$ pnpm exec oxfmt --check --threads=1 extensions/matrix/src/matrix/sdk/fake-indexeddb-transaction-cleanup.test.ts pnpm-workspace.yaml pnpm-lock.yaml
Checking formatting...

All matched files use the correct format.
Finished in 82ms on 2 files using 1 threads.

Platforms Tested

  • macOS local checkout with Node and the repository Vitest wrapper.

Limitations

  • This validates the fake-indexeddb transaction-retention behavior directly and through the Matrix persistence shard; it does not run a long-lived Matrix E2EE sync session.

…bounded heap growth (openclaw#90455)

Matrix E2EE with fake-indexeddb retains finished IndexedDB transactions
in the internal Database.transactions array forever, causing unbounded
heap growth over time.

Add pnpm patch to [email protected] that prunes finished transactions
(_state === 'finished') at the top of processTransactions(). Once a
transaction commits or aborts, its _state becomes 'finished' and
processTransactions never uses it again, so removing it is safe and
matches the IndexedDB spec.

Add focused regression test covering both commit and abort paths.
@sahibzada-allahyar
sahibzada-allahyar requested a review from a team as a code owner June 5, 2026 02:38
@openclaw-barnacle openclaw-barnacle Bot added channel: matrix Channel integration: matrix size: S labels Jun 5, 2026
@github-actions github-actions Bot added the dependencies-changed PR changes dependency-related files label Jun 5, 2026
@github-actions

github-actions Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Dependency Guard

This PR changes dependency-related files. Maintainers should confirm these changes are intentional.

Changed files:

Maintainer follow-up:

  • Review whether the dependency changes are intentional.
  • Inspect resolved package deltas when lockfile, shrinkwrap, or workspace dependency policy changes are present.
  • Treat package-lock.json and npm-shrinkwrap.json diffs as security-review surfaces.
  • Run pnpm deps:changes:report -- --base-ref origin/main --markdown /tmp/dependency-changes.md --json /tmp/dependency-changes.json locally for detailed release-style evidence.

@openclaw-barnacle openclaw-barnacle Bot added the triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. label Jun 5, 2026
@github-actions

github-actions Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Dependency graph changes are blocked

OpenClaw does not accept dependency graph changes through PRs unless a repository admin or security explicitly authorizes the current head SHA. Dependency updates are generated internally by maintainers so external PRs cannot change the resolved graph.

Detected dependency graph changes:

  • pnpm-lock.yaml changed.

Auto-scrub was not attempted because this PR also changes dependency-related files that are not package lockfiles:

Please remove lockfile changes manually if they are not needed.

To remove lockfile changes, restore them from the target branch:

git fetch origin
git checkout 'origin/main' -- 'pnpm-lock.yaml'
git commit -m 'chore: remove dependency lockfile change'
git push

If this PR intentionally needs a dependency graph change, ask a repository admin or member of @openclaw/openclaw-secops to comment:

/allow-dependencies-change

The action will approve the current head SHA (d9a7439db00a172aceb4de019d344b65d6b2d13a) when it reruns. A later push requires a fresh approval.

@sahibzada-allahyar

Copy link
Copy Markdown
Contributor Author

Dependency Guard context for the patch wiring:

pnpm deps:changes:report -- --base-ref origin/main --markdown /tmp/openclaw-90521-dependency-changes.md --json /tmp/openclaw-90521-dependency-changes.json
INFO dependency change report: 0 added, 0 removed, 0 changed resolved packages and 3 dependency file changes relative to origin/main.

The dependency-file diff is intentional and limited to patches/[email protected], pnpm-workspace.yaml, and pnpm-lock.yaml; it does not add/remove packages or change resolved package versions.

@clawsweeper

clawsweeper Bot commented Jun 5, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: found issues before merge. Reviewed June 4, 2026, 10:54 PM ET / 02:54 UTC.

Summary
The PR adds a pnpm patch for [email protected], wires it into the root workspace and lockfile, and adds a Matrix regression test for finished transaction cleanup.

PR surface: Tests +88, Config +1, Other +30. Total +119 across 4 files.

Reproducibility: yes. at source/proof level: upstream fake-indexeddb v6.2.5 retains finished transactions in the backing array, and current Matrix crypto uses that shim for persistent IndexedDB work. I did not execute the long heap loop in this read-only review.

Review metrics: 2 noteworthy metrics.

  • Dependency patch surfaces: 1 new patch, 1 workspace patchedDependency, 1 lockfile patch hash. These are security- and admin-sensitive dependency graph changes before merge.
  • Matrix package shrinkwrap coverage: 0 package-local shrinkwrap entries changed. Official external Matrix installs use the package-local shrinkwrap, so workspace-only proof does not cover released plugin users.

Merge readiness
Overall: 🧂 unranked krab
Proof: 🦞 diamond lobster
Patch quality: 🧂 unranked krab
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:

  • [P2] Make the fix reach the installed @openclaw/matrix package path and prove that path after packaging or install.
  • Remove the root dependency graph change, or get explicit admin/secops authorization for the exact head if maintainers choose to keep it.
  • [P2] Add verification that the installed Matrix package resolves the fixed fake-indexeddb behavior.

Risk before merge

  • [P1] The root pnpm patch and lockfile changes are dependency/security surfaces from an external contributor and are blocked unless a repository admin or secops explicitly authorizes this exact head or the dependency graph change is removed.
  • [P1] The current diff does not update or prove the package-installed @openclaw/matrix path; its package-local shrinkwrap still resolves the unpatched fake-indexeddb tarball, so ClawHub/npm-installed Matrix users can keep the OOM failure after a release.
  • [P1] Maintainers still need to choose the fix shape: upstream dependency bump, package-local authorized patch and shrinkwrap proof, or a Matrix-owned cleanup that avoids a root dependency patch.

Maintainer options:

  1. Repair the installed package path first (recommended)
    Change the fix so ClawHub/npm-installed @openclaw/matrix resolves the cleaned-up transaction behavior, then add package-install or package-acceptance proof for that path.
  2. Authorize the dependency patch explicitly
    If maintainers want the root pnpm patch approach, a repository admin or secops reviewer should approve the exact head and require proof that the published Matrix package also carries the patched dependency.
  3. Pause for upstream or owner rewrite
    If neither a root patch nor a Matrix-local internal cleanup is acceptable, pause this branch and track the upstream fake-indexeddb fix or a maintainer-owned replacement PR.

Next step before merge

  • [P2] A maintainer needs to choose and authorize the dependency-policy path before an automated repair can safely proceed.

Security
Needs attention: The diff adds an externally submitted pnpm patch and lockfile graph change for third-party dependency code without the required admin/secops authorization.

Review findings

  • [P1] Patch the package-installed Matrix runtime — pnpm-workspace.yaml:124
  • [P1] Do not merge an unauthorized dependency patch — patches/[email protected]:1
Review details

Best possible solution:

Pick a maintainer-approved dependency path and prove the fixed behavior through an installed @openclaw/matrix package, not only the pnpm workspace checkout.

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

Yes, at source/proof level: upstream fake-indexeddb v6.2.5 retains finished transactions in the backing array, and current Matrix crypto uses that shim for persistent IndexedDB work. I did not execute the long heap loop in this read-only review.

Is this the best way to solve the issue?

No, this is only a plausible local fix. The best mergeable solution must either use an authorized dependency path that reaches the published Matrix package or move the cleanup into Matrix-owned runtime code with package-install proof.

Full review comments:

  • [P1] Patch the package-installed Matrix runtime — pnpm-workspace.yaml:124
    Adding fake-indexeddb to the root patchedDependencies only fixes the pnpm workspace/root package path. @openclaw/matrix is an official external package and its package-local npm-shrinkwrap.json still resolves the registry [email protected] tarball, so users installing Matrix through ClawHub/npm can continue to hit the OOM after release. Move the fix into a path that the published Matrix package resolves, or add an authorized package-local dependency fix plus package-install proof.
    Confidence: 0.93
  • [P1] Do not merge an unauthorized dependency patch — patches/[email protected]:1
    This branch adds a patch to third-party dependency code and changes the lockfile from an external contributor. Root policy and the dependency guard require explicit admin/secops authorization for this exact head, or a repair that removes the dependency graph change before merge.
    Confidence: 0.9

Overall correctness: patch is incorrect
Overall confidence: 0.91

AGENTS.md: found and applied where relevant.

Codex review notes: model gpt-5.5, reasoning high; reviewed against c8bb7330b5cf.

Label changes

Label changes:

  • add merge-risk: 🚨 security-boundary: The branch introduces an externally submitted patch to third-party dependency code plus lockfile changes, which is a supply-chain review surface.

Label justifications:

  • P1: The linked Matrix E2EE leak can OOM the gateway for affected deployments, but the PR still needs dependency-path and security review before merge.
  • merge-risk: 🚨 automation: The diff changes dependency files in a way the dependency-graph guard currently blocks until explicit authorization or removal.
  • merge-risk: 🚨 security-boundary: The branch introduces an externally submitted patch to third-party dependency code plus lockfile changes, which is a supply-chain review surface.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🦞 diamond lobster and patch quality is 🧂 unranked krab.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Sufficient (terminal): The PR body includes before/after terminal output showing the raw fake-indexeddb transaction count dropping from 6 to 0 after five sequential transactions, plus a focused Matrix Vitest shard; that proves the local patched behavior but not the installed-package path.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes before/after terminal output showing the raw fake-indexeddb transaction count dropping from 6 to 0 after five sequential transactions, plus a focused Matrix Vitest shard; that proves the local patched behavior but not the installed-package path.
Evidence reviewed

PR surface:

Tests +88, Config +1, Other +30. Total +119 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 0 0 0 0
Tests 1 88 0 +88
Docs 0 0 0 0
Config 1 1 0 +1
Generated 0 0 0 0
Other 2 32 2 +30
Total 4 121 2 +119

Security concerns:

  • [medium] External dependency patch needs authorization — patches/[email protected]:1
    fake-indexeddb is patched through root pnpm metadata and pnpm-lock.yaml; because lockfiles and dependency patches are security surfaces, this needs explicit repository admin/secops approval or a no-graph-change repair before merge.
    Confidence: 0.91

What I checked:

  • Matrix runtime uses fake-indexeddb for crypto IndexedDB work: Current main imports fake-indexeddb/auto in the Matrix crypto runtime and initializes Rust crypto with cryptoDatabasePrefix, then persists IndexedDB snapshots on startup and a 60-second interval. (extensions/matrix/src/matrix/sdk/crypto-runtime.ts:2, c8bb7330b5cf)
  • Published Matrix package pins unpatched fake-indexeddb: @openclaw/matrix declares fake-indexeddb 6.2.5 and its package-local shrinkwrap resolves the registry tarball with the existing integrity, with no patch or replacement path in current main. (extensions/matrix/npm-shrinkwrap.json:183, c8bb7330b5cf)
  • Matrix is an external published plugin: The Matrix package is configured for ClawHub and npm publication, and the generated plugin inventory lists it as an official external package installed through ClawHub/npm. (extensions/matrix/package.json:96, c8bb7330b5cf)
  • Plugin installs use package-local shrinkwrap: OpenClaw docs say published plugin packages use npm-shrinkwrap.json during managed npm installs and OpenClaw-owned publishable plugins must include a package-local shrinkwrap generated from that plugin dependency graph. Public docs: docs/plugins/dependency-resolution.md. (docs/plugins/dependency-resolution.md:62, c8bb7330b5cf)
  • Upstream dependency leak mechanism inspected: fake-indexeddb v6.2.5 pushes every transaction into Database.transactions, marks transactions finished later, and processTransactions() only filters running/waiting temporary arrays rather than pruning the backing array.
  • Dependency policy applies: Root policy requires explicit approval for dependency patches/overrides/vendor changes and treats lockfiles/shrinkwrap as security surfaces; the provided dependency-graph guard comment also blocks this external head until admin/secops authorization or removal of the graph change. (AGENTS.md:249, c8bb7330b5cf)

Likely related people:

  • steipete: Git blame and log in the available checkout tie the current Matrix package, package-local shrinkwrap, crypto runtime, and pnpm workspace dependency surfaces to Peter Steinberger's recent commits; confidence is limited by the grafted/shallow history. (role: recent area contributor; confidence: medium; commits: 12a56d4d46dd, efd1a9ace6f5; files: extensions/matrix/package.json, extensions/matrix/npm-shrinkwrap.json, extensions/matrix/src/matrix/sdk.ts)
  • openclaw/openclaw-secops: CODEOWNERS explicitly owns pnpm-lock.yaml, root/plugin shrinkwrap files, and the dependency guard workflow, which are central to this PR's dependency-patch risk. (role: required security reviewer; confidence: high; files: .github/CODEOWNERS, pnpm-lock.yaml, patches/[email protected])
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: 🧂 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. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. labels Jun 5, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. label Jun 5, 2026
@clawsweeper clawsweeper Bot added the merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. label Jun 5, 2026
@sahibzada-allahyar

Copy link
Copy Markdown
Contributor Author

Closing to reduce my active PR queue under the repository cap. This branch is dependency-guard blocked and should be revisited only if a maintainer wants the dependency-change path.

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

Labels

channel: matrix Channel integration: matrix dependencies-changed PR changes dependency-related files merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: S 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