Skip to content

fix(matrix): send fallback media when attachment list is blank - #128479

Merged
steipete merged 4 commits into
openclaw:mainfrom
Alix-007:alix/fix-matrix-blank-media-fallback
Aug 25, 2026
Merged

steipete merged 4 commits into
openclaw:mainfrom
Alix-007:alix/fix-matrix-blank-media-fallback

Conversation

@Alix-007

@Alix-007 Alix-007 commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

AI-assisted: This change was implemented and validated with Codex.

What Problem This Solves

Matrix automatic replies could discard a valid singular attachment when mediaUrls existed but contained only blank entries. The raw text/array checks and the normalized delivery list also disagreed when neither text nor media was sendable, allowing whitespace-only replies to end with neither a visible message nor the expected missing-result diagnostic.

Why This Change Was Made

The Matrix automatic-reply path now resolves hasText, hasMedia, and mediaUrls once through the Plugin SDK's canonical sendable-reply selector. Validation, missing-result reporting, and delivery therefore consume the same normalized state, while whitespace filtering and singular fallback remain owned by the shared selector.

Sibling PR #128372 established the shared blank-list fallback. This PR connects the omitted Matrix automatic-reply consumer. PR #127653 covers shared fan-out and durable reconciliation, while #128254 changes reasoning-notice delivery in the same Matrix files; neither changes this selector or covers this failure.

User Impact

Matrix automatic replies now upload and send a valid fallback attachment when plural attachment entries are blank. A reply containing only whitespace text and blank media now records the normal matrix reply missing text/media outcome instead of disappearing silently.

Evidence

  • Exact head: 6b04c79e5f03c9ca9a1b5aa0e5b0f4b4c0b31714. Original parent-red gate: c337919f6d4ff030bc46180fea89f7935fe46b4f. Upstream main at this body refresh: 2aa5eee34e51d0655fd6e7dca1c41f1da1e53e04.
  • Original parent-red: node scripts/run-vitest.mjs extensions/matrix/src/matrix/monitor/replies.test.ts failed only the new fallback regression: expected https://example.com/fallback.jpg, received three spaces.
  • First review-finding parent-red on PR head e9f5e59df82682f012cd0443634ab78597e8a98d: blank-only media expected matrix reply missing text/media, but the error hook had zero calls and the send path emitted nothing.
  • Second review-finding parent-red on PR head a4f70619cdbdbdb69c740988ac3fd6d07a0bb30b: whitespace text plus blank-only media again expected the diagnostic, but the error hook had zero calls. Exact head uses the selector's normalized hasText and hasMedia for the gate.
  • Exact-head affected suite on Node 24.15.0: node scripts/run-vitest.mjs extensions/matrix/src/matrix/monitor/replies.test.ts extensions/matrix/src/matrix/monitor/replies.file-boundary.test.ts passed 2 files / 20 tests. The boundary test reads a real temporary file through loadOutboundMediaFromUrl and exercises the production reply/send pipeline.
  • pnpm exec oxfmt --check passed for all 3 changed files, and git diff --check passed.
  • Production delta: +5/-9 (net -4). Tests: +142/-0. All 3 commits use Alix-007 <[email protected]> as author and committer.

Real homeserver proof: fallback delivery

PR head a4f70619cdbdbdb69c740988ac3fd6d07a0bb30b, the direct parent of the final normalized-text gate, was run against a disposable loopback Tuwunel v1.8.2 homeserver. The official v1.8.2-release-all-x86_64-v1-linux-gnu-tuwunel.zst asset reported digest sha256:823796258f9252e0b1215d12e6190abba70d81a2a39efc86b419e5a6b3a2cd6c; the downloaded asset matched that SHA-256 before its static binary was started. The proof performed real token registration, created and joined a real room, then ran deliverMatrixReplies with mediaUrls: [" "] and a real local-file mediaUrl.

{
  "proof": "PASS",
  "source": "PR head a4f70619 deliverMatrixReplies",
  "homeserver": {
    "binary": "Tuwunel v1.8.2 static x86_64-v1",
    "releaseAssetSha256": "823796258f9252e0b1215d12e6190abba70d81a2a39efc86b419e5a6b3a2cd6c",
    "scope": "disposable loopback; base URL redacted"
  },
  "fallback": {
    "plural": "blank-only",
    "singular": "local file selected"
  },
  "upload": {
    "bytes": 30,
    "route": "/_matrix/media/v3/upload",
    "status": 200
  },
  "roomEvent": {
    "body": "fallback caption",
    "filename": "fallback.txt",
    "msgtype": "m.file",
    "route": "/_matrix/client/v3/rooms/{roomId}/send/m.room.message/{transactionId}",
    "status": 200,
    "type": "m.room.message",
    "urlScheme": "mxc"
  },
  "roundTrip": {
    "bytes": 30,
    "route": "/_matrix/client/v1/media/download/{serverName}/{mediaId}",
    "sha256": "0ff5b069e913b3ee5670a1481165227a8c6dfd62033be45f5393601218fde9d0",
    "sourceMatchesDownload": true,
    "status": 200
  },
  "visibleReplySent": true,
  "eventCount": 1,
  "secretsPrinted": false
}

Real homeserver proof: normalized-empty no-event

The exact final head repeated the same checksum-pinned static homeserver setup, registered three fresh accounts, created and joined a fresh room, and ran deliverMatrixReplies with whitespace-only text and blank-only media. It then read the real room timeline from the homeserver.

{
  "proof": "PASS",
  "source": "exact head 6b04c79e deliverMatrixReplies",
  "homeserver": {
    "binary": "Tuwunel v1.8.2 static x86_64-v1",
    "releaseAssetSha256": "823796258f9252e0b1215d12e6190abba70d81a2a39efc86b419e5a6b3a2cd6c",
    "scope": "disposable loopback; base URL redacted"
  },
  "input": {
    "text": "blank-only",
    "mediaUrls": "blank-only"
  },
  "outcome": {
    "diagnostic": "matrix reply missing text/media",
    "suppression": "no_visible_result",
    "visibleReplySent": false
  },
  "transport": {
    "uploadRequestCount": 0,
    "sendRequestCount": 0
  },
  "roomReadback": {
    "route": "/_matrix/client/v3/rooms/{roomId}/messages",
    "status": 200,
    "roomMessageEventCount": 0
  },
  "secretsPrinted": false
}

Both proofs omitted or normalized account IDs, room/event IDs, access tokens, registration tokens, loopback ports, and media IDs. Each Tuwunel process, binary, config, database, and payload was removed after exit; no external credentials or persistent room were used.

The repository's Compose-based fixture could not start on this host because its Docker 17.03.3 installation lacks the Compose plugin, and the same daemon rejected the modern image layer with archive/tar: invalid tar header. The checksum-pinned official static release provided the equivalent real homeserver boundary without weakening TLS or artifact verification. During the first proof shutdown, the minimal non-persistent Matrix runtime logged one IndexedDB snapshot warning before its existing stop fallback completed; all transport assertions had already passed, the process exited 0, and all temporary state was removed. The exact-head no-event proof used the explicit non-persisting stop path and emitted no such warning.

Limitations

The real homeservers were loopback-only and the rooms were unencrypted. The proofs cover registration, room creation/join, normalized empty-result handling, production attachment selection, real media upload, real room event storage/readback, and real media download; they do not exercise federation or an external operator-owned Matrix room.

@clawsweeper

clawsweeper Bot commented Aug 24, 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 channel: matrix Channel integration: matrix size: S labels Aug 24, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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. labels Aug 24, 2026
@clawsweeper

clawsweeper Bot commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed August 25, 2026, 12:56 PM ET / 16:56 UTC.

ClawSweeper review

What this changes

The PR makes Matrix automatic replies use the shared sendable-reply selector so blank plural media entries fall back to a valid singular attachment and fully blank replies record the normal diagnostic.

Regression provenance

Possible regression — probable (reviewed change; reproduction). No predecessor PR is attributed.

Merge readiness

⛔ Blocked until stronger real behavior proof is added - 3 items remain

No blocking code defect found. Current main still uses the raw attachment checks this PR replaces, but the supplied homeserver proof predates the current head’s streaming-dispatch change, so exact-head automatic-reply proof is needed before merge.

