Skip to content

fix(cli): release Windows file handles after reads - #12097

Merged
marius-kilocode merged 5 commits into
mainfrom
fix/windows-file-handles
Jul 14, 2026
Merged

fix(cli): release Windows file handles after reads#12097
marius-kilocode merged 5 commits into
mainfrom
fix/windows-file-handles

Conversation

@marius-kilocode

@marius-kilocode marius-kilocode commented Jul 10, 2026

Copy link
Copy Markdown
Collaborator

On Windows, project files can remain open in the long-running Kilo process after the read tool truncates, aborts, or retries decoding. Atomic replacement then fails with EPERM, preventing Kilo, editors, formatters, and filesystem tools from updating existing files until the process restarts.

This regression was introduced in #11533 when streaming reads were restored after the OpenCode integration had switched the Read tool back to whole-file buffering. That restoration correctly preserved bounded UTF-8 streaming and legacy-encoding fallback, but the Readable.from(Stream.toAsyncIterable(...)) bridge did not wait for the Effect iterator and its filesystem scope to finalize when the consumer stopped early. The Read tool could therefore return while Windows still considered the source file open.

Make the Node-readable bridge explicitly own the Effect stream iterator. Destroying the consumer now awaits iterator finalization, and the read operation does not complete or retry decoding until the underlying filesystem scope has closed. This keeps the behavior restored by #11533, including pull-based streaming, output-cap short-circuiting, cancellation, encoding fallback, and the injected filesystem abstraction, while establishing a reliable handle-release boundary.

Add regression coverage that immediately replaces files after truncated, aborted, and fallback reads, including the Windows sharing semantics that expose retained handles.

Fixes #12005

@marius-kilocode
marius-kilocode marked this pull request as ready for review July 10, 2026 12:33
@kilo-code-bot

kilo-code-bot Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Reviewed the Windows file-handle fix in text-stream.ts: the new utf8() bridge explicitly owns the effect-stream iterator, destroy() awaits iterator.return() before signaling close, and withFallback now unconditionally destroys and awaits closure of the optimistic UTF-8 stream (success, error, and abort paths) before returning or falling back to openDecoded. Traced the abort/backpressure paths and the accompanying regression tests (truncated read, mid-stream abort, and legacy-encoding fallback, each followed by an immediate temp-file rename) and didn't find a correctness gap in the changed lines. A changeset is included and appropriately user-facing. This change is confined to packages/opencode/src/kilocode/ (Kilo-only), so no fork-merge concerns apply.

Files Reviewed (3 files)
  • packages/opencode/src/kilocode/text-stream.ts
  • packages/opencode/test/kilocode/tool-encoding.test.ts
  • .changeset/clean-windows-file-handles.md

Reviewed by claude-sonnet-5 · Input: 50 · Output: 22.9K · Cached: 1.6M

Review guidance: REVIEW.md from base branch main

AlexOcculate pushed a commit to AlexOcculate/kilocode that referenced this pull request Jul 14, 2026
@marius-kilocode
marius-kilocode merged commit cb654e5 into main Jul 14, 2026
29 checks passed
@marius-kilocode
marius-kilocode deleted the fix/windows-file-handles branch July 14, 2026 07:35
t7tran pushed a commit to t7tran/kilocode that referenced this pull request Aug 14, 2026
fix(cli): release Windows file handles after reads
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: File editing CONSTANTLY fails with EPERM because kilo.exe keeps multiple handles open to the target file. Not able to use KILO later 7.4.1 vers

2 participants