Skip to content

Windows: os.replace fails with WinError 17 during Kiro install and AST cache writes #3508

Closed

Description

@shanyoush

Summary

On Windows, Graphify fails when performing atomic file replacement with os.replace().

The error is:

OSError: [WinError 17] The system cannot move the file to a different disk drive.

This happens even when the source temporary file and destination file are in the same directory and on the same drive.

I encountered this in two Graphify workflows:

  1. Installing the Graphify skill for Kiro.
  2. Running AST extraction with graphify extract . --code-only.

The underlying os.replace() behavior can also be reproduced independently of Graphify.


Environment

  • OS: Windows

  • Shell: PowerShell

  • Graphify version: graphify 0.9.58

  • Graphify installation: installed with uv

  • Platform integration: Kiro

  • System Python:

    • Python 3.12.10
  • Graphify uv environment:

    • Python 3.14.7

Graphify was installed for the project with:

graphify install --project --platform kiro

Problem 1: Kiro skill installation fails

Command:

graphify install --project --platform kiro

The installation starts successfully:

references -> .kiro\skills\graphify\references

but fails while replacing the temporary SKILL.md file:

Traceback (most recent call last):
  ...
  File "...graphify\install.py", line 253, in _copy_skill_file
    os.replace(tmp_dst, skill_dst)

OSError: [WinError 17] 系统无法将文件移到不同的磁盘驱动器。:
'.kiro\\skills\\graphify\\SKILL.md.tmp'
->
'.kiro\\skills\\graphify\\SKILL.md'

Both files are in the same project directory.


Problem 2: AST cache writes fail

Command:

graphify extract . --code-only

Example output:

[graphify extract] scanning D:\KiroWorkSpace\demo_opensepc
[graphify extract] --code-only: skipping 39 non-code file(s)
[graphify extract] found 23 code, 0 docs, 0 papers, 0 images
[graphify extract] AST extraction on 23 code files...

Then AST workers fail when replacing temporary cache files:

warning: worker failed for D:\KiroWorkSpace\demo_opensepc\lib\main.dart:

[WinError 17] 系统无法将文件移到不同的磁盘驱动器。:

'D:\\KiroWorkSpace\\demo_opensepc\\graphify-out\\cache\\ast\\v0.9.58-s2\\356bd78755ed7f82cd4be93ad20e54d855288714709e86ed2f9861115a13db77.3hhh4pp_.tmp'

->

'D:\\KiroWorkSpace\\demo_opensepc\\graphify-out\\cache\\ast\\v0.9.58-s2\\356bd78755ed7f82cd4be93ad20e54d855288714709e86ed2f9861115a13db77.json'

Eventually:

[graphify extract] AST extraction failed: [WinError 17]
系统无法将文件移到不同的磁盘驱动器。

The .tmp file and .json destination are clearly in the same directory and on the same D: drive.


Minimal reproduction outside Graphify

The same issue can be reproduced with plain Python.

Python 3.12

$dir = "C:\graphify-replace-test"

New-Item -ItemType Directory -Force $dir | Out-Null

python -c "import os,tempfile; d=r'$dir'; fd,tmp=tempfile.mkstemp(dir=d,suffix='.tmp'); os.write(fd,b'test'); os.close(fd); dst=os.path.join(d,'test.json'); print(tmp,'->',dst); os.replace(tmp,dst); print('SUCCESS')"

Result:

C:\graphify-replace-test\tmp0zs5shgn.tmp
->
C:\graphify-replace-test\test.json

Traceback (most recent call last):
  File "<string>", line 1, in <module>

OSError: [WinError 17] 系统无法将文件移到不同的磁盘驱动器。:
'C:\\graphify-replace-test\\tmp0zs5shgn.tmp'
->
'C:\\graphify-replace-test\\test.json'

This is important because both paths are on the same C: drive and in the same directory.


Reproduced with Graphify's Python environment

The same behavior also occurs with Graphify's uv-managed Python 3.14.7:

& "$env:APPDATA\uv\tools\graphifyy\Scripts\python.exe" -c "import os,tempfile; d=r'C:\graphify-uv-test'; os.makedirs(d,exist_ok=True); fd,tmp=tempfile.mkstemp(dir=d,suffix='.tmp'); os.write(fd,b'test'); os.close(fd); dst=os.path.join(d,'test.json'); print(tmp,'->',dst); os.replace(tmp,dst); print('SUCCESS')"

Result:

C:\graphify-uv-test\tmptme75wbc.tmp
->
C:\graphify-uv-test\test.json

OSError: [WinError 17] 系统无法将文件移到不同的磁盘驱动器。

So the issue is reproducible with both:

Python 3.12.10
Python 3.14.7

Other file operations work correctly

PowerShell rename works:

$dir = "C:\native-rename-test"

New-Item -ItemType Directory -Force $dir | Out-Null

Set-Content "$dir\test.tmp" "hello"

Rename-Item "$dir\test.tmp" "test.json"

Result:

Success

Python copy + delete also works:

$dir = "C:\python-copy-test"

New-Item -ItemType Directory -Force $dir | Out-Null

python -c "import os,shutil; d=r'$dir'; src=os.path.join(d,'test.tmp'); dst=os.path.join(d,'test.json'); open(src,'w').write('hello'); shutil.copy2(src,dst); os.unlink(src); print('SUCCESS')"

Result:

SUCCESS

So currently:

PowerShell Rename-Item       ✅
Python shutil.copy2          ✅
Python os.unlink             ✅
Python copy2 + unlink        ✅

Python os.replace            ❌ WinError 17
Graphify atomic replacement  ❌ WinError 17

Expected behavior

Graphify should successfully write the destination file, or gracefully fall back to a copy/delete strategy when atomic replacement fails on Windows.

For example:

try:
    os.replace(tmp_path, destination)
except OSError as exc:
    if getattr(exc, "winerror", None) in (5, 17, 32):
        shutil.copy2(tmp_path, destination)
        os.unlink(tmp_path)
    else:
        raise

Graphify already appears to have Windows fallback logic for s

Activity

  1. added a commit that references this issue on Sep 12, 2026
    784b1fb
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions