Files
yetone f1c9014cd9 wsl, masking: a hung WSL or a slow local model no longer holds requests
vsoullai on X (0.1.4190, Windows): the gateway froze. Each request waited
15s in turn on the local masking model, routing was held 30s and got a
504, and a stopped WSL distro's probe dragged everything down until
redactModel and WSL were turned off. #6167 (Codex held 30s then 504,
fixed by restarting WSL) and #4856 (masking timeouts, 504s) are the same.

WSL (internal/agent/wsl.go, wsl_links.go):
- wsl's lock was held through wsl.exe and through the stat of
  \\wsl.localhost\<distro>, which can't be cancelled. The GUI's look held
  it, and every request's Codex/Claude stand-in, wslUp, distroAt and
  Copilot's WSL folders queued behind it.
- A look (wslRefresh) now runs wsl.exe, the probes and the stat outside
  the lock. Looks take turns on wslRefreshMu, and the lock only guards
  reads and writes.
- wslRoot's stat is bounded (wslRootWait 5s); a distro whose / can't be
  opened fails its probe and is tried again later.
- What a request asks never waits on a look. "Which distros run" is
  asked single-flight in the background and waited for at most
  wslRunningWait (2s). A distro wsl.exe hasn't named as running counts
  as stopped, so nothing opens or wakes a distro on a guess.
- Copilot's WSL sign-in (internal/provider/copilot_cli.go) is read the
  same way: single-flight, waited for at most copilotWSLWait (2s), with
  the last answer kept. Before, its own mutex queued every request
  behind the first one's read.

Masking (internal/masking/masking.go):
- With redactModel on, each request waited up to strictWait (15s). In a
  burst the backlog grew and the requests waited one after another.
- Once a strict request runs out its wait with texts unread, the model
  is "behind". The next requests then wait only defaultWait (2s) until a
  request is read whole or a minute passes (behind, waitFor). The rules
  still mask everything the model hasn't read.

Docs: docs/subsystems/agent-wiring.md (WSL twins) and gateway-routing.md
(masking).

Run:
- New tests, on mote, -race -count=3: TestWSLHangHoldsNoRequest (wsl.exe
  --running, a distro's probe, the stat; each hang injected),
  TestWSLRootHangFailsProbe, TestCopilotWSLHangHoldsNoRequest and
  TestStrictModelBehindWaitsTheDefault, with the other WSL, Copilot WSL
  and masking tests. All ok.
- Broken by hand: the same tests on the old code (origin/main's files
  with only the new tests added). Each WSL hang case failed ("a Codex
  stand-in waited on a hung WSL past 2.2s", "the GUI's look didn't wait
  on the hung WSL"). The Copilot test failed ("13 requests waited on a
  hung WSL past 2.2s"). The masking test failed ("request 2 after the
  model fell behind waited 2.0s").
- Full suite on mica at f08597a58 (this change on b754cb095):
  `go test -timeout 45m ./...`, exit 0, 101 packages ok.
- Rebased on f03869520 (a gateway/provider change). At this head, on
  mica: go test -count=1 ./internal/agent ./internal/provider
  ./internal/masking ./internal/gateway all ok, go vet ./internal/... and
  GOOS=windows vet of those four ok, gofmt clean. The full suite ran at
  the base before it, not again at this head.
- Rebased again on c0cf352a8 (four commits: gateway, provider Codex
  hold, providers base URL, LESSONS). At this pushed head, on mica:
  go test -count=1 ./internal/provider ./internal/masking ok, the WSL and
  Copilot tests of internal/agent ok, go vet of agent, provider and
  gateway (darwin and GOOS=windows) ok.
- gofmt -l clean; go vet ./... on darwin, GOOS=linux -tags nogui and
  GOOS=windows: ok.
- Windows (xiaomi-gpu, win-run), internal/agent, internal/provider and
  internal/masking. masking: ok. agent and provider: 52 reds, all in the
  53 that origin/main f03869520 has on the same box (#6068, #1827,
  #5068, #5344, #5950; this run's list is on #6068). None touch WSL,
  Copilot's WSL or masking.

Not tried: a real hung WSL. On xiaomi-gpu, wsl -l -q and -l --running
answered in ~55ms, and a terminated distro's \\wsl.localhost path failed
in 131ms, so the hang was injected in the tests, not reproduced live.

(vsoullai on X, #6167, #4856)
2026-11-15 06:20:15 +08:00
..