Skip to content

Sample only the first frame when picking bar text color - #8925

Closed
chessing234 wants to merge 4 commits into
omacom:quattrofrom
chessing234:fix/omarchy-bar-text-color-first-frame
Closed

chessing234 wants to merge 4 commits into
omacom:quattrofrom
chessing234:fix/omarchy-bar-text-color-first-frame

Conversation

@chessing234

@chessing234 chessing234 commented Aug 29, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Test plan

  • Extended test/shell.d/bar-text-color-test.sh with a multi-frame GIF fixture (CI).
  • Point current/background at an animated GIF/video with a transparent bar and confirm RSS stays bounded.

Fixes #8906

Multi-frame wallpapers (GIF/video) made ImageMagick decode every
frame before the crop and could exhaust system memory.
Copilot AI balanced review requested due to automatic review settings August 29, 2026 10:50

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

Limits wallpaper sampling to the first frame to prevent excessive resource use.

Changes:

  • Adds ImageMagick memory limits and a 10-second timeout.
  • Adds a multi-frame GIF regression test.

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 1 out of 2 changed files in this pull request and generated 1 comment.

File Description
bin/omarchy-bar-text-color Samples frame zero with bounded memory and execution time.
test/shell.d/bar-text-color-test.sh Adds multi-frame sampling coverage.

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

Comment thread test/shell.d/bar-text-color-test.sh Outdated
Comment on lines +35 to +39
magick -size 100x100 xc:'#f5f5f5' -fill '#202020' -draw 'rectangle 0,0 99,19' \
\( -size 100x100 xc:'#00ff00' \) \( -size 100x100 xc:'#0000ff' \) "$multi_frame"
result=$(HOME="$TMPDIR" omarchy-bar-text-color top 20 '#ffffff' '#101010' --background "$multi_frame" --screen 100x100)
[[ $result == "#ffffff" ]] || fail "transparent bar text samples only the first frame of a multi-frame background" "expected #ffffff, got $result"
pass "transparent bar text samples only the first frame of a multi-frame background"
Frame 0 was dark-topped, so the correct answer was #ffffff — the same value fallback() prints when sampling fails. Without the [0] selector the pipeline emits one triple per frame, "32,32,320,255,00,0,255", which the regex guard rejects, so the script fell back to #ffffff and the assertion passed on unfixed code. Removing [0] and rerunning the suite confirmed it: 4 passed.

Light-topping frame 0 makes the expected result #101010, which fallback() cannot produce. The same mutation now fails with "expected #101010, got #ffffff".

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed at bffe2de, with a second opinion from Codex at xhigh reasoning. One real problem, and it is in the test rather than the fix. I pushed the correction to this branch as e4037c6; everything else here holds up.

The new test passed on unfixed code. Frame 0 was dark-topped (#f5f5f5 body with #202020 across the top 20 rows), so the correct answer was #ffffff — which is also exactly what fallback() prints. Without [0] the pipeline emits one triple per frame:

$ magick multi.gif ... -format '%[fx:int(255*r)],...' info:-
32,32,320,255,00,0,255

The guard at bin/omarchy-bar-text-color:123 rejects that, fallback() at :36 prints $text_color, and the assertion on line 38 was satisfied by the failure path. Confirmed by mutation: reverting only the [0] on line 116 left the suite at 4 passed, 0 failed. e4037c6 light-tops frame 0 so the expected result is #101010, which fallback() cannot produce; the same mutation now gives expected #101010, got #ffffff.

The three things the fix does, checked separately on a disposable VM running ImageMagick 7.1.2-30 Q16-HDRI, the build Omarchy ships:

  • "${background_path}[0]" is safe with bracketed filenames. ImageMagick strips only the trailing selector, so wall [2].png[0], cool[1].png[0] and even photo[1][0] all open the right file. Codex traced the mechanism in coders/video.c, where the selector becomes -vframes 1 — so [0] reaches the ffmpeg delegate rather than discarding frames after a full decode. Measured on a 720-frame clip: magick "clip.mp4[0]" returns in 0.12s and touches no temp space, against 9.27s for magick clip.mp4. [0] is doing the real work here.
  • MAGICK_MEMORY_LIMIT=256MiB does not break large stills, but it is not a memory cap either. An 8K RGB wallpaper's 398 MB source cache exceeds both limits and ImageMagick falls through its heap → map → disk hierarchy instead of failing: open big8k-rgb.png[0] (/tmp/magick-..., Disk, 7680x4320x3 398.131MB). Same colour out, 1.20s against 1.03s unbounded. Since MAGICK_DISK_LIMIT is unlimited and $TMPDIR is tmpfs on a stock install, the limits relocate the allocation into tmpfs rather than bounding RAM. Worth knowing they are not the safety net they look like — [0] is what fixes omarchy-bar-text-color decodes every frame of a multi-frame background, exhausting system memory #8906.
  • timeout 10 is comfortable; the worst still I could build finished in 1.2s. It also cleans up after itself: GNU timeout puts the child in its own process group and signals the group, so the ffmpeg delegate goes with it. No orphan survived my timed-out run, which answers the concern raised in omarchy-bar-text-color decodes every frame of a multi-frame background, exhausting system memory #8906's comment.

One pre-existing thing worth knowing, not introduced here. A fallback is sticky. Bar.qml:857 accepts it as an ordinary valid hex, and nothing retries — refreshTransparentForeground() at Bar.qml:831 drops a request outright while the process is running, and there is no onExited or onRunningChanged handler in the file to pick it back up. Recomputation happens only on a theme, position, transparency or background change, so any spurious fallback holds the plain theme foreground for the rest of the session. Codex raised this; I verified the absent handler.

Tests ran on the VM, never locally: test/shell.d/bar-text-color-test.sh at 4 passed 0 failed and ./test/cli clean, both after the pushed commit.

Codex agreed with the test finding, which I had already reached by mutation, so read that agreement with the caveat that its independence is not currently guaranteed; the coders/video.c mechanism and the Bar.qml:831 dropped-refresh race are its own contributions and stand on their own.

One for the maintainer rather than for you: #8307 rewrites the same magick invocation and the same test file, so whichever lands second needs a rebase, and its integer-shrink/size-hint sampling should keep the [0].

@chessing234

Copy link
Copy Markdown
Contributor Author

folding into #12115 with the other bar panel fixes

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.

omarchy-bar-text-color decodes every frame of a multi-frame background, exhausting system memory

3 participants