Skip to content

fix(gix): report cancellation and omit outcome when status::Iter is interrupted - #3242

Open
BHARATH CHANDRA VADDARAM (bharathvbcr) wants to merge 1 commit into
GitoxideLabs:mainfrom
bharathvbcr:fix/status-iter-interrupt
Open

BHARATH CHANDRA VADDARAM (bharathvbcr) wants to merge 1 commit into
GitoxideLabs:mainfrom
bharathvbcr:fix/status-iter-interrupt

Conversation

@bharathvbcr

Copy link
Copy Markdown

Note: This pull request was authored and locally tested by an AI coding assistant acting at @bharathvbcr's request. I am speaking only for my own analysis and the local checks listed below, and make no claim that @bharathvbcr has personally reviewed or tested this code.

Motivation

Discovered while integrating gix::Repository::status() into GitPulse (a desktop Git client replacing spawned git status processes with in-process gix status, wired with per-request cancellation and timeouts). On a dirty repository, interrupting status::Iter via should_interrupt_owned / should_interrupt_shared could silently terminate iteration with None and even populate Iter::into_outcome() with Some(Outcome), making a cancelled or timed-out status scan indistinguishable from a clean working tree unless callers re-checked their own interrupt flag afterward.

Problem

In gix/src/status/iter/mod.rs:

  1. parallel feature (Iterator for Iter):
    • On RecvTimeoutError::Timeout, when self.should_interrupt.load(Ordering::SeqCst) is true, next() returned None instead of yielding Some(Err(cancelled("Interrupted").raise())), and left self.rx_and_join set so subsequent next() calls would keep polling/detaching instead of staying terminated.
    • Before entering rx.recv_timeout(...), should_interrupt was not checked.
    • On RecvTimeoutError::Disconnected, especially when the directory walk is disabled (UntrackedFiles::None) and the producer finishes with Ok(out) quickly after interruption, next() stored self.out = Some(out) and returned None even though should_interrupt was set — contradicting Iter::into_outcome()'s doc comment ("None on error or if the iteration isn't complete").
  2. not(feature = "parallel") (Platform::into_iter):
    • Did not check should_interrupt before starting or after index_worktree_status(...) returned, so an interrupted serial status run populated iter.out = Some(out) and returned Ok(iter) with potentially partial results.

Changes

  • gix/src/status/iter/mod.rs:
    • Check should_interrupt.load(Ordering::SeqCst) at the start of each next() poll (clearing rx_and_join), on RecvTimeoutError::Timeout (clearing rx_and_join), and before setting self.out on RecvTimeoutError::Disconnected, yielding Some(Err(cancelled("Interrupted").raise())) without populating self.out.
    • Check should_interrupt.load(Ordering::SeqCst) before starting and after index_worktree_status(...) in the non-parallel path, returning Err(cancelled("Interrupted").raise()).
  • gix/src/status/platform.rs:
    • Clarify in should_interrupt_shared / should_interrupt_owned docs that interruption stops iteration with a cancellation error and leaves Iter::into_outcome() empty.
  • gix/tests/gix/status.rs:
    • Add regression tests covering UntrackedFiles::None pre-interruption, UntrackedFiles::Files pre-interruption, and mid-iteration interruption across parallel and non-parallel configurations.

Verification

All commands below were run in the shallow fork checkout on macOS after the final edit:

  • cargo fmt -p gix -- --check (passed)
  • cargo clippy -p gix --tests --features status,parallel -- -D warnings (passed)
  • cargo clippy -p gix --lib --no-default-features --features status,sha1 -- -D warnings (passed)
  • cargo test -p gix --features status,parallel -- status (48 passed, 0 failed)
  • cargo test -p gix --no-default-features --features status,sha1 -- status (46 passed, 0 failed)
  • cargo test -p gitoxide-core -- status (compiled and ran with 0 failures; status submodule filters 0 unit tests)

…nterrupted

Ensure interrupted gix::status::Iter emits Err(cancelled("Interrupted")) in both parallel and non-parallel paths and leaves Iter::into_outcome() empty instead of silently ending iteration with None or returning a partial Outcome. Update docstrings on should_interrupt_shared and should_interrupt_owned and add regression tests.

Assisted-by: Antigravity
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-24T17:15:33.219519Z d822886 PR opened
ℹ️ About Codex in GitHub

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

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@Byron

Byron commented Nov 24, 2026

Copy link
Copy Markdown
Member

This is by design. I will improve the docs instead to make clear this is a feature.

Turns out that if the dirwalk gets interrupted, it just aborts, which will trickle up to the caller. Of course, that could be fixed, but it feels more straightforward to just abort on interrupts.

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.

parallel_iter_drop toggles and immediately resets caller-provided should_interrupt without joining detached threads

2 participants