← Back to Pull requests

switch from `IntoRawFd` to `Into<OwnedFd>` (take two) #123

Merged
oconnor663 merged 2 files (52 lines) on Sep 20, 2026 19:00 UTC
View on GitHub
oconnor663 oconnor663 commented on Sep 20, 2026 17:33 UTC
Author

Previously I made but then reverted this change, because it breaks
callers who pass in RawFd. That's both a bug and a feature: you can
get a RawFd from .as_raw_fd() without having ownership of a File.
That makes this change both a bugfix and a compatibility break. That
said, Codex couldn't find any public callers that would actually break:
https://github.com/oconnor663/duct.rs/pull/123#issuecomment-5751618415

Diff: 52 lines (+17 / -35) across 2 files Reviewer: oconnor663 Review duration: 86m
All Vouch review confidence checks passed
Residual risk 0.07 = Change Risk (0.42) × (1 − Review Confidence (0.83)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.42 · 52 lines diff across 2 files
0.42
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.90 · 5 substantive comment(s)
0.90
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 50%
83%
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.238
Self Review self_review
0.140
Real PR Conversation Timeline
8 items
chatgpt-codex-connector[bot] chatgpt-codex-connector[bot] commented on Sep 20, 2026 17:34 UTC
Bot

<!-- codex-pull-request-review-summary -->

Codex Review Summary

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

| Review | Status | Commit | Review trigger |
| --- | --- | --- | --- |
| 📝 Code Review | ✅ Completed <relative-time datetime="2026-09-20T17:35:42.734905Z">2026-09-20T17:35:42.734905Z</relative-time> | 1103af5 | PR opened |

<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" or "@codex security review".
  • Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

    </details>

    chatgpt-codex-connector[bot] chatgpt-codex-connector[bot] commented on code on Sep 20, 2026 17:35 UTC
    Code Review
    src/lib.rs:1
    @@ -458,8 +453,8 @@ impl Expression {
         /// # }
         /// # }
         /// ```
    -    pub fn stdin_file<T: IntoRawFdOrHandle>(&self, file: T) -> Expression {
    -        Self::new(Io(StdinFile(owned_from_raw(file)), self.clone()))
    +    pub fn stdin_file<T: Into<OwnedFdOrHandle>>(&self, file: T) -> Expression {
    +        Self::new(Io(StdinFile(file.into()), self.clone()))

    <sub><sub>!P1 Badge</sub></sub> Preserve raw descriptor support in redirection APIs

    For callers passing a Unix RawFd, Windows RawHandle, or another type that only implements IntoRawFd/IntoRawHandle, this new bound no longer compiles because those types do not necessarily implement Into<OwnedFd>/Into<OwnedHandle>. This breaks the existing public contract of stdin_file, stdout_file, and stderr_file for downstream users in a non-major release; retain a compatible conversion path or defer the API change to a major version.

    Useful? React with 👍 / 👎.

    chatgpt-codex-connector[bot] chatgpt-codex-connector[bot] commented on Sep 20, 2026 17:35 UTC
    Reviewer

    💡 Codex Review

    Here are some automated review suggestions for this pull request.

    Reviewed commit: 1103af5632

    <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 Sep 20, 2026 17:36 UTC
    Code Review
    src/lib.rs:1
    @@ -458,8 +453,8 @@ impl Expression {
         /// # }
         /// # }
         /// ```
    -    pub fn stdin_file<T: IntoRawFdOrHandle>(&self, file: T) -> Expression {
    -        Self::new(Io(StdinFile(owned_from_raw(file)), self.clone()))
    +    pub fn stdin_file<T: Into<OwnedFdOrHandle>>(&self, file: T) -> Expression {
    +        Self::new(Io(StdinFile(file.into()), self.clone()))

    yeah that's the whole point

    oconnor663 oconnor663 commented on Sep 20, 2026 18:04 UTC
    Author

    Note: This comment was written and posted by Codex on behalf of @oconnor663.

    crates.io compatibility audit

    Bottom line: at the caller-source level, I found no published, unyanked crate that can automatically resolve a prospective duct 1.1.3 and has an active call broken by this PR. (There is one direct dependency-floor cleanup I recommend on the branch, noted below.)

    Coverage

  • I used the official 2026-09-20 crates.io database dump plus the live sparse index, rather than relying only on the reverse-dependencies API. I selected every release whose Cargo requirement admits duct 1.1.3, downloaded every archive, and scanned all text files (including tests, examples, build scripts, and cfg-gated modules) for stdin_file, stdout_file, and stderr_file. I also checked likely macro-generated spellings.

  • That covered 1,646 unique unyanked releases across 106 crate names, plus all 25 yanked releases with an upgrade-reachable requirement. The ordinary API exposed 244 stable-first rows overall; additionally, 200 upgrade-reachable releases belonged to 11 crate names absent from that API entirely.

  • After excluding false positives such as xx documentation for an unrelated API, the scan found 410 actual duct call expressions across 87 published releases, all belonging to five crate families. They pass only:

  • - std::fs::File (pitchfork-cli), or
    - os_pipe::PipeReader / PipeWriter (cargo-mobile2, tauri-cli, tessera-mobile, and verctl).
  • I ran Linux cargo check on the relevant targets of the current releases of all five using the code from this PR's exact commit (1103af5632d37e028b51248b770053445bfc3680): cargo-mobile2 0.22.5, pitchfork-cli 2.27.0, tauri-cli 2.11.5, tessera-mobile 0.0.0, and verctl 0.3.1. All passed. (For pitchfork-cli's ^1.1.2 constraint, I locally labeled the same code 1.1.3.) Separate focused probes with File, PipeReader, and PipeWriter passed for both x86_64-unknown-linux-gnu and x86_64-pc-windows-gnu.
  • This cannot say anything about private, unpublished, or git-only dependents, which might still use one of the raw-descriptor patterns below.

    One structurally incompatible generic caller

    shadowsocks-gtk-rs 0.4.1 has a helper whose parameters are Option<impl IntoRawFd> and forwards those generic values to stdout_file / stderr_file. That helper definition fails under the new bound, because IntoRawFd does not imply Into<OwnedFd>.

    However, that crate requires duct ^0.13.5, so it cannot resolve to this duct 1.x change. It is a useful concrete warning if this is ever backported to 0.13, but it is not an upgrade break from publishing 1.1.3.

    I also found click 0.6.3 passing an os_pipe::PipeReader while its published lockfile uses os_pipe 1.1.4 without the io_safety feature, so the owned-FD conversion is not enabled. Its open os_pipe = "1" requirement can re-resolve to 1.2+, and it likewise requires duct 0.13, so it is not reachable from this release; it is another backport/minimum-version edge case.

    More generally, the newly rejected Unix patterns are raw RawFd/i32 values, results of as_raw_fd() or into_raw_fd(), custom types that implement only IntoRawFd, and generic forwarding APIs bounded only by IntoRawFd. That is the intended ownership tightening. On Windows, RawHandle itself was never accepted by the old IntoRawHandle bound, so it is not a newly broken case; custom/generic IntoRawHandle-only values are.

    One branch follow-up

    I recommend raising the direct os_pipe = "1.0.0" dependency to at least 1.2.0. The conversions this branch now uses are absent in os_pipe 1.0.x and gated by io_safety in 1.1.x; they are unconditional in 1.2+. The current shared_child -> sigchld dependency graph already forces os_pipe >=1.2.2, so this is not an observed failure today, but duct should declare the minimum its own source requires instead of relying on that transitive constraint.

    This change also does not appear to raise duct's effective MSRV: std::os::fd requires Rust 1.66, while the OnceLock usage already present in duct requires Rust 1.70.

    oconnor663 oconnor663 commented on Sep 20, 2026 18:17 UTC
    Author

    Based on the Codex audit above, I'll probably ship this as a patch release, instead of creating a v2 just for this. Of note is the fact that RawHandle never implemented IntoRawHandle on Windows. I didn't know that.

    oconnor663 oconnor663 commented on Sep 20, 2026 18:19 UTC
    Author

    Re: os_pipe, I'll probably just remove the dependency in a followup commit. (Edit: Never mind, I do use the dup_stdout etc. functions that aren't in the standard library.)

    Reviewers
    Assignees
    oconnor663 oconnor663
    Labels
    risk: low confidence: 83.3% reviewed
    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: 42.2% (MEDIUM) · Higher = larger blast radius
    42.2%
    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: 83.3% · Lower = rushed or shallow review
    83.3%
    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: 7% · Safe to merge
    7%