fix(rules): terminate findProjectRoot walk at non-cwd drive roots - #19
Open
lavi-kj wants to merge 1 commit into
Open
fix(rules): terminate findProjectRoot walk at non-cwd drive roots#19lavi-kj wants to merge 1 commit into
lavi-kj wants to merge 1 commit into
Conversation
On Windows, resolve("/") is the cwd drive's root, but dirname() of
another drive's root returns itself. For targets on a different drive
than cwd (or UNC shares), the marker walk never reaches
filesystemRoot and spins forever - a synchronous infinite loop that
freezes the host agent's event loop at 100% CPU on every
read/edit/write tool_result for such paths.
Stop the walk when dirname() stops progressing, and add a cross-drive
regression test (real scenario on multi-drive Windows machines).
code-yeongyu
pushed a commit
to code-yeongyu/senpi
that referenced
this pull request
Jul 30, 2026
…on-cwd drive roots
On Windows, resolve("/") is the cwd drive's root, but dirname() of
another drive's root returns itself. For targets on a different drive
than cwd (or UNC shares), the vendored pi-rules findProjectRoot marker
walk never reaches filesystemRoot and spins forever - a synchronous
infinite loop in the rules extension's tool_result handler that freezes
the agent session (100% CPU, abort signal never processed) on every
read/edit/write call targeting such paths.
Stop the walk when dirname() stops progressing, document the adaptation
in the extension's changes.md, and add a cross-drive regression test.
Upstream fix for the vendored source: code-yeongyu/pi-rules#19
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
On Windows,
findProjectRootloops forever when the target path is on a different drive than the process cwd (or on a UNC share) and no project marker exists up-tree. This is a synchronous infinite loop, so it freezes the host agent's entire event loop at 100% CPU.Root cause
The walk terminates only when it reaches
resolve("/"), which is cwd's drive root. For a target on another drive,dirname()of that drive's root returns the root itself, so the equality never holds and the loop never exits.Real-world impact (how this was found)
Discovered while debugging frozen sessions in @code-yeongyu/senpi, which vendors pi-rules as a builtin extension. On a Windows machine with the workspace on
E:, everyread/edit/writetool call targeting a file onC:(temp screenshots, files under the user profile, etc.) froze the session permanently:Because the loop is synchronous, the abort signal is never processed:
esccannot interrupt, and users must kill the process.Fix
Stop the walk when
dirname()stops progressing (parentDirectory === currentDirectory). This preserves the existingresolve("/")early-exit and covers cross-drive roots and UNC share roots uniformly.Tests
nullinstantly).E:, temp onC:): the new test passes in ~1ms with the fix.scanner/finder/engine/extension-registration/tool-pathstests); no new failures.Downstream
senpi vendors this package (
packages/coding-agent/src/core/extensions/builtin/rules, MANUAL_PACKAGES). A companion senpi PR applying the same guard to the vendored copy +changes.mdentry will follow.Summary by cubic
Fixes a Windows-only infinite loop in
findProjectRootthat froze the agent on cross‑drive or UNC paths without markers. The walk now terminates correctly, preventing 100% CPU hangs on these tool calls.dirname()stops changing the path instead of relying only onresolve("/"), covering cross-drive and UNC roots.nullinstead of hanging.Written for commit 2fc5bc4. Summary will update on new commits.