Skip to content

fix(line): route inbound media to matching caches - #34233

Closed
onebook7285 wants to merge 1 commit into
NousResearch:mainfrom
onebook7285:fix/line-inbound-media-types
Closed

fix(line): route inbound media to matching caches#34233
onebook7285 wants to merge 1 commit into
NousResearch:mainfrom
onebook7285:fix/line-inbound-media-types

Conversation

@onebook7285

Copy link
Copy Markdown

Summary

This PR addresses the inbound media crashes and issues on the LINE Messaging API platform adapter:

  1. MessageType Mapping Fix: Maps LINE inbound message types (image, audio, video, file, sticker, location) to standard gateway MessageType enums instead of forcing MessageType.IMAGE (which does not exist and raised AttributeError: IMAGE).
  2. Non-Image Cache Support: Imports and routes cache storage to the correct type-specific helpers (cache_audio_from_bytes, cache_video_from_bytes, cache_document_from_bytes) based on msg_type instead of writing everything to cache_image_from_bytes (which rejected non-image payloads).
  3. MIME Normalization: Enhances _LineClient.fetch_content() to return the Content-Type header, enabling _download_media to guess correct extensions via mimetypes.guess_extension instead of forcing .bin.
  4. Unit Tests: Adds comprehensive unit/regression tests in tests/gateway/test_line_plugin.py to cover media download/caching and mapping behavior.

@onebook7285
onebook7285 marked this pull request as ready for review May 29, 2026 01:32
@dso2ng

dso2ng commented May 29, 2026

Copy link
Copy Markdown
Contributor

Thanks for working on this. I hit this exact bug from a live LINE image webhook on current main, and this PR matches the root cause.

Sanitized traceback from the gateway log:

ERROR hermes_plugins.line_platform.adapter: LINE: dispatch_event failed
Traceback (most recent call last):
  File "plugins/platforms/line/adapter.py", line 877, in _handle_webhook
  File "plugins/platforms/line/adapter.py", line 910, in _dispatch_event
  File "plugins/platforms/line/adapter.py", line 972, in _handle_message_event
    message_type=MessageType.TEXT if msg_type == "text" else MessageType.IMAGE,
  File ".../enum.py", line 786, in __getattr__
    raise AttributeError(name) from None
AttributeError: IMAGE

I also checked this PR locally in a detached worktree:

git fetch origin pull/34233/head:refs/remotes/pr/34233
git worktree add --detach /tmp/hermes-pr34233-check refs/remotes/pr/34233
cd /tmp/hermes-pr34233-check
python -m pytest tests/gateway/test_line_plugin.py -q
# 81 passed in 1.18s

A merge-tree probe against current origin/main did not report conflicts in my local check. This looks like the right fix direction for the MessageType.IMAGE crash, and the broader media cache routing in this PR is useful beyond the minimal image-only hotfix.

@alt-glitch alt-glitch added type/bug Something isn't working comp/plugins Plugin system and bundled plugins comp/gateway Gateway runner, session dispatch, delivery P3 Low — cosmetic, nice to have labels May 29, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Duplicate of #27142 (same fix: LINE adapter treats all inbound media as image, maps wrong MessageType, routes to wrong cache helper). Also related to #23867.

@onebook7285

onebook7285 commented May 29, 2026

Copy link
Copy Markdown
Author

Thanks for the pointer. I opened this from a live LINE webhook crash on current main and kept it focused on the MessageType.IMAGE failure plus the related cache-helper mismatch for non-image media.

I agree this overlaps with #27142. The main differences here are:

  • includes a sanitized live traceback for the crash
  • covers image/audio/video/file cache routing
  • adds focused LINE adapter tests, currently 81 passing locally
  • is mergeable against current main

If maintainers prefer #27142 as the canonical PR, I’m happy to close this one or help move the tests/evidence there. Otherwise this PR is ready from my side.

@onebook7285
onebook7285 force-pushed the fix/line-inbound-media-types branch from d462bcf to 4fdf7c1 Compare June 6, 2026 02:43
@onebook7285 onebook7285 changed the title fix(line): map inbound media to valid MessageType and support non-image media cache fix(line): route inbound media to matching caches Jun 6, 2026
@onebook7285

Copy link
Copy Markdown
Author

Updated this PR after upstream commit 7309f3bef landed the LINE MessageType mapping fix.

The PR is now narrowed to the remaining inbound media cache issue only:

  • keep upstream's existing _LINE_MESSAGE_TYPES mapping
  • preserve Content-Type from LINE content downloads
  • route image/audio/video/file payloads to the matching cache helpers
  • expose MIME-style media_types for downstream gateway handling
  • keep focused regression tests for media cache routing and MIME extension fallback

So this is no longer intended to duplicate the MessageType.IMAGE crash fix. That part is already fixed on main. This PR now covers the remaining path where non-image LINE payloads were still being passed through cache_image_from_bytes.

Local verification after the rebase/scope reduction:

scripts/run_tests.sh tests/gateway/test_line_plugin.py
# 82 passed, 0 failed

git diff --check upstream/main...HEAD
# pass

@alt-glitch alt-glitch added duplicate This issue or pull request already exists sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages and removed comp/gateway Gateway runner, session dispatch, delivery duplicate This issue or pull request already exists labels Jun 29, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

This was generated by AI during triage.

Correcting an earlier duplicate call. The MessageType.IMAGE crash that #27142 fixed has since merged to main (_LINE_MESSAGE_TYPES mapping is now present), and the author narrowed this PR to the remaining still-broken path: main still imports only cache_image_from_bytes and routes all inbound media through it (adapter.py:1070), so non-image LINE payloads (audio/video/file) are still mis-cached. This PR routes them to the matching cache_audio/video/document_from_bytes helpers + adds Content-Type/MIME extension handling.

Re-classifying as related_to #27142 and #44019 (same LINE cache-routing cluster), not a duplicate. Maintainer pick: #34233 is mergeable against current main with focused tests; #27142's MessageType half is already merged; #44019 also adds outbound media serving.

@GottZ GottZ left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This was generated by AI during triage.

Summary

Two open PRs address the remaining LINE inbound-media defect after the MessageType mapping fix landed on main: both replace the incorrect image-only cache path with typed cache helpers. #34233 additionally preserves Content-Type for MIME-aware extensions and downstream media types, while #35785 preserves LINE file names but includes unrelated author-map churn.

Related pull requests

  • #34233 related — (+116/-12) — preferred consolidation target: Routes image, audio, video, and file payloads to the established typed cache helpers, preserves response Content-Type for extension selection, emits MIME-style media types, and adds focused production-path regressions.
  • #35785 duplicate — (+125/-10) — duplicate core fix with a useful filename detail: After responding to the contributor keep_open review by removing the redundant generic cache API and adding production-path tests, the diff now implements the same typed-helper routing as #34233; its distinct useful behavior is forwarding LINE fileName, while scripts/release.py attribution changes are unrelated to the reported defect.

Duplicates

#34233 and #35785 now substantially duplicate the same LINE inbound image/audio/video/file cache-routing fix and regression coverage.

Suggested consolidation

Merge #34233 as the narrower, MIME-aware consolidation target, preferably carrying over #35785's fileName forwarding and corresponding regression before merge; then close #35785 as superseded. Despite the keep_open review on #35785, the requested salvage has been completed, and the resulting production diff now overlaps #34233 rather than providing an independent fix.

Complex graph

flowchart LR
    classDef open fill:#dbeafe,stroke:#1d4ed8,color:#1e3a8a
    classDef merged fill:#dcfce7,stroke:#15803d,color:#14532d
    classDef closed fill:#e5e7eb,stroke:#6b7280,color:#1f2937
    classDef unverified fill:#f3f4f6,stroke:#9ca3af,color:#374151
    classDef best stroke-width:3px,stroke:#b45309
    classDef target stroke-width:3px,stroke:#4338ca
    subgraph Dup34233 ["PRs duplicating each other"]
        P34233["PR #34233 (open)"]
        P35785["PR #35785 (open)"]
    end
    class P34233 open
    class P35785 open
    class P34233 target
    click P34233 "https://github.com/NousResearch/hermes-agent/pull/34233"
    click P35785 "https://github.com/NousResearch/hermes-agent/pull/35785"
Loading

Graph: solid arrow = fixes / best fix, dashed arrow = partial or unverified (see edge label); boxed group = PRs duplicating each other; amber border = best fix; indigo border = target; gray node = closed or no verify verdict yet (state tag in the node label).

Cross-PR triage: Reviewed 2 pull requests and 0 issues in this complex. Each diff was read against this issue; Assessment working set: 18 kB of PR diffs, 2 kB of issue/PR text, 9 kB of discussion (12 comments), 1 verify verdict. verdicts reflect diff content, not PR titles. Part of an automated triage batch.

@onebook7285

Copy link
Copy Markdown
Author

Closing this PR because its main fixes have now been superseded upstream.

The remaining difference here is Content-Type-based extension inference. I do not currently have a production case that justifies maintaining a separate patch for that narrower improvement, so I am intentionally not carrying that delta forward. If a concrete MIME/extension failure appears, I can submit a focused current-main PR.

Thanks to everyone who reviewed and helped triage this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/plugins Plugin system and bundled plugins P3 Low — cosmetic, nice to have sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants