Skip to content

Preserve signed filesystem timestamps in os.utime - #9047

Merged
youknowone merged 1 commit into
RustPython:mainfrom
youknowdot:fix-signed-utime-timestamps
Oct 10, 2026
Merged

youknowone merged 1 commit into
RustPython:mainfrom
youknowdot:fix-signed-utime-timestamps

Conversation

@youknowdot

@youknowdot youknowdot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Extract signed filesystem timestamps for os.utime from #8954 while preserving the Python 3.14.7 contract:

  • Keep signed platform seconds and C-long nanoseconds through POSIX/WASI calls; reuse the existing Windows FILETIME helper from host_env: bound symlink probe; add Win32 times #8733.
  • Preserve floor rounding, float-payload precedence, index conversion, and original exceptions from a nanosecond remainder's index.
  • Exclude the megaPR's 3.15 argument widening/error wording and unsupported Windows range restriction.

The POSIX/WASI host-helper signatures now take signed FileTime fields rather than Duration. This is scoped to filesystem timestamps, not a general time ABI change.

Three concise calls in the existing os snippet verify negative integer/fractional/ns arguments reach an invalid second timestamp, without assuming filesystem date ranges or precision. No implementation guard or canonical assertion change.

Validation

  • Two independent source reviews against exact CPython 3.14.7; related merged PRs checked for overlap.
  • Fresh native Linux tempfile probes pass signed round trips, floor normalization, range/NaN errors, float/index protocols and exact remainder exceptions. Unchanged implementation rejects the first negative timestamp.
  • Unchanged canonical UtimeTests run in an isolated harness: 10 pass, 3 existing skips. The harness omits unrelated test_os module imports; this is not a full test_os run.
  • Full os snippet reaches and passes the new regression, then fails an unchanged chown assertion because this executor returns errno22 instead of PermissionError. The identical failure reproduces on unmodified main with CPython3.14.7; the assertion is left intact.
  • Normal hooks, VM Clippy and separate CAPI Clippy pass.
  • Native Windows/macOS/WASI behavior and full hosted workspace/CAPI checks remain pending.

Extraction, regression and validation were AI-assisted with OpenAI Codex. Draft pending hosted platform CI and review. README unchanged.

Summary by CodeRabbit

  • New Features
    • Improved os.utime timestamp handling for integer, floating-point, and nanosecond inputs, including negative fractional timestamps.
    • Added clearer errors for invalid, out-of-range, and non-finite timestamp values.
    • Improved filesystem timestamp support across Unix-like, Windows, and WASI platforms.

Extract the Python 3.14-compatible signed timestamp conversion from RustPython#8954, preserving floor rounding, float-or-index argument rules and signed divmod remainders. Reuse the existing Windows file-time helper rather than the mega patch range restriction, and keep the 3.14 argument diagnostics. Add three concise parser regressions to the existing os snippet without native filesystem range assumptions.

Assisted-by: OpenAI Codex:model identifier unavailable
@coderabbitai

coderabbitai Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: RustPython/RustPython/.coderabbit.yml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: abc6a0e9-484a-4056-b489-728034ede4b6

📥 Commits

Reviewing files that changed from the base of the PR and between 3af5f8a and ac2e2fc.


📒 Files selected for processing (5)
  • crates/host_env/src/os.rs
  • crates/host_env/src/posix.rs
  • crates/host_env/src/posix_wasi.rs
  • crates/vm/src/stdlib/os.rs
  • extra_tests/snippets/stdlib_os.py

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.



📝 Walkthrough

Walkthrough

os.utime now converts timestamp inputs to seconds and nanoseconds using FileTime. POSIX, WASI, and Windows paths pass those values to platform timestamp operations. New regression checks cover invalid modification-time values.

Changes

Filesystem timestamp handling

Layer / File(s) Summary
Timestamp types and POSIX adapters
crates/host_env/src/os.rs, crates/host_env/src/posix.rs, crates/host_env/src/posix_wasi.rs
Adds FileTimeSeconds and FileTime. POSIX and WASI timestamp functions accept FileTime and build system time values from its fields.
Python timestamp conversion
crates/vm/src/stdlib/os.rs
Converts times and ns tuple values, or the current time, to FileTime. Checks input types and platform range limits.
Platform dispatch and regression checks
crates/vm/src/stdlib/os.rs, extra_tests/snippets/stdlib_os.py
utime_impl passes seconds and nanoseconds to the Windows timestamp API. Regression checks cover invalid modification-time values in tuple and ns forms.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant Python as os.utime
  participant VM as utime_impl
  participant Host as Platform timestamp API
  Python->>VM: Pass converted FileTime values
  VM->>Host: Pass seconds and nanoseconds
Loading

Suggested reviewers: youknowone


Merge Risk: ⚪ Minimal · up to ac2e2

No actionable issue is established from the supplied evidence. The change is mergeable after normal checks.

Pre-merge checks | Passed 4 | Failed 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 55.56% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 9 functions across 5 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the primary change: preserving signed filesystem timestamps in os.utime.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@youknowone
youknowone marked this pull request as ready for review October 10, 2026 10:56
@youknowone
youknowone enabled auto-merge (squash) October 10, 2026 10:56
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-10T11:05:07.509295Z ac2e2fc Draft marked ready
ℹ️ About Codex in GitHub

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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ac2e2fcd8a

ℹ️ About Codex in GitHub

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".

Comment on lines +149 to +151
for atime in (-1, -0.25):
assert_raises(TypeError, os.utime, fname, (atime, object()))
assert_raises(TypeError, os.utime, fname, ns=(-1, object()))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Revert the forbidden test-logic additions

These new calls add assertions and test logic to extra_tests/snippets/stdlib_os.py, but the root AGENTS.md explicitly permits test-file edits only for adding or removing expected-failure markers and forbids modifying assertions or test logic. Revert this test-file hunk so the commit complies with the repository's scoped contribution rules.

AGENTS.md reference: AGENTS.md:L275-L279

Useful? React with 👍 / 👎.

crate::host_env::os::set_file_times(&path, acc, modif)
.map_err(|err| OSErrorBuilder::with_filename(&err, path, vm))
let wide_path = path.to_wide_cstring(vm)?;
host_nt::set_file_times(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve Windows sharing when setting file times

In the Windows branch, when the target already has an open read or write handle, switching to host_nt::set_file_times makes os.utime(path, ...) fail with a sharing violation: that helper calls CreateFileW with dwShareMode = 0 (crates/host_env/src/nt.rs:406-412), whereas the previous OpenOptions path used the normal read/write/delete sharing flags. Preserve those share flags in the new helper so updating timestamps does not regress for open files.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The access-mode change matters here: this helper requests only FILE_WRITE_ATTRIBUTES, whereas the old OpenOptions path requested data-write access. Windows excludes attribute-only access from its sharing-conflict checks, and CPython 3.14.7 uses the same FILE_WRITE_ATTRIBUTES/share-mode-zero call. Sources: https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-fsa/8c0e3f4f-0729-49f4-a14d-7f7add593819 and https://github.com/python/cpython/blob/v3.14.7/Modules/posixmodule.c#L6269-L6274 . On that evidence, changing the sharing flags is not warranted. This is source verification; I have not run an open-handle Windows runtime test locally.

@youknowone
youknowone merged commit 082a48a into RustPython:main Oct 10, 2026
30 checks passed
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.

2 participants