Skip to content

[type:fix] avoid retrying partial AI streams - #7205

Merged
Aias00 merged 2 commits into
apache:masterfrom
dengliming:fix-6647-disable-midstream-ai-retry
Sep 24, 2026
Merged

Aias00 merged 2 commits into
apache:masterfrom
dengliming:fix-6647-disable-midstream-ai-retry

Conversation

@dengliming

Copy link
Copy Markdown
Member

Fixes #6647.\n\nTrack whether the main stream has emitted a chunk and allow retry/fallback only before the first emission. Mid-stream failures now propagate to the client instead of replaying or mixing content.\n\nTests: ./mvnw -q -pl shenyu-plugin/shenyu-plugin-ai/shenyu-plugin-ai-proxy -am -DskipTests=false -Dcheckstyle.skip=false -Dtest=AiProxyExecutorServiceTest -DfailIfNoTests=false test

@Aias00 Aias00 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.

Correct and important fix. Before this change, a stream that emitted some chunks and then failed was retried from scratch and, worse, onErrorResume replayed the whole request through the fallback provider — so the client received duplicated/overlapping content. Gating both retryWhen and onErrorResume on "nothing has been emitted yet" is exactly the right predicate.

Implementation notes I verified:

  • Flux.defer gives each subscription its own AtomicBoolean, so concurrent subscribers don't share state. Good.
  • retryWhen sits inside the defer, so a retry re-subscribes to the captured chatCompletionStream source but reuses the same emitted flag — which is precisely what makes "emitted once → never retry" hold across attempts.
  • emitted is only flipped in doOnNext, so a failure before the first chunk still falls back as intended (the existing testExecuteDirectStreamFallbackSuccess covers that).

The new test (Flux.concat(just(chunk), error(...))) asserts both properties directly: the error propagates and the fallback is never invoked. One non-blocking thought: a doOnCancel/doOnTerminate hook isn't needed here, but if a future change adds buffering, the "emitted" flag would need to move to "committed to the client" — worth a short comment on the field for the next reader.

@Aias00
Aias00 merged commit 41dee74 into apache:master Sep 24, 2026
22 checks passed
eye-gu pushed a commit to eye-gu/shenyu that referenced this pull request Sep 30, 2026
@Aias00 Aias00 added this to the 2.7.2 milestone Nov 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] AiProxy stream retry replays the whole upstream, duplicating SSE content

2 participants