Priority: P2
Reviewed head: 7157cf74ae30b5b2e9e0255bc7295afd2fed8d15

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The owner-boundary repair and regression coverage are solid, but real behavior evidence does not cover the current head’s added streaming path.
Proof confidence 🦐 gold shrimp (3/6) Needs stronger real behavior proof before merge: The body has strong redacted homeserver logs for earlier heads, but current head 7157cf7 additionally changes streaming draft finalization and lacks after-fix automatic-reply proof for that exact behavior; add redacted exact-head output. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Needs proof Needs stronger real behavior proof before merge: The body has strong redacted homeserver logs for earlier heads, but current head 7157cf7 additionally changes streaming draft finalization and lacks after-fix automatic-reply proof for that exact behavior; add redacted exact-head output. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed 8 items Current-main gap: Current main still treats any nonempty mediaUrls array as media and selects it ahead of mediaUrl, so blank plural entries can suppress the singular fallback.
Shared owner contract: The existing shared selector chooses plural media only when an entry is nonblank, otherwise uses the singular field, then trims media and derives sendability once.
PR delivery repair: The current head consumes normalized hasText, hasMedia, and mediaUrls for Matrix validation and sending, eliminating the local raw-array decision.
Findings None None.
Security None None.

How this fits together

Matrix automatic replies transform generated text and attachment fields into Matrix upload/send operations or an intentional suppressed result. The Plugin SDK selector provides normalized sendable text and media state to the Matrix delivery and draft-finalization paths.

flowchart LR
  A[Generated reply payload] --> B[Shared reply selector]
  B --> C[Matrix reply delivery]
  C --> D{Sendable content?}
  D -->|Media or text| E[Upload and room event]
  D -->|Neither| F[Missing-result diagnostic]
  E --> G[Visible Matrix reply]
Loading

Before merge

  • Add real behavior proof - Needs stronger real behavior proof before merge: The body has strong redacted homeserver logs for earlier heads, but current head 7157cf7 additionally changes streaming draft finalization and lacks after-fix automatic-reply proof for that exact behavior; add redacted exact-head output. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Resolve merge risk (P2) - The real homeserver traces cover direct delivery on earlier heads, while the current head also changes streaming draft finalization; an exact-head automatic-reply run is needed to rule out a duplicate, retained draft, or suppressed fallback attachment.
  • Complete next step (P2) - A maintainer or contributor needs to attach exact-head automatic-reply evidence; there is no narrow code repair finding to dispatch.
Agent review details

Security

None.

PR surface

Source -3, Tests +152. Total +149 across 5 files.

View PR surface stats
Area Files Added Removed Net
Source 2 7 10 -3
Tests 3 157 5 +152
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 164 15 +149

Review metrics

Metric Value Why it matters
Production vs test delta production +7/-10 (net -3); tests +157/-5 (net +152) The production repair remains net-negative while focused coverage expands across direct delivery, file handling, and draft streaming.

Root-cause cluster

Relationship: canonical
Canonical: #128479
Summary: This PR is the remaining Matrix automatic-reply consumer repair; the shared selector was already fixed separately.

Members:

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

Merge-risk options

Maintainer options:

  1. Add exact-head automatic-reply proof (recommended)
    Run the current head through the Matrix automatic-reply and draft-finalization path, then attach redacted output showing fallback delivery and normalized-empty suppression.

Technical review

Best possible solution:

Keep Matrix automatic-reply delivery and streaming finalization on the shared selector, with one exact-head disposable-homeserver trace through the automatic-reply entry point proving fallback upload/send and blank-result suppression.

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

Yes, by source: current main’s raw mediaUrls length check selects blank plural entries before the valid singular field, while the PR’s focused tests encode that failing shape. This review did not execute contributor code locally.

Is this the best way to solve the issue?

Yes. Reusing the existing Plugin SDK selector is the canonical owner-boundary repair; it removes Matrix-specific raw checks rather than adding another fallback policy.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 16c097b2dae9.

Labels

Label changes:

  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs stronger real behavior proof before merge: The body has strong redacted homeserver logs for earlier heads, but current head 7157cf7 additionally changes streaming draft finalization and lacks after-fix automatic-reply proof for that exact behavior; add redacted exact-head output. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • remove proof: sufficient: Current real behavior proof status is insufficient, not sufficient.
  • remove rating: 🦞 diamond lobster: Current PR rating is rating: 🦐 gold shrimp, so this older rating label is no longer current.
  • remove status: 👀 ready for maintainer look: Current PR status label is status: 📣 needs proof.

