Skip to content

fix(windows): repair the 8.3-alias abort, the trash shim's module type, Chinese prose in math, and the assumptions a POSIX host hides - #14

Merged
UncleMoc merged 10 commits into
mcode-webui:mainfrom
antianqi:fix/windows-process-and-trash-defects
Nov 10, 2026
Merged

UncleMoc merged 10 commits into
mcode-webui:mainfrom
antianqi:fix/windows-process-and-trash-defects

Conversation

@antianqi

@antianqi antianqi commented Nov 10, 2026 •

Copy link
Copy Markdown
Collaborator

Change

Seven defects a Windows host exposes, each reproduced before the fix and verified after it. This branch carries only what #11 (fix/webui-ci-baseline) does not already have; #11 has since merged, and this branch is rebased onto main.

  • An 8.3 alias aborted the process. fs.watch is given the path the event carries, and a Windows event can carry the short form (C:\Users\ADMINI~1\...\) of a directory that is watched by its long form. libuv then asserts that the two agree and the whole process aborts with 0xC0000409 — not an exception, so nothing can catch it. Both watchers now resolve the directory through realpathSync.native, which resolves the alias; the JavaScript realpathSync does not. The test watches a short path and writes through the long one, in a child process, because an abort kills the worker that ran it.

  • The trash shim could not run. It is a CommonJS script seeded as mavis-trash.js, and Node reads the module type of a .js file from the nearest ancestor package.json. An ancestor that says "type": "module" — one normal package in a home directory is enough — makes Node parse the shim as ESM, where require is not defined. It is seeded as mavis-trash.cjs now. The consequence was not cosmetic: the permission pipeline rewrites rm to mavis-trash so that a deletion stays recoverable, and with the shim dead the rewrite had nothing to run and a Windows deletion fell back to a hard one. The runtime's own probe reported mavis-trash is not callable on every startup — 21 times in one test:capabilities run, 42 in one test:webui run.

  • Chinese prose was read as math. A dollar-delimited run that carries Chinese is prose, not a formula: 用 $state 读取,结果是 $x^2$。 opened at the first dollar and swallowed the paragraph into the formula, and KaTeX then complained about every Chinese character in it. Math is not written in Chinese, so a body that carries it is not math.

  • Two suites could not run on Windows at all. The observability directory is a filesystem path, so it carries the host's separator, but the assertions compared it against POSIX-shaped literals — on Windows the directory is \data\v2\observability\mcode and the literal never matched. The Bash output suite ran commands written for sh: printf does not exist in PowerShell, and a quoted executable is a string expression to PowerShell rather than a program to run, so "C:\... ode.exe" -e "..." is a ParserError. The commands are now spelled for the shell that will run them, and PowerShell carries the native exit code over explicitly. The POSIX commands are unchanged, so a POSIX host runs exactly what it ran before.

  • The SSH store's atomic write could fail at random on Windows. It renamed a sibling file over the real one, and Windows refuses a rename while another process holds the file open for a moment — an indexer, a scanner, a concurrent reader. Every other atomic write in the repository already retries that refusal (the TUI's auth and identity stores, the update service, the local runtime's auth context, the provider-presets repository); the SSH store was the one path that did not. The shared helper needed for it did not exist yet — it was synchronous, and this rename is a promise — so it gains an asynchronous sibling whose wait is a timer rather than a blocking sleep. The rename stays awaited: the commit must not return before the document is in place, and a suite case says so.

  • Two more suites could not run on Windows at all. The sandbox backend joins the git template dir onto the sandbox temp dir, so the path carries the host's separator, and the assertion compared it against a POSIX-shaped literal. The mcode-tools acceptance read the host keys back with env | grep, which is POSIX shell syntax — on the Windows runtime the shell is PowerShell, where env does not exist and the command does not parse.

  • The native PTY acceptance host stayed alive after it was done. Node-pty's Windows console-list helper is forked on every terminal kill to enumerate the processes attached to the shell's console; a shell hosted by ConPTY has a pseudo-console rather than a console, so the helper's AttachConsole always fails there, it dies without answering, and node-pty falls back to a five-second timer to resolve the promise. That timer lives in the process that killed the terminal, so every kill left the host five seconds of work it had not asked for — measured at 720ms of real work inside a 5.74s process. The acceptance host now exits once it has reported, in the send callback, which runs after the message has been flushed. The case says so: the host has to be gone within two seconds of reporting that it closed, and a shutdown that does not arrive carries the host's own trace of where it was. The alternative — node-pty's useConptyDll option, which skips the helper entirely — was measured and is worse: the process did not exit at all.

