Skip to content

fix(channels): Matrix attachment delivery and ClickClack recovery - #127653

Closed
steipete wants to merge 3 commits into
mainfrom
codex/qa-canonical-media-fanout
Closed

steipete wants to merge 3 commits into
mainfrom
codex/qa-canonical-media-fanout

Conversation

@steipete

@steipete steipete commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where users sending an attachment to Matrix would receive no message when the normal reply producer populated both the primary attachment and its attachment list. The same mismatch could prevent ClickClack from recognizing an attachment that was already delivered during crash recovery.

Why This Change Was Made

The reply-payload owner now provides the single canonical attachment-selection rule to rendered-message planning, outbound payload preparation, durable delivery, the existing plugin SDK, text-to-speech, and ClickClack recovery. Nonempty attachment lists supersede the legacy primary field, empty lists retain the existing primary-field fallback, and obsolete infra-owned helpers and duplicate planner/recovery policy are removed without changing the public SDK.

User Impact

Normalized Matrix attachments are delivered exactly once with both automatic and explicit durable reconciliation, and ClickClack recovers previously uploaded attachments without searching for a nonexistent duplicate. Other channel planners inherit the same attachment order and trimming contract.

Evidence

  • Failing-first planner proof: one producer-normalized attachment was counted twice, and a plural attachment list incorrectly included an unrelated legacy primary attachment.
  • Passed 39 focused tests across shared rendered planning, legacy media contract coverage, real SQLite-backed Matrix durable delivery, and ClickClack outbound/crash recovery:
    node scripts/run-vitest.mjs src/channels/message/rendered-batch.test.ts src/media/media-retirement-non-goals.test.ts src/infra/outbound/deliver-queue.exact-reconciliation.integration.test.ts extensions/clickclack/src/outbound.test.ts
  • Applied the exact-head ClawSweeper finding and both rank-up moves at the outbound payload-plan owner; the strengthened real SQLite-backed Matrix suite passes all six cases, including automatic and explicit reconciliation with distinct legacy and plural attachment URLs:
    node node_modules/vitest/vitest.mjs run --config test/vitest/vitest.infra.config.ts src/infra/outbound/deliver-queue.exact-reconciliation.integration.test.ts --maxWorkers 1 --no-file-parallelism
  • Passed strict core types:
    node scripts/run-tsgo.mjs -p tsconfig.core.json --incremental --tsBuildInfoFile .artifacts/tsgo-cache/core.tsbuildinfo
  • Full extension typecheck reported only two existing, unrelated ACPX dependency-contract errors and no ClickClack errors.
  • All touched files pass the repository formatter, and the refactor removes 27 production lines while preserving the existing public plugin SDK.
  • Real external channel delivery was not attempted because it would require live credentials and sending messages to real users; the durable queue regression runs the actual delivery pipeline against isolated SQLite and a controlled transport boundary.

@clawsweeper

clawsweeper Bot commented Aug 21, 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.

@steipete
steipete marked this pull request as ready for review August 21, 2026 22:03
@clawsweeper clawsweeper Bot added merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. P1 High-priority user-facing bug, regression, or broken workflow. 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 21, 2026
@clawsweeper

clawsweeper Bot commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed October 2, 2026, 5:03 PM ET / 21:03 UTC (Revision 7).

ClawSweeper review

What this changes

The branch centralizes attachment selection across outbound planning, channel rendering, and ClickClack recovery, with regression coverage for duplicate attachment fields.

Regression provenance

Possible regression — suspected (reviewed change). No predecessor PR is attributed.

Merge readiness

⛔ Blocked before merge - 4 items remain

The previously raised attachment-loss blocker remains on the unchanged head. Current main already repairs duplicate rendered counts while preserving distinct attachments; this protected PR needs reconciliation with that implementation.

Priority: P1
Reviewed head: 2f0e56f9b7913ecb60753739bf924f6ce437d996

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The consolidation is useful and reduces production code, but the unchanged attachment-loss defect prevents a correctness pass.
Proof confidence 🌊 off-meta tidepool Not applicable: The supplied maintainer classification exempts ordinary contributor proof. Reported SQLite delivery tests exercise production queue preparation with mocked channel transport, and recovery tests mock the HTTP client; these remain supplemental evidence, with live-channel infeasibility stated in the body. No stored-data schema or serialized-format contract is changed.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The supplied maintainer classification exempts ordinary contributor proof. Reported SQLite delivery tests exercise production queue preparation with mocked channel transport, and recovery tests mock the HTTP client; these remain supplemental evidence, with live-channel infeasibility stated in the body. No stored-data schema or serialized-format contract is changed.
Evidence reviewed 10 items Pinned introduced change: The merge-base-to-head diff replaces merged attachment inputs with plural-list precedence in payload preparation, rendering, and ClickClack recovery. The helper move preserves its existing implementation; applying it to these additional owners introduces the behavioral change.
Source-proven attachment loss: The selector chooses any nonempty mediaUrls array before trimming. Consequently, mediaUrl='a.png' with mediaUrls=[' '] becomes empty, and mediaUrl='a.png' with mediaUrls=['b.png'] loses a.png. Payload preparation subsequently clears the singular field. The former merge loop retained both valid inputs and removed duplicate URLs.
Production entry point and queue boundary: prepareOutboundPayloadBatch calls createOutboundPayloadPlan before modifiers and queue custody. deliver-queue then creates the rendered plan from accepted prepared payloads. Attachments discarded during planning cannot reach transport or durable recovery.
Findings 1 actionable finding [P1] [P1] Preserve valid attachments when normalizing both media fields
Security None None.

How this fits together

Outbound planning converts agent replies into channel messages and durable delivery records. Attachment selection determines which files are sent and which platform messages recovery must reconcile after a restart.

flowchart TD
  A[Agent reply and attachments] --> B[Outbound payload preparation]
  B --> C[Attachment selection]
  C --> D[Rendered delivery plan]
  D --> E[Durable delivery queue]
  E --> F[Channel attachment send]
  E --> G[ClickClack crash recovery]
  F --> H[Delivery receipt]
  G --> H
Loading

Before merge

  • [P1] Preserve valid attachments when normalizing both media fields (P1) - The previously raised blocker remains: replacing the merge with this selector drops mediaUrl: "a.png" when mediaUrls is [" "] or ["b.png"]. The helper selects the raw plural array first, and the normalized payload subsequently clears the singular field, so the valid attachment never reaches delivery. The original merge retained valid inputs, and v2026.9.7 explicitly tests preservation of distinct singular and plural attachments. Merge and normalize the inputs before deduplication, then cover both cases through preparation and recovery.
  • Resolve merge risk (P1) - Recovery compatibility remains unverified for existing mixed-field queued payloads without a stored render plan: changing attachment selection can change the number and ordering of nonce-indexed parts.
  • Resolve merge risk (P1) - Integration with current main remains unresolved; the captured context reports merge conflicts and provides no verified test-merge result.
  • Complete next step (P2) - Restore the merged attachment contract, cover blank-list and distinct-input recovery, and reconcile the branch with current main.

Findings

  • [P1] [P1] Preserve valid attachments when normalizing both media fields — src/infra/outbound/payloads.ts:203-208
Agent review details

Security

None.

PR surface

Source -27, Tests +136. Total +109 across 11 files.

View PR surface stats
Area Files Added Removed Net
Source 6 22 49 -27
Tests 5 140 4 +136
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 11 162 53 +109

Review metrics

Metric Value Why it matters
Production versus tests Production +22/-49 (net -27); tests +140/-4 (net +136), discounting the helper move The refactor reduces production code, but the new distinct-input assertions encode an incompatible selection rule.

Merge-risk options

Maintainer options:

  1. Preserve merged attachment inputs (recommended)
    Reconcile with current main and cover blank plural lists, distinct singular inputs, duplicate aliases, and existing queued recovery before landing.
  2. Retire overlapping branch work
    A maintainer can retain any useful recovery coverage separately and retire this branch after checking the merged planner repair covers the intended workflow.

Technical review

Best possible solution:

Use current main's normalized merged-input behavior, retain distinct attachments and blank-list fallback, and share delivery facts with recovery without changing stored part ordering.

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

Yes, source establishes the patch defect: plan a valid mediaUrl alongside either blank-only mediaUrls or a distinct plural URL. The singular attachment is discarded; this review did not execute tests.

Is this the best way to solve the issue?

No. Sharing normalization is appropriate, but plural precedence changes established behavior; current main's merged-input deduplication solves duplicate counting while retaining valid attachments.

Full review comments:

  • [P1] [P1] Preserve valid attachments when normalizing both media fields — src/infra/outbound/payloads.ts:203-208
    The previously raised blocker remains: replacing the merge with this selector drops mediaUrl: "a.png" when mediaUrls is [" "] or ["b.png"]. The helper selects the raw plural array first, and the normalized payload subsequently clears the singular field, so the valid attachment never reaches delivery. The original merge retained valid inputs, and v2026.9.7 explicitly tests preservation of distinct singular and plural attachments. Merge and normalize the inputs before deduplication, then cover both cases through preparation and recovery.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.98

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🦐 gold shrimp, so this older rating label is no longer current.

Label justifications:

  • P1: The unresolved introduced selector can silently drop attachments from agent replies.
  • merge-risk: 🚨 compatibility: Plural precedence conflicts with the stable-release merged-input contract and leaves queued recovery ordering unverified.
  • merge-risk: 🚨 message-delivery: Valid singular attachments can disappear before transport and durable queue preparation.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: The supplied maintainer classification exempts ordinary contributor proof. Reported SQLite delivery tests exercise production queue preparation with mocked channel transport, and recovery tests mock the HTTP client; these remain supplemental evidence, with live-channel infeasibility stated in the body. No stored-data schema or serialized-format contract is changed.

Evidence

What I checked:

  • Pinned introduced change: The merge-base-to-head diff replaces merged attachment inputs with plural-list precedence in payload preparation, rendering, and ClickClack recovery. The helper move preserves its existing implementation; applying it to these additional owners introduces the behavioral change. (src/infra/outbound/payloads.ts:205, 2f0e56f9b791)
  • Source-proven attachment loss: The selector chooses any nonempty mediaUrls array before trimming. Consequently, mediaUrl='a.png' with mediaUrls=[' '] becomes empty, and mediaUrl='a.png' with mediaUrls=['b.png'] loses a.png. Payload preparation subsequently clears the singular field. The former merge loop retained both valid inputs and removed duplicate URLs. (src/auto-reply/reply-payload-parts.ts:27, 2f0e56f9b791)
  • Production entry point and queue boundary: prepareOutboundPayloadBatch calls createOutboundPayloadPlan before modifiers and queue custody. deliver-queue then creates the rendered plan from accepted prepared payloads. Attachments discarded during planning cannot reach transport or durable recovery. (src/infra/outbound/deliver-prepare.ts:129, 2f0e56f9b791)
  • Shipped merged-input contract: The v2026.9.7 payload tests require explicit plural attachments, a distinct singular attachment, and parsed attachments to survive in source order across delivery, transport, JSON, and mirror projections. This independently contradicts the branch's new precedence assertions. (src/infra/outbound/payloads.test.ts:88, c074824a27c9)
  • Current-main behavior: Current main trims plural entries and includes a distinct singular attachment, omitting only an overlapping singular alias. Its aggregate counts derive from those same rendered items. Main's outbound payload owner likewise collects and deduplicates merged inputs. (src/channels/message/rendered-batch.ts:10, d5c6cbfb4b8c)
  • Merged repair overlaps the central problem: GitHub verifies fix(channels): keep title-only cards visible and media counts accurate #129193 as merged. Its body explicitly addresses a producer mirroring one attachment into both fields, preserves distinct and intentionally repeated attachments, and reports producer plus durable-send boundary coverage. The repaired selector is also present in v2026.9.7. (src/channels/message/rendered-batch.ts:15, 2da70a885d66)

Likely related people:

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

Rank-up moves

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

  • Replace precedence assertions with coverage preserving blank-list fallback and distinct attachments.
  • Reconcile with current main and verify existing queued recovery retains its attachment part ordering.

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 (6 earlier review cycles)
  • reviewed 2026-08-21T22:24:48.554Z sha 4132a09 :: found issues before merge. :: [P1] Normalize the delivery payload before freezing media fan-out
  • reviewed 2026-08-21T23:04:26.171Z sha 2f0e56f :: needs maintainer review before merge. :: none
  • reviewed 2026-08-24T04:07:28.015Z sha 2f0e56f :: needs changes before merge. :: [P1] Preserve fallback for all-blank plural attachment lists
  • reviewed August 27, 2026, 11:22 AM ET / 15:22 UTC sha unknown :: needs changes before merge. :: [P1] Preserve the merged attachment contract
  • reviewed September 4, 2026, 4:24 AM ET / 08:24 UTC sha unknown :: blocked before merge. :: [P1] [P1] Preserve valid attachments when normalizing both media fields
  • reviewed 2026-09-25T20:57:45.823Z sha 2f0e56f :: blocked before merge. :: [P1] [P1] Preserve valid attachments when normalizing both media fields

@clawsweeper clawsweeper Bot added 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. 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 21, 2026
@clawsweeper clawsweeper Bot added 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. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. and removed 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 Aug 24, 2026
@fuller-stack-dev fuller-stack-dev self-assigned this Sep 17, 2026
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Sep 26, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

The duplicate rendered-media count was fixed in #129193 (2da70a8), and ClickClack recovery now consumes that rendered plan. This branch's broader plural-list precedence would discard distinct valid attachments, so the overlapping implementation should be retired.

Closed in a sweep of stale maintainer PRs (no activity for 7+ days). Reopen with a current reproduction if this still matters.

@steipete steipete closed this Oct 21, 2026
@RomneyDa
RomneyDa deleted the codex/qa-canonical-media-fanout branch October 22, 2026 05:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extensions: clickclack 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. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: M 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.

2 participants