Skip to content

[Bug]: Telegram group photos sent without an @mention are dropped (observed-context content stringified) #47415

Description

@gitsacha

Bug Description

In a Telegram group chat, a photo sent without an explicit bot @mention never reaches the model. The agent acts as if no attachment arrived — it repeatedly asks the user to "re-send the attachment," guesses from stale cache, or claims nothing came through. The same image works when (a) re-sent as a PDF document, or (b) sent with an @bot mention in the same message.

Root cause is in the observed-group-context assembly in gateway/run.py: observed message content is coerced with str(content), which mangles a multimodal parts list (text + image_url) into a Python repr string. The actual image is lost and the context prefix is polluted with {'type': 'image_url', ...} noise.

This is not a download/routing failure — the gateway logs Image routing: native … attached inline and the file is cached. It is corrupted at history assembly, and only for observed (unmentioned) group turns.

Steps to Reproduce

  1. Telegram group with the bot, observe_unmentioned_group_messages enabled (observed-context prompt active).
  2. Send a photo to the group without mentioning the bot.
  3. Later/again, prompt the bot (e.g. @bot what was in that image?).
  4. The model has no usable image; it asks for a re-send.
  5. Re-send the same image with @bot in the message → works (native inline path, bypasses the observed accumulator).

Expected Behavior

An observed group photo should be represented in the replayed context as text (e.g. its caption plus an [image attachment] placeholder) — never as a stringified Python dict. The observed-context prefix is text-only by design (_wrap_current_message_with_observed_context), so multimodal content must be flattened to text rather than str()-ed.

Actual Behavior

observed_group_context.append(str(content).strip()) turns a multimodal list:

[{"type": "text", "text": "[Alice|111] here's the desk sheet"},
 {"type": "image_url", "image_url": {"url": "data:image/png;base64,..."}}]

into the literal string "[{'type': 'text', 'text': '...'}, {'type': 'image_url', 'image_url': {'url': 'data:image/png;base64,...'}}]", which is then prepended as the observed-context prefix. The image content is unusable and the prefix is polluted.

Affected Component

  • Gateway (Telegram/Discord/Slack/WhatsApp)

Messaging Platform (if gateway-related)

  • Telegram

Debug Report

Not run intentionally — this was diagnosed on a production deployment, and hermes debug share would upload that instance's config/secrets/logs to a public paste service. Inline evidence below instead.

# gateway.log (per photo send) — image WAS routed:
Image routing: native (model supports vision). 1 image(s) will be attached inline.

# agent.log turn_context — but the turn is observed-only:
msg='[1 image] [Observed Telegram group context - context only, not requests] [Alice|...'

# images present on disk (download succeeded), e.g. /opt/data/image_cache/img_*.jpg

# code: gateway/run.py, _build_gateway_agent_history
content = msg.get("content")
if separate_observed_context and msg.get("observed") and role == "user" and content:
    observed_group_context.append(str(content).strip())   # <-- str() on a multimodal list
    continue

Operating System

Debian GNU/Linux 13 (trixie) — official nousresearch/hermes-agent container

Python Version

3.13.5

Hermes Version

0.16.0 (main; container image built 2026-06-15, revision 5f6be7f)

Root Cause Analysis (optional)

gateway/run.py → _build_gateway_agent_history: the observed-context branch does observed_group_context.append(str(content).strip()). For text messages str(str) is a no-op, so the bug only surfaces once content is a multimodal list (photo). The accumulated observed_group_context is later joined and replayed as a text prefix via _wrap_current_message_with_observed_context, so the image cannot survive there regardless — it must be flattened to text deliberately.

Proposed Fix (optional)

Add a helper that renders observed content as plain text — keep text parts, replace image_url/other parts with a short placeholder ([image attachment]) — and call it instead of str(content). PR attached.

Are you willing to submit a PR for this?

  • I'd like to fix this myself and submit a PR

Activity

  1. added
    type/bugSomething isn't working
    P2Medium — degraded but workaround exists
    comp/gatewayGateway runner, session dispatch, delivery
    on Jun 16, 2026
  2. gitsacha commented on Jul 17, 2026

    @gitsacha
    Author

    Correcting my own root-cause analysis — the symptom is real, the mechanism I described is not.

    I claimed observed content is a multimodal parts list mangled by str(). It is not. Verified on current main by driving _handle_media_message with an unmentioned group photo — the persisted content is a plain str carrying a cached-path note:

    "[Alice Example|111]\nVeja esta foto\n\n[image 'observed.png' saved at: /tmp/img_probe.png]"
    

    The real asymmetry: _cache_observed_media() caches the image and appends [image '...' saved at: <path>] to the observed text, but the image is never attached inline. The @mention path dispatches the event with media_urls and the model receives the image natively; the observed path only ever replays a text note. That is why re-sending with @bot works.

    So the fix is not flattening (see #47416, which I have closed as a no-op). Leaving this open with an accurate diagnosis for maintainer triage.

    thanks!

  3. GottZ commented on Aug 3, 2026

    @GottZ

    This was generated by AI during triage.

    Summary

    Four PRs address or reference #47415. #47416, #47427, and #47584 flatten hypothetical list-shaped observed content, but the corrected diagnosis shows that Telegram persists observed photos as plain text; #73661 instead targets the actual loss of image metadata between observation and the next addressed turn.

    Related pull requests

    Duplicates

    #47427 and #47584 are substantive duplicates of #47416: all three replace the observed-context str(content) call with text-flattening helpers, but none addresses the corrected media-persistence asymmetry. #73661 supersedes that approach rather than duplicating it.

    Suggested consolidation

    Keep #73661 open with a salvage path as the best existing fix: preserve its structural observed-media persistence, bounded native-image collection, queued observed-tail reload, and normal/queued regression coverage, then validate those paths against current main before further disposition. Keep #47416 closed despite its earlier keep_open review because the producer-path probe invalidated its premise; keep #47427 and #47584 closed as duplicates of #47416.

    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
        I47415(["issue #47415 (open)"])
        P73661["PR #73661 (open)"]
        subgraph Dup47416 ["PRs duplicating each other"]
            P47416["PR #47416 (closed)"]
            P47427["PR #47427 (closed)"]
            P47584["PR #47584 (closed)"]
        end
        P73661 -->|best fix| I47415
        class I47415 open
        class I47415 target
        class P47416 closed
        class P47427 closed
        class P47584 closed
        class P73661 open
        class P73661 best
        click I47415 "https://github.com/NousResearch/hermes-agent/issues/47415"
        click P47416 "https://github.com/NousResearch/hermes-agent/pull/47416"
        click P47427 "https://github.com/NousResearch/hermes-agent/pull/47427"
        click P47584 "https://github.com/NousResearch/hermes-agent/pull/47584"
        click P73661 "https://github.com/NousResearch/hermes-agent/pull/73661"
    
    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 (state tag in the node label).

    Cross-PR triage: Reviewed 4 pull requests and 1 issue in this complex. Each diff was read against this issue; Assessment working set: 36 kB of PR diffs, 16 kB of issue/PR text, 7 kB of discussion (10 comments), 3 verify verdicts. verdicts reflect diff content, not PR titles. Part of an automated triage batch.

  4. added a commit that references this issue on Oct 19, 2026
    a1ab58d
  5. added a commit that references this issue on Nov 10, 2026
    ab9bdce
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Medium — degraded but workaround existscomp/gatewayGateway runner, session dispatch, deliveryplatform/telegramTelegram bot adaptertype/bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions