Commit Graph
5 Commits
Author SHA1 Message Date
yetoneandvincent f4068ccc25 proc: with Detect agents in WSL off, no wsl.exe is started on any path (#4872)
With Settings' Detect agents in WSL off (noWSLAgents), every Claude
request still reached wsl.exe: wslReady (wslClaudeStandIn,
wslCodexStandIn) and wslClaudeClassifier listed the running distros
without asking wslLooks, the gate #1264 put on wslAgents, wslHomes and
WSLRunning. wslrun's Up, In and running weren't gated either (only
Find was). On a computer without WSL, Windows' inbox wsl.exe answers
each ask with a window offering to install WSL, one per request.

The fix is at the one choke point every command magpie starts goes
through (TestNoCommandBypassesProc): proc.Command and CommandContext
(and so ProbeContext, wslrun.Tool.Command/Probe, the Claude TUI
helper's ConPTY start, which checks cmd.Err) refuse wsl.exe by any
name or path (wsl, WSL.EXE, C:\Windows\System32\wsl.exe) with
proc.ErrWSLOff while the setting is off, as a probe of an app's own
program is refused. The paths that reach it: agent's wslRun/wslExec
(lists, probes, links, chmod, reach), wslrun.Run/Find/In/Up/Stop,
library's cmdvars, mcp_wsl, mcp_check and rtk_wsl, claudetui's
wslread, the gateway's Claude Code in WSL. The settings read is
settings.Shared() and only for a wsl name. Not gated: the Sessions
page's resume line for a WSL session (a string a terminal runs on the
user's click), whose sessions aren't listed with detection off.
skygunner/vincent's stand-in fix is kept as well, so the stand-in and
classifier return before taking wsl's lock or recording a failed list.

Run:
- mote-run: go vet ./internal/proc ./internal/agent ./internal/wslrun;
  GOOS=windows go vet of proc, agent, wslrun, claudetui, library,
  gateway; GOOS=linux go vet of proc, agent, wslrun, claudetui: clean.
  go test -count=1 ./internal/proc ./internal/wslrun ./internal/claudetui:
  ok; -run 'WSL|Wsl|Dsh' ./internal/agent ./internal/library
  ./internal/sessions: ok. gofmt -l: nothing.
- win-run on xiaomi-gpu (Windows 11, real wsl.exe present): the four new
  tests plus TestWSLDetectionOff, TestWSLClaudeStandIn,
  TestWSLCodexStandIn, TestNoCommandBypassesProc: ok; -v shows each new
  test PASS; go test ./internal/proc ./internal/wslrun whole: ok.
  TestWSLRunnerRefusedWhenOff runs agent's real wslRun there.

Broken by hand (wslOff's check made `if false && …`, agent/wsl.go at
origin/main, new tests kept), on mote: TestWSLOffStartsNoWSL red for
every name and maker, TestRunRefusedWhenOff "Run ran wsl.exe: exit
status 1", TestWSLRunnerRefusedWhenOff red, TestWSLStandInAsksNothing
WhenOff red with three "-l --running -q" asks.

Not tried: the reporter's own Windows without WSL (the install window
itself); the full suite runs after the push under the suite lock.

Reported-by: 陌离 (Discord)
Co-authored-by: vincent <vincent@users.noreply.github.com>
2026-11-06 21:28:24 +08:00
yetone 68a96b67b8 proc: a command's context ending on Windows kills what it started too (#2341)
The Store's WSL runs System32's wsl.exe, which starts Program Files'
wsl.exe and waits on it. When `wsl.exe -l --running -q` hung past its
timeout, CommandContext killed the first only; the second, waiting on
a hung WSL service, was left. With a retry every few seconds that came
to dozens of wsl.exe a day on the reporter's machine. ProbeContext had
the same gap on Windows: Output starts the command out of a job's
reach, so the probe was killed alone.

CommandContext's Cancel on Windows now finds the command's descendants
by parent pid (a Toolhelp snapshot; a reused pid is told apart by a
start before its parent's) and terminates them before the command.
ProbeContext's Windows cancel does the same. wslrun's cancelable kept
its own Cancel and dropped proc's: it now runs proc's after stopping
the run inside the distro, so it gets the tree kill too (and a probe's
end, which it had lost).

Measured on the Windows box (10.0.0.132), cmd.exe running ping as the
two wsl.exe:
  before: 1 child left running per ended context (CommandContext and
          ProbeContext both)
  after:  0 left

Run:
- TestContextEndKillsWhatTheCommandStarted, windows/amd64 test binary
  on the Windows box. With killDescendants commented out in both
  cancels:
    killtree_windows_test.go:71: process 57548 that cmd.exe started still runs after its context ended
    killtree_windows_test.go:71: process 42264 that cmd.exe started still runs after its context ended
    --- FAIL: TestContextEndKillsWhatTheCommandStarted (4.08s)
  With the fix: --- PASS (0.09s), both subtests.
- The whole proc test binary on the Windows box: everything passes but
  TestNoCommandBypassesProc, which walks the source tree from the
  binary's folder and read other checkouts under C:\Users\yeton (the
  binary ran outside a checkout). wslrun's test binary there: PASS.
- macOS, sandbox HOME: go test -count=1 -timeout 45m ./internal/proc/
  ./internal/wslrun/ -> ok proc 54.098s, ok wslrun 2.872s.
- gofmt -l clean; go vet ./internal/proc ./internal/wslrun;
  GOOS=linux and GOOS=windows go vet -tags nogui ./... clean.

Not tried: a real hung WSL service. The box's WSL answers, so the
reporter's hang itself wasn't reproduced; the test's cmd.exe→ping
stands in for System32 wsl.exe→Program Files wsl.exe.
2026-10-20 20:23:51 +08:00
yetone 9fcd332b6c proc: a .cmd or .bat is run through cmd.exe with each argument quoted for it, so npm.cmd under C:\Program Files\nodejs (nvm-windows) no longer runs "C:\Program" when magpie updates Claude Code (wztlink1013 on Discord)
Windows starts a batch file as `cmd.exe /c <line>`, and Go builds that
line for a program's parser: with more than two quotes cmd.exe drops the
first and last, so `"C:\Program Files\nodejs\npm.cmd" install -g --prefix
"C:\Program Files\nodejs" …` ran C:\Program. An argument with & or | was
also left unquoted and split into a second command. Every command magpie
runs is made by proc.Command/CommandContext, so the fix is there:
cmd.exe /d /e:ON /v:OFF /s /c "<script> <args>", each argument quoted as
Rust's std does for batch files (doubled ", % broken up).

TestBatchFileInFolderWithSpace (windows) runs npm.cmd, a .bat and npm via
PATH under "Program Files" with the reporter's arguments plus & | % ^ and
trailing-\ cases, through a script that hands %* to a real program. On the
old code it fails on the Windows box with "'…\Program' 不是内部或外部命令".
On the Windows box (Windows 11, zh-CN) magpie's own updater
(howInstalled + runUpdate) on a real npm install of Claude Code 2.0.50
under "…\Program Files\nodejs": old code failed with the reporter's error,
new code updated it to 2.1.293.
2026-10-08 15:04:24 +08:00
yetone 8ad73e8bfc accounts: a slow or hanging agent CLI no longer holds the providers page (#123) — its timeout now ends the call (a CLI that is a script running node left node holding the output, and the call waited for it however long, the 10s timeouts notwithstanding: a CLI's pipes are closed 2s after); a CLI never answered before is waited for 3s, once, then served as nobody signed in until its answer comes behind; and a CLI saying nobody is signed in is kept like any answer, where before it wasn't and every start waited for it again. Tried with cursor-agent and devin hanging 20s and the network black-holed: the first providers call went from 40.6s to 6s on a first start, and to 13ms on the next 2026-09-28 11:20:14 +08:00
yetone e8b3be572c windows: the desktop app no longer opens a console window for every command it runs (#54) — it is linked as a GUI program and has no console, so each console CLI it started (devin auth status and models list, devin acp for every Devin turn, claude, codex, cursor-agent and grok probes and runs, grok login) was given a new console by Windows, and a Windows Terminal window with it, some every few seconds while the app sat idle. Every command magpie runs is now made through internal/proc, which starts it with CREATE_NO_WINDOW when magpie has no console of its own: the child gets a console without a window, and its output, which magpie always pipes back, arrives as before. A magpie run in a terminal (magpie serve, the TUI, the desktop app started from one with a command) has one, and its children share it as they did, so Ctrl+C there still reaches them. The relaunch after an update keeps its DETACHED_PROCESS, added to rather than replacing the flags it was made with, and a test fails on any command made with os/exec directly, so a new one can't bring the windows back 2026-09-25 14:04:44 +08:00