Label justifications:

  • P2: The PR fixes a bounded Matrix automatic-reply delivery defect with limited channel blast radius.
  • merge-risk: 🚨 message-delivery: The changed decision determines whether Matrix uploads an attachment, finalizes a draft, or suppresses output.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs stronger real behavior proof before merge: The body has strong redacted homeserver logs for earlier heads, but current head 7157cf7 additionally changes streaming draft finalization and lacks after-fix automatic-reply proof for that exact behavior; add redacted exact-head output. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Evidence

What I checked:

Likely related people:

  • steipete: Authored merged shared-selector repair 4d00dc4 and the current-head Matrix streaming normalization. (role: shared-rule and recent Matrix contributor; confidence: high; commits: 4d00dc4fca12, 7157cf74ae30; files: src/infra/outbound/reply-payload-parts.ts, extensions/matrix/src/matrix/monitor/replies.ts, extensions/matrix/src/matrix/monitor/handler-reply-dispatcher.ts)
  • joshavant: Recent history includes Matrix automatic-reply settlement and draft-replacement work in the affected delivery area. (role: recent adjacent Matrix delivery contributor; confidence: medium; commits: 32a61cabf026, 4408ceb68e91; files: extensions/matrix/src/matrix/monitor/replies.ts, extensions/matrix/src/matrix/monitor/handler-reply-dispatcher.ts)

Rank-up moves

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

  • Attach redacted exact-head Matrix automatic-reply output covering the streaming draft path, fallback attachment upload/send, and normalized-empty diagnostic.

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 (5 earlier review cycles)
  • reviewed 2026-08-24T03:54:55.605Z sha e9f5e59 :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-24T04:37:15.947Z sha e9f5e59 :: needs real behavior proof before merge. :: [P2] Derive validation from resolved media state
  • reviewed 2026-08-24T05:37:19.887Z sha a4f7061 :: needs changes before merge. :: [P2] Use normalized text state for blank-result validation
  • reviewed 2026-08-24T06:02:51.389Z sha 6b04c79 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-25T07:02:37.004Z sha 6b04c79 :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added the merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. label Aug 24, 2026
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed 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. labels Aug 24, 2026
@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 24, 2026
@steipete

steipete commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

Maintainer verification: exact final head 7157cf74ae30b5b2e9e0255bc7295afd2fed8d15; production +7/-10 (net -3); tests +157/-5. Matrix automatic delivery and streaming draft dispatch now both use the canonical resolveSendableOutboundReplyParts owner, matching the existing Matrix direct-outbound sibling.

The contributor's real disposable Tuwunel homeserver proof covers singular fallback upload, a visible m.file room event, byte-identical download, and blank-only no-event diagnostics. Additional table-driven streaming regressions prove blank plural media still finalizes a valid text preview, genuinely empty final previews are cleaned up, and valid singular fallback attachments retain normal media delivery. Existing approved file roots, encryption, transaction deduplication, and reasoning suppression remain unchanged. Federation and encrypted operator-owned rooms were not exercised.

Exact-head CI run https://github.com/openclaw/openclaw/actions/runs/32874239548 passed all 67 jobs; Workflow Sanity https://github.com/openclaw/openclaw/actions/runs/32874239589 passed. Full final-branch structured review and a separate standalone independent review found no actionable defects. Original contributor @Alix-007 is preserved as the PR author and exact co-author.

The prior stale-base/rebase rank-up remains intentionally skipped: the affected Matrix owner, dispatcher, tests, and shared selector have no conflicting current-main changes. The behavioral follow-up was applied at its canonical owner instead.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 25, 2026
@clawsweeper

clawsweeper Bot commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@steipete
steipete merged commit 930f740 into openclaw:main Aug 25, 2026
119 of 120 checks passed
@steipete

Copy link
Copy Markdown
Contributor

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 26, 2026
…law#128479)

* fix(matrix): send fallback media when attachment list is blank

* fix(matrix): align media validation and delivery

* fix(matrix): reject whitespace-only reply parts

* fix(matrix): normalize streamed reply media before draft finalization

Co-authored-by: Alix-007 <[email protected]>

---------

Co-authored-by: Peter Steinberger <[email protected]>
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: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: S 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.

2 participants