Skip to content

Don't mistake a stale Chromium singleton lock for an open browser - #6872

Open
dhh wants to merge 9 commits into
quattrofrom
stale-singleton-lock
Open

dhh wants to merge 9 commits into
quattrofrom
stale-singleton-lock

Conversation

@dhh

@dhh dhh commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

The Copy URL migration asks for browser windows to be closed, then waits for the affected profile to actually close. It decided a profile was open by testing for a SingletonLock link — but Chromium's lock is always a dangling symlink: it points at <hostname>-<pid>, never at a file. So the test only ever meant "a lock link exists", which a crash or a reboot leaves behind indefinitely. Pressing Continue changed nothing, and the prompt repeated forever. Removing the link by hand was the only way through, as #6866 reports.

The lock now answers the question it was always meant to answer: is a browser still holding this profile. The pid encoded in the link decides, the way Chromium decides about its own lock before clearing it. A lock another machine wrote still counts as open — that one is genuinely unreadable from here, and deferring the repair is the harmless direction to be wrong in.

A dead pid gets handed on to whatever starts next, so a live pid alone isn't enough either. What the process holds open settles it: a browser keeps dozens of files inside the profile it owns — leveldb locks, the login database, the quota manager — and that identifies the owner without depending on what its binary is called, which is what the Edge and Brave and Vivaldi naming would otherwise turn into a guessing game. The executable name stays as a fallback, again erring toward deferring.

Only a pid that is demonstrably gone, or demonstrably not a browser, clears the way. One that exists but answers nothing about itself — another user's process, or one that hides its files and binary — counts as open, so a browser this migration fails to recognize costs a deferred repair rather than a silently reverted one.

The prompt loop is now bounded, which matters more than the detection itself: it runs inside omarchy-update, where waiting forever hangs the update with nothing the user can do. Three rounds with no movement on the profile it is waiting for, and it names that profile, says which links to delete, and leaves the repair to a later run. Closing profiles one at a time still counts as progress, so working through four browsers does not exhaust a budget meant for one that never closes.

I verified this against a real Chromium rather than only the fixtures: a headless browser on a scratch profile writes mbu-r9-3000350 into the lock and holds 27 files inside the profile, the migration defers while it runs, kill -9 leaves the lock exactly as the report describes, and the migration then repairs through it and completes.

Fixes #6866

— 🤖 Claude, posting on behalf of @dhh

dhh and others added 2 commits August 14, 2026 07:27
The lock is always a dangling symlink to <hostname>-<pid>, 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) <noreply@anthropic.com>
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) <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings August 14, 2026 14:57

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Fixes stale Chromium locks blocking the Copy URL migration indefinitely.

Changes:

  • Determines lock ownership using PID, open files, and executable name.
  • Adds coverage for stale, reused, and profile-owning PIDs.

Tip

If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or run gh pr ready --undo.
Click "Ready for review" or run gh pr ready to reengage.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
migrations/1786643346.sh Improves Chromium profile lock detection.
test/shell.d/copy-url-shortcut-migration-test.sh Tests live and stale lock scenarios.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread migrations/1786643346.sh Resolved
# running holds this test's output pipe open long after the run.
holder_pid=""
cleanup() {
kill $browser_pid ${holder_pid:-} 2>/dev/null
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) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings August 14, 2026 15:06

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

Suppressed comments (1)

migrations/1786643346.sh:151

  • readlink returns a non-zero status if any descriptor from the expanded glob closes before it is inspected. The || fds="" branch then discards paths successfully read from the remaining descriptors, so a busy browser with an unrecognized executable name can be mistaken for a reused PID even while it still holds profile files open. Preserve partial output (or inspect descriptors individually) so descriptor churn cannot bypass the open-profile guard.
    fds=$(readlink -- /proc/$pid/fd/* 2>/dev/null) || fds=""

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) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings August 14, 2026 15:13

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

Suppressed comments (1)

migrations/1786643346.sh:151

  • readlink exits nonzero if even one descriptor disappears after glob expansion, despite printing targets for the descriptors it did read. Resetting fds on that status discards all successful evidence, so normal FD churn can make a live browser with an unrecognized executable look closed and allow the repair while it owns the profile. Preserve the partial output while making readlink failure nonfatal.
    fds=$(readlink -- /proc/$pid/fd/* 2>/dev/null) || fds=""

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) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings August 14, 2026 15:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

Suppressed comments (1)

migrations/1786643346.sh:151

  • readlink returns nonzero if any descriptor disappears after glob expansion, and this || then discards every successfully read target. Chromium processes churn descriptors, so an unrecognized browser can be misclassified as a reused PID even when other descriptors still point into the profile, allowing the repair while it is open. Preserve partial output and only use an empty result when nothing was readable.
    fds=$(readlink -- /proc/$pid/fd/* 2>/dev/null) || fds=""

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) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings August 14, 2026 15:33

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

Suppressed comments (2)

migrations/1786643346.sh:157

  • readlink returns a failure status if any FD disappears between glob expansion and inspection. The || fds="" branch then discards targets successfully read from the other descriptors, so an active browser with a nonstandard executable name can be misclassified as a reused PID during normal FD churn. Preserve partial output and let the executable check handle the case where nothing was readable.
    fds=$(readlink -- /proc/$pid/fd/* 2>/dev/null) || fds=""

test/shell.d/copy-url-shortcut-migration-test.sh:142

  • The fixed delay does not establish that the background process has opened the profile before the migration inspects it. On a busy runner the process can still be starting, causing the migration to classify the PID as unrelated and making this test fail nondeterministically. Poll the specific inherited descriptor and fail explicitly if the holder never becomes ready.
sleep 0.2

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) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings August 14, 2026 15:42

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

Suppressed comments (1)

migrations/1786643346.sh:157

  • If any descriptor closes between glob expansion and readlink, GNU readlink returns nonzero even though it printed the other valid targets; the || fds="" then discards all of that evidence. An active browser with an unrecognized executable name can consequently be classified as closed and have its Preferences repaired while running. Preserve successful outputs while tolerating individual disappearing descriptors.
    fds=$(readlink -- /proc/$pid/fd/* 2>/dev/null) || fds=""

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 <noreply@openai.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed and tested on a fresh Omarchy worker. The fix works, and I pushed one small correction to it, but the branch no longer merges: quattro deleted test/shell.d/copy-url-shortcut-migration-test.sh in 1aa1423 ("Retire the shipped Copy URL migration test"), and this PR edits that file.

What was checked. A reproduction of #6866 of my own: a profile with a pending Copy URL repair, a SingletonLock naming a dead pid on this host, and a user who presses Continue every time. On the merge base the migration prompted 10,565 times in 15 seconds and never repaired anything. On this branch it repairs through the stale lock without prompting. With a live stand-in browser holding the lock, it prompts three times and then defers, leaving the preferences untouched. The PR's own test passes on the head and fails on the base migration ("migration repairs through a stale singleton lock"). ./test/cli is green. All of this ran against the merge base b15ec6c, not current quattro.

Pushed: aa9724d. fds=$(readlink -- /proc/$pid/fd/* 2>/dev/null) || fds="" discarded every descriptor whenever any one of them failed to read. readlink still prints the ones it could read, but it exits non-zero, and a running browser opens and closes descriptors constantly. So a browser whose binary is not on the name list could read as closed, and the repair would run underneath it. It now keeps the partial output (|| true inside the substitution). A regression test stubs readlink to fail one extra descriptor. That test fails with the fix reverted and passes with it, and the full suite is green on the new head.

Second opinion. Codex Medium reviewed it and found the readlink defect above. It reviewed the new commit a second time and found nothing. It also raised two design points that I have left alone, because they are choices rather than defects:

  • A browser reaching its profile through a symlink (~/.config/chromium pointing elsewhere) never matches the descriptor check. It is protected only by the executable-name list at migrations/1786643346.sh:166. The comment there says so, but a Chromium build under an unlisted name in that setup would get the repair made under it.
  • A smaller fix would count only a dead or zombie pid as closed and treat any other live pid as open. That would drop the descriptor and executable checks, and with them the only path by which a live browser can be misread as closed. The cost is that a reused pid would defer the repair after three prompts instead of letting it through.

The new tests also report a pass when the unreadable-pid and zombie cases cannot be set up, and a pass there is really a skip.

Waiting on the author, to resolve the conflict with quattro: either restore the test file with these cases or drop it along with the retirement, then rebase. verified is withheld until the branch merges cleanly. It fixes #6866, and no competing pull request was found.

edanidzerda added a commit to edanidzerda/omarchy that referenced this pull request Oct 8, 2026
Fold in PR omacom#6872: a lock holds only while its pid still owns the
profile (open files, browser name, zombies), and the prompt gives up
after three tries per profile so omarchy-update cannot hang. Keep a
live SingletonSocket connect() as the fallback when that pid looks
dead or reused. Port those cases into copy-url-migration-test.sh
instead of restoring the retired shortcut test.
test/shell.d/copy-url-shortcut-migration-test.sh: quattro retired this test once 1786643346 shipped and froze (1aa1423), then cut it down to the Brave Origin rerun (4fa9615); these cases re-tested the frozen migration and kept the branch from merging.
@ryanrhughes

Copy link
Copy Markdown
Collaborator

Trimmed the test changes so this merges with quattro again: 9d3ff58.

  • test/shell.d/copy-url-shortcut-migration-test.sh (+184 lines dropped): quattro retired the full test once 1786643346 shipped and froze (1aa1423), then cut it down to the Brave Origin rerun (4fa9615). These cases extended the retired version, re-tested the frozen migration, and were the only thing that kept the branch from merging.

The migration change is untouched. git merge-tree against current quattro is clean now, and the merge differs from quattro only in migrations/1786643346.sh.

On a disposable worker, quattro's remaining test passes against the merged tree. The old full test passes against the migration too. A reproduction against the merged tree, run both directly and through the Brave Origin rerun (1792474908, which sources this migration), showed:

  • a lock naming a dead pid on this host: repairs with no prompt
  • a live process named like a browser holding the lock: prompts 3 times, exits 1 naming the profile, preferences untouched
  • a lock from another host: prompts 3 times, exits 1

🤖 Reviewed by Claude Opus 5.5 in Claude Code, second opinion Codex XHigh.

@greptile-apps

greptile-apps Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 4/5

[Medium impact] The change reaches the Copy URL repair in the update workflow.

The PR appears safe to merge, with a non-blocking request for tests covering the new lock checks and prompt limit.

Findings

  1. P2 New branches lack tests ▶

Summary

The migration now checks whether a Chromium lock still names a running browser instead of treating every leftover link as an open profile.

  • The migration checks whether a lock belongs to a browser using the affected profile.
  • The migration gives each open profile three prompts before deferring the repair.

Acknowledgments: dhh explicitly describes foreign-machine locks and uncertain browser ownership as reasons to defer repair. dhh also states that three unsuccessful rounds for the same profile should defer the migration. These choices are intentional, not reported defects.

Reviews (1) · Last reviewed commit: "Drop the test changes for the retired Co..." · Reviewed by Greptile

Comment thread migrations/1786643346.sh
# 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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 New branches lack tests

Every simulated lock names test-host-1234, so the existing tests return at this hostname check without reaching the new PID checks. Successful confirmations also close the browser immediately, leaving the three-prompt limit untested.

Add cases for a dead PID, a live owner, a reused non-browser PID, and the prompt limit resetting when the waiting profile changes. Otherwise, both fixes can regress while the tests still pass.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@aholbreich

Copy link
Copy Markdown
Contributor

One thing #14457 has that this branch doesn't: an omarchy update -y guard. bin/omarchy-update:103 exports OMARCHY_UPDATE_UNATTENDED=1 for -y, but the migration still reaches gum confirm (migrations/1786643346.sh:236 here). With a terminal attached that waits for a key, so the three-round cap never counts. Since #10308, 1792474908.sh sources this migration for Brave Origin profiles, so the next omarchy update -y can stop there on any machine where a Brave Origin profile needs the repair and the browser is open.

#14457's 85f8938a checks the variable right before the prompt and reports and exits 1, leaving the migration pending, the same as a declined prompt and as omarchy-update-system-pkgs-when-conflicted:74 does. It comes with a test that stubs a hanging gum. Could that block come along here? I checked this by reading the source at 9d3ff58f and quattro@0a7beb7d, not by running it.

@omarchybot omarchybot added the verified Omarchy Triage has verified that this issue is ready for final review label Oct 21, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

Re-verified at 9d3ff58, merged into current quattro (087f73d) on a fresh Omarchy worker. The fix works there and the branch now merges cleanly. It is waiting on the maintainer to choose between this and #14457, which fixes the same bug.

What was checked. My own reproduction of #6866 ran with a gum that presses Continue every time and a 15-second limit. On quattro's migration, every one of these loops for the full 15 seconds (2,687 to 3,361 prompts) and repairs nothing:

  • a SingletonLock naming a dead pid on this host
  • a pid since reused by an unrelated process
  • a zombie
  • a live process holding the profile open
  • another host's lock
  • the Brave Origin rerun (1792474908.sh, which sources this migration) with a dead pid

On the merged tree, the dead, reused and zombie pids and the Brave Origin rerun all repair without a prompt. A live holder and a foreign lock prompt three times, exit 1 and leave Preferences untouched. The migration file is the only difference between the two trees, so the quattro run is also the run with the fix reverted. ./test/cli and test/shell.d/copy-url-shortcut-migration-test.sh pass on the merged tree.

Second opinion. Codex Medium reviewed the merged tree and found nothing wrong with it, including the sourcing from 1792474908.sh. It agreed with my reading, and its independence is not guaranteed.

Competing fix: #14457. It carries this PR's lock check verbatim and adds three things:

  • A guard that defers instead of prompting when OMARCHY_UPDATE_UNATTENDED=1 (85f8938). @aholbreich is right that this branch lacks it: omarchy update -y exports that variable at bin/omarchy-update:103, yet this migration still reaches gum confirm at migrations/1786643346.sh:237, which waits for a key, so the three-round limit never applies. quattro has the same gap today, so it predates this PR and is not the stale-lock bug in Migration 1786643346 loops after reboot on stale Chromium SingletonLock #6866.
  • A check that the SingletonSocket still accepts a connection, so a leftover socket with no lock no longer counts as an open browser. Here a socket alone still counts, as it does on quattro.
  • A --user-data-dir check on the lock's pid.

The two reviewers disagree on which fix should win. Codex Medium picks #14457 for the -y guard and the socket check. I would keep this one, because it came first, it fixes the reported cause, and #14457's lock check is copied from it. The -y guard is a real improvement, and it could come here as a five-line change crediting @edanidzerda. Either way, the choice is the maintainer's. I have not pushed anything.

On the Greptile note that the new branches have no tests: those cases were dropped in 9d3ff58, following quattro's retirement of this frozen migration's test. The stale-lock behaviour above was exercised on the worker rather than by a test in the repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working verified Omarchy Triage has verified that this issue is ready for final review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Migration 1786643346 loops after reboot on stale Chromium SingletonLock

5 participants