Skip to content

fix(wpm): deliver and migrate the shim forwarder across the wpm lifecycle (#1207) - #1228

Merged
caomengxuan666 merged 1 commit into
mainfrom
fix/1207-shim-dispatch-followup
Oct 18, 2026
Merged

caomengxuan666 merged 1 commit into
mainfrom
fix/1207-shim-dispatch-followup

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

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:

  1. The release never carried the forwarder. The install rules only install(TARGETS winuxcmd), so the 1.1.14 zip has no winuxcmd-shim.exe (verified against the published release), and wpm update winuxcmd — which stages exactly what the index files mapping names — copied only the image. An updated install stayed on the old dispatcher.
  2. Existing installs had no migration. .wpm/shims.map is written by install only. A root that predates the forwarder (this machine's niubash root: no forwarder, no map, shims hardlinked to the old winuxcmd.exe) had nothing to relink its shims with, and rebuild_links's shim loop iterated a map that did not exist.
  3. Uninstall regressed. Shims were recognised by content against winuxcmd.exe only. A forwarder shim (188 KB vs 4.7 MB) fails both checks, so uninstalling any shim package reported skipping protected file for every command, left every shim behind, and left its .wpm/shims.map entries pointing at a deleted payload. remove_shim_map_entries existed but was never called from anywhere.

Changes

  • CMake: install(TARGETS winuxcmd-shim ...) — the next release zip carries the forwarder.
  • Self-update: update_winuxcmd picks up winuxcmd-shim.exe from the extraction and passes it to the helper (__apply-update --forwarder); apply_update lands it in usr\bin after a successful swap, before the relink. Best effort: a failure is reported, the image update stands.
  • Migration in 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 runs links rebuild --force at 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 bare failed count.
  • Uninstall: a shim is ours if it links the forwarder or (roots predating the forwarder) links/equals winuxcmd.exe; anything else stays and is reported as protected. The package's map entries are dropped (remove_shim_map_entries finally 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, verbose rebuild_links lines) 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)

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.exe from this branch and its map. Hop = shim call − direct payload call.

payload before shim before hop after shim after hop saved
ssh −V 41.8 ms +24.7 30.4 ms +10.3 14.4 ms
curl --version 40.4 ms +23.7 30.6 ms +12.6 11.1 ms
node --version 45.0 ms +21.3 35.8 ms +9.1 12.2 ms
python -c pass 59.2 ms +19.2 56.6 ms +15.0 4.2 ms

Standalone runs agree (n=15, medians):

case live root (before) fixture (after)
usr\bin\python.exe -c pass / payload 49.8 / 31.0 55.3 / 40.3
usr\bin\ssh.exe -V / payload 33.5 / 14.6 33.9 / 19.3
usr\bin\curl.exe --version / payload 33.6 / 13.5 32.0 / 18.2
usr\bin\node.exe --version / payload 38.4 / 20.8 35.8 / 24.6
usr\bin\ls.exe (builtin link) 16.0 17.8
bin\git.exe (entry link, no hop) 11.1 13.4

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

  • End-to-end on a replica of the stale root: links rebuild --force writes the 9-command map, relinks all shims to the forwarder, is idempotent on a second run; uninstall python --yes then removes the shim, the map entry and the receipt, exit 0, no protected.
  • New tests: 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.
  • Argument/stdio/exit-code fidelity of the forwarder itself was pinned by perf(wpm): a small forwarder for layout: shim packages (-12.4 ms per call) #1217 and is untouched here.

Follow-up (separate repo, after the next release)

unixwin/wpm-source's files mapping for winuxcmd still names only winuxcmd.exe. With this PR the next release zip contains winuxcmd-shim.exe; the index entry should be added when that release exists (as #1217 already planned), after which the --forwarder staging here becomes a belt-and-suspenders path.

…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 caomengxuan666 left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 --install into a staging prefix puts usr/bin/winuxcmd-shim.exe next to the image; CI packages via CPack (Runtime component is in CPACK_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: --forwarder is optional end to end (parse_hidden_value → empty → skip); install_forwarder is best-effort (every failure reported, never fails the update), runs after a successful swap and before finish_update, so the relink sees it, and is correctly skipped on the two image-failure paths. Test pins both the delivery and the no---forwarder no-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 against activate-winuxcmd.sh:103.
  • (d) Uninstall: is_our_shim covers forwarder links and the legacy winuxcmd.exe link/copy fallback; aliases are removed before command shims and are now compared against usr\bin\<target>.exe — the file create_package_aliases actually links (the old payload comparison could never match); remove_shim_map_entries finally 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 /Os release 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 walks command_names() (builtins) — package shims never enter stale_command_links; a live shim run resolved libcrypto.dll/libcurl-x64.dll from 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

  1. CHANGELOG.md — no [Unreleased] entry, while the repo convention documents user-visible wpm fixes (see the #1217 forwarder and #1226 verify entries). The fixed skipping protected file uninstall regression and the forwarder delivery deserve a line.
  2. 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.
  3. wpm.cpp:842 — the write_shim_map return value is discarded while the verbose lines above (836-839) already announce registration; a failed write is silent (self-heals on the next rebuild). Contrast set_shim_map_entry's caller at 3211-3217, which reports this failure.
  4. 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.
  5. 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 caomengxuan666 left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 --install into a staging prefix puts usr/bin/winuxcmd-shim.exe next to the image; CI packages via CPack (Runtime component is in CPACK_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: --forwarder is optional end to end (parse_hidden_value → empty → skip); install_forwarder is best-effort (every failure reported, never fails the update), runs after a successful swap and before finish_update, so the relink sees it, and is correctly skipped on the two image-failure paths. Test pins both the delivery and the no---forwarder no-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 against activate-winuxcmd.sh:103.
  • (d) Uninstall: is_our_shim covers forwarder links and the legacy winuxcmd.exe link/copy fallback; aliases are removed before command shims and are now compared against usr\bin\<target>.exe — the file create_package_aliases actually links (the old payload comparison could never match); remove_shim_map_entries finally 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 /Os release 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 walks command_names() (builtins) — package shims never enter stale_command_links; a live shim run resolved libcrypto.dll/libcurl-x64.dll from 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

  1. CHANGELOG.md — no [Unreleased] entry, while the repo convention documents user-visible wpm fixes (see the #1217 forwarder and #1226 verify entries). The fixed skipping protected file uninstall regression and the forwarder delivery deserve a line.
  2. 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.
  3. wpm.cpp:842 — the write_shim_map return value is discarded while the verbose lines above (836-839) already announce registration; a failed write is silent (self-heals on the next rebuild). Contrast set_shim_map_entry's caller at 3211-3217, which reports this failure.
  4. 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.
  5. 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
caomengxuan666 merged commit 63f8cc7 into main Oct 18, 2026
8 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/1207-shim-dispatch-followup branch October 18, 2026 18:31
@caomengxuan666

Copy link
Copy Markdown
Member Author

Merge note (nits from the review, non-blocking): please add the [Unreleased] CHANGELOG entry in a follow-up (repo convention — #1217/#1226 both carry one; the user-visible uninstall-ownership fix deserves the line). The remaining review nits (index-resolution comment at wpm.cpp:711, write_shim_map return-value logging) are recorded in the review for a follow-up pass.

caomengxuan666 added a commit that referenced this pull request Oct 19, 2026
… landed via #1228; keep main's comment, this branch retains the index guard
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.

1 participant