Skip to main content

resolve_prompt_and_check_idle

Function resolve_prompt_and_check_idle 

Source
fn resolve_prompt_and_check_idle(
    outstanding: &mut HashSet<u64>,
    resolved_id: u64,
) -> bool
Expand description

Remove resolved_id from the set of outstanding (sent, not yet resolved) prompts and report whether the set is now EMPTY — i.e. whether every prompt sent so far has now been resolved, by either a real stopReason completion or a JSON-RPC error rejection, meaning the turn has genuinely ended. Extracted as a pure function over a plain HashSet so this exact logic is directly unit-testable; call sites wrap it with the shared mutex around the real outstanding_prompt_ids.

Tracking every outstanding prompt — not just “the latest” — is what makes response ORDERING irrelevant: “is the turn over” only ever asks “is anything still outstanding,” never “was this the most recent one.” codex P2 on PR #2338 (thirtieth re-review) — superseded the twenty-seventh through twenty-ninth re-reviews’ single latest/ previous-id tracking (is_latest_prompt_completion + rollback_latest_prompt_id_if_unchanged, both removed), which could permanently strand turn_active at true: a steering prompt’s rejection arriving AFTER the earlier prompt’s completion had already been consumed (and discarded as “not the latest”) rolled latest_prompt_id back to a prompt whose own completion would never arrive again — nothing left to ever satisfy the match.