Skip to content

fix(run_code): run a script inside a Windows computer - #545

Merged
earakely-scale merged 6 commits into
mainfrom
edgararakelyan/fd-5315-run-code-windows
Nov 9, 2026
Merged

earakely-scale merged 6 commits into
mainfrom
edgararakelyan/fd-5315-run-code-windows

Conversation

@earakely-scale

@earakely-scale earakely-scale commented Nov 8, 2026 •

Copy link
Copy Markdown
Collaborator

Part of FD-5315.

run_code couldn't run a script inside a Windows computer, so every bench trial on Windows failed at its arm step: cannot run 'pkill': The system cannot find the file specified.

The step worked inside a computer with POSIX tools: pkill -f ended a runner a dropped call left going, rm -rf removed the run folder, and wc -c sized the result. Its runner registered SIGHUP and ended a timed-out script's process group with os.killpg. Windows has none of these.

What changes

Inside a computer, run_code runs only its runner, so the step itself doesn't know or ask what OS the computer runs:

Before Now
pkill -f <escaped path>, then rm -rf <folder> python3 -I -c <runner> --clear <folder>
rm -rf <folder> after the run the same --clear
wc -c <result> python3 -I -c <runner> --size <result>
python3 <folder>/runner.py ... unchanged

The runner locks its folder. While it supervises a script, it holds an exclusive lock on runner.lock in the run folder and writes its pid to runner.pid. --clear tries that lock:

  • free: nothing runs from the folder, so it removes the folder;
  • held: the recorded pid is the live supervisor. --clear ends it, with all it started, waits for the lock to free, then removes the folder.

This replaces matching command lines, so it can't end the wrong process, and it needs neither pkill nor a Windows process list. Clearing after the run now also ends a runner a dropped call left going, rather than waiting for the step's next run.

The OS-specific code is two small pieces of the runner, both stdlib:

The lock Ending the supervisor and all it started
Linux, macOS fcntl.flock SIGTERM, which it passes on to its script's process group
Windows msvcrt.locking taskkill /T /F

The runner also registers only the signals the OS has, and on Windows ends a timed-out script's tree with taskkill, as Windows has no process groups.

Why -I: --clear and --size run with the home as their working directory, which the agent can write. Isolated mode keeps a shutil.py planted there from running.

No shell in the user's session. trycua's GUI-only guard counts any shell started in the session against the agent, and the disarm step runs while the sentinel is armed. python3 and taskkill aren't side doors to it. A first version of this PR used PowerShell and failed a trial on exactly that.

Hosts and containers are POSIX by construction and keep their commands. runner.lock and runner.pid join the member names a script universe may not use.

Tests

  • Unit (box 1, tst/unit/task_step/: 2447 passed; ruff clean):

    • a script in a computer runs as --clear, the run, --size, --clear, and nothing else;
    • a dropped call's step clears its folder on both attempts;
    • on POSIX, --clear ends a live supervisor and the child its script started (128 + SIGTERM), then removes the folder;
    • on Windows, the runner ends a tree with taskkill.
  • On a Windows 11 guest, the runner itself:

    • a normal run wrote and sized its result, with the lock and pid files beside it;
    • clearing a finished run took 0.06 s;
    • clearing a live supervisor took 0.44 s and ended it and its script's child, so Windows frees the lock promptly;
    • a 2 s timeout exited 124, the child gone;
    • clearing a missing folder is a no-op, and sizing a missing file fails with the reason;
    • the runner's whole source came through intact as -c.
  • Chaos, the same harness on a deployed Windows computer (notes-desk) and a Linux one (the app bundle's desk), every check passing on both:

    Check Windows Linux
    A dropped call's leftover runner and its child, alive, then ended by the step's next run, which returns its own result ok, 1.0 s ok, 0.4 s
    A timed-out script's tree ended, its folder gone ok ok
    Six steps at once, each its own result, no folder left ok, 4.9 s ok, 3.3 s
    One step rerun five times ok, 0.8–0.9 s each ok, 0.3 s each
    shutil.py, subprocess.py and others planted in the home never run ok ok
    An over-cap result refused, its folder cleared ok ok
  • Integration:

    • Windows: windows_test.py's notes task gains a run_code step that runs inside the computer, in the session user's home, reaching the driver on loopback. It passed (inside done in 1.3s; passed (before: 1, session: 1, after: 1)).
    • Linux: computer_app_test.py's three tests that run run_code inside a computer passed (alone, the two composed apps, the data plane).
  • Bench trials (cua-driver, Sonnet 5.5): IR-01 r1 in the foreground passed on Windows (88.5 s) and on Linux (45.4 s), GUI-only 1 and grade 1 each. Earlier on this branch, all 12 Windows r1 trials of the seven BenchLab tasks armed, ran, disarmed and were graded.

🤖 Generated with Claude Code

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge; no new actionable issue was found.

Summary

The PR lets run_code run inside Windows computers without POSIX tools.

  • run_code runs scripts inside Windows computers.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[Clear previous run] --> B[Stage script and input]
  B --> C[Supervisor holds lock]
  C --> D[Run script with timeout]
  D --> E[Size and read result]
  E --> F[Clear run folder]
  A --> G{Lock held?}
  G -->|Yes| H[Stop supervisor and script]
  H --> B
Loading

Reviews (8) · Last reviewed commit: "refactor(run_code): the runner clears an..." · Reviewed by Greptile

earakely-scale and others added 4 commits November 8, 2026 11:35
run_code reached inside a computer with pkill, rm -rf and wc -c, and its runner registered SIGHUP and ended a timed-out
script's process group, none of which Windows has. On a computer whose card says Windows, the step ends a leftover
runner through PowerShell's process list, removes its folder and sizes the result with Python, and the runner ends the
script's process tree with taskkill.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A shell started in the user's session reads as the agent leaving the GUI, and the disarm step's PowerShell did
during a bench trial. The leftover runner is now ended by a stdlib Python program that reads each process's command
line through NtQueryInformationProcess.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@earakely-scale
earakely-scale requested a review from a team as a code owner November 8, 2026 19:54
earakely-scale and others added 2 commits November 8, 2026 12:13
…tarted

TerminateProcess ended only the processes whose command line held the runner's path, so a script's children outlived
them. Each match's process tree is now ended with taskkill, and the program's Windows values are named.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… the step needs no OS

Inside a computer, run_code now runs only the runner: `--clear` ends the supervisor that holds the run folder's lock,
with all it started, and removes the folder, and `--size` sizes the result. The supervisor holds that lock while it
runs. The step no longer reads the computer's OS, sends pkill, rm or wc, or carries Windows programs; the runner's
lock and process ending are the only OS-specific code, fcntl and signals on POSIX, msvcrt and taskkill on Windows.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@earakely-scale
earakely-scale merged commit 3b62568 into main Nov 9, 2026
35 checks passed
@earakely-scale
earakely-scale deleted the edgararakelyan/fd-5315-run-code-windows branch November 9, 2026 00:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant