Repository navigation
Commit 81ada7c
committed
fix(codex): restore an unprobeable launcher on shim rollback (#1625)
A fresh install moves the user's existing launcher to
codex.opencodex-real before writing the wrapper, and records a
fingerprint so rollback can prove the backup is still the file it set
aside. That fingerprint came from stableShimPathProbe, which reads
content to judge whether a launcher looks like a healthy shim and
deliberately returns null at zero bytes.
An empty launcher is a legitimate thing to own, so the move was recorded
with no fingerprint at all, and rollback -- which requires a match before
it will restore -- refused. The install failed and left the user with no
codex on PATH, the original stranded at codex.opencodex-real.
Identity is metadata, not content. Add shimPathFingerprint, which reads
dev/ino/mode/size/times (following a symlink to fingerprint its target
too) and re-reads them to reject a path that moved under us. Record it
right after the move and validate against it during rollback; the content
probe still runs where it can, now purely as a consistency check.
Two details the fix has to respect:
Only Unix reaches the rollback path -- Windows rethrows freshApplyError
without rolling back -- so only Unix treats a missing fingerprint as
fatal. Throwing on Windows would abort after the original had already
moved, stranding it with nothing to restore it.
The restore itself no longer uses renameSync. sourceOccupied is sampled
before the fingerprint check, so a concurrent installer can publish its
own launcher at the original path in between, and rename would silently
delete it. Regular files are republished with link()+unlink() and
symlinks with symlink()+unlink(); both fail EEXIST on an occupied
destination, which is the no-replace guarantee, and neither needs a
native helper. Checking existence and then renaming would only narrow the
race, not close it.
Covered by two regression tests, each demonstrated red against the
behavior it pins: the zero-byte launcher is restored rather than
stranded, and a launcher published inside the restore window survives
with the original still recoverable from the backup. The second needs a
seam inside that window, because publishing any earlier makes
sourceOccupied true and skips the restore branch.
Ported by hand from #1625's f36aedf, taking only the fingerprint and
rollback hunks. That commit also introduces a bun:ffi native no-replace
helper with C sources and a Windows multi-launcher transaction rewrite;
those are a separate proposal needing their own cross-platform validation.
Closes #16251 parent d30ab74 commit 81ada7c
2 files changed
Lines changed: 196 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| 17 | + | |
16 | 18 | | |
17 | 19 | | |
18 | 20 | | |
19 | 21 | | |
20 | 22 | | |
| 23 | + | |
21 | 24 | | |
22 | 25 | | |
23 | 26 | | |
| |||
407 | 410 | | |
408 | 411 | | |
409 | 412 | | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
410 | 470 | | |
411 | 471 | | |
412 | 472 | | |
| |||
644 | 704 | | |
645 | 705 | | |
646 | 706 | | |
| 707 | + | |
647 | 708 | | |
648 | 709 | | |
649 | 710 | | |
| |||
671 | 732 | | |
672 | 733 | | |
673 | 734 | | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
674 | 749 | | |
675 | 750 | | |
676 | 751 | | |
| |||
830 | 905 | | |
831 | 906 | | |
832 | 907 | | |
833 | | - | |
| 908 | + | |
834 | 909 | | |
835 | | - | |
| 910 | + | |
836 | 911 | | |
837 | 912 | | |
838 | 913 | | |
| |||
842 | 917 | | |
843 | 918 | | |
844 | 919 | | |
845 | | - | |
| 920 | + | |
| 921 | + | |
| 922 | + | |
| 923 | + | |
| 924 | + | |
| 925 | + | |
846 | 926 | | |
847 | 927 | | |
848 | 928 | | |
| |||
1832 | 1912 | | |
1833 | 1913 | | |
1834 | 1914 | | |
| 1915 | + | |
| 1916 | + | |
| 1917 | + | |
| 1918 | + | |
| 1919 | + | |
| 1920 | + | |
| 1921 | + | |
| 1922 | + | |
| 1923 | + | |
1835 | 1924 | | |
| 1925 | + | |
| 1926 | + | |
| 1927 | + | |
1836 | 1928 | | |
1837 | | - | |
1838 | | - | |
| 1929 | + | |
| 1930 | + | |
| 1931 | + | |
| 1932 | + | |
| 1933 | + | |
1839 | 1934 | | |
1840 | 1935 | | |
1841 | 1936 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| |||
826 | 826 | | |
827 | 827 | | |
828 | 828 | | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
| 856 | + | |
| 857 | + | |
| 858 | + | |
| 859 | + | |
| 860 | + | |
| 861 | + | |
| 862 | + | |
| 863 | + | |
| 864 | + | |
| 865 | + | |
| 866 | + | |
| 867 | + | |
| 868 | + | |
| 869 | + | |
| 870 | + | |
| 871 | + | |
| 872 | + | |
| 873 | + | |
| 874 | + | |
| 875 | + | |
| 876 | + | |
| 877 | + | |
| 878 | + | |
| 879 | + | |
| 880 | + | |
| 881 | + | |
| 882 | + | |
| 883 | + | |
| 884 | + | |
| 885 | + | |
| 886 | + | |
| 887 | + | |
| 888 | + | |
| 889 | + | |
| 890 | + | |
| 891 | + | |
| 892 | + | |
| 893 | + | |
| 894 | + | |
| 895 | + | |
| 896 | + | |
| 897 | + | |
| 898 | + | |
| 899 | + | |
| 900 | + | |
| 901 | + | |
| 902 | + | |
| 903 | + | |
| 904 | + | |
| 905 | + | |
| 906 | + | |
| 907 | + | |
| 908 | + | |
| 909 | + | |
| 910 | + | |
| 911 | + | |
| 912 | + | |
| 913 | + | |
| 914 | + | |
| 915 | + | |
| 916 | + | |
| 917 | + | |
| 918 | + | |
| 919 | + | |
| 920 | + | |
| 921 | + | |
| 922 | + | |
| 923 | + | |
829 | 924 | | |
830 | 925 | | |
831 | 926 | | |
| |||
0 commit comments