Two release-tool checks could not pass on a Windows host and now do. The marketplace-version check compared a path.relative() result against POSIX-shaped literals, so the shared module it is meant to exclude never matched. The locale check asserted an en-US ICU locale that Windows cannot be made to report — LC_ALL, LANG, NODE_ICU_DATA and ICU_DEFAULT_LOCALE were each measured to leave it alone.

Validation

Windows 11 (10.0.26100), Node 24.18.0, Chrome and Edge installed.

Check Result
check:source (6110 paths), typecheck:webui, check:webui-dependency, check:webui-presentation, check:webui-motion, check:webui-overlays, check:webui-feedback, build:webui, check:webui-boundary, test:release-tools pass
test:windows 6/6 pass (5 before, plus the new trash contract)
test:webui 0 failed / 4452 passed / 44 skipped
test:webui-browser 474 passed / 4 failed of 478
test:capabilities 40 failed / 6393 passed / 63 skipped

Red before, green after, for each change:

  • 8.3 alias — the child exited 3221226505 (0xC0000409); with the fix reverted the same child aborts again. On the base, the abort also takes the Vitest worker with it: real-host-mcode-tools-bash-environment fails with Worker exited unexpectedly on the base and only with the assertion on this branch.
  • trash shim — the runtime's own probe answered available = false with require is not defined in ES module scope; it answers available = true now, and through the installed launcher both a file and a Chinese-named file reach the Recycle Bin.
  • Chinese prose — KaTeX warned about every Chinese character in the paragraph; the paragraph is prose now and the formula beside it still renders as math.

Failures that are not this branch's:

  • the 4 test:webui-browser failures are screenshot comparisons against the *-win32.png baselines fix(webui): repair baseline CI across Linux, macOS and Windows #11 recorded. They fail identically on fix(webui): repair baseline CI across Linux, macOS and Windows #11's head without this branch's changes, on this host: those baselines do not match this machine's rendering. fix(webui): repair baseline CI across Linux, macOS and Windows #11's own Windows CI passes them.
  • the 40 test:capabilities failures are the set this branch started from, less the seven this branch fixes. test:webui is now clean on Windows; test:status-contract, test:release-tools, test:sandbox and test:webui-package all pass here too. test:capabilities was compared change-for-change against origin/main and the failing sets are identical. That test's command (env | grep ...) is POSIX-only, and it passes on the CI runner only because Git-for-Windows' bash is on PATH there.
  • test:policy fails 15 cases on Windows because the POSIX branch of the trash check asks for an execute bit, which Windows does not have. test:policy is restricted to Linux and macOS, so this never reaches CI. Left alone here.

The Windows CI run on the first push

The first Windows run failed in test:webui, on real-host-loopback.test.ts → "lists builtin models on first boot without runtime environment or a remote catalog", with Test timed out in 5000ms. That case boots the real host and calls an operation over the loopback service — exactly what the four cases after it do, and all four of those run on 120s. This one alone fell back to Vitest's 5s default, which a cold, loaded Windows runner does not always clear. It passes on this host, on this branch and on the base alike, so it is the deadline rather than the behaviour: the case now carries the file's own 120s, and the assertions are unchanged.

test:windows is not part of any workflow at the moment, so the new trash contract test is not exercised by CI. Whether to put it back into the platform verification is a maintainer call.

Publication and contribution checks

  • I have permission to contribute these changes under the existing licenses applicable to the changed files/packages; imported material and its provenance are identified and existing notices are preserved.
  • No credentials, account data, real user content, internal source history or private review material is included.
  • Added/removed source files were reviewed before regenerating release/public-source.json; new tests are declared in test/vitest-suites.json where applicable.
  • Shared English/Chinese documentation and capability/verification records are updated where applicable. Mock/offline results are not described as live-service acceptance.

