Skip to content

fix(qqbot): treat inbound attachment content types case-insensitively - #102753

Merged
vincentkoc merged 2 commits into
openclaw:mainfrom
masatohoshino:qqbot-content-type-case-insensitive
Jul 9, 2026
Merged

vincentkoc merged 2 commits into
openclaw:mainfrom
masatohoshino:qqbot-content-type-case-insensitive

Conversation

@masatohoshino

Copy link
Copy Markdown
Contributor

Summary

Prompt request: Make QQ Bot inbound attachment classification treat content types case-insensitively per RFC 2045, while returning the raw content_type values unchanged.

Proof target: Show that mixed-case image and voice content types now classify identically to their lowercase forms (image display, remote-URL fallback on failed download, voice download and transcription routing), and that non-media types are still not promoted.

What Problem This Solves

Fixes an issue where QQ Bot inbound attachments with a mixed-case content_type (such as Image/PNG or Audio/Silk) were silently misclassified. MIME types are case-insensitive per RFC 2045, but the qqbot inbound pipeline compared the raw value against lowercase literals at three sites:

  • extensions/qqbot/src/engine/gateway/inbound-attachments.ts (download-success branch): att.content_type?.startsWith("image/") — a mixed-case image fell out of the image path into a generic [Attachment: ...] note, so the agent never received it as an image.
  • extensions/qqbot/src/engine/gateway/inbound-attachments.ts (download-failure branch): the same comparison — a mixed-case image lost its remote-URL fallback and was reported as a plain failed download.
  • extensions/qqbot/src/engine/utils/audio.ts isVoiceAttachment: content_type === "voice" || startsWith("audio/") — a mixed-case voice attachment (with no rescuing filename extension) skipped the voice download and transcription routing entirely and was treated as a generic file.

The same isVoiceAttachment already lowercases the filename-extension side of its check via normalizeLowercase; the content_type side was the missed half. This is the qqbot sibling of merged #102431, which fixed the same content-type case-sensitivity class in the msteams plugin on the same RFC 2045 reasoning.

Why This Change Was Made

  • Root cause: raw content_type values were compared against lowercase literals, while relay payloads may emit mixed-case MIME types.
  • Fix: normalize with the plugin's existing normalizeLowercaseStringOrEmpty helper at the three comparison sites. Lowercasing is compare-only: the returned fields (contentType, media-type passthrough, filename fallback) keep the raw value, and lowercase inputs keep their existing behavior. MIME types are case-insensitive by spec, so lowercasing the comparison can only add matches, never remove one.
  • The bare voice value in the same check is a QQ-specific content marker rather than a MIME type; it is normalized the same way for the same relay-variability reason.
  • Scope is limited to inbound attachment classification in the qqbot plugin.

User Impact

QQ Bot inbound images with mixed-case content types are now delivered to the agent as images (including the remote-URL fallback when the download fails), and mixed-case voice attachments route through voice download and transcription instead of being treated as generic files. Lowercase content types behave exactly as before.

Evidence

Boundary-capture of the production classification pipeline: node --import tsx drives the real processAttachments (download → classify) and the real isVoiceAttachment, with only the external media fetch replaced by a minimal adapter that performs a real HTTP GET against a local server (real bytes, real file writes through the production downloadFile). Fixtures: mixed-case image with successful download, mixed-case image with failed (404) download, extension-less mixed-case voice attachment, and a mixed-case PDF as negative control.

Before (unmodified base branch):

imageUrls: []
imageMediaTypes: []
voiceAttachmentPaths: []
attachmentInfo:
  [Attachment: <media-dir>/a_<id>.png]              <- Image/PNG demoted to generic note
  [Attachment: missing.jpg] (download failed)        <- Image/JPEG lost its URL fallback
  [Attachment: <media-dir>/voice-message_<id>]      <- Audio/Silk treated as generic file
  [Attachment: <media-dir>/doc_<id>.pdf]

isVoiceAttachment: "voice" -> true, "Voice" -> false, "Audio/Silk" -> false,
                   "audio/amr" -> true, "Image/PNG" -> false

After (this PR):

imageUrls: ["<media-dir>/a_<id>.png", "https://cdn.example.test/missing.jpg"]
imageMediaTypes: ["Image/PNG", "Image/JPEG"]         <- raw casing passes through unchanged
voiceAttachmentPaths: ["<media-dir>/voice-message_<id>"]
voiceTranscripts: ["[Voice message - transcription unavailable because STT is not configured]"]
attachmentInfo:
  [Attachment: <media-dir>/doc_<id>.pdf]            <- PDF negative control stays generic

isVoiceAttachment: "voice" -> true, "Voice" -> true, "Audio/Silk" -> true,
                   "audio/amr" -> true, "Image/PNG" -> false

Real behavior proof

# Field Value
1 Behavior or issue addressed Mixed-case inbound content_type values (Image/PNG, Audio/Silk) were misclassified: images dropped out of the image path (both download-success and URL-fallback branches) and voice attachments skipped voice download and transcription routing.
2 Real environment tested Linux x64, Node 22, commit c28d69c2c8d930c7d5f09395f8448d5e54597fb0
3 Exact steps or command run OPENCLAW_HOME=$(mktemp -d) node --import tsx <proof script> — imports the production processAttachments and isVoiceAttachment, wires the audio-convert port exactly like the production bridge assembly, serves attachment bytes from a local HTTP server through the platform-adapter seam, and prints the resulting classification. Run once against the unmodified base branch and once against this PR's HEAD.
4 Evidence after fix Terminal capture above (After block): mixed-case image classified as image with the raw media type passed through, failed download falls back to the remote URL, extension-less Audio/Silk enters the voice transcription path, Application/PDF stays a generic attachment.
5 Observed result after fix Mixed-case content types classify identically to their lowercase forms; returned content_type values keep their original casing; non-media types are not promoted.
6 What was not tested Live QQ platform traffic with a real mixed-case relay payload (no credentialled QQ bot available); the external CDN fetch was served by a local HTTP server through the plugin's platform-adapter seam. The colocated unit tests cover the same branches directly and are supplemental to the capture above.

Tests and validation

$ node scripts/run-vitest.mjs extensions/qqbot/src/engine/gateway/inbound-attachments.test.ts extensions/qqbot/src/engine/utils/audio.test.ts
 Test Files  2 passed (2)
      Tests  47 passed (47)

New tests cover: mixed-case image classification on the download-success branch (with lowercase regression in the same run and raw passthrough asserted), the remote-URL fallback on the download-failure branch, isVoiceAttachment mixed-case recognition (Voice, Audio/Silk) with a non-audio rejection, and a mixed-case non-image type that must not be promoted.

Risk checklist

  • One concern, one PR — content-type case-insensitivity in qqbot inbound classification only.

  • No config, env, or default surface change.

  • Backward compatible — lowercase inputs produce identical results; comparisons only gain matches, and returned values are unchanged.

  • No new deps, no new helpers (uses the plugin's existing normalize helper).

  • No CHANGELOG edit (per release policy).

  • Tests added.

  • Allow edits by maintainers

@clawsweeper

clawsweeper Bot commented Jul 9, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed July 9, 2026, 7:56 AM ET / 11:56 UTC.

Summary
The PR lowercases QQ Bot inbound attachment content-type comparisons for image and voice classification while preserving raw content_type values, and adds targeted regression tests.

PR surface: Source +11, Tests +58. Total +69 across 4 files.

Reproducibility: yes. Current main and the latest release compare raw QQ content_type strings against lowercase image/audio literals, so mixed-case Image/PNG and Audio/Silk miss those branches by source inspection.

Review metrics: none identified.

Merge readiness
Overall: 🐚 platinum hermit
Proof: 🐚 platinum hermit
Patch quality: 🐚 platinum hermit
Result: ready for maintainer review.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • none.

Next step before merge

  • No repair job is needed; the PR has no concrete code findings and only needs normal maintainer review and merge gating.

Security
Cleared: The diff only changes QQ Bot attachment classification comparisons and tests; it does not touch dependencies, workflows, secrets, auth, or executable supply-chain surfaces.

Review details

Best possible solution:

Merge this focused QQ Bot plugin fix after routine exact-head checks, keeping raw content_type passthrough while normalizing only comparisons.

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

Yes. Current main and the latest release compare raw QQ content_type strings against lowercase image/audio literals, so mixed-case Image/PNG and Audio/Silk miss those branches by source inspection.

Is this the best way to solve the issue?

Yes. Compare-only lowercasing at the two image branches and the voice detector is the narrowest maintainable fix; broader MIME plumbing or raw payload mutation would be less targeted.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 8d6c54f51313.

Label changes

Label changes:

  • add P2: This is a normal-priority QQ Bot inbound media bug fix with limited channel-specific blast radius.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes before/after copied terminal output from a runtime script that imports the production classification path with local HTTP-served attachments, and the PR proof workflow succeeded.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.

Label justifications:

  • P2: This is a normal-priority QQ Bot inbound media bug fix with limited channel-specific blast radius.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes before/after copied terminal output from a runtime script that imports the production classification path with local HTTP-served attachments, and the PR proof workflow succeeded.
Evidence reviewed

PR surface:

Source +11, Tests +58. Total +69 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 2 15 4 +11
Tests 2 58 0 +58
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 73 4 +69

What I checked:

Likely related people:

  • cxyhhhhh: Path history shows the QQ Bot inbound pipeline, audio adapter wiring, and attachment processing were added or heavily refactored in the merged QQ Bot architecture work. (role: introduced behavior; confidence: high; commits: 5e72e39c1852, 5ccf179a34a9; files: extensions/qqbot/src/engine/gateway/inbound-attachments.ts, extensions/qqbot/src/engine/gateway/inbound-pipeline.ts, extensions/qqbot/src/engine/utils/audio.ts)
  • vincentkoc: Recent commit history for inbound-attachments.ts shows a QQ inbound attachment preview fix shortly before this PR. (role: recent area contributor; confidence: medium; commits: ccbd9eb28dfb; files: extensions/qqbot/src/engine/gateway/inbound-attachments.ts)
  • sliverp: CONTRIBUTING.md lists Sliverp for Chinese channels including QQ, and the main QQ Bot architecture commits include Sliverp as a co-author. (role: adjacent owner; confidence: medium; commits: 5e72e39c1852, 5ccf179a34a9; files: extensions/qqbot/src/engine/gateway/inbound-attachments.ts, extensions/qqbot/src/engine/utils/audio.ts)
  • steipete: History for the touched QQ Bot files shows recent lint and helper-export refactors around this area. (role: recent refactor contributor; confidence: medium; commits: 6868cde4d45f, 0ce0509856d9, a607661a71d8; files: extensions/qqbot/src/engine/gateway/inbound-attachments.ts, extensions/qqbot/src/engine/utils/audio.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

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.

How this review workflow works
  • 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 steipete self-assigned this Jul 9, 2026
@vincentkoc vincentkoc self-assigned this Jul 9, 2026
@vincentkoc

Copy link
Copy Markdown
Member

Land-ready review complete. Verified the full QQBot inbound attachment path, quote replay caller, normalization helper, sibling classifiers, current main, and RFC 2045 media-type matching. Fresh Codex autoreview was clean (0.86 confidence). Exact head c28d69c has 58 successful hosted checks with no failures or pending checks. Sanitized direct AWS Crabbox provider=aws lease=cbx_26d6df347069 run=run_ad0d0ec62efb ran pnpm test extensions/qqbot/src/engine/gateway/inbound-attachments.test.ts extensions/qqbot/src/engine/utils/audio.test.ts: 2 files, 47 tests passed. The lease was public-only, had no Tailscale state, and is released. Known gap: no credentialed live QQ payload; deterministic production-path classification proof is sufficient for this compare-only fix.

@vincentkoc
vincentkoc merged commit a49567c into openclaw:main Jul 9, 2026
104 of 106 checks passed
@vincentkoc

Copy link
Copy Markdown
Member

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 10, 2026
…openclaw#102753)

* fix(qqbot): treat inbound attachment content types case-insensitively

* test(qqbot): use distinct download paths per image; note voice sentinel in comment
RomneyDa pushed a commit that referenced this pull request Aug 30, 2026
…#102753)

* fix(qqbot): treat inbound attachment content types case-insensitively

* test(qqbot): use distinct download paths per image; note voice sentinel in comment

(cherry picked from commit a49567c)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants