Skip to content

fix(matrix): preserve selected reply targets inside threads - #139479

Merged
steipete merged 4 commits into
mainfrom
codex/qa30-02-matrix-thread-replies-20260905
Sep 6, 2026
Merged

steipete merged 4 commits into
mainfrom
codex/qa30-02-matrix-thread-replies-20260905

Conversation

@steipete

@steipete steipete commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor
Additional instructions

Keep Allow edits from maintainers enabled for this PR.

What Problem This Solves

Fixes an issue where users selecting a Matrix reply target inside a thread would receive an ordinary threaded message without the selected-message quote. Thread compatibility metadata could also appear as quoted context to the agent, and a streamed preview could lose the final answer's explicit reply target.

Why This Change Was Made

One Matrix relation owner now distinguishes selected replies from compatibility fallbacks across outgoing messages, incoming context, and delivery receipts, following the existing Matrix thread-reply contract. Automatic replies and recovery notices retain their fallback behavior, while a draft whose immutable reply target differs from the final answer is replaced.

User Impact

Explicit replies preserve both the thread root and the selected message. Ordinary thread fallbacks remain available to older clients and no longer masquerade as selected quotes in agent context or receipts. No configuration, storage, authentication, or dependency changes are required.

Evidence

  • A full sendMessageMatrix → native Matrix SDK wire probe fails on the baseline's incorrect fallback flag and passes with this change. The recovery-notice control retains m.notice, fallback metadata, and an accurate receipt.
  • Focused Matrix send, reply, thread, and handler tests: 279 passed. Recovery-notice regression failed before its caller migration; threaded-preview controls passed before and after. After hosted CI exposed a stale sibling mock assertion, the corrected provider-boundary test and its send/formatting/thread siblings passed 120 tests.
  • OPENCLAW_BUILD_PRIVATE_QA=1 pnpm build passed; the supported CLI refreshed the runtime after the final caller correction.
  • pnpm openclaw qa matrix --provider-mode mock-openai --scenario matrix-thread-nested-reply-shape --output-dir .artifacts/qa30-matrix-thread-gateway-review1 --concurrency 1: 1 passed, 0 failed, 0 skipped. A disposable local Tuwunel homeserver and ephemeral Gateway observed the automatic fallback and the explicit selected reply. Owned containers and ports were cleaned up.
  • Fresh managed Codex review: scoped-clean at P0–P2, two passes on the runtime repair and one bounded pass on the subsequent test correction, no actionable findings.
  • Full changed-file gate: passed on the 18-file runtime repair, including production/test type checks, plugin contracts, exports, lint, and runtime boundary checks. The later one-file test correction preserves the automatic fallback and explicit-reply controls at the native event boundary; hosted CI must validate its new head.
{
  "scenario": "matrix-thread-nested-reply-shape",
  "providerMode": "mock-openai",
  "channelDriver": "live",
  "total": 1,
  "passed": 1,
  "failed": 0,
  "skipped": 0,
  "automaticThreadFallback": true,
  "explicitReplyFallback": false,
  "threadRootPreserved": true,
  "selectedReplyPreserved": true
}

Production: +76/−92 (net −16). Tests and QA support: +176/−67 (net +109). The recorded assertion count drops from 2 to 1; no checks are weakened.

Distinguish selected replies from compatibility fallbacks at the Matrix
relation owner, preserving that distinction through incoming context,
delivery receipts, automatic replies, and streamed finalization.

Keep the existing thread scenario and verify both relations through an
isolated homeserver and Gateway.
@clawsweeper

clawsweeper Bot commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation channel: matrix Channel integration: matrix extensions: qa-lab size: M maintainer Maintainer-authored PR labels Sep 5, 2026
@steipete
steipete marked this pull request as ready for review September 5, 2026 22:49
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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. labels Sep 5, 2026
@clawsweeper

clawsweeper Bot commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 5, 2026, 9:10 PM ET / September 6, 2026, 01:10 UTC.

ClawSweeper review

What this changes

Preserves selected Matrix reply targets within threads, excludes compatibility fallbacks from quoted context and receipts, and replaces streamed previews when the final reply target differs.

Merge readiness

✅ Ready for maintainer review

This PR remains useful: current main still conflates selected thread replies with compatibility fallbacks. The reviewed patch has no actionable correctness findings, and the recorded live Matrix proof supports the repair.

