Skip to content

Verify on Windows That fstat and lstat Agree on File Identity in write_regular_file's Cleanup #2494

Closed as not planned

Description

@ptr727

What is unverified

PR #2493 has write_regular_file in host-setup/agent-safety/claude/install.py remove a file it created when the write fails. It removes the file only where os.lstat(path) reports the same st_dev and st_ino as os.fstat on the descriptor it created. On Linux the two agree.

On Windows, CPython fills these fields through different calls for a descriptor and for a path. os.fstat uses the handle-based file information. os.lstat on Python 3.12 and later can take the GetFileInformationByName fast path. Nothing has checked that the two give the same st_dev width and st_ino value on NTFS, or on ReFS.

What a mismatch would do

It fails safe. The created file is never removed, and a failed write on a new file raises IncompleteWrite rather than OSError. The installer then stamps the leftover the same way it stamps any other, so nothing is deleted that should not be, and #2454's mislabel stays fixed. What would be lost is the clean "left absent as it was found" outcome on Windows.

How to settle it

Run these two tests natively on Windows, from a hub checkout that holds #2493:

  • python -m unittest -k test_a_failed_write_removes_the_file_it_created test_install
  • python -m unittest -k test_a_failed_check_before_the_write_removes_the_file_it_created test_install

Run them on the Python versions the host has, 3.12 or later included. Both pass where the identities agree. If they fail, compare identity with os.path.samestat on a os.stat(path) taken right after the create, or decide the fail-safe behavior is acceptable on Windows and document it.

Found by the local strict review of #2493.

Activity

  1. added
    agents
    on Oct 7, 2026
  2. ptr727 commented on Oct 8, 2026

    @ptr727
    OwnerAuthor

    Declined under GOVERNANCE.md "Trust Boundaries and Hardening Effort" (#2501, released in 2.0.867), at the maintainer's direction. A disagreement between fstat and lstat on Windows fails safe, as this issue states: the write raises IncompleteWrite loudly, nothing is deleted, and the leftover is stamped. A case whose failure is loud and non-destructive is declined, neither fixed nor filed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agents

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions