Skip to content

fix(cache): complete atomic shard writes on Windows - #914

Merged
junhoyeo merged 1 commit into
junhoyeo:mainfrom
Nanako0129:fix-windows-cache-handles
Jul 17, 2026
Merged

fix(cache): complete atomic shard writes on Windows#914
junhoyeo merged 1 commit into
junhoyeo:mainfrom
Nanako0129:fix-windows-cache-handles

Conversation

@Nanako0129

@Nanako0129 Nanako0129 commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Fixes #913

Summary

  • Release the temporary cache shard writer before atomic replacement so the cache does not keep its own source handle open across MoveFileExW.
  • Reopen the installed shard with read and write access before the final durability sync, matching the access requirements of Windows FlushFileBuffers.
  • Add a direct shard write/read regression without changing cache format, parser versions, shard identity, retry policy, or TUI warning behavior.

Current-upstream adaptation

Validated downstream behavior Current upstream location Adaptation
Flush and sync the monolithic temporary cache, then drop its writer before replacement write_shard_with_limit temporary envelope writer Apply the same handle ordering to each shard writer
Reopen the installed cache read/write before sync_all() Final shard durability sync Use OpenOptions::new().read(true).write(true)
Monolithic cache layout and schema Sharded envelopes and per-parser versions Deliberately excluded; no format or identity change
Atomic replacement implementation Shared fs_atomic::replace_file with #906 retry behavior Deliberately unchanged

The source behavior was recovered into TokenBar PR #59. The Windows validation ancestry and full downstream evidence are recorded in the handoff comment.

Verification

  • cargo test -p tokscale-core test_write_shard_round_trips_after_atomic_replace -- --test-threads=1
  • cargo test -p tokscale-core test_save_if_dirty_marks_cache_clean -- --test-threads=1
  • cargo fmt --all -- --check
  • cargo clippy --locked --workspace --all-features -- -D warnings
  • cargo test --workspace --all-features
  • cargo build --release -p tokscale-cli
  • git diff --check

Windows evidence boundary

The downstream handle-ordering fix was executed and validated on Windows. This PR adapts that invariant to the current shard writer. Upstream Build Native checks Windows x64 and arm64 compilation only; it does not execute this regression on Windows. Unless an additional Windows runner runs the test, this PR does not claim independent upstream Windows runtime verification.


Summary by cubic

Fixes atomic shard writes on Windows by closing the temp writer before replacement and reopening the final shard for a proper flush. Prevents handle conflicts and ensures cache durability after writes.

  • Bug Fixes
    • Drop the temporary shard writer before atomic replace to avoid carrying an open source handle into MoveFileExW.
    • Reopen the installed shard with read+write before the final sync_all() to satisfy Windows FlushFileBuffers.
    • Add a regression test to verify shard write/read round-trip after replace.
    • No changes to cache format, shard identity, parser versions, retry policy, or TUI behavior.

Written for commit e15e66b. Summary will update on new commits.

Review in cubic

Drop the temporary shard writer before atomic replacement, then reopen the installed shard with read and write access for the final durability sync. This avoids carrying a caller-owned source handle into MoveFileExW and gives FlushFileBuffers the access mode it requires.\n\nAdd a direct shard write/read regression without changing cache format, parser versions, shard identity, retry policy, or TUI behavior. Fixes junhoyeo#913.
@vercel

vercel Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
tokscale Ignored Ignored Preview Jul 17, 2026 3:07pm

Request Review

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No issues found across 1 file

Re-trigger cubic

@junhoyeo junhoyeo left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks a lot!

@junhoyeo
junhoyeo merged commit 163ec57 into junhoyeo:main Jul 17, 2026
15 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.

Windows cache shard writes can fail with self-held or read-only file handles

2 participants