From 9eb1c79d6affc762a31b8b7a1b51f17a13dec81f Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Fri, 14 Aug 2026 07:27:38 -0700 Subject: [PATCH 1/9] Treat a dead Chromium singleton lock as a closed profile The lock is always a dangling symlink to -, so testing for the link alone reads every crashed or rebooted-away browser as still running, and the migration's close-the-browser prompt repeats forever. Follow Chromium and let the pid decide. Fixes #6866 Co-Authored-By: Claude Opus 5 (1M context) --- migrations/1786643346.sh | 23 +++++++++++++--- .../copy-url-shortcut-migration-test.sh | 27 ++++++++++++++++--- 2 files changed, 43 insertions(+), 7 deletions(-) diff --git a/migrations/1786643346.sh b/migrations/1786643346.sh index cc197a916c0e..7e54b79ddbd0 100644 --- a/migrations/1786643346.sh +++ b/migrations/1786643346.sh @@ -127,9 +127,26 @@ unverified_repairs_exist() { # Whether a profile is open is mechanical: a running Chromium-family browser # holds a SingletonLock (and socket) inside its user-data-dir. profile_open() { - # -L catches a SingletonLock left as a dangling symlink; -e covers a plain - # file, and -S the socket — any of them means a browser is attached. - [[ -L $1/SingletonLock || -e $1/SingletonLock || -S $1/SingletonSocket ]] + local lock=$1/SingletonLock target host pid + + # The lock always dangles: it points at -, never at a file. So + # only that pid says whether a browser is still attached, and a crash or a + # reboot routinely leaves the link behind with a pid that is long gone. + if [[ -L $lock ]]; then + target=$(readlink "$lock") + host=${target%-*} + pid=${target##*-} + + # A lock another machine wrote (or one that doesn't parse) says nothing + # from here, so leave it counting as open rather than repair under a + # browser we cannot see. + [[ $host == "$(uname -n)" && $pid =~ ^[0-9]+$ ]] || return 0 + + [[ -d /proc/$pid ]] + return + fi + + [[ -e $lock || -S $1/SingletonSocket ]] } # Gate on a pending — or to-be-verified — profile actually being open, not on diff --git a/test/shell.d/copy-url-shortcut-migration-test.sh b/test/shell.d/copy-url-shortcut-migration-test.sh index f8cf34975b2e..a4e99905396b 100644 --- a/test/shell.d/copy-url-shortcut-migration-test.sh +++ b/test/shell.d/copy-url-shortcut-migration-test.sh @@ -37,10 +37,14 @@ run_migration() { # A running Chromium-family browser marks its profile root with a SingletonLock # symlink to -, a target that never exists on disk. That lock — -# not the mere presence of a browser process — is what the migration waits on. +# not the mere presence of a browser process — is what the migration waits on, +# and it counts as held only while the pid it names is alive: this test's own. +LIVE_LOCK="$(uname -n)-$$" +export LIVE_LOCK + open_browser() { mkdir -p "$profile_root" - ln -sfn "test-host-1234" "$profile_root/SingletonLock" + ln -sfn "$LIVE_LOCK" "$profile_root/SingletonLock" } close_browser() { rm -f "$profile_root/SingletonLock" @@ -80,7 +84,7 @@ pass "migration keeps the browser prompt visible" # prompt, which the still-declining gum stub would otherwise fail. close_browser mkdir -p "$home/.config/google-chrome" -ln -sfn "test-host-1234" "$home/.config/google-chrome/SingletonLock" +ln -sfn "$LIVE_LOCK" "$home/.config/google-chrome/SingletonLock" write_stale_preferences run_migration || fail "migration repairs while a different profile root is open" jq -e --arg pinned "$pinned_id" '.extensions.commands["linux:Alt+Shift+L"].extension == $pinned' "$preferences" >/dev/null || @@ -88,6 +92,21 @@ jq -e --arg pinned "$pinned_id" '.extensions.commands["linux:Alt+Shift+L"].exten pass "migration ignores a browser on a different profile root" rm -f "$home/.config/google-chrome/SingletonLock" "$preferences.omarchy-copy-url-repair.bak" +# A crash or a reboot leaves the lock behind naming a pid that is gone. Waiting +# on that profile can never end — no keypress makes a dead browser exit — so a +# stale lock has to read as closed. +write_stale_preferences +(exit) & +stale_pid=$! +wait "$stale_pid" +ln -sfn "$(uname -n)-$stale_pid" "$profile_root/SingletonLock" +run_migration || fail "migration repairs through a stale singleton lock" +jq -e --arg pinned "$pinned_id" '.extensions.commands["linux:Alt+Shift+L"].extension == $pinned' "$preferences" >/dev/null || + fail "migration repairs the shortcut through a stale singleton lock" +pass "migration repairs through a stale singleton lock" +close_browser +rm -f "$preferences.omarchy-copy-url-repair.bak" + # Closing the affected profile and confirming the prompt lets the repair # proceed. write_stale_preferences @@ -167,7 +186,7 @@ cat >"$stub_bin/python3" <<'STUB' # the check calls report a surviving ghost through their exit status. "${REAL_PYTHON}" "$@" status=$? -[[ ${5:-} == "repair" ]] && ln -sfn "test-host-1234" "$HOME/.config/chromium/SingletonLock" +[[ ${5:-} == "repair" ]] && ln -sfn "${LIVE_LOCK:?}" "$HOME/.config/chromium/SingletonLock" exit $status STUB chmod +x "$stub_bin/python3" From d59959bb82d03eba78454a93107034de98198b83 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Fri, 14 Aug 2026 07:36:35 -0700 Subject: [PATCH 2/9] Hold the lock only while its pid still owns the profile A pid the kernel has handed on to some unrelated process would otherwise keep reading as an open profile, which is the same loop a dead pid caused. What the process holds open answers that better than what it is called: a browser keeps dozens of files inside the profile it owns, whatever its binary is named. Co-Authored-By: Claude Opus 5 (1M context) --- migrations/1786643346.sh | 18 ++++++-- .../copy-url-shortcut-migration-test.sh | 44 ++++++++++++++++++- 2 files changed, 57 insertions(+), 5 deletions(-) diff --git a/migrations/1786643346.sh b/migrations/1786643346.sh index 7e54b79ddbd0..0d6a7a95aebb 100644 --- a/migrations/1786643346.sh +++ b/migrations/1786643346.sh @@ -127,7 +127,7 @@ unverified_repairs_exist() { # Whether a profile is open is mechanical: a running Chromium-family browser # holds a SingletonLock (and socket) inside its user-data-dir. profile_open() { - local lock=$1/SingletonLock target host pid + local lock=$1/SingletonLock target host pid fds exe # The lock always dangles: it points at -, never at a file. So # only that pid says whether a browser is still attached, and a crash or a @@ -142,8 +142,20 @@ profile_open() { # browser we cannot see. [[ $host == "$(uname -n)" && $pid =~ ^[0-9]+$ ]] || return 0 - [[ -d /proc/$pid ]] - return + # The number outlives the browser and the kernel hands it on, so the lock + # holds only while that pid still keeps a file open inside this profile — + # a browser holds dozens, from leveldb locks to the login database. + fds=$(readlink -- /proc/$pid/fd/* 2>/dev/null) || fds="" + [[ $fds == *"$1/"* ]] && return 0 + + # Failing that, take a browser binary as owner enough: better a repair + # deferred than one made under a browser that reverts it on exit. + exe=$(readlink "/proc/$pid/exe" 2>/dev/null) + case ${exe##*/} in + *chrom* | brave* | msedge* | microsoft-edge* | vivaldi* | opera* | helium*) return 0 ;; + esac + + return 1 fi [[ -e $lock || -S $1/SingletonSocket ]] diff --git a/test/shell.d/copy-url-shortcut-migration-test.sh b/test/shell.d/copy-url-shortcut-migration-test.sh index a4e99905396b..682dbeafcccf 100644 --- a/test/shell.d/copy-url-shortcut-migration-test.sh +++ b/test/shell.d/copy-url-shortcut-migration-test.sh @@ -38,8 +38,22 @@ run_migration() { # A running Chromium-family browser marks its profile root with a SingletonLock # symlink to -, a target that never exists on disk. That lock — # not the mere presence of a browser process — is what the migration waits on, -# and it counts as held only while the pid it names is alive: this test's own. -LIVE_LOCK="$(uname -n)-$$" +# and it holds only while the pid it names is still a live browser. A copy of +# sleep under a browser's name is one, as far as /proc//exe is concerned. +cp "$(command -v sleep)" "$stub_bin/chromium" +"$stub_bin/chromium" 600 & +browser_pid=$! + +# Every stand-in has to go on the way out, including a failing exit: one left +# running holds this test's output pipe open long after the run. +holder_pid="" +cleanup() { + kill $browser_pid ${holder_pid:-} 2>/dev/null + rm -rf "$test_dir" +} +trap cleanup EXIT + +LIVE_LOCK="$(uname -n)-$browser_pid" export LIVE_LOCK open_browser() { @@ -107,6 +121,32 @@ pass "migration repairs through a stale singleton lock" close_browser rm -f "$preferences.omarchy-copy-url-repair.bak" +# The kernel hands a dead browser's pid on to whatever starts next, and this +# test's own shell stands in for that unrelated process: the number matches, +# but nothing about it is a browser. +write_stale_preferences +ln -sfn "$(uname -n)-$$" "$profile_root/SingletonLock" +run_migration || fail "migration repairs through a lock whose pid was reused" +jq -e --arg pinned "$pinned_id" '.extensions.commands["linux:Alt+Shift+L"].extension == $pinned' "$preferences" >/dev/null || + fail "migration repairs the shortcut through a lock whose pid was reused" +pass "migration repairs through a lock whose pid was reused" +close_browser +rm -f "$preferences.omarchy-copy-url-repair.bak" + +# Browsers this migration has never heard of still hold their profile open, so +# a lock whose pid keeps a file open in there counts however it is named. +write_stale_preferences +bash -c "exec 9<\"$preferences\"; sleep 600" >/dev/null 2>&1 & +holder_pid=$! +sleep 0.2 +ln -sfn "$(uname -n)-$holder_pid" "$profile_root/SingletonLock" +run_migration && fail "migration defers to a lock whose pid holds the profile open" +[[ $(jq -r '.extensions.commands["linux:Alt+Shift+L"].extension' "$preferences") == "$ghost_id" ]] || + fail "migration leaves preferences alone while the lock's pid holds the profile open" +pass "migration defers to a lock whose pid holds the profile open" +kill "$holder_pid" 2>/dev/null +close_browser + # Closing the affected profile and confirming the prompt lets the repair # proceed. write_stale_preferences From f8503062757dbd334f22d06e4e99a8ab8f046f5f Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Fri, 14 Aug 2026 08:06:27 -0700 Subject: [PATCH 3/9] Keep a lock we cannot read from unblocking the repair MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Only a pid that is demonstrably gone, or demonstrably not a browser, clears the way now. One that exists but answers nothing about itself — a process another user owns, or one that hides its files and binary — kept the repair from running under a browser we simply failed to recognize. Co-Authored-By: Claude Opus 5 (1M context) --- migrations/1786643346.sh | 11 +++++++---- test/shell.d/copy-url-shortcut-migration-test.sh | 12 ++++++++++++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/migrations/1786643346.sh b/migrations/1786643346.sh index 0d6a7a95aebb..d2f419ca71f8 100644 --- a/migrations/1786643346.sh +++ b/migrations/1786643346.sh @@ -142,15 +142,18 @@ profile_open() { # browser we cannot see. [[ $host == "$(uname -n)" && $pid =~ ^[0-9]+$ ]] || return 0 - # The number outlives the browser and the kernel hands it on, so the lock - # holds only while that pid still keeps a file open inside this profile — + # Whatever wrote a lock naming a pid that is gone is gone with it. + [[ -d /proc/$pid ]] || return 1 + + # The kernel hands that number on to whatever starts next, so the lock + # holds only while the pid still keeps a file open inside this profile — # a browser holds dozens, from leveldb locks to the login database. fds=$(readlink -- /proc/$pid/fd/* 2>/dev/null) || fds="" [[ $fds == *"$1/"* ]] && return 0 - # Failing that, take a browser binary as owner enough: better a repair + # A process that answers for neither counts as open: better a repair # deferred than one made under a browser that reverts it on exit. - exe=$(readlink "/proc/$pid/exe" 2>/dev/null) + exe=$(readlink "/proc/$pid/exe" 2>/dev/null) || return 0 case ${exe##*/} in *chrom* | brave* | msedge* | microsoft-edge* | vivaldi* | opera* | helium*) return 0 ;; esac diff --git a/test/shell.d/copy-url-shortcut-migration-test.sh b/test/shell.d/copy-url-shortcut-migration-test.sh index 682dbeafcccf..2e360f3e3388 100644 --- a/test/shell.d/copy-url-shortcut-migration-test.sh +++ b/test/shell.d/copy-url-shortcut-migration-test.sh @@ -145,6 +145,18 @@ run_migration && fail "migration defers to a lock whose pid holds the profile op fail "migration leaves preferences alone while the lock's pid holds the profile open" pass "migration defers to a lock whose pid holds the profile open" kill "$holder_pid" 2>/dev/null +holder_pid="" +close_browser + +# A pid that answers nothing about itself — pid 1 is alive and root-owned, so +# neither its files nor its binary are readable here — is no proof of a dead +# browser, and a deferred repair beats one made under a live one. +write_stale_preferences +ln -sfn "$(uname -n)-1" "$profile_root/SingletonLock" +run_migration && fail "migration defers to a lock whose pid it cannot read" +[[ $(jq -r '.extensions.commands["linux:Alt+Shift+L"].extension' "$preferences") == "$ghost_id" ]] || + fail "migration leaves preferences alone while the lock's pid is unreadable" +pass "migration defers to a lock whose pid it cannot read" close_browser # Closing the affected profile and confirming the prompt lets the repair From 8c56a6f5d044e5e5070707a8642d6e4073c26d76 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Fri, 14 Aug 2026 08:13:11 -0700 Subject: [PATCH 4/9] Give up on a profile that never closes instead of asking forever The prompt loop sits inside omarchy-update, so a profile that reads as open whatever the user does hangs the update itself, with no way past it. Three rounds is someone closing windows; past that, name the profile, say how to clear a leftover lock, and leave the repair to a later run. Co-Authored-By: Claude Opus 5 (1M context) --- migrations/1786643346.sh | 24 ++++++++++++++--- .../copy-url-shortcut-migration-test.sh | 26 +++++++++++++++++++ 2 files changed, 47 insertions(+), 3 deletions(-) diff --git a/migrations/1786643346.sh b/migrations/1786643346.sh index d2f419ca71f8..3218d8dab5b8 100644 --- a/migrations/1786643346.sh +++ b/migrations/1786643346.sh @@ -169,17 +169,23 @@ profile_open() { # machines whose main browser is effectively never closed: the pending ghosts # commonly sit in a stale profile nobody has open, yet the update blocks on the # always-open one. +# Leaves the profile it stopped on in open_profile, so a wait that goes +# nowhere can say which one it is waiting for. affected_profile_open() { - local preferences backup profile_root + local preferences backup profile_root profile + + open_profile="" for preferences in "${pending[@]}"; do - profile_open "$(dirname "$(dirname "$preferences")")" && return 0 + profile=$(dirname "$(dirname "$preferences")") + profile_open "$profile" && open_profile=$profile && return 0 done for profile_root in "${profile_roots[@]}"; do for backup in "$profile_root"/*/Preferences.omarchy-copy-url-repair.bak; do [[ -f $backup ]] || continue - profile_open "$(dirname "$(dirname "$backup")")" && return 0 + profile=$(dirname "$(dirname "$backup")") + profile_open "$profile" && open_profile=$profile && return 0 done done @@ -198,7 +204,19 @@ fi # ask in, gum fails; then — as on decline — fail so the migration stays # pending, and the login notifier keeps prompting until a rerun goes through # with the affected profiles closed. +# +# Three rounds is someone closing windows. Past that the profile reads as open +# whatever the user does, and this loop runs inside omarchy-update: waiting on +# it forever hangs the update itself, where deferring only postpones a repair +# the next run can still make. +attempts=0 while affected_profile_open; do + if (( ++attempts > 3 )); then + echo "$open_profile still looks like it has a browser attached." >&2 + echo "If none is running, delete the leftover $open_profile/Singleton* links, then run: omarchy-migrate" >&2 + exit 1 + fi + if ! gum confirm "Close the browser windows to repair the Copy URL shortcut, then continue"; then echo "A running browser would undo the Copy URL shortcut repair." >&2 echo "Close the browser windows, then run: omarchy-migrate" >&2 diff --git a/test/shell.d/copy-url-shortcut-migration-test.sh b/test/shell.d/copy-url-shortcut-migration-test.sh index 2e360f3e3388..d7680ad3e124 100644 --- a/test/shell.d/copy-url-shortcut-migration-test.sh +++ b/test/shell.d/copy-url-shortcut-migration-test.sh @@ -297,3 +297,29 @@ run_migration || fail "migration leaves installed third-party extensions alone" [[ $(sha256sum "$preferences" | cut -d' ' -f1) == "$untouched_hash" ]] || fail "migration does not steal a third-party copy-url command registration" pass "migration leaves installed third-party extensions alone" + +# Confirming a prompt that changes nothing must end the wait rather than ask +# again forever: this loop runs inside omarchy-update, so an unbounded one +# hangs the update with nothing the user can do about it. +write_stale_preferences +open_browser +cat >"$stub_bin/gum" <<'STUB' +#!/bin/bash +echo asked >>"${GUM_CALLS:?}" +exit 0 +STUB +give_up_stderr="$test_dir/give-up-stderr" +gum_calls="$test_dir/gum-calls" +: >"$gum_calls" +status=0 +HOME="$home" PATH="$stub_bin:$PATH" GUM_CALLS="$gum_calls" timeout 30 bash -euo pipefail "$migration" \ + >/dev/null 2>"$give_up_stderr" || status=$? +(( $(wc -l <"$gum_calls") == 3 )) || fail "migration asks three times before giving up" +(( status != 124 )) || fail "migration gives up instead of asking forever about a profile that stays open" +(( status != 0 )) || fail "migration defers while the profile stays open" +grep -q "$profile_root" "$give_up_stderr" || fail "migration names the profile it gave up on" +grep -q "Singleton" "$give_up_stderr" || fail "migration says how to clear a leftover lock" +[[ $(jq -r '.extensions.commands["linux:Alt+Shift+L"].extension' "$preferences") == "$ghost_id" ]] || + fail "migration leaves preferences alone when it gives up" +pass "migration gives up instead of asking forever about a profile that stays open" +close_browser From d85e14b611261e7746a1e3b290fa59acbdd727de Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Fri, 14 Aug 2026 08:22:07 -0700 Subject: [PATCH 5/9] Count the wait per profile, not per prompt Someone closing four browsers one prompt at a time is making progress every time, and a budget meant for a profile that never closes was cutting them off at the fourth. Start the count over whenever the wait moves on to a different profile. Co-Authored-By: Claude Opus 5 (1M context) --- migrations/1786643346.sh | 10 +++- .../copy-url-shortcut-migration-test.sh | 54 +++++++++++++++---- 2 files changed, 53 insertions(+), 11 deletions(-) diff --git a/migrations/1786643346.sh b/migrations/1786643346.sh index 3218d8dab5b8..44553f8f0d69 100644 --- a/migrations/1786643346.sh +++ b/migrations/1786643346.sh @@ -208,9 +208,17 @@ fi # Three rounds is someone closing windows. Past that the profile reads as open # whatever the user does, and this loop runs inside omarchy-update: waiting on # it forever hangs the update itself, where deferring only postpones a repair -# the next run can still make. +# the next run can still make. Closing one profile and moving on to the next is +# progress, so the count follows the profile being waited on rather than the +# prompt. attempts=0 +waiting_on="" while affected_profile_open; do + if [[ $open_profile != "$waiting_on" ]]; then + waiting_on=$open_profile + attempts=0 + fi + if (( ++attempts > 3 )); then echo "$open_profile still looks like it has a browser attached." >&2 echo "If none is running, delete the leftover $open_profile/Singleton* links, then run: omarchy-migrate" >&2 diff --git a/test/shell.d/copy-url-shortcut-migration-test.sh b/test/shell.d/copy-url-shortcut-migration-test.sh index d7680ad3e124..4a40d4571ce3 100644 --- a/test/shell.d/copy-url-shortcut-migration-test.sh +++ b/test/shell.d/copy-url-shortcut-migration-test.sh @@ -148,16 +148,21 @@ kill "$holder_pid" 2>/dev/null holder_pid="" close_browser -# A pid that answers nothing about itself — pid 1 is alive and root-owned, so -# neither its files nor its binary are readable here — is no proof of a dead -# browser, and a deferred repair beats one made under a live one. -write_stale_preferences -ln -sfn "$(uname -n)-1" "$profile_root/SingletonLock" -run_migration && fail "migration defers to a lock whose pid it cannot read" -[[ $(jq -r '.extensions.commands["linux:Alt+Shift+L"].extension' "$preferences") == "$ghost_id" ]] || - fail "migration leaves preferences alone while the lock's pid is unreadable" -pass "migration defers to a lock whose pid it cannot read" -close_browser +# A pid that answers nothing about itself is no proof of a dead browser, and a +# deferred repair beats one made under a live one. Pid 1 is that process on a +# normal system, being root-owned; inside a container that hands the test user +# its own pid 1, nothing here is unreadable to point at. +if readlink /proc/1/exe >/dev/null 2>&1; then + pass "pid 1 is readable here; skipping the unreadable lock pid case" +else + write_stale_preferences + ln -sfn "$(uname -n)-1" "$profile_root/SingletonLock" + run_migration && fail "migration defers to a lock whose pid it cannot read" + [[ $(jq -r '.extensions.commands["linux:Alt+Shift+L"].extension' "$preferences") == "$ghost_id" ]] || + fail "migration leaves preferences alone while the lock's pid is unreadable" + pass "migration defers to a lock whose pid it cannot read" + close_browser +fi # Closing the affected profile and confirming the prompt lets the repair # proceed. @@ -323,3 +328,32 @@ grep -q "Singleton" "$give_up_stderr" || fail "migration says how to clear a lef fail "migration leaves preferences alone when it gives up" pass "migration gives up instead of asking forever about a profile that stays open" close_browser + +# Working through open profiles one prompt at a time is progress, not a stuck +# wait: the budget for a profile that never closes must not run out on someone +# closing four of them in a row. +multi_roots=("$home/.config/chromium" "$home/.config/google-chrome" "$home/.config/vivaldi" "$home/.config/opera") +for root in "${multi_roots[@]}"; do + mkdir -p "$root/Default" + jq -n --arg ghost "$ghost_id" '{extensions: {commands: {"linux:Alt+Shift+L": {command_name: "copy-url", extension: $ghost, global: false}}, settings: {}}}' >"$root/Default/Preferences" + ln -sfn "$LIVE_LOCK" "$root/SingletonLock" +done +cat >"$stub_bin/gum" <<'STUB' +#!/bin/bash +# One window closed per prompt, in the order the migration asks about them. +for root in "$HOME/.config/chromium" "$HOME/.config/google-chrome" "$HOME/.config/vivaldi" "$HOME/.config/opera"; do + [[ -L $root/SingletonLock ]] || continue + rm -f "$root/SingletonLock" + break +done +exit 0 +STUB +chmod +x "$stub_bin/gum" +status=0 +HOME="$home" PATH="$stub_bin:$PATH" timeout 60 bash -euo pipefail "$migration" >/dev/null 2>&1 || status=$? +(( status == 0 )) || fail "migration works through profiles closed one prompt at a time" +for root in "${multi_roots[@]}"; do + jq -e --arg pinned "$pinned_id" '.extensions.commands["linux:Alt+Shift+L"].extension == $pinned' \ + "$root/Default/Preferences" >/dev/null || fail "migration repairs every profile once it closes" +done +pass "migration works through profiles closed one prompt at a time" From 6d9f7bc6de684fb480142874fbf2919d1460685b Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Fri, 14 Aug 2026 08:33:09 -0700 Subject: [PATCH 6/9] Read a zombie as the dead browser it is MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A browser that crashed while its parent was not watching keeps its /proc entry with no files and no binary behind it, which the unreadable-process rule took for a browser too secretive to identify — and held the repair on a profile nothing has open. Co-Authored-By: Claude Opus 5 (1M context) --- migrations/1786643346.sh | 8 +++- .../copy-url-shortcut-migration-test.sh | 37 ++++++++++++++++++- 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/migrations/1786643346.sh b/migrations/1786643346.sh index 44553f8f0d69..1e266db34476 100644 --- a/migrations/1786643346.sh +++ b/migrations/1786643346.sh @@ -127,7 +127,7 @@ unverified_repairs_exist() { # Whether a profile is open is mechanical: a running Chromium-family browser # holds a SingletonLock (and socket) inside its user-data-dir. profile_open() { - local lock=$1/SingletonLock target host pid fds exe + local lock=$1/SingletonLock target host pid state fds exe # The lock always dangles: it points at -, never at a file. So # only that pid says whether a browser is still attached, and a crash or a @@ -145,6 +145,12 @@ profile_open() { # Whatever wrote a lock naming a pid that is gone is gone with it. [[ -d /proc/$pid ]] || return 1 + # A zombie is just as gone; it only still has an entry because nobody has + # reaped it. Left to the checks below it would read as a process too + # secretive to see into, since a zombie has no files and no binary. + state=$(/dev/null + kill $browser_pid ${holder_pid:-} ${zombie_parent:-} 2>/dev/null rm -rf "$test_dir" } trap cleanup EXIT @@ -164,6 +165,40 @@ else close_browser fi +# A browser that crashed while its parent was not watching leaves a zombie: an +# entry in /proc with no files and no binary behind it, which is a dead browser +# however much of the pid survives. +python3 -c " +import os, sys, time +pid = os.fork() +if pid == 0: + os._exit(0) +open(sys.argv[1], 'w').write(str(pid)) +time.sleep(600) +" "$test_dir/zombie-pid" & +zombie_parent=$! +for _ in {1..50}; do + [[ -s $test_dir/zombie-pid ]] && break + sleep 0.1 +done +zombie_pid=$(cat "$test_dir/zombie-pid" 2>/dev/null) || zombie_pid="" +zombie_state=$(awk '{print $3}' "/proc/${zombie_pid:-0}/stat" 2>/dev/null) || zombie_state="" + +if [[ $zombie_state == "Z" ]]; then + write_stale_preferences + ln -sfn "$(uname -n)-$zombie_pid" "$profile_root/SingletonLock" + run_migration || fail "migration repairs through a lock naming a zombie" + jq -e --arg pinned "$pinned_id" '.extensions.commands["linux:Alt+Shift+L"].extension == $pinned' "$preferences" >/dev/null || + fail "migration repairs the shortcut through a lock naming a zombie" + pass "migration repairs through a lock naming a zombie" + close_browser + rm -f "$preferences.omarchy-copy-url-repair.bak" +else + pass "no zombie to point a lock at; skipping the zombie lock pid case" +fi +kill "$zombie_parent" 2>/dev/null +zombie_parent="" + # Closing the affected profile and confirming the prompt lets the repair # proceed. write_stale_preferences From 1c855d9b872cc3f7eb5f09b3ed1446b3d49c7691 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Fri, 14 Aug 2026 08:42:01 -0700 Subject: [PATCH 7/9] Say why a browser's name alone keeps the lock held Reviewers keep asking to drop the name check once the file scan comes back clean, which would repair under any browser whose files this cannot see. Co-Authored-By: Claude Opus 5 (1M context) --- migrations/1786643346.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/migrations/1786643346.sh b/migrations/1786643346.sh index 1e266db34476..33dc830b666a 100644 --- a/migrations/1786643346.sh +++ b/migrations/1786643346.sh @@ -157,8 +157,10 @@ profile_open() { fds=$(readlink -- /proc/$pid/fd/* 2>/dev/null) || fds="" [[ $fds == *"$1/"* ]] && return 0 - # A process that answers for neither counts as open: better a repair - # deferred than one made under a browser that reverts it on exit. + # A browser whose files this cannot see — one reaching the profile through + # a symlink, or holding it open only in a child — still counts as open by + # its name alone. Waiting on the wrong browser costs a deferred repair the + # next run makes; repairing under a live one loses the fix for good. exe=$(readlink "/proc/$pid/exe" 2>/dev/null) || return 0 case ${exe##*/} in *chrom* | brave* | msedge* | microsoft-edge* | vivaldi* | opera* | helium*) return 0 ;; From aa9724d114905304e4d2bd85407f3be27afafe6f Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Mon, 28 Sep 2026 03:59:00 +0200 Subject: [PATCH 8/9] Keep the descriptors readlink did read when one closes mid-read readlink exits non-zero when any one of its arguments fails, while still printing the rest. A browser opening and closing descriptors between the glob and the read made `|| fds=""` throw away every descriptor inside the profile, so a browser whose binary the name list does not know read as closed and the repair ran under it. Co-Authored-By: Codex Medium Co-Authored-By: Claude Opus 5.5 --- migrations/1786643346.sh | 2 +- test/shell.d/copy-url-shortcut-migration-test.sh | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/migrations/1786643346.sh b/migrations/1786643346.sh index 33dc830b666a..daa4583923b0 100644 --- a/migrations/1786643346.sh +++ b/migrations/1786643346.sh @@ -154,7 +154,7 @@ profile_open() { # The kernel hands that number on to whatever starts next, so the lock # holds only while the pid still keeps a file open inside this profile — # a browser holds dozens, from leveldb locks to the login database. - fds=$(readlink -- /proc/$pid/fd/* 2>/dev/null) || fds="" + fds=$(readlink -- /proc/$pid/fd/* 2>/dev/null || true) [[ $fds == *"$1/"* ]] && return 0 # A browser whose files this cannot see — one reaching the profile through diff --git a/test/shell.d/copy-url-shortcut-migration-test.sh b/test/shell.d/copy-url-shortcut-migration-test.sh index 9fb09643d874..2ff52e2bda61 100644 --- a/test/shell.d/copy-url-shortcut-migration-test.sh +++ b/test/shell.d/copy-url-shortcut-migration-test.sh @@ -145,6 +145,20 @@ run_migration && fail "migration defers to a lock whose pid holds the profile op [[ $(jq -r '.extensions.commands["linux:Alt+Shift+L"].extension' "$preferences") == "$ghost_id" ]] || fail "migration leaves preferences alone while the lock's pid holds the profile open" pass "migration defers to a lock whose pid holds the profile open" + +# A descriptor closing between the glob and the read fails readlink for that +# one alone, and what it did read still places the browser in the profile. +cat >"$stub_bin/readlink" </dev/null holder_pid="" close_browser From 9d3ff58ff947743365796628be07226eb7a387ef Mon Sep 17 00:00:00 2001 From: Ryan Hughes Date: Tue, 20 Oct 2026 02:55:58 -0400 Subject: [PATCH 9/9] Drop the test changes for the retired Copy URL migration test test/shell.d/copy-url-shortcut-migration-test.sh: quattro retired this test once 1786643346 shipped and froze (1aa1423e), then cut it down to the Brave Origin rerun (4fa96158); these cases re-tested the frozen migration and kept the branch from merging. --- .../copy-url-shortcut-migration-test.sh | 188 +----------------- 1 file changed, 4 insertions(+), 184 deletions(-) diff --git a/test/shell.d/copy-url-shortcut-migration-test.sh b/test/shell.d/copy-url-shortcut-migration-test.sh index 2ff52e2bda61..f8cf34975b2e 100644 --- a/test/shell.d/copy-url-shortcut-migration-test.sh +++ b/test/shell.d/copy-url-shortcut-migration-test.sh @@ -37,29 +37,10 @@ run_migration() { # A running Chromium-family browser marks its profile root with a SingletonLock # symlink to -, a target that never exists on disk. That lock — -# not the mere presence of a browser process — is what the migration waits on, -# and it holds only while the pid it names is still a live browser. A copy of -# sleep under a browser's name is one, as far as /proc//exe is concerned. -cp "$(command -v sleep)" "$stub_bin/chromium" -"$stub_bin/chromium" 600 & -browser_pid=$! - -# Every stand-in has to go on the way out, including a failing exit: one left -# running holds this test's output pipe open long after the run. -holder_pid="" -zombie_parent="" -cleanup() { - kill $browser_pid ${holder_pid:-} ${zombie_parent:-} 2>/dev/null - rm -rf "$test_dir" -} -trap cleanup EXIT - -LIVE_LOCK="$(uname -n)-$browser_pid" -export LIVE_LOCK - +# not the mere presence of a browser process — is what the migration waits on. open_browser() { mkdir -p "$profile_root" - ln -sfn "$LIVE_LOCK" "$profile_root/SingletonLock" + ln -sfn "test-host-1234" "$profile_root/SingletonLock" } close_browser() { rm -f "$profile_root/SingletonLock" @@ -99,7 +80,7 @@ pass "migration keeps the browser prompt visible" # prompt, which the still-declining gum stub would otherwise fail. close_browser mkdir -p "$home/.config/google-chrome" -ln -sfn "$LIVE_LOCK" "$home/.config/google-chrome/SingletonLock" +ln -sfn "test-host-1234" "$home/.config/google-chrome/SingletonLock" write_stale_preferences run_migration || fail "migration repairs while a different profile root is open" jq -e --arg pinned "$pinned_id" '.extensions.commands["linux:Alt+Shift+L"].extension == $pinned' "$preferences" >/dev/null || @@ -107,112 +88,6 @@ jq -e --arg pinned "$pinned_id" '.extensions.commands["linux:Alt+Shift+L"].exten pass "migration ignores a browser on a different profile root" rm -f "$home/.config/google-chrome/SingletonLock" "$preferences.omarchy-copy-url-repair.bak" -# A crash or a reboot leaves the lock behind naming a pid that is gone. Waiting -# on that profile can never end — no keypress makes a dead browser exit — so a -# stale lock has to read as closed. -write_stale_preferences -(exit) & -stale_pid=$! -wait "$stale_pid" -ln -sfn "$(uname -n)-$stale_pid" "$profile_root/SingletonLock" -run_migration || fail "migration repairs through a stale singleton lock" -jq -e --arg pinned "$pinned_id" '.extensions.commands["linux:Alt+Shift+L"].extension == $pinned' "$preferences" >/dev/null || - fail "migration repairs the shortcut through a stale singleton lock" -pass "migration repairs through a stale singleton lock" -close_browser -rm -f "$preferences.omarchy-copy-url-repair.bak" - -# The kernel hands a dead browser's pid on to whatever starts next, and this -# test's own shell stands in for that unrelated process: the number matches, -# but nothing about it is a browser. -write_stale_preferences -ln -sfn "$(uname -n)-$$" "$profile_root/SingletonLock" -run_migration || fail "migration repairs through a lock whose pid was reused" -jq -e --arg pinned "$pinned_id" '.extensions.commands["linux:Alt+Shift+L"].extension == $pinned' "$preferences" >/dev/null || - fail "migration repairs the shortcut through a lock whose pid was reused" -pass "migration repairs through a lock whose pid was reused" -close_browser -rm -f "$preferences.omarchy-copy-url-repair.bak" - -# Browsers this migration has never heard of still hold their profile open, so -# a lock whose pid keeps a file open in there counts however it is named. -write_stale_preferences -bash -c "exec 9<\"$preferences\"; sleep 600" >/dev/null 2>&1 & -holder_pid=$! -sleep 0.2 -ln -sfn "$(uname -n)-$holder_pid" "$profile_root/SingletonLock" -run_migration && fail "migration defers to a lock whose pid holds the profile open" -[[ $(jq -r '.extensions.commands["linux:Alt+Shift+L"].extension' "$preferences") == "$ghost_id" ]] || - fail "migration leaves preferences alone while the lock's pid holds the profile open" -pass "migration defers to a lock whose pid holds the profile open" - -# A descriptor closing between the glob and the read fails readlink for that -# one alone, and what it did read still places the browser in the profile. -cat >"$stub_bin/readlink" </dev/null -holder_pid="" -close_browser - -# A pid that answers nothing about itself is no proof of a dead browser, and a -# deferred repair beats one made under a live one. Pid 1 is that process on a -# normal system, being root-owned; inside a container that hands the test user -# its own pid 1, nothing here is unreadable to point at. -if readlink /proc/1/exe >/dev/null 2>&1; then - pass "pid 1 is readable here; skipping the unreadable lock pid case" -else - write_stale_preferences - ln -sfn "$(uname -n)-1" "$profile_root/SingletonLock" - run_migration && fail "migration defers to a lock whose pid it cannot read" - [[ $(jq -r '.extensions.commands["linux:Alt+Shift+L"].extension' "$preferences") == "$ghost_id" ]] || - fail "migration leaves preferences alone while the lock's pid is unreadable" - pass "migration defers to a lock whose pid it cannot read" - close_browser -fi - -# A browser that crashed while its parent was not watching leaves a zombie: an -# entry in /proc with no files and no binary behind it, which is a dead browser -# however much of the pid survives. -python3 -c " -import os, sys, time -pid = os.fork() -if pid == 0: - os._exit(0) -open(sys.argv[1], 'w').write(str(pid)) -time.sleep(600) -" "$test_dir/zombie-pid" & -zombie_parent=$! -for _ in {1..50}; do - [[ -s $test_dir/zombie-pid ]] && break - sleep 0.1 -done -zombie_pid=$(cat "$test_dir/zombie-pid" 2>/dev/null) || zombie_pid="" -zombie_state=$(awk '{print $3}' "/proc/${zombie_pid:-0}/stat" 2>/dev/null) || zombie_state="" - -if [[ $zombie_state == "Z" ]]; then - write_stale_preferences - ln -sfn "$(uname -n)-$zombie_pid" "$profile_root/SingletonLock" - run_migration || fail "migration repairs through a lock naming a zombie" - jq -e --arg pinned "$pinned_id" '.extensions.commands["linux:Alt+Shift+L"].extension == $pinned' "$preferences" >/dev/null || - fail "migration repairs the shortcut through a lock naming a zombie" - pass "migration repairs through a lock naming a zombie" - close_browser - rm -f "$preferences.omarchy-copy-url-repair.bak" -else - pass "no zombie to point a lock at; skipping the zombie lock pid case" -fi -kill "$zombie_parent" 2>/dev/null -zombie_parent="" - # Closing the affected profile and confirming the prompt lets the repair # proceed. write_stale_preferences @@ -292,7 +167,7 @@ cat >"$stub_bin/python3" <<'STUB' # the check calls report a surviving ghost through their exit status. "${REAL_PYTHON}" "$@" status=$? -[[ ${5:-} == "repair" ]] && ln -sfn "${LIVE_LOCK:?}" "$HOME/.config/chromium/SingletonLock" +[[ ${5:-} == "repair" ]] && ln -sfn "test-host-1234" "$HOME/.config/chromium/SingletonLock" exit $status STUB chmod +x "$stub_bin/python3" @@ -351,58 +226,3 @@ run_migration || fail "migration leaves installed third-party extensions alone" [[ $(sha256sum "$preferences" | cut -d' ' -f1) == "$untouched_hash" ]] || fail "migration does not steal a third-party copy-url command registration" pass "migration leaves installed third-party extensions alone" - -# Confirming a prompt that changes nothing must end the wait rather than ask -# again forever: this loop runs inside omarchy-update, so an unbounded one -# hangs the update with nothing the user can do about it. -write_stale_preferences -open_browser -cat >"$stub_bin/gum" <<'STUB' -#!/bin/bash -echo asked >>"${GUM_CALLS:?}" -exit 0 -STUB -give_up_stderr="$test_dir/give-up-stderr" -gum_calls="$test_dir/gum-calls" -: >"$gum_calls" -status=0 -HOME="$home" PATH="$stub_bin:$PATH" GUM_CALLS="$gum_calls" timeout 30 bash -euo pipefail "$migration" \ - >/dev/null 2>"$give_up_stderr" || status=$? -(( $(wc -l <"$gum_calls") == 3 )) || fail "migration asks three times before giving up" -(( status != 124 )) || fail "migration gives up instead of asking forever about a profile that stays open" -(( status != 0 )) || fail "migration defers while the profile stays open" -grep -q "$profile_root" "$give_up_stderr" || fail "migration names the profile it gave up on" -grep -q "Singleton" "$give_up_stderr" || fail "migration says how to clear a leftover lock" -[[ $(jq -r '.extensions.commands["linux:Alt+Shift+L"].extension' "$preferences") == "$ghost_id" ]] || - fail "migration leaves preferences alone when it gives up" -pass "migration gives up instead of asking forever about a profile that stays open" -close_browser - -# Working through open profiles one prompt at a time is progress, not a stuck -# wait: the budget for a profile that never closes must not run out on someone -# closing four of them in a row. -multi_roots=("$home/.config/chromium" "$home/.config/google-chrome" "$home/.config/vivaldi" "$home/.config/opera") -for root in "${multi_roots[@]}"; do - mkdir -p "$root/Default" - jq -n --arg ghost "$ghost_id" '{extensions: {commands: {"linux:Alt+Shift+L": {command_name: "copy-url", extension: $ghost, global: false}}, settings: {}}}' >"$root/Default/Preferences" - ln -sfn "$LIVE_LOCK" "$root/SingletonLock" -done -cat >"$stub_bin/gum" <<'STUB' -#!/bin/bash -# One window closed per prompt, in the order the migration asks about them. -for root in "$HOME/.config/chromium" "$HOME/.config/google-chrome" "$HOME/.config/vivaldi" "$HOME/.config/opera"; do - [[ -L $root/SingletonLock ]] || continue - rm -f "$root/SingletonLock" - break -done -exit 0 -STUB -chmod +x "$stub_bin/gum" -status=0 -HOME="$home" PATH="$stub_bin:$PATH" timeout 60 bash -euo pipefail "$migration" >/dev/null 2>&1 || status=$? -(( status == 0 )) || fail "migration works through profiles closed one prompt at a time" -for root in "${multi_roots[@]}"; do - jq -e --arg pinned "$pinned_id" '.extensions.commands["linux:Alt+Shift+L"].extension == $pinned' \ - "$root/Default/Preferences" >/dev/null || fail "migration repairs every profile once it closes" -done -pass "migration works through profiles closed one prompt at a time"