Priority: P2
Reviewed head: 0844e83de1510b407a429d6ad639085298d6aed7

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-level repair with relevant live transport evidence and useful regression coverage; no blocking defect was found.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The captured PR body records an after-fix Gateway-to-Tuwunel run of the inspected nested-reply scenario: the real Matrix transport preserved the selected message and thread root, with fallback true for automatic replies and false for explicit replies.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The captured PR body records an after-fix Gateway-to-Tuwunel run of the inspected nested-reply scenario: the real Matrix transport preserved the selected message and thread root, with fallback true for automatic replies and false for explicit replies.
Evidence reviewed 9 items Current main still needs the repair: The fetched main implementation sets is_falling_back=true whenever a threaded send includes a reply target, without distinguishing an explicitly selected message.
Latest release retains the same behavior: The v2026.9.2 implementation also unconditionally marks supplied threaded reply targets as compatibility fallbacks; the requested distinction is not present there.
Canonical relation handling: The new relation owner gives explicit reply targets precedence, marks only compatibility replies as falling back, and excludes those fallbacks when reading selected reply context. Automatic replies supply fallbackReplyToId separately.
Findings None None.
Security None None.

How this fits together

The Matrix plugin translates incoming room events into agent context and outgoing answers into Matrix messages. Thread placement and selected reply targets affect chat presentation, quoted context, and delivery receipts.

flowchart LR
  A[Incoming Matrix event] --> B[Interpret thread and reply metadata]
  B --> C[Agent context]
  C --> D[Reply or streamed preview]
  D --> E[Encode selected reply or fallback]
  E --> F[Matrix room message]
  E --> G[Delivery receipt]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +27, Tests +66, Docs +2, Other 0. Total +95 across 19 files.

View PR surface stats
Area Files Added Removed Net
Source 12 121 94 +27
Tests 5 131 65 +66
Docs 1 2 0 +2
Config 0 0 0 0
Generated 0 0 0 0
Other 1 1 1 0
Total 19 255 160 +95

Review metrics

None.

Technical review

Best possible solution:

Keep one Matrix relation owner that preserves selected replies independently of thread placement while retaining automatic compatibility fallbacks.

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

Yes, from source: sending both a thread ID and selected reply ID on current main unconditionally marks the reply as a compatibility fallback. This review did not execute a reproduction.

Is this the best way to solve the issue?

Yes. Centralizing relation encoding and interpretation fixes the protocol distinction at its owner, and the caller migrations preserve automatic fallback behavior.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against d85142c70935.

Labels

Label justifications:

  • P2: Repairs a bounded Matrix thread-reply presentation and context defect without changing configuration or authorization.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The captured PR body records an after-fix Gateway-to-Tuwunel run of the inspected nested-reply scenario: the real Matrix transport preserved the selected message and thread root, with fallback true for automatic replies and false for explicit replies.
  • proof: sufficient: Contributor real behavior proof is sufficient. The captured PR body records an after-fix Gateway-to-Tuwunel run of the inspected nested-reply scenario: the real Matrix transport preserved the selected message and thread root, with fallback true for automatic replies and false for explicit replies.

Evidence

What I checked:

  • Current main still needs the repair: The fetched main implementation sets is_falling_back=true whenever a threaded send includes a reply target, without distinguishing an explicitly selected message. (extensions/matrix/src/matrix/send/formatting.ts:155, d85142c70935)
  • Latest release retains the same behavior: The v2026.9.2 implementation also unconditionally marks supplied threaded reply targets as compatibility fallbacks; the requested distinction is not present there. (extensions/matrix/src/matrix/send/formatting.ts:155, 3928bad9badf)
  • Canonical relation handling: The new relation owner gives explicit reply targets precedence, marks only compatibility replies as falling back, and excludes those fallbacks when reading selected reply context. Automatic replies supply fallbackReplyToId separately. (extensions/matrix/src/matrix/relations.ts:11, 0844e83de151)
  • Authoritative Matrix protocol contract: The PR explicitly depends on the Matrix thread-reply contract. The specification distinguishes selected replies using false or omitted is_falling_back, while compatibility fallback uses true: Matrix replies within threads.
  • Recorded real behavior proof: The supplied PR-body snapshot, sourceRevision 08df5f80311abdb43ba545dadd998b246f462d14f05449f9a6318629ebf97fb7, records a disposable Tuwunel homeserver and ephemeral Gateway run with one passing scenario. Its observed results preserve the thread root and selected reply while distinguishing automatic fallback. The inspected scenario invokes Gateway send and checks the resulting Matrix event's root, selected target, and fallback flag. (extensions/qa-lab/src/live-transports/matrix/scenarios/scenario-runtime-thread.ts:212, 0844e83de151)
  • Review continuity: The Matrix subtree and changed Matrix QA scenario have no differences from the preceding reviewed head. The supplied completed review contains no findings or published rank-up moves. (0844e83de151)

Likely related people:

  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Eden: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

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.

History

Review history (3 earlier review cycles)
  • reviewed 2026-09-05T22:56:02.426Z sha 2d7b322 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-05T23:28:06.497Z sha 5d8af62 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-06T00:49:10.541Z sha fd91cf6 :: needs maintainer review before merge. :: none

Move the consumed first-reply fallback case into the existing native send
table and retain explicit selected-reply coverage without depending on
the private send-option name.
@steipete
steipete merged commit fe1c879 into main Sep 6, 2026
151 checks passed
@steipete
steipete deleted the codex/qa30-02-matrix-thread-replies-20260905 branch September 6, 2026 01:38
@steipete

