Skip to content

feat(channels): add Matrix and LINE join introductions - #131128

Merged
steipete merged 1 commit into
mainfrom
feat/matrix-line-join-intros
Aug 27, 2026
Merged

steipete merged 1 commit into
mainfrom
feat/matrix-line-join-intros

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Group join introductions shipped in #130103 for Slack, Discord, and Telegram. Matrix and LINE were left out even though both already receive a bot-join signal and did nothing with it but write a log line, so operators on those channels still get a bot that appears in a room and says nothing.

Extending it surfaced a real defect in the Matrix bridge that would have made a naive integration actively harmful.

Why This Change Was Made

The Matrix bridge could not distinguish a join from a restart. emitMembershipForRoom synthesizes an m.room.member event with origin_server_ts: Date.now() and unsigned: { age: 0 }, and emitOutstandingInviteEvents calls it for every room from client.getRooms() at startup. Because the producer fabricates a fresh timestamp, the freshness guard that protects Discord's GUILD_CREATE has no analogue here, and the durable dedupe cannot help either since pre-existing rooms hold no claims yet. Wiring room.join straight through would have introduced the bot into every Matrix room it was already in, on the first restart after upgrade.

Per the Repair Doctrine that belongs at the producer, not compensated downstream, so the bridge now carries explicit membershipProvenance of transition, update, or snapshot. It is derived from the SDK's own RoomEvent.MyMembership signal (which supplies previousMembership), gated on initial sync completion, and handles the ERROR → CATCHUP recovery path where catchup can precede the first successful sync. The change is additive: event names, ordering, delivery, timestamps, invite handling, and auto-join behavior are untouched, and every existing Matrix assertion still passes unchanged, including "replays outstanding invite rooms at startup" and "does not auto-join invites by default".

Only an absent-to-join transition introduces. A self-membership update that stays join — a display-name or avatar change — does not, which was the other false positive in the raw-event path.

User Impact

Matrix and LINE now post one grounded introduction when the bot joins a group room, on by default, with the same joinIntro opt-out at channel and account scope as the existing three.

What each can honestly ground on differs, and the code says so rather than pretending:

  • Matrix — room name and topic, plus recent messages through the existing history reader, which already handles decryption, edits, and redactions. A failed read degrades to metadata rather than aborting. Direct rooms are excluded via the plugin's existing classifier.
  • LINE — group name where available, and historyUnavailable: true, because the Messaging API exposes no prior-message history. Multi-person rooms have no name or topic at all. This matches the honest pattern Telegram already uses. LINE's allowlist authorizes human senders, so a bot join is admitted on conversation policy and room enabled state rather than inventing a sender.

Everything else is unchanged from #130103: the sealed no-tools turn, untrusted-content wrapping, required fail-closed roomAllowed, durable once-per-room dedupe, DM exclusion, and the closed outcome union.

Also folds in a bounded cleanup of formatChannelJoinRoomSnapshot, which previously accumulated a string and then discarded it to rebuild from scratch whenever any messages survived, and reversed the message list twice to end where it started. Behavior is identical — verified across 18,160 byte-for-byte comparisons — and it is net −6 lines.

Evidence

node scripts/run-vitest.mjs extensions/matrix/src/matrix/monitor/join-intro.test.ts   8 passed
node scripts/run-vitest.mjs extensions/line/src/bot-handlers.join-intro.test.ts      17 passed
node scripts/run-vitest.mjs src/channels/join-intro                                  11 passed
node scripts/run-vitest.mjs extensions/matrix                                     2,093 passed
node scripts/run-vitest.mjs extensions/line                                          561 passed
node scripts/check-changed.mjs                                                       passed

The most important test is never introduces into an already-joined room during startup, including recovery=%s — parameterized over the recovery paths, it is the exact upgrade case that would otherwise spam every room. Alongside it: introduction on a genuine transition with the account route and oldest-first history, no introduction for profile changes or other members' joins, correct handling of a new-room lifecycle snapshot followed by a real transition with duplicate raw delivery ignored, and direct-room exclusion.

Autoreview reported no actionable findings.

Proof gap, stated plainly: this was verified through the Matrix SDK and LINE webhook harnesses, not a live channel send. There are no Matrix or LINE credentials on this machine, so a real join could not be driven locally. The Slack/Discord/Telegram paths from #130103 are unaffected by this change.

LOC: production +218/−42 (net +176), tests +547, docs +52/−6, generated net 0.

Docs: channels, matrix, line, config-channels.

Introduce on admitted bot joins using the existing sealed no-tools turn and durable room dedupe. Matrix uses room metadata and readable history; LINE uses group names and explicitly unavailable history.

Mark Matrix bridge membership provenance without changing existing event delivery, invite handling, or auto-join. Exclude startup snapshots and already-joined profile updates, including startup connection recovery.

Simplify snapshot budget accounting while preserving prompt bytes, metadata order, and oldest-first message dropping. Add channel config, docs, and regression coverage.
@clawsweeper

