fix(agent): Python's private temp folders work in the Windows sandbox #33
No reviewers
Labels
No labels
kind
bug
kind
chore
kind
docs
kind
feature
kind
performance
kind
question
priority
critical
priority
high
priority
low
risk
high
risk
low
risk
medium
status
blocked
status
confirmed
status
duplicate
status
invalid
status
needs-info
status
wontfix
ci: approved
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Beanstalk!33
Loading…
Reference in a new issue
No description provided.
Delete branch "HumanBean/Beanstalk:fix/win-mkdtemp"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Why
Every Windows job fails before it builds anything. The tester's PC runs
make_game.py, its compiler check stops withPermissionError: [WinError 5] Access is denied: '...\Beanstalk\work\longshot\tmpXXXX', and the job reports an error (Longshot #910, RTX 4070, Windows 11). #25 and #28 didn't fix it, but #28's probe lines in the run on nightly-52 (rp_d7a616581e156950) show the cause. There are two problems:0o700on Windows gets an access list of its own: SYSTEM, the Administrators and the owner, protected from inheritance. That is whattempfile.mkdtempandTemporaryDirectoryask for. A process in an AppContainer is let in only when the list also names its AppContainer. So in the sandbox Python makes the folder, then can't write its first file in it (t.c), and can't clean it up either. The probe shows the pattern: a plainos.mkdirin the checkout works ("dir ok"), the0o700one doesn't.LOCALAPPDATA\Packages\beanstalk.sandbox\AC\Temp, whatever the environment says, and that folder was never made. Python found no usable temp folder and fell back to the current one, the Longshot checkout.What changed
WinPythonFix(Core/WindowsPlan.cs): a.pthfile and a short module the agent writes into its own builder Python's site-packages (tools/python). Only whereBEANSTALK_SANDBOX_PYTHON=1(the Windows sandbox's environment) and only on Windows,os.mkdir(path, 0o700)makes the folder with the plain mode instead, so it inherits the sandbox's grants like any other folder in the job. Other modes are unchanged, and outside the sandbox nothing changes.Workspace.InstallPythonFixAsync: writes those files after the Windows tools are fetched, only into the agent's owntools/python. It finds site-packages withsysconfigand refuses a path outside the tools folder. A Python the tester named in the setup is theirs and is left alone, with a line in the log.WinEnv.Folders: also makes<home>\AppData\Local\Packages\beanstalk.sandbox\AC\Tempbefore each start, so Python's temp files go to the job's home and not the checkout. The AppContainer's name has one home,WinSandboxName.Name, whichWinAppContainernow uses.TemporaryDirectory, writes a file in it, and says whether the fix was loaded (@@probe mkdtemp ok fix).Testing
0o700, only on Windows, only in the sandbox.sys.platformfaked aswin32: with the variable set,tempfile.mkdtemp()asks for0o777; without it,0o700;os.mkdir(..., 0o755)stays0o755either way.@Beanstalkon Longshot #910 should get past "the main base". The report's probe lines should say@@probe mkdtemp ok fix, andgettempdirshould be theAC\Tempfolder.Risks
The fix only touches the agent's own copy of Python, and only inside the sandbox. There, temp folders are no longer private to the job's account. That's fine: the sandbox's job folder is the job's alone. If the fix doesn't load, nothing changes from today, and the probe says so.