alibaba/spring-ai-alibaba · error · IllegalStateException

no generator found!

Error message

no generator found!

What it means

AsyncGenerator's internal implementation maintains a stack of embedded generators; next() peeks the top of the stack. If the stack is empty there is no generator to pull from, which is an internal invariant violation, so it throws IllegalStateException('no generator found!').

Solutions

  1. Do not call next() after the generator reported done — check Data.isDone() first
  2. Consume the AsyncGenerator through its public iterator/stream APIs rather than the internal cursor
  3. Ensure each embed/nested generator push is balanced with a pop in your custom extensions
  4. If triggered inside framework code, capture the full stack trace and report with reproduction steps

Example fix

// before
Data<E> d = cursor.next(); // may throw if exhausted
// after
if (!cursor.hasGenerator()) { return; }
Data<E> d = cursor.next();
Defensive patterns

Strategy: try-catch

Validate before calling

if (cursor == null || cursor.noGenerators()) return; // don't pull

Try / catch

try { Data<E> d = cursor.next(); } catch (IllegalStateException e) { if ("no generator found!".equals(e.getMessage())) { /* stop consumption */ } else throw e; }

Prevention

When it happens

Trigger: Calling next() on the AsyncGenerator's internal cursor when no generator was pushed onto generatorsStack — e.g. pulling from the generator after completion or using the cursor API without proper initialization via the enclosing EmbeddingIterator.

Common situations: Custom code reaching into AsyncGenerator internals to drive the cursor manually; double-consumption of an already exhausted async generator stream; library bugs in embedded-generator bookkeeping when embedding nested generators.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


AI-assisted analysis of alibaba/spring-ai-alibaba@f82da0b50f (2026-09-09). Data as JSON: /api/errors/3f21d6e212bcfb4b. Report an issue: GitHub.

Appendix: source

Thrown at spring-ai-alibaba-graph-core/src/main/java/com/alibaba/cloud/ai/graph/async/AsyncGenerator.java:160

				returnValueStack.clear();
			}
		}

		// private AsyncGenerator.WithResult<E> toGeneratorWithResult( AsyncGenerator<E>
		// generator ) {
		// return ( generator instanceof WithResult ) ?
		// (AsyncGenerator.WithResult<E>) generator :
		// new WithResult<>(generator);
		// }

		protected boolean isLastGenerator() {
			return generatorsStack.size() == 1;
		}

		@Override
		public Data<E> next() {
			if (generatorsStack.isEmpty()) { // GUARD
				throw new IllegalStateException("no generator found!");
			}

			final Embed<E> embed = generatorsStack.peek();
			final Data<E> result = embed.generator.next();

			if (result.isDone()) {
				clearPreviousReturnsValuesIfAny();
				returnValueStack.push(result);
				if (embed.onCompletion != null /* && result.resultValue != null */ ) {
					try {
						embed.onCompletion.accept(result.resultValue);
					}
					catch (Exception e) {
						return Data.error(e);
					}
				}
				if (isLastGenerator()) {
					return result;

View on GitHub (pinned to f82da0b50f)