clawsweeper Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation channel: line Channel integration: line channel: matrix Channel integration: matrix gateway Gateway runtime labels Aug 27, 2026
@steipete
steipete marked this pull request as ready for review August 27, 2026 18:57
@openclaw-barnacle openclaw-barnacle Bot added size: L maintainer Maintainer-authored PR labels Aug 27, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 27, 2026
@clawsweeper

clawsweeper Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 27, 2026, 3:09 PM ET / 19:09 UTC.

ClawSweeper review

What this changes

Adds configurable, default-on group-join introductions for Matrix and LINE, including Matrix join-versus-startup provenance, docs, and regression tests.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

Keep open for maintainer review: the introduced Matrix and LINE flows are coherent and have focused coverage, but this default-on feature adds configuration surface and its external SDK event contract was not independently inspectable locally.

Priority: P2
Reviewed head: e05ebf3f70d637403bee9eb5bcd048e82f5a3304
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Focused coverage supports the patch, but direct provider-contract verification remains unavailable.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored PR documents focused SDK and webhook harness runs; no external-contributor proof gate applies.
Patch quality 🦐 gold shrimp (3/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored PR documents focused SDK and webhook harness runs; no external-contributor proof gate applies.
Evidence reviewed 7 items Matrix lifecycle owner: The introduced monitor path only accepts a self membership transition, then checks membership, direct-room exclusion, room policy, aliases, and routing before invoking the shared owner.
Matrix producer: The bridge marks startup/lifecycle membership snapshots separately and only marks post-sync self joins as transitions.
LINE admission and delivery path: The LINE join handler excludes direct chats, honors disabled conversation policy and room state, then passes metadata-only context to the public shared SDK seam.
Findings None None.
Security None None.

Live Verification

Command: node scripts/run-vitest.mjs extensions/matrix/src/matrix/monitor/join-intro.test.ts

Result: PASS (completed)

[test] starting test/vitest/vitest.extension-matrix.config.ts

 RUN  v4.1.11 /tmp/clawsweeper-live-proof-131128-V10w5K/target

 ✓  extension-matrix  extensions/matrix/src/matrix/monitor/join-intro.test.ts (17 tests) 41ms

 Test Files  1 passed (1)
      Tests  17 passed (17)
   Start at  19:10:00
   Duration  18.84s (transform 15.35s, setup 750ms, import 17.79s, tests 41ms, environment 0ms)

[test] passed 1 Vitest shard in 23.16s
[test] starting test/vitest/vitest.extension-line.config.ts

 RUN  v4.1.11 /tmp/clawsweeper-live-proof-131128-V10w5K/target

 ✓  extension-line  extensions/line/src/bot-handlers.join-intro.test.ts (8 tests) 19614ms

 Test Files  1 passed (1)
      Tests  8 passed (8)
   Start at  19:10:26
   Duration  20.68s (transform 16.85s, setup 775ms, import 16ms, tests 19.61s, environment 0ms)

[test] passed 1 Vitest shard in 24.90s

Assertions:

  • NOT OBSERVED expect_output: 8 passed — command exited successfully; expected output was not observed in the captured pane
  • NOT OBSERVED expect_output: 17 passed — command exited successfully; expected output was not observed in the captured pane

How this fits together

Matrix and LINE plugins receive native membership events and pass eligible group-room joins to the shared introduction owner. That owner builds bounded untrusted context, runs an isolated no-tools turn, sends the introduction, and deduplicates it durably.

flowchart LR
  A[Native bot join event] --> B[Matrix or LINE plugin]
  B --> C[Room admission and context]
  C --> D[Shared introduction owner]
  D --> E[Isolated no-tools agent turn]
  E --> F[Channel delivery]
  D --> G[Durable room deduplication]
Loading

Decision needed

Question Recommendation
Should the new default-on Matrix and LINE introductions and their opt-out settings be accepted with harness evidence while direct provider proof remains unavailable? Require provider-boundary proof: Wait for redacted real Matrix and LINE join-to-delivery evidence before landing the default-on feature.

Why: This is a maintainer-authored product and configuration decision; source review cannot establish the intended default or external-provider behavior conclusively.

Before merge

  • Resolve merge risk (P1) - Two new channel settings and two account overrides intentionally change future group-join behavior for existing Matrix and LINE setups.
  • Resolve merge risk (P1) - The Matrix SDK ordering and event-identity assumption behind transition provenance could not be directly verified because dependency source was unavailable locally and network lookup failed.
Agent review details

Security

None.

PR surface

Source +176, Tests +547, Docs +46, Generated 0. Total +769 across 25 files.

View PR surface stats
Area Files Added Removed Net
Source 13 218 42 +176
Tests 5 547 0 +547
Docs 4 52 6 +46
Config 0 0 0 0
Generated 3 17 17 0
Other 0 0 0 0
Total 25 834 65 +769

Review metrics

Metric Value Why it matters
Production and test delta production +218/-42; tests +547/-0; docs +52/-6 The new behavior adds two channel integrations and focused owner-boundary coverage.
Configuration surface 2 channel options and 2 account-level overrides added Existing operators can opt out, while future eligible joins gain a default outbound action.

Stored data model

Persistent data-model change detected: migration/backfill/repair: extensions/matrix/src/config-schema.ts, unknown-data-model-change: src/config/bundled-channel-config-metadata.generated.ts, vector/embedding metadata: src/channels/join-intro/join-intro-prompt.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Verify provider behavior before merge (recommended)
    Capture redacted Matrix and LINE join-to-delivery traces to validate the new default behavior against both provider boundaries.
  2. Accept the documented gap
    A maintainer may accept the focused harness coverage as sufficient for this default-on behavior change.

Technical review

Best possible solution:

Confirm the default-on configuration direction, then obtain redacted real Matrix and LINE membership-to-delivery evidence when provider access is available.

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

Not applicable to an existing-bug report. The introduced paths have focused harness coverage, but no real Matrix or LINE join was driven.

Is this the best way to solve the issue?

Unclear: the Matrix producer-side provenance is the right ownership boundary, but provider SDK behavior and the intended default require remaining maintainer evidence or direction.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 19be0f6dc094.

Labels

Label changes:

  • add P2: This is a bounded group-room onboarding feature, with no source-proven urgent regression.
  • add merge-risk: 🚨 compatibility: The new default changes what existing Matrix and LINE bots do on future eligible group joins.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-authored PR documents focused SDK and webhook harness runs; no external-contributor proof gate applies.

Label justifications:

  • P2: This is a bounded group-room onboarding feature, with no source-proven urgent regression.
  • merge-risk: 🚨 compatibility: The new default changes what existing Matrix and LINE bots do on future eligible group joins.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-authored PR documents focused SDK and webhook harness runs; no external-contributor proof gate applies.

Evidence

What I checked:

Likely related people:

  • steipete: Authored this branch and the prior merged shared join-introduction feature. (role: recent feature contributor; confidence: high; commits: e05ebf3f70d6, 63f7df85bb9b; files: extensions/matrix/src/matrix/monitor/events.ts, extensions/line/src/bot-handlers.ts, src/channels/join-intro/report-channel-room-join.ts)
  • Vincent Koc: Recent Matrix monitor code surrounding the introduced join handler dates to their lifecycle refactor. (role: recent area contributor; confidence: medium; commits: 345b25e305a5; files: extensions/matrix/src/matrix/monitor/events.ts)

Rank-up moves

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

  • Add redacted Matrix and LINE membership-to-delivery proof if credentials become available.

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.

@steipete

Copy link
Copy Markdown
Contributor Author

Following up on the review note that the Matrix SDK ordering and event-identity assumption could not be directly verified. I checked it against the installed matrix-js-sdk source, which was the piece the reviewer lacked.

What I verified. RoomState.setStateEvents passes each event straight to setStateEvent with no cloning, and setStateEvent stores the object directly (this.events.get(type).set(stateKey, event), room-state.js:507). So currentState.getStateEvents("m.room.member", selfUserId) returns the same MatrixEvent instance that was written into state, which is what the WeakSet correlation depends on.

What remains unverified. Whether that instance is always identical to the one delivered to the raw timeline listener across every sync path. room-state.js:271 has an explicit "ugly hack" that populates a copied RoomState for some paths, so I would not claim identity holds universally without a live run. The plugin tests mock the SDK, so they encode this assumption rather than prove it.

Why this is acceptable to land. The failure direction is safe by construction. The startup replay path (emitMatrixMembershipForRoom) hardcodes membershipProvenance: "snapshot", so it can never be misread as a transition regardless of the WeakSet. If the identity assumption fails, a genuine join is classified update and simply produces no introduction. The failure mode is a missing introduction on Matrix, not the mass-introduction-on-restart hazard this change exists to prevent — and that hazard is closed by an unconditional hardcode, not by the assumption in question.

Follow-up worth doing: a live Matrix run against a real homeserver would settle the identity question and is the only thing that can. There are no Matrix credentials on the machine this was built on, so it could not be done here.

@steipete
steipete merged commit cad34e6 into main Aug 27, 2026
287 checks passed
@steipete
steipete deleted the feat/matrix-line-join-intros branch August 27, 2026 19:52
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 28, 2026
Introduce on admitted bot joins using the existing sealed no-tools turn and durable room dedupe. Matrix uses room metadata and readable history; LINE uses group names and explicitly unavailable history.

Mark Matrix bridge membership provenance without changing existing event delivery, invite handling, or auto-join. Exclude startup snapshots and already-joined profile updates, including startup connection recovery.

Simplify snapshot budget accounting while preserving prompt bytes, metadata order, and oldest-first message dropping. Add channel config, docs, and regression coverage.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: line Channel integration: line channel: matrix Channel integration: matrix docs Improvements or additions to documentation gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: L status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant