Skip to content

Heal broken background symlink during theme refresh - #10731

Open
epkoen wants to merge 7 commits into
omacom:quattrofrom
epkoen:fix/theme-refresh-broken-background-link
Open

epkoen wants to merge 7 commits into
omacom:quattrofrom
epkoen:fix/theme-refresh-broken-background-link

Conversation

@epkoen

@epkoen epkoen commented Sep 7, 2026

Copy link
Copy Markdown

When OMARCHY_THEME_SKIP_BACKGROUND=1 is set (such as during omarchy theme refresh, template regenerations, or post-update migrations), omarchy-theme-set wipes and swaps the staged theme directory in place but bypasses updating the active background symlink (~/.local/state/omarchy/current/background).

If an active theme background file was renamed, converted (e.g. .jpg -> .webp as in commit a4219f8), or removed upstream, the background symlink is left dangling pointing to the non-existent file path. On subsequent boots or lock screen activations, omarchy-shell / Background.qml logs Cannot open: file://... and fails to render the desktop background, leaving a black/empty screen until the user manually re-selects the theme.

Solution

  1. Self-heal broken links on refresh: When OMARCHY_THEME_SKIP_BACKGROUND=1 is active, check whether CURRENT_BACKGROUND_LINK exists and resolves to a valid file ([[ ! -e $CURRENT_BACKGROUND_LINK ]]). If the link is broken or missing, fall back to setting an available theme background instead of leaving a dead link.
  2. Stem matching: When looking up the current background in choose_theme_background, if exact path matching fails, check for a matching filename stem (${background%.*}). This ensures that when upstream converts image formats (e.g. 1-cosmic.jpg -> 1-cosmic.webp), the user's active wallpaper selection is preserved rather than jumping to the default wallpaper.
  3. Skip cycling when refreshing: When OMARCHY_THEME_SKIP_BACKGROUND=1 is set, preserve the matched index rather than advancing to next_index, honoring the caller's intent not to cycle the wallpaper.
  4. Headless healing: In headless mode (THEME_HEADLESS=1), also heal CURRENT_BACKGROUND_LINK if it is a dangling symlink.

Verification

Added test/shell.d/theme-refresh-background-test.sh covering:

  • Preserving the active background when its file remains present during refresh.
  • Resolving converted formats by stem (e.g. .jpg -> .webp) and healing the symlink.
  • Falling back to an available background when an active image is deleted.
  • Healing dangling symlinks during headless theme refresh.

All 4 test cases pass:

ok - theme refresh preserves the active background when its file exists
ok - theme refresh matches converted background extensions by stem
ok - theme refresh heals a dangling symlink when the file is removed
ok - headless theme refresh repairs a dangling background symlink

Existing theme tests (test/shell.d/theme-staging-test.sh and test/shell.d/video-background-test.sh) continue to pass.

When OMARCHY_THEME_SKIP_BACKGROUND=1 is set (such as during theme refresh
or template regeneration), omarchy-theme-set swaps the staged theme
directory in place but skips updating the current background symlink.
If the active background was renamed, converted (e.g. .jpg to .webp),
or removed upstream, the background symlink is left dangling, causing
omarchy-shell to fail rendering the desktop background on subsequent sessions.

Check whether CURRENT_BACKGROUND_LINK is missing or dangling before
skipping background setup. If broken, fall back to setting an available
theme background, matching filename stem when possible to preserve the
user's wallpaper selection across extension changes.
@omarchybot omarchybot added the bug Something isn't working label Sep 27, 2026
omarchybot and others added 3 commits October 2, 2026 11:21
quattro now remembers a wallpaper per theme and only looks at the current link when the theme is unchanged, so the stem match and the refresh-keeps-the-same-background rule move inside that branch, which is the only one a refresh takes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Unquoted, the stem is a glob pattern, so a renamed 1-art[wide].jpg never matched its .webp and a * or ? in a path could match an unrelated file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Codex Medium <noreply@openai.com>
Two cases run omarchy-theme-set outside headless mode, which runs every post-theme command for real: kitty and ghostty get signalled and GNOME settings change on whatever desktop runs the suite. Stubbing each command on PATH is not enough, because run_parallel starts them through bash -lc and env-bootstrap puts a dev-linked $OMARCHY_PATH/bin back in front, so a bash shim drops the -lc calls and passes everything else to /bin/bash.

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

Copy link
Copy Markdown
Collaborator

Reviewed, with three commits pushed to the branch. The bug is real on quattro: omarchy-theme-refresh restages the theme without touching current/background, migration 1787481315.sh runs it during an update, and the jpg→webp conversion in #7477 leaves that link pointing at a file the restage removed.

Pushed

  • fb0e92d8c merges quattro, which had conflicted. quattro now remembers a wallpaper per theme and only reads the current link when the theme is unchanged, so the stem match and the keep-the-same-background-on-refresh rule now sit inside that same-theme branch, the only one a refresh takes. Per-theme memory is untouched.
  • a4b2d3a88 quotes "$current_stem" in choose_theme_background. Unquoted, it is a glob, so 1-art[wide].jpg would never match its .webp, and a * or ? in a path could match an unrelated file.
  • 3d5ecbe72 keeps the new test off the desktop that runs it. Its two non-headless cases ran every post-theme command for real: kitty and ghostty got signalled, and GNOME settings changed. Stubbing them on PATH is not enough, because run_parallel starts them through bash -lc and env-bootstrap puts a dev-linked $OMARCHY_PATH/bin back in front. A bash shim now drops the -lc calls, and the other session calls are stubbed.

Checked, on a worker built from the Omarchy ISO

  • theme-refresh-background-test.sh passes 4/4 at 3d5ecbe72. With quattro's omarchy-theme-set in place of the fix, it fails at "theme refresh does not leave a dangling symlink".
  • A sentinel in the dev-linked omarchy-restart-terminal stayed untouched with the shim and fired without it.
  • theme-background-memory, theme-staging, background, user-theme and theme-templates pass.
  • Two failures are not this PR's: they happen identically with quattro's own script. ./test/cli stops at "vscode generated theme references current theme file", and video-background-test.sh exits on PREPARED_BACKGROUND_SNAPSHOT: unbound variable.

Second opinion: Codex Medium reviewed it in two rounds. The first round found both the unquoted stem and the test reaching the real session hooks. The second round, pinned to 3d5ecbe72, found nothing open.

Still open

Next: this is labelled verified. It is waiting on the maintainer, and ready waits on ./test/cli passing on quattro again.

@greptile-apps

greptile-apps Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge, with one non-blocking test coverage gap from the previous review.

Findings

  1. P2 Shell transition goes untested ▶

Summary

Repairs missing or broken background links when refreshing a theme.

  • Theme refresh repairs missing wallpaper links without cycling selections.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Refresh swaps in theme] --> B{Background target exists?}
  B -->|Yes| C[Keep background]
  B -->|No| D{Available background?}
  D -->|No| E[Apply colors only]
  D -->|Yes| F[Match old path or stem; otherwise use first]
  F --> G{Headless?}
  G -->|Yes| H[Repair link]
  G -->|No| I[Tell shell and repair link]
Loading

Reviews (2) · Last reviewed commit: "Stub the retints in the theme refresh te..." · Reviewed by Greptile

Comment on lines +48 to +50
for command in omarchy-shell omarchy-hook omarchy-notification-send omarchy-theme-set-herdr-machines omarchy-theme-bg-cache; do
printf '#!/bin/bash\nexit 0\n' >"$stub_bin/$command"
done

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 Shell transition goes untested The non-headless refresh tests check that the repaired symlink points to a file, but this stub always reports success and records no calls. The tests would still pass if the running shell were never told to display the replacement background. Please record and assert the transition call and its target so the visible repair is covered.

Knowledge Base Used: Theme switching and application sync

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 omarchybot removed the verified Omarchy Triage has verified that this issue is ready for final review label Nov 16, 2026
omarchybot and others added 3 commits November 16, 2026 23:06
quattro now retints Omarchy's app icons in the headless branch, beside this branch's heal of a dangling background link; both are kept.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A refresh of a theme with no backgrounds found the link missing, called set_theme_background, and sent "No background was found for theme" on every update that refreshes the theme. It now heals only when choose_theme_background finds a file, and otherwise applies the palette as before. The headless branch heals a missing link as well as a dangling one, so the two branches agree.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
run_parallel now starts each retint straight from PATH rather than through bash -lc, so the bash shim intercepted nothing and the non-headless cases ran the real omarchy-restart-* and omarchy-theme-set-* commands: terminals signalled and Hyprland reloaded on whatever desktop ran the test. Every one of them is stubbed on PATH instead, as theme-set-retint-order-test.sh does, keeping omarchy-theme-set-templates real.

The refresh also sets OMARCHY_THEME_WAIT=1, as omarchy-theme-refresh does. Without it the other retints ran detached, and the test's cleanup could remove the stubs before they started, so a late lookup would fall through to the real command in bin/.

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

Copy link
Copy Markdown
Collaborator

Reviewed again after quattro moved under it, with three commits pushed to the branch. The bug is still on quattro: a refresh with OMARCHY_THEME_SKIP_BACKGROUND=1 never looks at current/background, so a wallpaper the restaged theme no longer has (the jpg→webp conversion, say) is left as a dangling link.

Pushed

  • 33ecffb99 merges quattro, which had conflicted again. quattro added an omarchy-theme-set-icons call to the headless branch beside this PR's heal; both are kept.
  • 3853eae0c heals on a refresh only when the theme has a wallpaper to offer. Without that, refreshing a theme with no backgrounds went into set_theme_background and showed "No background was found for theme" on every update that refreshes the theme. The headless branch now heals a missing link as well as a dangling one, so the two branches agree. A new case in the test covers the quiet refresh.
  • ef73a6980 keeps the test off the desktop that runs it. run_parallel now starts each retint directly instead of through bash -lc, so the old bash shim stopped nothing, and the non-headless cases ran the real omarchy-restart-terminal and omarchy-restart-hyprctl. Every omarchy-restart-* and omarchy-theme-set-* is now stubbed on PATH, as theme-set-retint-order-test.sh does, and the refresh sets OMARCHY_THEME_WAIT=1 like omarchy-theme-refresh, so the retints finish before the test cleans up.

Checked, on a worker built from the Omarchy ISO

  • theme-refresh-background-test.sh passes 5/5 at ef73a6980. With quattro's omarchy-theme-set it fails at "theme refresh does not leave a dangling symlink", and without the new guard it fails at the no-background case.
  • With the real omarchy-restart-terminal and omarchy-restart-hyprctl swapped for sentinels, the previous version of the test fired both and this one fires neither.
  • ./test/cli passes, as do theme-background-memory, theme-staging, user-theme, theme-templates, video-background, theme-intro-switch, theme-set-retint-order, theme-set-budget and background-pending-theme. The two failures noted last time, in ./test/cli and video-background-test.sh, no longer happen.

Second opinion: Codex Medium and muse-wonder via pi (thinking high) reviewed it in three rounds. They found the test still reaching real restart commands, and the detached retints outliving the test; both are fixed above. Both models agree the merge lost nothing from quattro, and the heal is sound. Their independence is not guaranteed.

Still open

  • In the last round, both reviewers flagged one remaining race in the test. omarchy-theme-bg-cache and the setsid herdr mirror are started in the background and never waited for, so the test's cleanup could in principle delete their stubs before they start. theme-set-retint-order-test.sh on quattro has the same exposure. It is left as it is here.
  • When the link no longer matches any file exactly, stem matching also changes what a normal theme switch picks: the wallpaper after the matched one, instead of the first.
  • Show Hyprland's background colour when a theme has no wallpaper #13955 removes the link when a theme has no wallpaper. This PR leaves the link alone in that case and refreshes quietly. If both land, the refresh branch should remove the link too.

Next: this is labelled verified and waits on the maintainer.

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.

2 participants