Repository navigation
Conversation
On the comspec path (.cmd/.bat shims such as claude.cmd, and dsh.cmd),
quoteWinToken wrapped a whitespace-bearing token in quotes but left its
trailing backslashes as they were. The program the shim starts parses
2n backslashes before a quote as n (MSVCRT / CommandLineToArgvW, the
same rule splitWindowsCommandLine implements), so:
- an odd run ("list C:\My Projects\") was refused by winCmdUnsafeToken
as "an odd number of trailing backslashes";
- an even run passed the ranxianglei#2196 guard as safe but arrived with half its
backslashes ("C:\My Dir\\" -> "C:\My Dir\").
Doubling the trailing run inside the quotes makes both lossless, so the
odd-run refusal is removed. Round-tripping 200,000 random tokens of
letters, spaces, tabs and backslashes through quoteWinToken and
splitWindowsCommandLine now reproduces every token; before, 11,034 of
the tokens the guard accepted came back changed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014TonJ1geSd97oAtSBZofUK
[bot] 🏷 Conflict resolved and pushed. The merge conflict between PR #6190 and master is cleared. What I did this run:
Final live state (verified against GitHub this run, not from memory):
No red CI to fix (checks are passing/pending). The PR will transition to 八问(中文,供人工 reviewer):
判定:冲突已消解并推送,PR 现为 mergeable( |
# Conflicts: # CHANGELOG.md
[bot] 🏷 Conflict re-resolved and pushed. Master moved again since my last run, which re-dirtied the PR. I merged the current master tip into the PR branch and cleared the conflict. What I did this run:
Final live state (verified against GitHub this run, not from memory):
八问(中文,供人工 reviewer):
判定:冲突已再次消解并推送,PR 现为 mergeable( |
[bot] 🏷 Update — CI is now fully green. (My previous reply above at Floor 15 already covered the conflict resolution; this is a status update since CI has since finished.) Re-checked live state just now (not from memory):
Bottom line: the conflict is resolved and CI is green. The PR is ready to merge — the remaining |
[bot] 🏷 No action needed — the live state shows no conflict and CI is green. (Re-verified against GitHub this run, not from the forwarded claim.) Live state just now:
Summary across my runs on this PR:
The PR is ready to merge; the only remaining gate is human review/approval. I did not re-run the merge because the live state already reflects a clean, green, mergeable PR. |
[bot] 🏷 Fourth re-trigger — the live state is unchanged and there is no conflict to fix. (Re-verified against GitHub this run, not from the forwarded claim.) Live state just now:
Why the "dirty" alerts keep firing: the live merge state is What this means: the PR is ready to merge. The only remaining step is a human reviewing/approving and merging it. I have no further CI action to take:
Repeated "dirty" alerts will keep firing until the PR is merged (or the detection stops treating |
🔶 需要决策 PR #6190 is ready to merge — the only remaining gate is human review, and the CI-engineer lane keeps getting re-triggered on it. (Live-verified against GitHub this run; 5th check, state unchanged.) Live state:
Why the CI-engineer lane keeps firing: the blocker-detection treats any non- Options:
Recommendation: A. (CI engineer stopping here per owner policy 2026-11-01 — this needs a human decision, not more CI work.) |
The PR's exact-line tests pin the bytes quoteWinToken emits, but the property being fixed — that those bytes decode back to the token under the receiving program's CommandLineToArgvW rule — was only verified by a manual 200k-token probe. Add a committed round-trip (quoteWinToken -> splitWindowsCommandLine) so the lossless guarantee is testable in CI and a regression in either the doubling or the 2n->n halving is caught. Review of ranxianglei#6190 (small finding fixed on the spot).
ranxianglei
left a comment
There was a problem hiding this comment.
(ai: vllm-qwen/qwen3.8-27b)
APPROVE — correct, well-scoped, tests have teeth.
Correctness (traced, not assumed). The comspec leg builds comspec /d /s /c "<line>"; the receiving program parses it with the MSVCRT / CommandLineToArgvW rule — 2n backslashes before a quote → n (quote toggles), 2n+1 → n + literal quote. I traced that against splitWindowsCommandLine (src/claude-native-bootstrap.ts:232), which models the rule faithfully. Doubling the trailing run (token.replace(/(\\+)$/, "$1$1")) is exactly the inverse: the doubled run is even, so the receiver halves it back to the original. Verified standalone (no deps): the fixed quoters round-trip 6/6 representative tokens and 175k/175k randomized tokens through splitWindowsCommandLine; the pre-fix (master) quoters fail the odd case (backslash lost + quote swallowed) and the even case (halved). Both mirrors are updated identically (src/launcher.ts:6504, src/dsh-channel.ts:436), and dropping the odd-trailing refusal in src/win-cmd.ts is correct because the doubling makes that case lossless.
Tests. Real, not tautological: the exact-line pins (planClientSpawn/planDshSpawn) fail if the doubling regresses; the safe-set rows fail if the guard re-refuses odd trailing; the unit test pins the doubling itself.
Behavior change (disclosed, intended). Windows comspec leg only: a whitespace-bearing token ending in a backslash run — odd run: was refused → now verbatim; even run: was silently halved → now verbatim. Space-free tokens, interior backslashes, the direct-spawn (.exe) leg, non-win32, and every other #2196 refusal class are byte-identical (the existing #679 regression pin still passes). No cache/retry/cursor surface; no kernel/ changes; CI green.
已顺手修:补一条 comspec 尾随反斜杠 round-trip 测试(PR 的核心性质此前只有手工 200k 探针、未进 CI;现在 quoteWinToken → splitWindowsCommandLine 的无损往返在 CI 可测,加倍或 2n→n 砍半任一回归都会被抓住)+ commit d7f719b
Note (non-blocking): the PR has no linked issue; the body is self-sufficient and the e-work mirror carries the trace, but per house convention it would ideally reference a filed issue.
结构化八问(中文,供人工 reviewer)
- 是什么问题:Windows 上
.cmd/.batshim 走comspec /d /s /c "<line>",quoteWinToken给含空格 token 加引号时不加倍尾随反斜杠,而接收端按 MSVCRT/CommandLineToArgvW 把「引号前 2n 个反斜杠」解析成 n 个——奇数尾随被 #2196 守卫拒掉、偶数尾随过了守卫却被砍半,两者都违反「安全 token 逐字通过」的契约。 - 什么原因导致的:
quoteWinToken(launcher 与 dsh-channel 两处镜像)只加引号、没考虑 MSVCRT 的 2n→n 规则,尾随反斜杠在闭合引号前被砍半(偶)或吞掉引号(奇);#2196 守卫用「拒绝奇数尾随」打补丁,治标(拒绝普通 Windows 路径)且没修偶数砍半。 - 影响范围与严重程度:仅 Windows、仅 comspec 车道(claude.cmd/dsh.cmd/codex.cmd 等未升级到 node+entry 的 shim)。触发:含空格的 prompt/参数/profile 以反斜杠结尾(如
C:\My Projects\)。奇数→硬拒绝(启动失败、报可操作错误);偶数→静默损坏(参数砍半)。非全量不可用(.exe 直发与无空格 token 不受影响),但对常见输入形状是真实功能损坏。 - 怎么修复的:引号内把尾随反斜杠串加倍(
token.replace(/(\\+)$/, "$1$1"),cross-spawn 同款标准修法),接收端 2n→n 砍半后正好还原;同步删掉 winCmdUnsafeToken 里已无必要的奇数尾随拒绝。 - 是否有回归问题:逐条过既有行为——无空格 token(原样裸输出、不加倍)✓;非尾随(内部)反斜杠(正则只匹配尾部
/(\\+)$/)✓;#2196 其余拒绝类(空/引号/%/元字符/换行)✓;#679 安全 argv 的 comspec 行字节级不变(既有回归钉测试仍过)✓;.exe 直发与非 win32 路径不动 ✓。高危模式(fail-fast 变吞错、阈值/时序/输出漂移)均无:守卫仍拒绝所有危险类,改动只让「更多」token 变安全(原先被拒/被坏的),从不让更少。行为变更已披露(见上)。 - 是否破坏缓存:不涉及——进程 argv 启动路径,无缓存/重试/游标/去重键。
- 是否改了设计方向:否——补完既有 #679/#2196 comspec 包裹设计(安全集合契约),把尾随反斜杠从「拒绝/砍半」变为「无损」,无架构/边界/数据流转向。
- 是否引入了新的配置:否——无新 env/config/默认值。
判定:可合(APPROVE)。 修法正确、独立验证过 round-trip、测试有牙、无 kernel 改动、CI 全绿。
[bot] PR #6190(fix(win-cmd):cmd.exe 引号内加倍尾随反斜杠)审核完成 → APPROVE。修法正确:独立验证 round-trip(fixed 版本 6/6 代表 token + 175k 随机全过;master 奇数尾随丢反斜杠+吞引号、偶数砍半,均坏),两处 quoteWinToken 镜像同步改、winCmdUnsafeToken 删奇数拒绝正确;测试有牙(exact-line 钉 + safe-set + 单测);无 kernel 改动、无新配置、行为变更已披露;CI 全绿(18 过 / 12 跳过 / 0 红)。已顺手补一条 comspec 尾随反斜杠 round-trip 测试进 CI(PR 核心性质此前只有手工 200k 探针、未进 CI)+ commit d7f719b。mergeable_state=blocked,等人工合并。 |
|
Landed via batch PR #6482 (merged) — closing as superseded. |
The PR's exact-line tests pin the bytes quoteWinToken emits, but the property being fixed — that those bytes decode back to the token under the receiving program's CommandLineToArgvW rule — was only verified by a manual 200k-token probe. Add a committed round-trip (quoteWinToken -> splitWindowsCommandLine) so the lossless guarantee is testable in CI and a regression in either the doubling or the 2n->n halving is caught. Review of ranxianglei#6190 (small finding fixed on the spot). (cherry picked from commit d7f719b)
Problem
Windows
.cmd/.batshims (claude.cmd,dsh.cmd, …) are launched ascomspec /d /s /c "<line>", andquoteWinTokenbuilds that line. It wraps a whitespace-bearing token in quotes but leaves its trailing backslashes as they are. The program the shim starts parses 2n backslashes before a quote as n. That's the MSVCRT / CommandLineToArgvW rule, whichsplitWindowsCommandLineinclaude-native-bootstrap.tsalready implements. So:list C:\My Projects\is rejected bywinCmdUnsafeTokenas "an odd number of trailing backslashes". This is an ordinary Windows path in a prompt.C:\My Dir\\→C:\My Dir\, andends in \\→ends in \. That contradicts the guard's contract that safe tokens cross verbatim.The live round-trip tests in
win-cmd-argv.test.tsonly exercise the direct-spawn leg, which is why this went unnoticed on the comspec leg.Change
quoteWinTokeninlauncher.ts, and its mirror indsh-channel.ts: when wrapping in quotes, double the trailing backslash run (token.replace(/(\\+)$/, "$1$1")). This is the standard fix, the same one cross-spawn uses. Space-free tokens and non-trailing backslashes are unchanged.winCmdUnsafeToken: drop the odd-trailing-backslash refusal, now unnecessary, and update the docstring.Tests
tests/fix-679-windows-launch.test.ts:quoteWinTokendoubles a trailing run and leaves everything else alone.tests/win-cmd-argv.test.ts:planClientSpawnandplanDshSpawnwith odd and even trailing runs.I couldn't install the repo's dev dependencies in my environment, so I didn't run the full suite,
tscor lint. What I did:src/win-cmd.tsand the exactquoteWinToken/splitWindowsCommandLinesources, using Node's built-in type stripping. They pass with this change, and the new ones fail onmaster.node --experimental-strip-types --check).quoteWinTokenand thensplitWindowsCommandLine. With this change all 200,000 come back identical with none refused. Onmaster, 11,034 of the guard-approved tokens come back changed and 54,174 are refused.CI will be the first full run. Happy to adjust anything it flags.
CHANGELOG.md: entry added under[Unreleased] → Fixed.