steipete commented Sep 6, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

vincentkoc added a commit that referenced this pull request Sep 6, 2026
* commit '047587a542ce205ee78354fbd88ba8ec05c07844': (45 commits)
  chore(ui): refresh control ui locales (#139481)
  fix(slack): keep prototype-named emoji shortcodes intact (#136374)
  fix(gateway): deliver upgrade rejection responses under Bun (#139516)
  refactor(test): simplify catalog guards and fix native report fixture (#139496)
  fix(macos): prevent dashboard fixture loopback timeouts (#139556)
  fix(matrix): preserve selected reply targets inside threads (#139479)
  test(gateway): preserve held-work close failures (#139593)
  refactor(exec): share package argument scanning (#139560)
  fix(audit): preserve sequence range validation before numeric decoding (#139587)
  fix(transcripts): retain capture ownership through failed cleanup (#139572)
  refactor(models): share selector reference traversal (#139571)
  perf(agents): classify allowlists without intermediate sets (#138392)
  chore(release): update appcast for 2026.9.2 (#139575)
  fix(ci): synchronize cloud retries and board widget input (#139506)
  fix(plugins): explain SDK incompatibilities after core updates (#139458)
  fix(voice-call): retain installed WebSocket behavior under Bun (#139567)
  test(text): consolidate literal sanitizer cases (#139579)
  test(gateway): observe native drain without a lint exception (#139576)
  test(memory): consolidate visibility fixtures without policy defaults (#139569)
  fix(ui): show shimmer skeletons while loading Control UI (#139525)
  ...
vincentkoc added a commit that referenced this pull request Sep 6, 2026
* origin/main:
  fix(cli): keep note text with Windows and Unicode line endings (#139512)
  fix(agents): keep isolated completion context on its admitted generation (#139607)
  fix: avoid declaration builds during source-server updates (#139392)
  fix(models): keep discovered models after catalog refresh failures (#139357)
  fix(gateway): record a transcript notice when a run fails before replying (#139439)
  refactor(ios): reuse shared integer conversion (#139581)
  fix(sessions): prevent database lock failures during reclamation (#139469)
  perf(test): reuse transforms within owned scheduler slots (#139553)
  test(agents): share sparse transcript input fixtures (#139589)
  chore(ui): refresh control ui locales (#139481)
  fix(slack): keep prototype-named emoji shortcodes intact (#136374)
  fix(gateway): deliver upgrade rejection responses under Bun (#139516)
  refactor(test): simplify catalog guards and fix native report fixture (#139496)
  fix(macos): prevent dashboard fixture loopback timeouts (#139556)
  fix(matrix): preserve selected reply targets inside threads (#139479)
vincentkoc added a commit that referenced this pull request Sep 6, 2026
* commit 'refs/openclaw/tasks/pr-135167-main': (2467 commits)
  refactor(ios): reuse shared integer conversion (#139581)
  fix(sessions): prevent database lock failures during reclamation (#139469)
  perf(test): reuse transforms within owned scheduler slots (#139553)
  test(agents): share sparse transcript input fixtures (#139589)
  chore(ui): refresh control ui locales (#139481)
  fix(slack): keep prototype-named emoji shortcodes intact (#136374)
  fix(gateway): deliver upgrade rejection responses under Bun (#139516)
  refactor(test): simplify catalog guards and fix native report fixture (#139496)
  fix(macos): prevent dashboard fixture loopback timeouts (#139556)
  fix(matrix): preserve selected reply targets inside threads (#139479)
  test(gateway): preserve held-work close failures (#139593)
  refactor(exec): share package argument scanning (#139560)
  fix(audit): preserve sequence range validation before numeric decoding (#139587)
  fix(transcripts): retain capture ownership through failed cleanup (#139572)
  refactor(models): share selector reference traversal (#139571)
  perf(agents): classify allowlists without intermediate sets (#138392)
  chore(release): update appcast for 2026.9.2 (#139575)
  fix(ci): synchronize cloud retries and board widget input (#139506)
  fix(plugins): explain SDK incompatibilities after core updates (#139458)
  fix(voice-call): retain installed WebSocket behavior under Bun (#139567)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 6, 2026
…#139479)

* fix(matrix): preserve selected reply targets inside threads

Distinguish selected replies from compatibility fallbacks at the Matrix
relation owner, preserving that distinction through incoming context,
delivery receipts, automatic replies, and streamed finalization.

Keep the existing thread scenario and verify both relations through an
isolated homeserver and Gateway.

* test(matrix): assert thread fallback at the provider boundary

Move the consumed first-reply fallback case into the existing native send
table and retain explicit selected-reply coverage without depending on
the private send-option name.
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 extensions: qa-lab maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M 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