Skip to content

refactor(matrix): adopt core claimable dedupe with doctor-owned state migration - #104391

Merged
steipete merged 4 commits into
mainfrom
claude/chanref-p1-matrix-dedupe
Jul 11, 2026
Merged

steipete merged 4 commits into
mainfrom
claude/chanref-p1-matrix-dedupe

Conversation

@steipete

Copy link
Copy Markdown
Contributor

Related: #104318

What Problem This Solves

Matrix maintained a 312-LOC hand-rolled inbound event deduper (own SQLite shape, eager startup loads, runtime legacy-JSON import) parallel to the core claimable dedupe used by eleven other channels. Replay protection is load-bearing on Matrix: /sync replays after unclean shutdown and async decrypt re-emission make duplicates routine.

Why This Change Was Made

The storage machinery moves onto core createClaimableDedupe (claim → commit-on-reply-success → release), matrix supplying only its (account, room, event) key derivation. Because this store is durable duplicate-side-effect protection (not a droppable cache), shipped state migrates via a one-time doctor-owned migration covering both shipped sources: ≥2026.6 SQLite rows and ≤2026.5 inbound-dedupe.json (verified live on shipped tags). Import preserves remaining 30-day TTL, is capacity-aware (never evicts newer runtime commits), retires sources only on success, and is idempotent. Single global namespace with account-scoped keys so the plugin-state capacity fuse composes safely (telegram's shipped shape). Runtime module: 100 LOC vs 312.

User Impact

No steady-state change; upgrades keep replay protection intact across the transition (no duplicate replies from post-upgrade /sync replays).

Evidence

  • Blacksmith Testbox tbx_01kx8agy63syhd2ca9bgtz6tcv: matrix monitor + doctor-contract suites 488 tests green (incl. pre-upgrade SQLite+JSON rows deduping post-migration through the real runtime guard, TTL expiry skip, retirement+idempotence, capacity preservation, malformed-JSON archival) + full pnpm check:changed (incl. database-first legacy-store guard).
  • Autoreview (codex gpt-5.6-sol, xhigh), three rounds: two earlier accepted findings (namespace fuse composition, import eviction of newer rows, unreadable-JSON retirement) fixed and verified against plugin-state-store.sqlite.ts; final run clean — "patch is correct (0.88)".
  • Runtime refactor alone is net −311 prod LOC; doctor migration machinery brings branch net to +131, paid for by deleting the parallel store and keeping the upgrade contract.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation channel: matrix Channel integration: matrix size: XL maintainer Maintainer-authored PR labels Jul 11, 2026
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. labels Jul 11, 2026
@clawsweeper

clawsweeper Bot commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 11, 2026, 6:32 AM ET / 10:32 UTC.

Summary
Refactors Matrix inbound-event replay protection onto core claimable dedupe and adds doctor-owned migration from shipped SQLite and JSON state.

PR surface: Source +125, Tests +34, Docs +5. Total +164 across 15 files.

Reproducibility: yes. source-level reproduction is high confidence: fill Matrix sibling namespaces to the 50,000-row plugin fuse while leaving dedupe-namespace room, retain an older canonical dedupe row, then import a missing legacy marker; overflow prunes the canonical row from the writing namespace.

Review metrics: 1 noteworthy metric.

  • Persisted-state migration: 2 released sources → 1 canonical store. The transition retires per-root SQLite rows and JSON files, so preservation under both namespace and plugin-wide capacity is merge-critical.

Stored data model
Persistent data-model change detected: migration/backfill/repair: extensions/matrix/doctor-contract-api.test.ts, migration/backfill/repair: extensions/matrix/doctor-contract-api.ts, migration/backfill/repair: extensions/matrix/src/matrix/monitor/inbound-dedupe-migration.ts, unknown-data-model-change: extensions/matrix/doctor-contract-api.test.ts, unknown-data-model-change: extensions/matrix/doctor-contract-api.ts, unknown-data-model-change: extensions/matrix/src/matrix/monitor/inbound-dedupe-migration.ts. Migration or upgrade compatibility proof is recorded; maintainers should verify it before merge.

Root-cause cluster
Relationship: fixed_by_candidate
Canonical: #104318
Summary: This PR is a concrete phase-one implementation candidate for the umbrella channel-refactor program’s shared-dedupe adoption work.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge readiness
Overall: 🦪 silver shellfish
Proof: 🦪 silver shellfish
Patch quality: 🦐 gold shrimp
Result: blocked until real behavior proof from a real setup is added.

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

Rank-up moves:

  • [P1] Make legacy import non-evicting at namespace and plugin-wide limits and add saturated-state regression coverage.
  • Attach redacted live Matrix upgrades from both released state formats through the real replay guard.

Proof guidance:

  • [P1] Needs real behavior proof before merge: The reported Testbox suites and checks are supplemental test evidence, not inspectable real Matrix upgrade proof; add a redacted live artifact or transcript, then update the PR body to trigger review or ask a maintainer for @clawsweeper re-review.

Risk before merge

  • [P1] At the Matrix plugin-wide row fuse, importing a legacy marker can replace an older canonical replay marker even though the dedupe namespace itself has free capacity, allowing a previously handled event to be dispatched again.
  • [P1] The PR reports Testbox suites but provides no inspectable live Matrix upgrade artifact, transcript, logs, or recording for either released source format.

Maintainer options:

  1. Make migration non-evicting (recommended)
    Prevent legacy imports from pruning existing canonical rows at either capacity boundary and add a saturated Matrix plugin-state regression test.
  2. Accept replay-marker loss risk
    Merge only if maintainers explicitly accept possible duplicate Matrix handling when an upgrading installation is at the plugin-wide state fuse.
  3. Pause the migration refactor
    Hold the PR if the shared store cannot provide a bounded preserve-existing import without broader API work.

Next step before merge

  • [P1] The maintainer-protected PR needs contributor repair and real upgrade proof before normal maintainer review; it is not eligible for automated work-lane promotion.

Security
Cleared: The exact patch adds no dependency, workflow, permission, secret, downloaded-artifact, or third-party execution changes; the blocker is persisted message-delivery correctness.

Review findings

  • [P1] Preserve canonical rows at the plugin-wide capacity fuse — extensions/matrix/src/matrix/monitor/inbound-dedupe-migration.ts:268-285
Review details

Best possible solution:

Keep the core claimable-dedupe runtime, but import legacy markers through an atomic non-evicting operation that preserves existing canonical rows under both namespace and plugin-wide limits, with saturated-state regression coverage and real Matrix upgrade proof.

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

Yes, source-level reproduction is high confidence: fill Matrix sibling namespaces to the 50,000-row plugin fuse while leaving dedupe-namespace room, retain an older canonical dedupe row, then import a missing legacy marker; overflow prunes the canonical row from the writing namespace.

Is this the best way to solve the issue?

No, not yet: adopting shared claimable dedupe is the narrowest maintainable runtime solution, but the one-time importer must first guarantee that existing canonical rows cannot be evicted at either capacity boundary.

Full review comments:

  • [P1] Preserve canonical rows at the plugin-wide capacity fuse — extensions/matrix/src/matrix/monitor/inbound-dedupe-migration.ts:268-285
    This capacity calculation only counts the dedupe namespace, but registerIfAbsent also enforces the 50,000-row plugin-wide fuse by pruning the oldest row from the writing namespace. If sibling Matrix state fills the plugin budget, importing a legacy marker can therefore evict an existing newer canonical replay marker even though this local capacity is positive, contradicting the preserve-newer guarantee and allowing duplicate handling after replay. Use an atomic non-evicting import path or account for plugin-wide capacity, and cover the saturated-plugin case.
    Confidence: 0.96

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 8917dac5ded4.

Label changes

Label changes:

  • add P2: This is a normal-priority Matrix reliability refactor with a concrete, bounded upgrade defect that must be repaired before merge.
  • add merge-risk: 🚨 compatibility: Released replay state is migrated and retired by an importer that can displace newer canonical rows at the plugin-wide fuse.
  • add merge-risk: 🚨 message-delivery: Losing a canonical replay marker can cause duplicate Matrix replies or other repeated message side effects.
  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦐 gold shrimp.
  • add status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The reported Testbox suites and checks are supplemental test evidence, not inspectable real Matrix upgrade proof; add a redacted live artifact or transcript, then update the PR body to trigger review or ask a maintainer for @clawsweeper re-review.

Label justifications:

  • P2: This is a normal-priority Matrix reliability refactor with a concrete, bounded upgrade defect that must be repaired before merge.
  • merge-risk: 🚨 compatibility: Released replay state is migrated and retired by an importer that can displace newer canonical rows at the plugin-wide fuse.
  • merge-risk: 🚨 message-delivery: Losing a canonical replay marker can cause duplicate Matrix replies or other repeated message side effects.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦐 gold shrimp.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The reported Testbox suites and checks are supplemental test evidence, not inspectable real Matrix upgrade proof; add a redacted live artifact or transcript, then update the PR body to trigger review or ask a maintainer for @clawsweeper re-review.
Evidence reviewed

PR surface:

Source +125, Tests +34, Docs +5. Total +164 across 15 files.

View PR surface stats
Area Files Added Removed Net
Source 8 502 377 +125
Tests 6 295 261 +34
Docs 1 9 4 +5
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 15 806 642 +164

What I checked:

Likely related people:

  • gumadeiras: Commit a05da76 introduced the merged Matrix restart replay-dedupe behavior that this PR refactors. (role: introduced Matrix replay dedupe; confidence: high; commits: a05da767180f; files: extensions/matrix/src/matrix/monitor/inbound-dedupe.ts)
  • vincentkoc: Commits 028434a and 6c12ec1 introduced and serialized claimable dedupe, while 9246732 owns the current plugin-state overflow contract relevant to the defect. (role: shared dedupe and state-store contributor; confidence: high; commits: 028434a00ffd, 6c12ec1ed22c, 92467325c02c; files: src/plugin-sdk/persistent-dedupe.ts, src/plugin-state/plugin-state-store.sqlite.ts)
  • steipete: Prior merged work unified channel dedupe primitives and refactored Matrix state paths, making this contributor relevant beyond authorship of the current proposal. (role: recent dedupe and Matrix-state contributor; confidence: medium; commits: 59807efa3126, 4890656d9d1d, 23a4ae4759b8; files: src/plugin-sdk/persistent-dedupe.ts, extensions/matrix/src/matrix/monitor/inbound-dedupe.ts, extensions/matrix/doctor-contract-api.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.

@steipete
steipete merged commit de282b4 into main Jul 11, 2026
155 of 164 checks passed
@steipete
steipete deleted the claude/chanref-p1-matrix-dedupe branch July 11, 2026 10:38
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 12, 2026
… migration (openclaw#104391)

* refactor(matrix): adopt core claimable dedupe for inbound events

* fix(matrix): migrate legacy inbound dedupe markers via doctor

* fix(matrix): single-pool dedupe namespace and capacity-aware legacy import

* fix(matrix): keep unreadable legacy dedupe JSON in place during doctor import
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: matrix Channel integration: matrix docs Improvements or additions to documentation maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: XL status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant