Agent client can reconnect forever on stale SSE events

Open
#46,975 1 comment 1 reaction 0 assignees View on GitHub

Maintainers usually reply within 1 day

@shaojian0514 is already working on this.

Since Nov 23, 2026.

  • #46976 by @shaojian0514 — open

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
38/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
python, redis
Domain
api, backend

Research direction

Start by reading the reconnect loop in the agent SSE client that backs stream_events and stream_events_sync, and the point where the reconnect budget and the existing reconnect-exhausted error are handled. Compare the incoming event id against the stored resume cursor, treating Redis Stream ids numerically with a fallback for nonstandard ids, and make the budget reset only when the cursor advances. Done means a test where every reconnect replays the same id ends in the reconnect-exhausted error with no duplicate progress, while id-less events still pass through. Note a pull request (#46976) is already open against this.

Written by the indexing model from the issue text.

Description

Description

The Dify Agent SSE client resets its reconnect budget whenever it receives any event. A misbehaving or stale upstream can replay the same event ID after every reconnect, causing the client to move no further while repeatedly restoring the budget and yielding duplicate progress.

Steps to reproduce

  1. Start stream_events or stream_events_sync with reconnects enabled.
  2. Let the first connection deliver a numbered event and disconnect.
  3. Have every subsequent connection replay the same event ID and disconnect again.

Current behavior

Each replayed event resets the reconnect counter, so a finite max_reconnects value may never be exhausted. The duplicate event is also delivered repeatedly.

Expected behavior

Only an event that advances the resume cursor should restore the reconnect budget. Duplicate or older numbered events should be ignored, and repeated stale reconnects should eventually raise the existing reconnect-exhausted error. Events without an ID should remain deliverable for compatibility but should not count as cursor progress.

Proposed change

Compare canonical Redis Stream IDs numerically, use a backward-compatible fallback for nonstandard IDs, and apply the same cursor-progress rule to synchronous and asynchronous streaming clients.

Dominant language
Python
Stars
162k
Forks
25.6k
Avg merge
15h 9m
Merged PRs (30d)
606

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from langgenius/dify

All issues in langgenius/dify

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.