← Back to Pull requests

WIP Codex migration to AsyncIterator + poll_progress #1

Open
oconnor663 opened this pull request with 2921 lines diff across 103 files
View on GitHub
oconnor663 oconnor663 commented on Jul 02, 2026 15:43 UTC
Author

This is a Codex branch for experimenting with poll_progress. This PR is local to my own fork. This will not build on stable or nightly; you need to use this Rust branch. You also need this futures-rs branch checked out next to tokio.

Diff: 2921 lines (+2076 / -845) across 103 files Reviewer: oconnor663 Review duration: 224122m
All Vouch review confidence checks passed
Residual risk 0.26 = Change Risk (0.96) × (1 − Review Confidence (0.73)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.96 · 2921 lines diff across 103 files
0.96
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.68 · 4 substantive comment(s)
0.68
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 50%
72%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.400
Self Review self_review
0.140
Sensitive Paths sensitive_paths
0.096
Mass File Touch mass_file_touch
0.080
Real PR Conversation Timeline
6 items
chatgpt-codex-connector[bot] chatgpt-codex-connector[bot] commented on code on Jul 02, 2026 15:50 UTC
Code Review
tokio-stream/src/stream_ext/chain.rs:1
@@ -19,30 +19,46 @@ pin_project! {
 impl<T, U> Chain<T, U> {
     pub(super) fn new(a: T, b: U) -> Chain<T, U>
     where
-        T: Stream,
-        U: Stream,
+        T: AsyncIterator,
+        U: AsyncIterator,
     {
         Chain { a: Fuse::new(a), b }
     }
 }
 
-impl<T, U> Stream for Chain<T, U>
+impl<T, U> AsyncIterator for Chain<T, U>
 where
-    T: Stream,
-    U: Stream<Item = T::Item>,
+    T: AsyncIterator,
+    U: AsyncIterator<Item = T::Item>,
 {
     type Item = T::Item;
 
-    fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<T::Item>> {
-        use Poll::Ready;
-
+    fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> PollNext<T::Item> {
         let me = self.project();
 
-        if let Some(v) = ready!(me.a.poll_next(cx)) {
-            return Ready(Some(v));
+        match me.a.poll_next(cx) {
+            PollNext::Item(v) => PollNext::Item(v),
+            PollNext::Pending => {
+                let _ = me.b.poll_progress(cx);

<sub><sub>!P2 Badge</sub></sub> Do not poll the chained tail before the head finishes

When the first iterator returns Pending, chain should remain lazy and sequential: the second iterator should not be driven until the first has returned Done. Calling me.b.poll_progress(cx) here lets a tail iterator with side effects or internal buffering run on every poll of a pending head, changing behavior that the previous implementation avoided.

Useful? React with 👍 / 👎.

chatgpt-codex-connector[bot] chatgpt-codex-connector[bot] commented on code on Jul 02, 2026 15:50 UTC
Code Review
tokio-stream/src/stream_ext/timeout.rs:1
@@ -37,35 +41,93 @@ impl<S: Stream> Timeout<S> {
             deadline,
             duration,
             poll_deadline: true,
+            outputs: VecDeque::new(),
+            stream_item_buffered: false,
         }
     }
 }
 
-impl<S: Stream> Stream for Timeout<S> {
+impl<S: AsyncIterator> AsyncIterator for Timeout<S> {
     type Item = Result<S::Item, Elapsed>;
 
-    fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
-        let me = self.project();
+    fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> PollNext<Self::Item> {
+        let mut me = self.project();
 
-        match me.stream.poll_next(cx) {
-            Poll::Ready(v) => {
-                if v.is_some() {
+        if let Some(output) = me.outputs.pop_front() {
+            if output.is_ok() {
+                *me.stream_item_buffered = false;
+            }
+            return PollNext::Item(output);
+        }
+
+        if *me.stream_item_buffered {
+            return PollNext::Pending;
+        }
+
+        match me.stream.as_mut().poll_next(cx) {
+            PollNext::Item(item) => {
+                let next = Instant::now() + *me.duration;
+                me.deadline.reset(next);
+                *me.poll_deadline = true;
+                return PollNext::Item(Ok(item));
+            }
+            PollNext::Pending => {}
+            PollNext::Done => return PollNext::Done,
+        };
+
+        if *me.poll_deadline && !me.stream.is_terminated() {
+            match me.deadline.as_mut().poll(cx) {
+                Poll::Ready(()) => {
+                    *me.poll_deadline = false;
+                    return PollNext::Item(Err(Elapsed::new()));
+                }
+                Poll::Pending => {}
+            }
+        }
+
+        PollNext::Pending
+    }
+
+    fn poll_progress(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<()> {
+        let mut me = self.project();
+        let mut pending = false;
+
+        if *me.stream_item_buffered {
+            if me.stream.as_mut().poll_progress(cx).is_pending() {
+                pending = true;
+            }
+        } else {
+            match me.stream.as_mut().poll_next(cx) {
+                PollNext::Item(item) => {
                     let next = Instant::now() + *me.duration;
-                    me.deadline.reset(next);
+                    me.deadline.as_mut().reset(next);
                     *me.poll_deadline = true;
+                    *me.stream_item_buffered = true;
+                    me.outputs.push_back(Ok(item));
+                    if me.stream.as_mut().poll_progress(cx).is_pending() {
+                        pending = true;
+                    }
                 }
-                return Poll::Ready(v.map(Ok));
+                PollNext::Pending => pending = true,
+                PollNext::Done => {}
             }
-            Poll::Pending => {}
-        };
+        }
 
         if *me.poll_deadline {
-            ready!(me.deadline.poll(cx));
-            *me.poll_deadline = false;
-            return Poll::Ready(Some(Err(Elapsed::new())));
+            match me.deadline.as_mut().poll(cx) {
+                Poll::Ready(()) => {
+                    *me.poll_deadline = false;
+                    me.outputs.push_back(Err(Elapsed::new()));

<sub><sub>!P2 Badge</sub></sub> Stop emitting timeouts after the inner iterator is done

If poll_progress is called when the wrapped iterator has just returned Done and the deadline is ready, this branch still queues an Err(Elapsed), so the next poll_next can yield a timeout after EOF. poll_next already avoids this with !me.stream.is_terminated(), and poll_progress needs the same guard to keep completed streams from producing extra timeout errors.

Useful? React with 👍 / 👎.

chatgpt-codex-connector[bot] chatgpt-codex-connector[bot] commented on Jul 02, 2026 15:50 UTC
Reviewer

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1f866626a6

<details> <summary>ℹ️ About Codex in GitHub</summary>
<br/>

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review

  • Mark a draft as ready

  • Comment "@codex review".
  • If Codex has suggestions, it will comment; otherwise it will react with 👍.

    Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

    </details>

    oconnor663 oconnor663 commented on code on Jul 02, 2026 16:08 UTC
    Code Review
    tokio-stream/src/stream_ext/chain.rs:1
    @@ -19,30 +19,46 @@ pin_project! {
     impl<T, U> Chain<T, U> {
         pub(super) fn new(a: T, b: U) -> Chain<T, U>
         where
    -        T: Stream,
    -        U: Stream,
    +        T: AsyncIterator,
    +        U: AsyncIterator,
         {
             Chain { a: Fuse::new(a), b }
         }
     }
     
    -impl<T, U> Stream for Chain<T, U>
    +impl<T, U> AsyncIterator for Chain<T, U>
     where
    -    T: Stream,
    -    U: Stream<Item = T::Item>,
    +    T: AsyncIterator,
    +    U: AsyncIterator<Item = T::Item>,
     {
         type Item = T::Item;
     
    -    fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<T::Item>> {
    -        use Poll::Ready;
    -
    +    fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> PollNext<T::Item> {
             let me = self.project();
     
    -        if let Some(v) = ready!(me.a.poll_next(cx)) {
    -            return Ready(Some(v));
    +        match me.a.poll_next(cx) {
    +            PollNext::Item(v) => PollNext::Item(v),
    +            PollNext::Pending => {
    +                let _ = me.b.poll_progress(cx);
    oconnor663 oconnor663 commented on code on Jul 02, 2026 16:09 UTC
    Code Review
    tokio-stream/src/stream_ext/timeout.rs:1
    @@ -37,35 +41,93 @@ impl<S: Stream> Timeout<S> {
                 deadline,
                 duration,
                 poll_deadline: true,
    +            outputs: VecDeque::new(),
    +            stream_item_buffered: false,
             }
         }
     }
     
    -impl<S: Stream> Stream for Timeout<S> {
    +impl<S: AsyncIterator> AsyncIterator for Timeout<S> {
         type Item = Result<S::Item, Elapsed>;
     
    -    fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
    -        let me = self.project();
    +    fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> PollNext<Self::Item> {
    +        let mut me = self.project();
     
    -        match me.stream.poll_next(cx) {
    -            Poll::Ready(v) => {
    -                if v.is_some() {
    +        if let Some(output) = me.outputs.pop_front() {
    +            if output.is_ok() {
    +                *me.stream_item_buffered = false;
    +            }
    +            return PollNext::Item(output);
    +        }
    +
    +        if *me.stream_item_buffered {
    +            return PollNext::Pending;
    +        }
    +
    +        match me.stream.as_mut().poll_next(cx) {
    +            PollNext::Item(item) => {
    +                let next = Instant::now() + *me.duration;
    +                me.deadline.reset(next);
    +                *me.poll_deadline = true;
    +                return PollNext::Item(Ok(item));
    +            }
    +            PollNext::Pending => {}
    +            PollNext::Done => return PollNext::Done,
    +        };
    +
    +        if *me.poll_deadline && !me.stream.is_terminated() {
    +            match me.deadline.as_mut().poll(cx) {
    +                Poll::Ready(()) => {
    +                    *me.poll_deadline = false;
    +                    return PollNext::Item(Err(Elapsed::new()));
    +                }
    +                Poll::Pending => {}
    +            }
    +        }
    +
    +        PollNext::Pending
    +    }
    +
    +    fn poll_progress(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<()> {
    +        let mut me = self.project();
    +        let mut pending = false;
    +
    +        if *me.stream_item_buffered {
    +            if me.stream.as_mut().poll_progress(cx).is_pending() {
    +                pending = true;
    +            }
    +        } else {
    +            match me.stream.as_mut().poll_next(cx) {
    +                PollNext::Item(item) => {
                         let next = Instant::now() + *me.duration;
    -                    me.deadline.reset(next);
    +                    me.deadline.as_mut().reset(next);
                         *me.poll_deadline = true;
    +                    *me.stream_item_buffered = true;
    +                    me.outputs.push_back(Ok(item));
    +                    if me.stream.as_mut().poll_progress(cx).is_pending() {
    +                        pending = true;
    +                    }
                     }
    -                return Poll::Ready(v.map(Ok));
    +                PollNext::Pending => pending = true,
    +                PollNext::Done => {}
                 }
    -            Poll::Pending => {}
    -        };
    +        }
     
             if *me.poll_deadline {
    -            ready!(me.deadline.poll(cx));
    -            *me.poll_deadline = false;
    -            return Poll::Ready(Some(Err(Elapsed::new())));
    +            match me.deadline.as_mut().poll(cx) {
    +                Poll::Ready(()) => {
    +                    *me.poll_deadline = false;
    +                    me.outputs.push_back(Err(Elapsed::new()));

    Agreed, good catch.

    Reviewers
    Assignees
    oconnor663 oconnor663
    Labels
    risk: low confidence: 72.6% reviewed sensitive_module
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 96% (HIGH) · Higher = larger blast radius
    96%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 72.6% · Lower = rushed or shallow review
    72.6%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 26.3% · Safe to merge
    26.3%