Skip to content

fix(agent): retrieve failed prefetch when closing an event stream - #46513

Merged
BeautyyuYanli merged 1 commit into
langgenius:mainfrom
Wang-Zephyr:fix/agent-stream-close-prefetch
Nov 17, 2026
Merged

BeautyyuYanli merged 1 commit into
langgenius:mainfrom
Wang-Zephyr:fix/agent-stream-close-prefetch

Conversation

@Wang-Zephyr

Copy link
Copy Markdown
Contributor

Fixes #46512

Summary

When a Dify Agent event stream is closed, retrieve any exception from its finished read-ahead task. Pending reads still follow the existing cancel-and-await path. A consumer that keeps reading still receives source errors, including after a buffered text flush.

Verification

  • At 7688f7c9b1b4, the new test reproduces the event-loop warning Task exception was never retrieved. With the fix, the same test closes quietly.

  • uv run --no-sync pytest -q tests/local/dify_agent/runtime/test_event_coalescer.py tests/local/dify_agent/runtime/test_runner.py passed all 31 tests with the locked server dependencies. No external service was used.

  • Ruff format and lint passed for both changed files. Targeted Pyrefly reported 0 errors.

Checklist

  • Linked the issue and verified the regression against the base and fix.

From Codex

@github-actions github-actions Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Nov 16, 2026

@BeautyyuYanli BeautyyuYanli left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

(This message is automated while I'm responsible for it.)

Verified the coalesce_agent_stream_events teardown fix and regression test against #46512: completed non-cancelled read-ahead exceptions are retrieved cleanly on early aclose() without affecting pending read-ahead cancellation or normal anext() error propagation. No additional changes were needed.

@BeautyyuYanli
BeautyyuYanli added this pull request to the merge queue Nov 17, 2026
Merged via the queue into langgenius:main with commit 61682d5 Nov 17, 2026
38 checks passed
@wylswz wylswz mentioned this pull request Nov 17, 2026
1 task done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Agent stream close leaves a failed read-ahead task unhandled

2 participants