-
Notifications
You must be signed in to change notification settings - Fork 1.9k
fix(coding-agent): rebuild the kernel venv while a kernel is running on Windows #763
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
Closed
FlamesONE
wants to merge
1
commit into
PrimeIntellect-ai:main
from
FlamesONE:fix/windows-kernel-venv-rebuild
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| import { spawn } from "node:child_process"; | ||
| import { copyFileSync, existsSync, mkdirSync, mkdtempSync, readdirSync, rmSync, writeFileSync } from "node:fs"; | ||
| import { tmpdir } from "node:os"; | ||
| import { basename, join } from "node:path"; | ||
| import { afterEach, beforeEach, describe, expect, it } from "vitest"; | ||
| import { discardVenvDir } from "../src/core/kernel/bootstrap.js"; | ||
|
|
||
| let tempDir = ""; | ||
|
|
||
| const binDir = process.platform === "win32" ? "Scripts" : "bin"; | ||
| const executableName = process.platform === "win32" ? "python.exe" : "python"; | ||
|
|
||
| function createVenv(): string { | ||
| const venv = join(tempDir, "kernel-venv"); | ||
| mkdirSync(join(venv, binDir), { recursive: true }); | ||
| // A copy of the current node binary stands in for the venv interpreter: running | ||
| // it produces the same mapped-image lock that a live kernel holds. | ||
| copyFileSync(process.execPath, join(venv, binDir, executableName)); | ||
| writeFileSync(join(venv, ".bootstrap-version"), "{}\n"); | ||
| return venv; | ||
| } | ||
|
|
||
| function stagedDirs(venv: string): string[] { | ||
| return readdirSync(tempDir).filter((entry) => entry !== basename(venv)); | ||
| } | ||
|
|
||
| describe("kernel venv discard", () => { | ||
| beforeEach(() => { | ||
| tempDir = mkdtempSync(join(tmpdir(), "prime-agent-kernel-venv-discard-")); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| if (!tempDir) return; | ||
| rmSync(tempDir, { recursive: true, force: true, maxRetries: 5, retryDelay: 50 }); | ||
| tempDir = ""; | ||
| }); | ||
|
|
||
| it("removes an idle venv outright", async () => { | ||
| const venv = createVenv(); | ||
|
|
||
| await discardVenvDir(venv); | ||
|
|
||
| expect(existsSync(venv)).toBe(false); | ||
| expect(stagedDirs(venv)).toEqual([]); | ||
| }); | ||
|
|
||
| it("does nothing when the venv is already gone", async () => { | ||
| await expect(discardVenvDir(join(tempDir, "kernel-venv"))).resolves.toBeUndefined(); | ||
| }); | ||
|
|
||
| it("frees the venv path while its interpreter is still running", async () => { | ||
| const venv = createVenv(); | ||
| const interpreter = join(venv, binDir, executableName); | ||
| const child = spawn(interpreter, ["-e", "setTimeout(() => {}, 30_000)"], { | ||
| stdio: "ignore", | ||
| windowsHide: true, | ||
| }); | ||
| try { | ||
| await new Promise<void>((resolve, reject) => { | ||
| child.once("spawn", resolve); | ||
| child.once("error", reject); | ||
| }); | ||
|
|
||
| await discardVenvDir(venv); | ||
|
|
||
| // The path must be reusable for the new venv even though the old | ||
| // interpreter still holds its image open. | ||
| expect(existsSync(venv)).toBe(false); | ||
| } finally { | ||
| const exited = new Promise<void>((resolve) => child.once("exit", () => resolve())); | ||
| child.kill(); | ||
| await exited; | ||
| } | ||
| }); | ||
|
|
||
| it("cleans up directories left behind by an earlier rebuild", async () => { | ||
| const venv = createVenv(); | ||
| const leftover = `${venv}.stale-1234-5678`; | ||
| mkdirSync(leftover, { recursive: true }); | ||
| writeFileSync(join(leftover, "python"), ""); | ||
|
|
||
| await discardVenvDir(venv); | ||
|
|
||
| expect(existsSync(leftover)).toBe(false); | ||
| expect(stagedDirs(venv)).toEqual([]); | ||
| }); | ||
| }); |
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.
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.
Missing venv bypasses stale cleanup
Low Severity
discardVenvDironly runs when the current venv exists, so a staged directory remains uncollected when a previous rebuild renamed the venv and then failed before recreating it.Reviewed by Cursor Bugbot for commit ab946de. Configure here.