Maintainer handoff

Publication scope or license changes (if any): none.

Shared-source port: not needed / pending / complete. Record public PR references only; keep private links and review material out of this PR.


Note on the branch location: the account that owns this branch has read-only access to this repository, so it lives on a fork and this pull request is opened against main. Cherry-picking the seven commits is equivalent.

@antianqi

Copy link
Copy Markdown
Collaborator Author

Windows-only defects #11 does not carry — merge #11 first, this PR is based on it.

@antianqi
antianqi force-pushed the fix/windows-process-and-trash-defects branch from 9ef8dd8 to 3f22ac5 Compare November 10, 2026 02:55
@antianqi
antianqi changed the base branch from fix/webui-ci-baseline to main November 10, 2026 02:55
@antianqi antianqi changed the title fix: repair an 8.3-alias abort, the trash shim's module type, and Chinese prose in math fix(windows): repair the 8.3-alias abort, the trash shim's module type, Chinese prose in math, and two POSIX assumptions Nov 10, 2026
…cess

Windows reports a changed file under its long name, and libuv compares that
name against the directory string the watch was given. A directory reached
through its 8.3 short alias -- which is how a temp directory under a
short-named home directory spells itself -- therefore fails libuv's own
!_wcsnicmp(filename, dir, dirlen) assertion, and that assertion takes the
process down instead of raising an error.

realpathSync.native resolves the alias to the long path; the JavaScript
implementation of realpathSync does not, so the native one is the one that
matters here. A directory that cannot be resolved falls back to the path it
was given.

The test runs the watcher in a child process on purpose: the assertion is
not catchable, so isolating it turns a regression into a failed assertion
instead of a dead test worker. The child watches the 8.3 alias and writes
through the long path, which is the pair that used to abort.

(cherry picked from commit 21b8ea65d9b7e79e319f2f848ffcc95a8893c1a3)
The plugin directory watcher had the same defect the skills watcher had:
Windows reports a changed file under its long name, and libuv compares that
name against the directory string the watch was given. A directory reached
through its 8.3 short alias — which is how the plugin directory under a
short-named home directory spells itself — therefore fails libuv's own
!_wcsnicmp(filename, dir, dirlen) assertion, and that assertion takes the
process down instead of raising an error.

realpathSync.native resolves the alias to the long path; the JavaScript
implementation of realpathSync does not. A directory that cannot be resolved
is watched under the path it was given.

(cherry picked from commit 841a9a032780286b78f6794c829ba4399c76ce78)
The shim is a CommonJS script, but it was seeded as `mavis-trash.js`, and
Node reads the module type of a `.js` file from the nearest ancestor
`package.json`. An ancestor that says `"type": "module"` — a user's home
directory can easily hold one — makes Node parse the shim as ESM, where
`require` is not defined, and the shim never runs.

The consequence was not cosmetic. The permission pipeline rewrites `rm` to
`mavis-trash` so that a deletion stays recoverable; with the shim dead the
rewrite had nothing to run, and a Windows deletion fell back to a hard one.
The runtime's own probe reported `mavis-trash is not callable` on every
startup.

The shim is seeded as `mavis-trash.cjs` now. `.cjs` is CommonJS whatever
the nearest ancestor says, and the `.cmd` launcher names the same file.

The executor's name guard accepts the old `.js` name as well. It answers
"does this path look like the trash script", and whether the script actually
runs is decided by the probe, not by its name.

The Windows contract test states the invariant: a data directory under an
ancestor that declares ESM still gets a shim the runtime can call.

(cherry picked from commit ca5a4d386f94d61c921b341eb78beba0a302ffcd)
The inline math tokenizer matched any two dollars on a line. A shell
variable in prose therefore paired with a later dollar and swallowed the
paragraph between them, and KaTeX then complained about every Chinese
character it found there.

Math is not written in Chinese, so a body that carries Chinese characters
or the punctuation that comes with them is not a formula. A real formula
between two dollars still renders as one.

(cherry picked from commit fb3aca1bcfef843a464957031a5da5861cb06941)
Two checks could not pass on Windows.

The marketplace-version check compared a path.relative() result against
POSIX-shaped literals, so the shared module it is meant to exclude never
matched and was reported as a second declaration. The same relative path
fed the test-file filter, whose pattern also expects a forward slash, so
test files were counted as offenders too. Normalizing the separator once
at the source fixes both.

The locale check asserted that the child's ICU locale is en-US. The
runner does pin LANG, LANGUAGE, LC_ALL and LC_MESSAGES, and on POSIX
Node derives its default locale from those. Windows has no POSIX locale
variables: Node reads the OS user default locale, and LC_ALL, LANG,
NODE_ICU_DATA and ICU_DEFAULT_LOCALE were each measured to leave it
unchanged. The child is a real process on this host whatever the
simulated platform says, so the assertion is now keyed on the host
platform and only demands a pinned locale where pinning is possible.

(cherry picked from commit edfa52d5d1d18c76e356b238298825e1144992b5)
The new watcher test is a reviewed source path, so the inventory names it.
The case boots the real host and calls an operation over the loopback
service, exactly as the four cases after it do, and all four of those run
on 120s. This one alone fell back to Vitest's 5s default, which a cold
Windows runner does not always clear: the host boot, the service start and
the catalog read all have to fit inside it, and the runner that failed it
was visibly loaded.

The assertions are unchanged, and the deadline is the file's own.
Both files assert something the host's own spelling made unreachable.

The observability directory is a filesystem path, so it carries the host's
separator, but the assertions compared it against POSIX-shaped literals.
On Windows the directory is `\data\v2\observability\mcode` and the
literal never matched.

The Bash tool runs PowerShell on Windows — the runtime prefers it, because
it is system-native and has no MSYS path problems — and the commands in the
output suite were written for `sh`: `printf` does not exist there, and a
quoted executable is a string expression to PowerShell rather than a program
to run, so `"C:\...\node.exe" -e "..."` is a ParserError. The commands are
now spelled for the shell that will run them, and PowerShell carries the
native exit code over explicitly, because it reports it in $LASTEXITCODE and
exits with its own status otherwise.

The POSIX commands are unchanged, so a POSIX host runs exactly what it ran
before.
@antianqi
antianqi force-pushed the fix/windows-process-and-trash-defects branch from 2296ad8 to c8000a3 Compare November 10, 2026 03:45
Both compared a path the host spells its own way against a POSIX-shaped
literal, and one ran a POSIX command on a host whose shell is PowerShell.

The sandbox backend joins the git template dir onto the sandbox temp dir,
so the path carries the host's separator; on Windows the directory is
`\tmp\session-1\git-templates-empty` and the literal never matched.

The mcode-tools acceptance read the host keys back with `env | grep`, which
is POSIX shell syntax — on the Windows runtime the shell is PowerShell,
where `env` does not exist and the command does not parse. Node reads the
same environment the child was given and prints it in the same shape on
both, so what the case measures is unchanged.
…rite does

Windows refuses a rename while another process holds the file open for a
moment — an indexer, a scanner, a concurrent reader — and the refusal is
transient. The SSH connection store wrote its document by renaming a
sibling file over the real one, so the store failed at random on Windows
and nowhere else.

Every other atomic write in the repository already retries that refusal:
the TUI's auth and identity stores, the update service, the local runtime's
auth context, the provider-presets repository. The SSH store was the one
path that did not, because the helper it needed did not exist yet — the
helper was synchronous, and the store's rename is a promise.

The shared helper gains an asynchronous sibling. Its wait is a timer
rather than a blocking sleep, so a server process does not stall its event
loop while a locked file is retried. The rename stays awaited: the commit
must not return before the document is in place, and the suite has a case
that says so.

The new helper has its own cases: a refusal is retried on Windows and
gives up after the budget, it is not retried off Windows, it is not
retried for an error that does not mean "held file", and the wait between
attempts lets other work run.
@antianqi antianqi changed the title fix(windows): repair the 8.3-alias abort, the trash shim's module type, Chinese prose in math, and two POSIX assumptions fix(windows): repair the 8.3-alias abort, the trash shim's module type, Chinese prose in math, and the assumptions a POSIX host hides Nov 10, 2026
@UncleMoc
UncleMoc merged commit e6db851 into mcode-webui:main Nov 10, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants