Skip to content

agent: Fix panic caused by polling ended stream#46839

Merged
rtfeldman merged 1 commit intozed-industries:mainfrom
tidely:agent-thread-fuse-fix
Jan 15, 2026
Merged

agent: Fix panic caused by polling ended stream#46839
rtfeldman merged 1 commit intozed-industries:mainfrom
tidely:agent-thread-fuse-fix

Conversation

@tidely
Copy link
Contributor

@tidely tidely commented Jan 14, 2026

Closes #ISSUE

Reproduction steps:

  • Zed main branch
  • Use Ollama (likely provider agnostic) in the agent panel with the following prompt: "Explore the codebase with subagents"
  • Panic
thread 'main' (36268) panicked at C:\Users\username\.cargo\registry\src\index.crates.io-1949cf8c6b5b557f\futures-util-0.3.31\src\stream\unfold.rs:108:21:
Unfold must not be polled after it returned `Poll::Ready(None)`

Following the stack trace we get to Thread::run_turn_internal. I believe the panic happens in the following code which was introduced in #46802

// Collect all immediately available events to process as a batch
let mut batch = vec![first_event];
while let Some(event) = events.next().now_or_never().flatten() {
    batch.push(event);
}

Both Options get flattened, however the inner Option represents the end of the stream, after which polling the stream using .next() will result in a panic.

We could fix the logic in this particular spot, but I believe the simpler solution is to .fuse() the stream, which stops the stream from panic'ing even after it has ended. This also prevents misuse in the future.

The panic was introduces on main and did not land on a release yet, so no release notes.

Release Notes:

  • N/A or Added/Fixed/Improved ...

@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Jan 14, 2026
@github-actions github-actions bot added the community champion Issues filed by our amazing community champions! 🫶 label Jan 14, 2026
@tidely tidely changed the title agent: Fix panic when polling ended stream agent: Fix panic caused by polling ended stream Jan 14, 2026
@SomeoneToIgnore SomeoneToIgnore added the area:ai Improvement related to Agent Panel, Edit Prediction, Copilot, or other AI features label Jan 15, 2026
Copy link
Contributor

@rtfeldman rtfeldman left a comment

Choose a reason for hiding this comment

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

Thanks @tidely, nice catch and nice fix! 🎉

@rtfeldman rtfeldman merged commit 20163f1 into zed-industries:main Jan 15, 2026
37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:ai Improvement related to Agent Panel, Edit Prediction, Copilot, or other AI features cla-signed The user has signed the Contributor License Agreement community champion Issues filed by our amazing community champions! 🫶

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants