-
-
Notifications
You must be signed in to change notification settings - Fork 577
fix(workspace): bound discovery in multi-project parent directories #374
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,7 +7,7 @@ import type { | |
| WorkspaceSession, | ||
| WorkspaceStore, | ||
| } from "./workspace-store.js"; | ||
| import { mkdir, opendir, readFile, realpath, stat } from "node:fs/promises"; | ||
| import { mkdir, opendir, readFile, readdir, realpath, stat } from "node:fs/promises"; | ||
| import { basename, dirname, join, relative, resolve, sep } from "node:path"; | ||
| import { loadProjectContextFiles } from "@earendil-works/pi-coding-agent"; | ||
| import type { ServerConfig } from "./config.js"; | ||
|
|
@@ -627,7 +627,7 @@ export class WorkspaceRegistry { | |
| if (realPath && loadedRealPaths.has(realPath)) return; | ||
|
|
||
| discovered.push({ path }); | ||
| }); | ||
| }, (await isMultiProjectParent(root)) ? 1 : Infinity); | ||
|
|
||
| return discovered.sort((a, b) => a.path.localeCompare(b.path)); | ||
| } | ||
|
|
@@ -723,9 +723,39 @@ async function tryRealpath(path: string): Promise<string | undefined> { | |
| } | ||
| } | ||
|
|
||
| // A non-Git parent with several direct Git children is a project catalogue. | ||
| // Selected checkouts still discover all their nested instruction files. | ||
| async function isMultiProjectParent(root: string): Promise<boolean> { | ||
| try { | ||
| await stat(join(root, ".git")); | ||
| return false; | ||
| } catch (error) { | ||
| if (!isErrnoException(error) || error.code !== "ENOENT") return false; | ||
| } | ||
|
|
||
| let entries; | ||
| try { | ||
| entries = await readdir(root, { withFileTypes: true }); | ||
| } catch { | ||
| return false; | ||
| } | ||
| let projects = 0; | ||
| for (const entry of entries) { | ||
| if (!entry.isDirectory() || SKIPPED_CONTEXT_DIRS.has(entry.name)) continue; | ||
| try { | ||
| await stat(join(root, entry.name, ".git")); | ||
| if (++projects >= 2) return true; | ||
| } catch { | ||
| // No accessible Git marker for this immediate child. | ||
| } | ||
|
Comment on lines
+743
to
+750
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If a parent directory has many immediate children on a slow filesystem, opening it waits for each child’s Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time! ArtifactsExecutable workspace-opening latency probe
Base workspace openings with delayed Git checks
PR head workspace openings with delayed Git checks
Base workspace openings without injected delay
PR head workspace openings without injected delay
|
||
| } | ||
| return false; | ||
| } | ||
|
|
||
| async function walkWorkspace( | ||
| directory: string, | ||
| visit: (path: string, entry: { name: string; isFile(): boolean; isDirectory(): boolean }) => Promise<void> | void, | ||
| remainingDepth = Infinity, | ||
| ): Promise<void> { | ||
| let entries; | ||
| try { | ||
|
|
@@ -737,8 +767,8 @@ async function walkWorkspace( | |
| for await (const entry of entries) { | ||
| const path = join(directory, entry.name); | ||
| if (entry.isDirectory()) { | ||
| if (!SKIPPED_CONTEXT_DIRS.has(entry.name)) { | ||
| await walkWorkspace(path, visit); | ||
| if (remainingDepth > 0 && !SKIPPED_CONTEXT_DIRS.has(entry.name)) { | ||
| await walkWorkspace(path, visit, remainingDepth - 1); | ||
| } | ||
| continue; | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: Waishnav/devspace
Length of output: 4368
🏁 Script executed:
Repository: Waishnav/devspace
Length of output: 13822
🏁 Script executed:
sed -n '690,755p' src/workspaces.tsRepository: Waishnav/devspace
Length of output: 1890
Propagate unexpected Git-marker errors.
When a Git-marker check returns an unexpected error,
isMultiProjectParentcan select the unbounded walk. The walk lists nested instruction-file paths inavailableAgentsFiles; it does not load their contents or block workspace opening. This can still produce an incorrect catalogue boundary, but it is not a major workflow outage.Treat only
ENOENTandENOTDIRas absent markers. Propagate other errors in both marker checks.Suggested fix
🤖 Prompt for AI Agents