langgenius / langgenius/dify

Annotation reply metadata is stripped from message_end events

Open
#37,000 4 comments 1 reaction 0 assignees View on GitHub
project#dify
Dominant language
TypeScript
Stars
156k
Forks
24.6k
Avg merge
22h 9m
Merged PRs (30d)
610

Description

## Description

When an app response is served by an annotation reply, the backend emits a `message_end` event without the `annotation_reply` metadata. The frontend relies on `messageEnd.metadata.annotation_reply` to recognize annotation-hit responses and clear the responding state.

In chatflow / advanced chat, annotation replies short-circuit the normal workflow execution path. No workflow started or workflow finished events are emitted, so the missing `annotation_reply` metadata leaves the UI in a responding state and the stop response button can remain visible even though no generation task is running.

## Steps to reproduce

1. Create a chatflow / advanced chat app.
2. Enable annotation reply for the app.
3. Add an annotation that matches a test query.
4. Open the web app or preview chat.
5. Send a query that hits the annotation reply.

## Actual behavior

- The annotation answer is returned.
- The `message_end` metadata does not include `annotation_reply`.
- The frontend cannot enter the annotation-reply handling branch.
- The stop response button can remain visible / stuck after the annotation reply.
- The message is not marked with annotation reply metadata such as the annotation author.

## Expected behavior

The `message_end` event should preserve `metadata.annotation_reply`, so the frontend can detect the annotation-hit response, clear the responding state, and display annotation metadata correctly.

## Root cause

The backend currently strips `annotation_reply` in two places:

- `api/core/app/apps/base_app_generate_response_converter.py`
- `api/core/app/apps/advanced_chat/generate_task_pipeline.py`

The first strip affects simple response conversion. The second one affects advanced chat / chatflow before response conversion.

## Verification

I verified locally that preserving `annotation_reply` in both locations fixes the stuck stop-response behavior for annotation replies.

Targeted backend tests pass after the change:

```text
33 passed
```

Test command used:

```bash
pytest -o addopts="" \
tests/unit_tests/core/app/apps/agent_chat/test_agent_chat_generate_response_converter.py \
tests/unit_tests/core/app/apps/completion/test_completion_generate_response_converter.py \
tests/unit_tests/core/app/apps/advanced_chat/test_generate_task_pipeline_core.py -q
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.