Skip to content

feat: name dropped attachments on wecom, weixin and whatsapp dms - #31729

Merged
bolichen97 merged 1 commit into
mainfrom
fix/8911-rest-dm-attachment-names
Nov 7, 2026
Merged

bolichen97 merged 1 commit into
mainfrom
fix/8911-rest-dm-attachment-names

Conversation

@bolichen97

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: A WeCom, Weixin or WhatsApp DM user whose message was refused while the gateway restarted is told which attachments to resend, not only how many.

A message that arrives while the gateway shuts down is answered on the next start with a restart notice. Discord, Telegram and Teams already name the dropped files there. On WeCom, Weixin and WhatsApp DMs the notice still said only "Its 2 attachment(s) are not carried over — resend those too.", because these three channels count the files before ingestion and handed that count on as a bare number.

Why it matters

The notice exists so a resend is one step. A count leaves the user guessing which of the files they sent were lost, and on WeCom and Weixin a single message can carry several. The messaging spec already lists these channels as "the count, until their names land", so this closes that gap for three of the four channels it names.

Not a goal

What changed (motivation → approach → change)

Each of the three channels now takes one name per attachment at the same point it took the count, before ingestion clears the attachments. The name is the one the file is ingested under: the sender's own file name where the platform gives one, otherwise the kind of media. That way an unnamed photo still tells the user what to resend, which a bare "and 1 more" would not.

Channel Where the names come from
WeCom (wecom/transport_dispatch.py) each attachment's name: a file's filename, else wecom-image / wecom-video
Weixin (weixin/transport_dispatch.py, weixin/attachments.py) attachment_names, the iLink naming ingestion already uses: a file's file_name, else image.jpg, voice.<ext>, video.mp4. _drive takes them as original_attachments and counts them
WhatsApp DMs (whatsapp/transport.py, whatsapp/transport_dispatch.py) the pending_original side table keeps the media's name instead of a count (a document's file name, else e.g. image.jpg); the route counts the names
docs/system-specs/modules/messaging.md the per-channel table moves the three channels to "the names"; Slack keeps its "until its names land" row

Backwards compatibility

Compatible: the spool entry and the notice are unchanged; only what these three channels put in InboundRoute.attachment_names changes, and the count each route records stays the same.

Removes nothing: no field, key or behaviour is taken away. WhatsApp's in-memory pending_original table holds names in place of a count, and its only reader, the dispatcher's _inbound_route, counts them.

Tests

  • test/test_wecom_dispatch.py::TestTurn::test_a_shutdown_refusal_spools_the_attachment_names — a refused WeCom callback with a named file and an image spools ("a.pdf", "wecom-image") and a count of 2.
  • test/test_weixin_dispatch.py::test_a_refused_callback_spools_the_attachment_names — the same for a refused Weixin callback: ("a.pdf", "image.jpg").
  • test/test_weixin_dispatch.py::test_the_turn_route_names_the_attachments_ingestion_consumed — the turn's route still names both files after ingestion has cleared inbound.attachments.
  • test/test_whatsapp_transport.py::TestPreIngestionOriginalIsCapturedForTheSpool::test_a_document_records_the_name_its_sender_gave_it — a document's fileName is what the side table keeps.
  • test/test_whatsapp_transport.py::TestPreIngestionOriginalIsCapturedForTheSpool::test_the_original_caption_survives_ingestion and test/test_whatsapp_dispatch.py::test_dm_route_spools_the_pre_ingestion_original_not_the_prompt — an image is kept as image.jpg and reaches the route as one named attachment.

Proof: PROVEN test/test_wecom_dispatch.py::TestTurn::test_a_shutdown_refusal_spools_the_attachment_names, test/test_weixin_dispatch.py::test_a_refused_callback_spools_the_attachment_names, test/test_weixin_dispatch.py::test_the_turn_route_names_the_attachments_ingestion_consumed, test/test_whatsapp_dispatch.py::test_dm_route_spools_the_pre_ingestion_original_not_the_prompt, test/test_whatsapp_transport.py::TestPreIngestionOriginalIsCapturedForTheSpool::test_the_original_caption_survives_ingestion (head 28933fd)

Related backend set run locally with 4 workers (the touched channels' test files, test_inbound_spool.py, test_messaging_dispatch.py and the files importing the changed modules): 1962 passed, 1 skipped. Determinism: the six node ids above passed 20 runs at -n0, one run in reversed order, and one run at -n 4 --dist loadgroup --max-worker-restart=2 beside the whole of test/test_weixin_dispatch.py and test/test_wecom_dispatch.py.

Manual verification

N/A — unit coverage drives each dispatcher's real refusal path and WhatsApp's real receive; no external service is involved.

Screenshots / video

N/A — no frontend change; the notice is chat text.

Related Issues

Part of #8911

Sibling sweep

Siblings: none -- this is a feature, not a defect fix

Pattern harvest

Not generalizable: this is a feature, not a defect fix

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

Contribution License Agreement

Contributed under the project's Apache-2.0 license (see CONTRIBUTING.md).

@bolichen97
bolichen97 requested review from a team and KiroCrewCaptain as code owners November 6, 2026 19:43
@bolichen97
bolichen97 requested a review from Zedmor November 6, 2026 19:44
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Nov 6, 2026
@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision 26562e63618cdecc9017cfc2635ef9b0dcb96454 touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Does not block merge.

@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of 26562e63618cdecc9017cfc2635ef9b0dcb96454 — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

First-Principles-Verdict: PASS

Every item reuses the existing InboundRoute.attachment_names seam and its notice renderer. The one Slack sibling left is deferred openly under #8911.

What this change ships

Inventory (6 items) — 6 justified

Intent: when a message is refused during a restart, a WeCom, Weixin or WhatsApp DM user is told which attachments to resend, not only how many. This is an ADDITION.

  1. On WeCom, the restart notice now names each dropped attachment; an unnamed image or video reads wecom-image or wecom-video. — justified
  2. On Weixin, the restart notice names each dropped attachment, both when the message is refused at callback and when it is refused at turn time; unnamed media reads as image.jpg, voice.<ext> or video.mp4. — justified
  3. On WhatsApp DMs, the restart notice names the dropped media; a document keeps its sender's file name. — justified
  4. New weixin.attachments.attachment_names export, which names files without a MIME guess so a URL-shaped name cannot raise before ingestion. Counted 2 consumers in weixin/transport_dispatch.py. — justified
  5. WhatsApp's in-memory pending_original table now holds names instead of a count; its only reader is _inbound_route. — justified
  6. In the messaging spec's per-channel table, the three channels move to "the names" and Slack keeps its own "the count" row. — justified

[FIRST-PRINCIPLES-REVIEWED] 26562e6

Description read

[DESCRIPTION-READ] 939e0a65986fbc417fc0321d9bb76d9e5729e696591a05b9dc8bcee878337d07

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@bolichen97
bolichen97 enabled auto-merge (squash) November 6, 2026 20:13
@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of 26562e63618cdecc9017cfc2635ef9b0dcb96454 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

Nothing blocks: each channel takes the names where it already took the count, and reuses the existing notice seam unchanged.

Notes

  • WhatsApp now calls attachment_for in receive before the fetch-authorization check, where it used to run only inside ingestion. If it ever raises on a malformed descriptor (for example int(desc.file_length)), the message is lost before it is refused. Consider a guard like the one Weixin's attachment_names has against the MIME-guess error.

[DESIGN-REVIEWED] 26562e6

Description read

[DESCRIPTION-READ] 029e33955c7f6e20bb475b8058c3bd622fcbb4be1b4ee8d19bdc0a4e85000c6c

That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 26562e63618cdecc9017cfc2635ef9b0dcb96454 — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 26562e6

Verdict parsed from the review's SHA-scoped output markers for commit 26562e63618cdecc9017cfc2635ef9b0dcb96454.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 26562e63618cdecc9017cfc2635ef9b0dcb96454 false-positive: <reason, 20 to 500 characters>

@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of 26562e63618cdecc9017cfc2635ef9b0dcb96454 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 26562e6

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 26562e63618cdecc9017cfc2635ef9b0dcb96454 false-positive: <reason, 20 to 500 characters>

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Nov 6, 2026
@bolichen97

Copy link
Copy Markdown
Contributor Author

[operator: bolichen97] The four red Backend Tests shards on this head are main's, not this change's:

This PR waits for #31803, then rebases onto main and re-runs.

@bolichen97
bolichen97 force-pushed the fix/8911-rest-dm-attachment-names branch from 28933fd to 21654c4 Compare November 7, 2026 01:52
@bolichen97

Copy link
Copy Markdown
Contributor Author

Rebased: main moved in docs/system-specs/modules/messaging.md, src/kiro_crew/wecom/transport_dispatch.py, test/test_wecom_dispatch.py since this head went green (8dbdf04 -> 678769e); CI re-running.

The rebase was clean and the patch is unchanged. The new base also carries the fixes for the two main reds this head hit: #31803 (pull_request_target allowlist) and #31625 (security package line budget).

[operator: bolichen97]

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Nov 7, 2026
@bolichen97
bolichen97 force-pushed the fix/8911-rest-dm-attachment-names branch from 21654c4 to 2128339 Compare November 7, 2026 05:00
@bolichen97

Copy link
Copy Markdown
Contributor Author

Rebased: main moved in docs/system-specs/modules/messaging.md, test/test_capability_ledger.py since this head went green (678769e -> e4611c5); CI re-running.

The rebase was clean and the patch is unchanged.

[operator: bolichen97]

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention merge conflict Branch has merge conflicts with its base — author must resolve before merge and removed readiness: passed Eligible automated validation passed for the current revision labels Nov 7, 2026
@bolichen97
bolichen97 force-pushed the fix/8911-rest-dm-attachment-names branch from 2128339 to 2a0827a Compare November 7, 2026 08:07
@bolichen97

Copy link
Copy Markdown
Contributor Author

Rebased: main moved in docs/system-specs/modules/messaging.md, src/kiro_crew/whatsapp/transport.py, src/kiro_crew/whatsapp/transport_dispatch.py since this head went green (e4611c5 -> b4089f7); CI re-running.

The rebase had one conflict, in the comment above pending_original in whatsapp/transport.py, which main had shortened. It keeps main's wording and changes only the line naming the tuple's second field; the lines this PR adds and removes are unchanged. The earlier reds on 2128339 were the GitHub API rate limit, not findings.

[operator: bolichen97]

@github-actions github-actions Bot removed the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Nov 7, 2026
@bolichen97

Copy link
Copy Markdown
Contributor Author

[operator: bolichen97] The red Backend Tests shard 2 (Linux and Windows), and the Coverage Gate that follows it, are main's, not this change's: test/test_security_gate_liveness.py::test_the_package_stays_within_its_line_budget fails on main's own tree (the security package is 34,855 lines against a budget of 34,845), and this PR touches no file in that package. #32183 raises the budget; this PR waits for it.

The other reds on this head (the AI review lanes, Sensitive Change Review, Dependency License Gate, Publish readiness signal) are the shared installation token hitting GitHub's rate limit at 08:08Z, not findings. They re-run with the next head.

A message refused at gateway shutdown comes back on the next start as a
restart notice. On WeCom, Weixin and WhatsApp DMs that notice said only
how many attachments were lost, because these channels take the count
before ingestion and handed it on as a bare number.

They now take each attachment's name at the same point, the name the
file is ingested under (the sender's own name, else its kind), so the
notice lists which files to resend. The messaging spec's per-channel
table moves the three channels to "the names"; Slack keeps the count
until its own capture carries names.

Part of #8911
@bolichen97
bolichen97 force-pushed the fix/8911-rest-dm-attachment-names branch from 2a0827a to 26562e6 Compare November 7, 2026 14:47
@bolichen97

Copy link
Copy Markdown
Contributor Author

Rebased: main moved in docs/system-specs/modules/messaging.md and src/kiro_crew/whatsapp/transport.py since this head went green (b4089f7 -> d27a5fd); CI re-running.

The new base carries #32252 and #32209, which fix the two main reds (the security line-budget test on Backend Tests shard 2, Windows shard 2 and Coverage Gate, and the Windows ignore-list test on shard 7). The previous head's GPT lane posted no verdict (the run reached none and its comment lookup failed), so it was not a finding.

This head also fixes one defect a local review found in this PR's own code: weixin.attachments.attachment_names named a file through _describe, whose mimetypes.guess_type raises ValueError on a URL-shaped name such as //[broken]/report.pdf. That call now runs before ingestion's error handling, so the whole message was lost. File names are now read without the MIME guess; test_a_url_shaped_file_name_is_spooled_without_a_mime_guess fails on the previous head and passes here.

Locally on 26562e6: the changed and related tests (356 passed), isort, flake8, mypy, the semgrep diff scan and the flake-pattern ratchet all exit 0; local GPT and Opus reviews returned PASS.

[operator: bolichen97]

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Nov 7, 2026
@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention labels Nov 7, 2026

@KiroCrewCaptain KiroCrewCaptain left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved: PR Readiness passed on 26562e6, and all five review lanes (Opus 5.5, GPT 6.1, Design, UX, First Principles) report no blocking finding on this head. No conflict and no open change request.

@bolichen97
bolichen97 merged commit c5d9bc0 into main Nov 7, 2026
154 of 156 checks passed
@bolichen97
bolichen97 deleted the fix/8911-rest-dm-attachment-names branch November 7, 2026 19:47
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Nov 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants