Repository navigation
fix(wpm): deliver and migrate the shim forwarder across the wpm lifecycle (#1207) - #1228
Conversation
…ycle (#1207) The forwarder from #1217 cut the dispatch cost of `layout: shim` commands, but three lifecycle paths still could not reach it: - self-update: the release zip never carried winuxcmd-shim.exe (the install rules only installed winuxcmd.exe) and apply_update copied only the image, so `wpm update winuxcmd` left the old winuxcmd dispatcher in place; - existing installs: .wpm/shims.map is written by install only, so a root that predates the forwarder had no map and its shims stayed hardlinks of the old winuxcmd.exe with nothing to relink them; - uninstall: shims were recognised by content against winuxcmd.exe only, so every forwarder shim was refused as a protected file, its map entry survived, and shim packages could not be uninstalled cleanly. remove_shim_map_entries existed but was never called. Measured on this machine (interleaved before/after roots, n=21, medians), hop = shim call minus the direct payload call: ssh +24.7 ms -> +10.3 ms curl +23.7 ms -> +12.6 ms node +21.3 ms -> +9.1 ms python +19.2 ms -> +15.0 ms Changes: - CMake install rules ship winuxcmd-shim.exe with the release; - update_winuxcmd stages the forwarder from the extraction and hands it to the helper (__apply-update --forwarder); apply_update lands it in usr/bin after a successful swap, before the relink, best effort; - rebuild_links records shim-layout receipts the map lacks from the local index (lazy: no index parse without shim receipts) and relinks those shims onto the forwarder, with the same park-and-relink contract the builtin links got in #1206/#1194; activation runs this rebuild at every shell start, so an old install migrates itself; - uninstall recognises forwarder shims (falling back to the winuxcmd.exe links of older roots), drops the package's map entries, and checks aliases against the shim they actually link instead of the payload. Semantics kept: roots without the forwarder behave exactly as before; links verify (#1226) still reports only builtin command links; private payload DLLs stay under opt/<pkg>, never in a directory on %PATH%.
caomengxuan666
left a comment
There was a problem hiding this comment.
Independent review (fresh worktree @ a816a2c, own build + test + bench run). Verdict: APPROVE-WITH-NITS. All four lifecycle paths verified end-to-end; findings are nits only.
Verified
- (a) CMake install:
cmake --installinto a staging prefix putsusr/bin/winuxcmd-shim.exenext to the image; CI packages via CPack (Runtimecomponent is inCPACK_COMPONENTS_ALL), so the next release zip carries the forwarder. The 1.1.14 install on this machine indeed has no shim — the premise holds. - (b) Self-update:
--forwarderis optional end to end (parse_hidden_value→ empty → skip);install_forwarderis best-effort (every failure reported, never fails the update), runs after a successful swap and beforefinish_update, so the relink sees it, and is correctly skipped on the two image-failure paths. Test pins both the delivery and the no---forwarderno-op. - (c) Migration: lazy claim verified — receipts-only first pass; the local index is parsed only when a shim receipt exists.
move_aside-based park-and-relink in the shim loop (wpm.cpp:856-870) is a faithful mirror of the builtin loop (775-788), matching the #1194/#1206 contract. "Activation runs this rebuild at every shell start" confirmed againstactivate-winuxcmd.sh:103. - (d) Uninstall:
is_our_shimcovers forwarder links and the legacywinuxcmd.exelink/copy fallback; aliases are removed before command shims and are now compared againstusr\bin\<target>.exe— the filecreate_package_aliasesactually links (the old payload comparison could never match);remove_shim_map_entriesfinally wired; a foreign file is soft-refused and kept. All three behaviors are test-pinned. - Benchmarks (same method, independent run: n=21, interleaved, medians, live niubash root as "before"): ssh hop +25.8 → +10.5 ms (author: +24.7 → +10.3), curl +25.4 → +12.1 ms (author: +23.7 → +12.6). A
/MT /Osrelease build of the shim is 187,904 bytes — the "~188 KB static-CRT forwarder" figure is real, and the residual after-hop sits inside the claimed 9-13 ms floor. - Semantics kept: the #1217 no-forwarder pin (shim links
winuxcmd.exe, no map) is unmodified and green;links verify(#1226) is untouched and only walkscommand_names()(builtins) — package shims never enterstale_command_links; a live shim run resolvedlibcrypto.dll/libcurl-x64.dllfrom beside the payload with nothing added to%PATH%. - Tests:
wpm.*69/69; full ctest 2982/2982 on this machine (the author's one machine-native failure did not reproduce here); PR CI (x64 + arm64, oracle, compare) green. - Red lines: diff is exactly 4 files +439/−30, every hunk on-topic (the two touched lines in the #1217 test are a cosmetic line-split); MIT throughout, the shim is an independent MIT unit.
Nits
- CHANGELOG.md — no
[Unreleased]entry, while the repo convention documents user-visible wpm fixes (see the #1217 forwarder and #1226 verify entries). The fixedskipping protected fileuninstall regression and the forwarder delivery deserve a line. - wpm.cpp:711 — migration resolves command names from the local index, not the receipt (receipts record no commands). A shim package dropped/renamed in its source index is silently never migrated; the payload-existence check bounds the damage and a reinstall heals it. Accepted trade-off, but worth a comment saying so.
- wpm.cpp:842 — the
write_shim_mapreturn value is discarded while the verbose lines above (836-839) already announce registration; a failed write is silent (self-heals on the next rebuild). Contrastset_shim_map_entry's caller at 3211-3217, which reports this failure. - wpm.cpp:688-689 (comment only) — "pays only a directory listing" understates: the first pass reads and JSON-parses every receipt. What it avoids is the index parse; the lazy claim itself is accurate.
- clang-format (informational): lines 692-695 and 713-724 are re-wrapped by current clang-format, but they match the file's established style (the same version flags pre-existing lines, e.g. 295-315), and CI does not gate formatting. No change requested.
caomengxuan666
left a comment
There was a problem hiding this comment.
Independent review (fresh worktree @ a816a2c, own build + test + bench run). Verdict: APPROVE-WITH-NITS. All four lifecycle paths verified end-to-end; findings are nits only.
Verified
- (a) CMake install:
cmake --installinto a staging prefix putsusr/bin/winuxcmd-shim.exenext to the image; CI packages via CPack (Runtimecomponent is inCPACK_COMPONENTS_ALL), so the next release zip carries the forwarder. The 1.1.14 install on this machine indeed has no shim — the premise holds. - (b) Self-update:
--forwarderis optional end to end (parse_hidden_value→ empty → skip);install_forwarderis best-effort (every failure reported, never fails the update), runs after a successful swap and beforefinish_update, so the relink sees it, and is correctly skipped on the two image-failure paths. Test pins both the delivery and the no---forwarderno-op. - (c) Migration: lazy claim verified — receipts-only first pass; the local index is parsed only when a shim receipt exists.
move_aside-based park-and-relink in the shim loop (wpm.cpp:856-870) is a faithful mirror of the builtin loop (775-788), matching the #1194/#1206 contract. "Activation runs this rebuild at every shell start" confirmed againstactivate-winuxcmd.sh:103. - (d) Uninstall:
is_our_shimcovers forwarder links and the legacywinuxcmd.exelink/copy fallback; aliases are removed before command shims and are now compared againstusr\bin\<target>.exe— the filecreate_package_aliasesactually links (the old payload comparison could never match);remove_shim_map_entriesfinally wired; a foreign file is soft-refused and kept. All three behaviors are test-pinned. - Benchmarks (same method, independent run: n=21, interleaved, medians, live niubash root as "before"): ssh hop +25.8 → +10.5 ms (author: +24.7 → +10.3), curl +25.4 → +12.1 ms (author: +23.7 → +12.6). A
/MT /Osrelease build of the shim is 187,904 bytes — the "~188 KB static-CRT forwarder" figure is real, and the residual after-hop sits inside the claimed 9-13 ms floor. - Semantics kept: the #1217 no-forwarder pin (shim links
winuxcmd.exe, no map) is unmodified and green;links verify(#1226) is untouched and only walkscommand_names()(builtins) — package shims never enterstale_command_links; a live shim run resolvedlibcrypto.dll/libcurl-x64.dllfrom beside the payload with nothing added to%PATH%. - Tests:
wpm.*69/69; full ctest 2982/2982 on this machine (the author's one machine-native failure did not reproduce here); PR CI (x64 + arm64, oracle, compare) green. - Red lines: diff is exactly 4 files +439/−30, every hunk on-topic (the two touched lines in the #1217 test are a cosmetic line-split); MIT throughout, the shim is an independent MIT unit.
Nits
- CHANGELOG.md — no
[Unreleased]entry, while the repo convention documents user-visible wpm fixes (see the #1217 forwarder and #1226 verify entries). The fixedskipping protected fileuninstall regression and the forwarder delivery deserve a line. - wpm.cpp:711 — migration resolves command names from the local index, not the receipt (receipts record no commands). A shim package dropped/renamed in its source index is silently never migrated; the payload-existence check bounds the damage and a reinstall heals it. Accepted trade-off, but worth a comment saying so.
- wpm.cpp:842 — the
write_shim_mapreturn value is discarded while the verbose lines above (836-839) already announce registration; a failed write is silent (self-heals on the next rebuild). Contrastset_shim_map_entry's caller at 3211-3217, which reports this failure. - wpm.cpp:688-689 (comment only) — "pays only a directory listing" understates: the first pass reads and JSON-parses every receipt. What it avoids is the index parse; the lazy claim itself is accurate.
- clang-format (informational): lines 692-695 and 713-724 are re-wrapped by current clang-format, but they match the file's established style (the same version flags pre-existing lines, e.g. 295-315), and CI does not gate formatting. No change requested.
|
Merge note (nits from the review, non-blocking): please add the |
… landed via #1228; keep main's comment, this branch retains the index guard
What was left of #1207, and what this closes
#1217 landed the forwarder itself (
winuxcmd-shim.exe, hop 24.5 → 12.1 ms) and noted a follow-up. Picking the ticket back up, the forwarder still could not reach an installation through any path except reinstalling packages — and one path had regressed:install(TARGETS winuxcmd), so the 1.1.14 zip has nowinuxcmd-shim.exe(verified against the published release), andwpm update winuxcmd— which stages exactly what the indexfilesmapping names — copied only the image. An updated install stayed on the old dispatcher..wpm/shims.mapis written byinstallonly. A root that predates the forwarder (this machine's niubash root: no forwarder, no map, shims hardlinked to the oldwinuxcmd.exe) had nothing to relink its shims with, andrebuild_links's shim loop iterated a map that did not exist.winuxcmd.exeonly. A forwarder shim (188 KB vs 4.7 MB) fails both checks, so uninstalling any shim package reportedskipping protected filefor every command, left every shim behind, and left its.wpm/shims.mapentries pointing at a deleted payload.remove_shim_map_entriesexisted but was never called from anywhere.Changes
install(TARGETS winuxcmd-shim ...)— the next release zip carries the forwarder.update_winuxcmdpicks upwinuxcmd-shim.exefrom the extraction and passes it to the helper (__apply-update --forwarder);apply_updatelands it inusr\binafter a successful swap, before the relink. Best effort: a failure is reported, the image update stands.rebuild_links: when the forwarder is present, shim-layout receipts whose commands the map lacks are recorded from the local index (lazy: no index parse for roots without shim receipts), then the same pass relinks those shims onto the forwarder. Activation runslinks rebuild --forceat every shell start, so an old install is one shell start away. Held shims now get the same park-and-relink contract the builtin links got in wpm update winuxcmd can leave command links on the previous image, silently #1206/fix(wpm): replace held payload files by parking them, not by refusing #1194 instead of a barefailedcount.winuxcmd.exe; anything else stays and is reported as protected. The package's map entries are dropped (remove_shim_map_entriesfinally called), and aliases are checked against the shim they actually link (usr\bin\<target>.exe) instead of the payload file, which never matched. Alias removal runs before command-shim removal, because alias identity is defined against the shim.No new i18n keys: the touched regions (
apply_update, verboserebuild_linkslines) use plain English by established in-file precedent (wpm: failed to backup winuxcmd.exe,wpm: relinked ...); the helper's output lands in the update log.Semantics kept (install / uninstall / update)
winuxcmd.exe, no map is written: the perf(wpm): a small forwarder for layout: shim packages (-12.4 ms per call) #1217 test still pins this).errors, package still removed).wpm update winuxcmdswaps the image exactly as before; the forwarder is added to what the helper lands when the release provides it. Links verify (fix(wpm): keep two rollback copies after an update, and pin the #1206/#1208 acceptance in tests #1226) still reports only builtin command links;stale_command_linksis untouched.opt\<pkg>, never in a directory on%PATH%(acceptance 2).Benchmarks (this machine, spawn-to-exit wall time, python harness, interleaved before/after roots, n=21, medians)
The "before" root is the live niubash install (WinuxCmd 1.1.14 image, shims hardlinked to the old dispatcher); the "after" root is the same payloads with
winuxcmd-shim.exefrom this branch and its map. Hop = shim call − direct payload call.Standalone runs agree (n=15, medians):
usr\bin\python.exe -c pass/ payloadusr\bin\ssh.exe -V/ payloadusr\bin\curl.exe --version/ payloadusr\bin\node.exe --version/ payloadusr\bin\ls.exe(builtin link)bin\git.exe(entry link, no hop)The remaining ~9–13 ms is one native spawn of a 188 KB static-CRT forwarder plus its map read and
CreateProcess— the irreducible cost of the two-process shape that keeps private DLLs off%PATH%. Python's after-hop is noisy (its payload median itself moved 40.0 → 41.6 ms between interleaved rounds).Verification
links rebuild --forcewrites the 9-command map, relinks all shims to the forwarder, is idempotent on a second run;uninstall python --yesthen removes the shim, the map entry and the receipt, exit 0, noprotected.wpm.wpm_uninstall_removes_forwarder_shims_and_map_entries,wpm.wpm_uninstall_keeps_a_foreign_shim_file,wpm.wpm_links_rebuild_migrates_legacy_shim_receipts,wpm.wpm_apply_update_installs_the_forwarder.wpm.*69/69 green; full suite green on this machine.Follow-up (separate repo, after the next release)
unixwin/wpm-source'sfilesmapping forwinuxcmdstill names onlywinuxcmd.exe. With this PR the next release zip containswinuxcmd-shim.exe; the index entry should be added when that release exists (as #1217 already planned), after which the--forwarderstaging here becomes a belt-and-suspenders path.