Skip to content

[Bug] Group image caption can be overtaken by a following text message #9634

Description

@PeiPei233

Description

When built-in group chat context awareness and image captioning are enabled, a text message sent immediately after an image can overtake the image while its caption is being generated.

The LLM request triggered by the text message then receives no context for the preceding image. If captioning fails, the stored group context also loses the image completely and contains only the sender/timestamp prefix.

Reproduction Steps

  1. Enable built-in group chat context awareness.
  2. Enable group image captioning with a vision provider.
  3. Send an image to a group.
  4. Immediately send a text comment about that image.
  5. Trigger an LLM response from the text message.
  6. Inspect the injected group context.

This is also reproducible without third-party plugins by invoking GroupChatContext.handle_message() concurrently: block the first image caption call, then handle a following plain-text event. The plain-text event completes first on current master.

Expected: the image record is completed before the later text record and is included in the text-triggered LLM request.

Actual: the text record can be appended first and the request contains no image caption.

AstrBot Version

v4.27.2 and master at a9bb8a6

Operating System

Linux

Deployment Method

Docker (soulter/astrbot:latest)

Message Platform Adapter

OneBot v11 (NapCat / aiocqhttp)

Error Log

[Core] [INFO] [core.event_bus]: user: [image]
[Core] [INFO] [core.event_bus]: user: text commenting on the image
[Plug] [DBUG] [astrbot.group_chat_context]: [user]: text commenting on the image
[Core] [DBUG] [agent_sub_stages.internal]: ready to request llm provider
[Plug] [DBUG] [astrbot.group_chat_context]: [user]: [Image: caption completed later]

There is no exception in the successful-caption case. Each event is dispatched in its own task while handle_message() waits for _format_message() before acquiring its per-session lock and appending the record.

On caption failure, the related log is:

[Plug] [ERRO] [astrbot.group_chat_context]: 获取图片描述失败: <provider error>
[Plug] [DBUG] [astrbot.group_chat_context]: [user/time]:

Supplementary Information

The issue is in the built-in GroupChatContext; a direct unit-level reproduction loads no third-party plugins.

Checklist

  • I searched existing issues and PRs. perf(ltm): pre-caption images outside session lock to unblock subsequent messages #7228 discusses a related main-agent/session-lock tradeoff, but it does not modify the built-in GroupChatContext path and was closed without merging.
  • Reproduced directly against the built-in class without loading plugins.
  • This is an AstrBot core issue rather than a plugin issue.
  • I have read and agree to the project's Code of Conduct.
  • I am willing to submit a PR to fix this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:coreThe bug / feature is about astrbot's core, backend

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions