Skip to content

Keep the sudo editor on one that blocks - #9503

Open
d-zalewski wants to merge 2 commits into
omacom:quattrofrom
d-zalewski:fix/sudo-editor-blocking
Open

d-zalewski wants to merge 2 commits into
omacom:quattrofrom
d-zalewski:fix/sudo-editor-blocking

Conversation

@d-zalewski

Copy link
Copy Markdown

The bug

sudo visudo and sudoedit silently throw away your edits if your Omarchy default editor is a graphical one.

sudo never lets the editor touch the real file. It copies the file to a temp path, runs the editor, waits for the editor to exit, then keeps whatever is on disk. That last step only works if the editor command stays running until you close it.

default/bash/envs sets SUDO_EDITOR="$EDITOR", which is omarchy-launch-editor --inline. That script only runs inline for nvim|vim|nano|micro|hx|helix|fresh; everything else takes the *) branch and runs exec setsid uwsm-app -- "$editor" — detached, returns instantly. So visudo sees an editor that closed without changing anything, prints unchanged, and deletes the temp copy. The editor window then opens on a file that is already gone.

Of the eight editors omarchy default editor offers, five detach: code, cursor, zed, sublime_text, emacs. Only nvim, vim, helix block — and since nvim is the default, the bug stays hidden.

Measured on a 4.0.0.alpha machine, visudo on a temp sudoers file with a stubbed uwsm-app:

===== default editor = nvim =====
(blocks correctly — killed at the 6s timeout)

===== default editor = code =====
visudo: t.sudoers.tmp unchanged        elapsed=0s
uwsm-app called: code -- t.sudoers.tmp

Zero seconds, unchanged, edit gone.

The fix

A --sudo mode on omarchy-launch-editor that never detaches: a terminal editor runs in place, anything else falls back to nvim. Falling back beats honouring the choice here — the alternative is running a full graphical IDE as root over an elevated Wayland connection.

default/bash/envs then points SUDO_EDITOR at it, but only when Omarchy is the one supplying EDITOR:

if [[ $EDITOR == "omarchy-launch-editor --inline" ]]; then
  export SUDO_EDITOR="${SUDO_EDITOR:-omarchy-launch-editor --sudo}"
else
  export SUDO_EDITOR="${SUDO_EDITOR:-$EDITOR}"
fi

An EDITOR the user exported themselves is left to them, and an explicit SUDO_EDITOR still wins over both. The --inline and windowed paths are untouched, so normal editor launching is unchanged.

Verified

Same scenario as the repro — default editor code, SUDO_EDITOR taken from the real default/bash/envs:

SUDO_EDITOR=[omarchy-launch-editor --sudo]
Nvim: Caught deadly signal 'SIGTERM'
elapsed=6s

It now blocks for the full timeout and had to be killed, and uwsm-app is never called. Before, the same run finished in 0s with the edit discarded.

Tests

  • test/shell.d/launch-editor-sudo-test.sh (new) — reads the editor list off omarchy-default-editor so an editor added there is covered without a second edit, and asserts --sudo never reaches setsid, uwsm-app, or omarchy-launch-tui (a separate terminal window returns just as early). Also pins the windowed and --inline paths so this does not change ordinary launching.
  • test/shell.d/editor-env-test.sh — updated for the new SUDO_EDITOR, plus cases for a user-set EDITOR and an explicit SUDO_EDITOR.

test/cli passes in full. test/shell: 216 of 222 files pass; the 6 failures (ascii, branding-about-animation, config, legacy-power-udev-rules-migration, snapper, unowned-system-paths) fail identically on a clean quattro.

Independent of #9500, which fixes a different editor bug (visudo as root finding no editor at all). No file overlap.

🤖 Generated with Claude Code

sudo hands the editor a temporary copy and keeps whatever is on disk once the
editor exits. SUDO_EDITOR was "$EDITOR", which is omarchy-launch-editor
--inline, and that detaches every graphical editor with setsid uwsm-app. The
launcher returns immediately, so visudo and sudoedit see a file that closed
without changing and discard the edit -- no error, and the editor window opens
on a file that is already gone.

That is five of the eight editors omarchy-default-editor offers: code, cursor,
zed, sublime_text, and emacs. Only nvim, vim, and helix block today, which is
why the default hides it.

Add a --sudo mode that runs a terminal editor in place and falls back to nvim
rather than detach, and point SUDO_EDITOR at it. An EDITOR the user set
themselves is left alone, and an explicit SUDO_EDITOR still wins over both.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
quattro now passes `--` before the path on every editor launch (omacom#11495), so the --sudo fallback does the same and the tests expect it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@omarchybot omarchybot added the verified Omarchy Triage has verified that this issue is ready for final review label Oct 3, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed and verified on a disposable Omarchy worker, and I pushed one commit: a merge of quattro into this branch (7bd2e67), because it no longer merged cleanly. Since #11495, quattro puts -- before the path on every editor launch, so the resolution does the same in the new --sudo fallback (exec nvim -- "$@"), and the windowed and inline expectations in launch-editor-sudo-test.sh now include it.

Reproduction. On the worker, with zed installed and set as the default editor, sudoedit running under a pty with secure_path pointed at the tree under test:

  • quattro: sudoedit printed /etc/... unchanged and returned in 0s, with the temp copy already deleted.
  • This branch: SUDO_EDITOR is omarchy-launch-editor --sudo, and sudoedit stayed blocked on nvim -- /var/tmp/... until the timeout killed it.

./test/cli passes 91 of 92, and the one failure ("vscode generated theme references current theme file") fails the same way on quattro. launch-editor-sudo-test.sh, editor-env-test.sh, command-operand-boundaries-test.sh and default-apps-test.sh all pass.

Two claims in the description and comments do not hold:

  • sudo visudo is not affected. On a stock install, sudo resets the environment and does not keep SUDO_EDITOR, so visudo never sees it. The bug is sudoedit / sudo -e.
  • This does not keep a graphical editor from running as root. sudoedit runs the editor as the invoking user, not as root. The comments in bin/omarchy-launch-editor and default/bash/envs say otherwise. What the nvim fallback really does is swap the user's chosen editor for nvim when editing as root, and that is a choice rather than a safety requirement.

Competing fixes. #13044 and #13094 (for #13037) fix the same root cause from the other side: they make --inline pass a wait flag and run setsid -w. That would also fix sudoedit with the user's own editor, since SUDO_EDITOR is --inline on quattro, and would cover git commit, crontab -e and systemctl edit too, which this PR leaves as they are. The two approaches can coexist, but they conflict in bin/omarchy-launch-editor. If both land, this PR's only remaining effect is sending sudo edits to nvim instead of the chosen editor. Which way sudoedit should go is the maintainer's call.

No second opinion. The configured reviewer (Codex Medium) answers its health check, but today's review budget was spent, so nothing reviewed this beyond my own review (Claude Opus 5.5). Without that review this cannot be marked ready.

Waiting on the maintainer: to choose between this approach and #13044 / #13094, and for a second-opinion review on a later run.

@greptile-apps

greptile-apps Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 3/5

[Medium risk] Changes how the editor launcher handles sudo mode.

The PR should not merge until inherited pre-upgrade editor values and an unavailable Neovim fallback are handled.

Findings

  1. P1 Inherited editor still detaches ▶
  2. P1 Fallback assumes Neovim exists ▶
  3. P2 Blocking behavior remains untested ▶

Summary

The PR adds a non-detaching --sudo editor mode, selects it for Omarchy’s default SUDO_EDITOR, and adds shell tests.

  • An inherited pre-upgrade editor value can bypass the new mode.
  • The graphical-editor fallback assumes Neovim remains available.
  • The new test checks dispatch but not blocking behavior.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Shell loads editor environment] --> B{EDITOR is Omarchy default?}
  B -- Yes --> C[SUDO_EDITOR: launch-editor --sudo]
  B -- No --> D[SUDO_EDITOR: EDITOR]
  C --> E{Existing SUDO_EDITOR inherited?}
  E -- Yes --> F[Preserve inherited value, possibly --inline]
  E -- No --> G[Use --sudo]
  G --> H{Selected editor is terminal?}
  H -- Yes --> I[Run selected editor in place]
  H -- No --> J[Run nvim in place]
Loading

Reviews (1) · Last reviewed commit: "Merge quattro into fix/sudo-editor-block..."

Comment thread default/bash/envs
# terminal editor. An EDITOR the user set themselves is left to them, and an
# explicit SUDO_EDITOR still wins over both.
if [[ $EDITOR == "omarchy-launch-editor --inline" ]]; then
export SUDO_EDITOR="${SUDO_EDITOR:-omarchy-launch-editor --sudo}"

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.

P1 Inherited editor still detaches

If a new shell inherits the old Omarchy value SUDO_EDITOR=omarchy-launch-editor --inline, this assignment preserves it instead of selecting --sudo. With a graphical default editor, sudoedit or visudo still launches the editor detached and discards the edit, so the bug this PR intends to fix remains reachable after an upgrade.

Comment thread bin/omarchy-launch-editor
*)
exec setsid uwsm-app -- "$editor" -- "$@"
if [[ $mode == "sudo" ]]; then
exec nvim -- "$@"

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.

P1 Fallback assumes Neovim exists

If a graphical editor is selected but Neovim has been removed or is unavailable on PATH, --sudo runs nvim without checking for it. The earlier availability check only tests the selected graphical editor, so sudoedit and visudo cannot open the temporary file.

fail "--sudo does not hand $editor to a separate terminal" "got: $launched"
done

pass "--sudo blocks for every editor the chooser offers"

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 Blocking behavior remains untested

The test reports that --sudo blocks, but its editor stubs exit immediately and the assertions check only logged arguments. A path that launches a different non-blocking editor could still pass, leaving the behavior this test is meant to protect unverified. A process-liveness check would cover that gap.

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!

@omarchybot

Copy link
Copy Markdown
Collaborator

Greptile's three findings on 7bd2e67, checked against the source by me (Claude Opus 5.5) alone. The configured second opinion (Codex Medium) answers its health check but the day's review budget is spent again, so nothing else has checked this.

  • Inherited SUDO_EDITOR keeps the old --inline value: holds, but narrowly. default/bash/envs is read only by interactive bash, and the uwsm session environment never sets SUDO_EDITOR, so the old value can only come from a parent shell that was started before the upgrade. The usual way to hit this is a tmux server that has been running since before the upgrade. It clears on the next terminal opened outside that parent, or on a reboot. It is minor, and I have not pushed a change for it.
  • The fallback assumes nvim exists: does not hold in practice. nvim is in install/omarchy-base.packages, and the launcher already falls back to nvim unconditionally when the chosen editor is missing (omarchy-cmd-present "$editor" || editor="nvim"), on quattro as well. If it were removed, sudoedit would report the editor failing rather than silently discard the edit, which is the bug this PR fixes.
  • The test checks argv rather than blocking: true, and acceptable. The test asserts that nothing on the --sudo path reaches setsid, uwsm-app or omarchy-launch-tui, which are the three ways the launcher returns early. The blocking itself was shown on the worker in the earlier review.

Nothing else has changed: this is still waiting on the maintainer to choose between this approach and #13044 / #13094, and on a second-opinion review.

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

Copy link
Copy Markdown
Collaborator

I looked at this again because it stopped merging cleanly. The head is still 7bd2e67, the merge I pushed last time.

Classification is unsettled. I asked again whether this is a bug fix or an enhancement, because the head changed after the last classification. Two models answered separately and disagreed. I (Claude Opus 5.5) called it a bug: on quattro, sudoedit silently discards the edit when the default editor is graphical, which I reproduced on a worker last time. The configured second opinion (Codex Medium) called it an enhancement. A likely reason is that the fix changes behaviour on purpose: when editing as root, it swaps the user's chosen graphical editor for nvim, which is a choice and not a requirement. Until the class is settled, I am not adding labels, verifying again or porting this. It goes back to the maintainer.

Why it conflicts. #16756 deleted test/shell.d/editor-env-test.sh from quattro, as one of a set of tests that could not fail. This PR edits that file. If it is ported, there are two options. One is to accept the deletion and lose the two new cases covering a user-set EDITOR and an explicit SUDO_EDITOR. The other is to keep only those two cases, which test the new conditional in default/bash/envs and can fail. bin/omarchy-launch-editor, default/bash/envs and launch-editor-sudo-test.sh merge cleanly.

Competing fixes are unchanged. #13044 and #13094 (for #13037) are still open. They fix the same sudoedit symptom by making --inline wait for graphical editors, and they keep the user's chosen editor.

Waiting on the maintainer: to settle whether this is a bug fix and whether sudoedit should keep the chosen editor or fall back to nvim. That choice also decides between this PR and #13044 / #13094.

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.

2 participants