Skip to content

Route fcitx5 D-Bus activation through omarchy-fcitx5.service - #13552

Closed
Ray0907 wants to merge 3 commits into
omacom:quattrofrom
Ray0907:fcitx5-dbus-activation
Closed

Ray0907 wants to merge 3 commits into
omacom:quattrofrom
Ray0907:fcitx5-dbus-activation

Conversation

@Ray0907

@Ray0907 Ray0907 commented Sep 28, 2026 •

Copy link
Copy Markdown

The fcitx5 package ships /usr/share/dbus-1/services/org.fcitx.Fcitx5.service. When any client asks for org.fcitx.Fcitx5 while omarchy-fcitx5.service is between restarts, dbus-broker spawns a bare fcitx5 outside the unit. The unit's instance then finds the name taken, exits 0, and Restart=always loops it every ~2s for the rest of the session.

This ships an activation file at /usr/local/share/dbus-1/services/org.fcitx.Fcitx5.service with SystemdService=omarchy-fcitx5.service. /usr/local/share precedes /usr/share in the session's XDG_DATA_DIRS (Omarchy already ships wayland-sessions there), so activation starts the unit instead of a second fcitx5. A migration reloads the bus config and hands a session that is already looping back to the unit; a healthy unit is left alone.

Needs the matching omarchy-settings PKGBUILD change: omacom/omarchy-pkgs#704

Testing

Fresh Omarchy 4.0.4 install, fcitx5 5.1.22, dbus-broker 37. Each case stops the unit, runs fcitx5-remote -n, starts the unit, waits 30s, then requires one fcitx5 owned by the unit with NRestarts no longer climbing:

Without this change With this change
D-Bus activation during a restart, ×3 FAIL ×3, loop PASS ×3, 0 restarts

Migration: on a session looping at 3 restarts it restored a single unit-owned fcitx5 with 0 restarts; rerun on the healthy unit it left the same MainPID running.

systemd-test.sh, config-test.sh, migrate-scope-test.sh, migrate-wrapper-test.sh, unowned-system-paths-test.sh pass.

Not covered

Refs #7461

🤖 Generated with Claude Code

The fcitx5 package's activation file spawns a bare fcitx5 whenever a client
asks for org.fcitx.Fcitx5 while the unit is between restarts. The unit's
instance then exits 0 on every start and Restart=always loops it forever.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@llstrk

llstrk commented Sep 29, 2026

Copy link
Copy Markdown

Automated AI review

Community review: Independent automated community review, unaffiliated with the Omarchy team, intended to help prepare PRs for their review.

Outcome: The new migration can abort omarchy update.

Migration fails when fcitx5 is not running

Migrations run under bash -euo pipefail. In a graphical session where nothing owns org.fcitx.Fcitx5 (unit stopped, failed or disabled), busctl --user status exits 1 and line 11 ends the migration silently. Impact: later migrations stay pending and omarchy update fails until fcitx5 runs again.

Suggested change: add || true to line 11 and the reproducer as a test.

Reproducer (fails at 722c006)

Save as test/shell.d/fcitx5-dbus-activation-migration-test.sh in the PR checkout (head 722c006) and run bash test/shell.d/fcitx5-dbus-activation-migration-test.sh. It stubs busctl, systemctl and omarchy-restart-xcompose, and runs the migration with the same bash -euo pipefail that omarchy-migrate uses.

#!/bin/bash

set -euo pipefail

source "$(dirname "${BASH_SOURCE[0]}")/base-test.sh"

migration="$ROOT/migrations/1790604026.sh"
test_dir=$(mktemp -d)
trap 'rm -rf "$test_dir"' EXIT

stub_bin="$test_dir/bin"
mkdir -p "$stub_bin"

# busctl answers `status` the way the real one does: a PID= line when someone
# owns the name, or exit 1 when nobody does. ReloadConfig just succeeds.
cat >"$stub_bin/busctl" <<'SH'
#!/bin/bash
if [[ $* == *" status org.fcitx.Fcitx5" ]]; then
  if [[ -z ${TEST_OWNER_PID:-} ]]; then
    echo "Failed to get credentials: No such device or address" >&2
    exit 1
  fi
  printf 'PID=%s\nPPID=1\nUID=1000\n' "$TEST_OWNER_PID"
fi
SH

# A graphical session is running; MainPID is whatever the case says.
cat >"$stub_bin/systemctl" <<'SH'
#!/bin/bash
case "$*" in
  "--user is-active --quiet graphical-session.target") exit 0 ;;
  "--user show --property MainPID --value omarchy-fcitx5.service") echo "${TEST_MAIN_PID:-0}" ;;
  *) exit 1 ;;
esac
SH

cat >"$stub_bin/omarchy-restart-xcompose" <<'SH'
#!/bin/bash
echo restart >>"$TEST_CALLS"
SH
chmod +x "$stub_bin"/*

calls="$test_dir/calls"

# Same shell options omarchy-migrate runs every migration with.
run_migration() {
  rm -f "$calls"
  TEST_CALLS="$calls" PATH="$stub_bin:$PATH" bash -euo pipefail "$migration" >/dev/null 2>&1
}

TEST_OWNER_PID=4242 TEST_MAIN_PID=4242 run_migration ||
  fail "migration succeeds when the unit owns the bus name"
[[ ! -e $calls ]] || fail "migration restarts a healthy unit"
pass "migration leaves a healthy unit alone"

TEST_OWNER_PID=5151 TEST_MAIN_PID=0 run_migration ||
  fail "migration succeeds when a D-Bus activated fcitx5 owns the bus name"
[[ -e $calls ]] || fail "migration hands a D-Bus activated fcitx5 back to the unit"
pass "migration hands a D-Bus activated fcitx5 back to the unit"

# Nobody owns org.fcitx.Fcitx5: the user stopped or disabled the unit, removed
# fcitx5, or it is between restarts. busctl status exits 1 here, and under
# pipefail that fails the assignment, errexit stops the migration, and
# omarchy-migrate stops the queue (and omarchy update with it).
TEST_MAIN_PID=0 run_migration ||
  fail "migration fails when nothing owns org.fcitx.Fcitx5"
[[ ! -e $calls ]] || fail "migration restarts fcitx5 when nothing owns its bus name"
pass "migration leaves a session without fcitx5 alone"

Actual output at 722c006 (exit status 1):

ok - migration leaves a healthy unit alone
ok - migration hands a D-Bus activated fcitx5 back to the unit
not ok - migration fails when nothing owns org.fcitx.Fcitx5

Actual output after changing only line 11 of migrations/1790604026.sh (exit status 0):

-  owner=$(busctl --user status org.fcitx.Fcitx5 2>/dev/null | sed -n 's/^PID=//p')
+  owner=$(busctl --user status org.fcitx.Fcitx5 2>/dev/null | sed -n 's/^PID=//p') || true
ok - migration leaves a healthy unit alone
ok - migration hands a D-Bus activated fcitx5 back to the unit
ok - migration leaves a session without fcitx5 alone

The stubbed busctl matches the real one. Against a private session bus run by dbus-broker 37, with activation files for org.fcitx.Fcitx5 present but nothing owning the name, systemd 261.2's busctl --user status org.fcitx.Fcitx5 printed Failed to get credentials: No such device or address and exited 1 without starting an activation. The unmodified migration, run with that real busctl and a stubbed systemctl that reports an active graphical session, exited 1 after printing only its echo line. Run through bin/omarchy-migrate with a later migration queued behind it, the runner printed (colour codes and the leading blank line removed):

Running migration (1790604026)
Route fcitx5 D-Bus activation through omarchy-fcitx5.service

and exited 1 with an empty stderr. It wrote no marker for 1790604026 and did not run the later migration.

omarchy-pkgs#704 packaging gaps

omarchy-settings is pinned to v4.0.4, which lacks default/dbus-1/, so #704's new install line fails package(). Impact: the release build fails at that pin; on the dev channel, omarchy-dev ships the migration but omarchy-settings-dev lacks the override.

Suggested change: guard that line with if [[ -f … ]] like the plocate drop-in, and add it to omarchy-settings-dev.

Reproducer (package() run locally, not in CI)

omarchy-pkgs#704 (head 748f8210) adds an unconditional install of default/dbus-1/services/org.fcitx.Fcitx5.service to pkgbuilds/omarchy-settings/PKGBUILD. That PKGBUILD pins _commit='c668141e9c42b13c80c9ca4ea108e11708c5e8a5' (v4.0.4), and that commit has no default/dbus-1/ directory:

$ git ls-tree c668141e9c42b13c80c9ca4ea108e11708c5e8a5 default/ | grep -E 'dbus|wayland'
040000 tree a1bad1507ff1841c92b4d0d469a4d16e65c48c1b	default/wayland-sessions

Harness: source the PKGBUILD, copy an omarchy checkout to $srcdir/omarchy, and call package() with errexit, errtrace and an ERR trap, which is how makepkg's run_function_safe runs it. magick is stubbed so icon conversion cannot fail for an unrelated reason.

run_package() {
  local label=$1 pkgbuild=$2 tree=$3 carch=${4:-x86_64}
  local work=/tmp/pkg-$label
  mkdir -p "$work/src" "$work/pkg"
  cp -a "$tree" "$work/src/omarchy"
  (
    cd "$work"
    export PATH="$stub:/usr/bin:/bin" CARCH=$carch srcdir="$work/src" pkgdir="$work/pkg"
    source "$pkgbuild"
    shopt -o -s errexit errtrace
    trap 'echo "ERR: package() stopped at: $BASH_COMMAND" >&2' ERR
    package
  )
}

Actual results:

PKGBUILD omarchy source exit override in package
omarchy-pkgs master 660cbe3, omarchy-settings c668141 (its pin) 0 no
#704 748f8210, omarchy-settings c668141 (its pin) 1 no
#704 748f8210, omarchy-settings 722c006 (this PR) 0 yes, mode 644
#704 748f8210, omarchy-settings-dev 722c006 (this PR) 0 no

stderr of the failing run:

install: cannot stat 'default/dbus-1/services/org.fcitx.Fcitx5.service': No such file or directory
ERR: package() stopped at: install -Dm644 default/dbus-1/services/org.fcitx.Fcitx5.service "$pkgdir/usr/local/share/dbus-1/services/org.fcitx.Fcitx5.service"

Files that are newer than the release pin already use a guard in the release PKGBUILD, for example lines 237-240 of #704's pkgbuilds/omarchy-settings/PKGBUILD:

  # Older release pins still configure locate through install/config/locate.sh.
  if [[ -f default/systemd/system/plocate-updatedb.service.d/10-omarchy.conf ]]; then
    install -Dm644 default/systemd/system/plocate-updatedb.service.d/10-omarchy.conf "$pkgdir/usr/lib/systemd/system/plocate-updatedb.service.d/10-omarchy.conf"
  fi

pkgbuilds/omarchy-settings-dev/PKGBUILD is pinned to each quattro tip (its header: "every quattro tip becomes a commit pin here"), and #704 does not change it. The last row shows that when the dev package is built from this PR's commit, it does not install the override under /usr/local/share.

Details

Verified

Optional notes

  • systemd-test.sh does not check Name=org.fcitx.Fcitx5: with Name=org.fcitx.Fcitx4 it still passes.
  • With SYSTEMD_COLORS=1, busctl colours the PID= value even into a pipe, so the comparison fails and a healthy unit is restarted (reproduced; Omarchy does not set this variable). SYSTEMD_COLORS=0 on that call avoids it.
  • docs/file-layout.md does not list the new /usr/local/share/dbus-1/services/ destination next to wayland-sessions.

Related PR: open #10578 changes the adjacent ExecStart assertion in test/shell.d/systemd-test.sh, and a three-way merge with this PR conflicts there. Keeping #10578's ExecStart assertion and this PR's SystemdService= assertion resolves it.


Review information

Test scope: Source and sandbox tests at 722c006; loop not re-run in a real session.

AI process: Opus 5.5 Medium coordination and synthesis, Opus 5.5 Xhigh technical review and final fact check, GPT 6 Sol Xhigh search for related issues, Opus 5.5 Medium editorial check.

Opt out: To stop receiving these reviews, reply to this comment saying so.

busctl status exits 1 when no process owns org.fcitx.Fcitx5. Under the
bash -euo pipefail that omarchy-migrate runs migrations with, the owner
lookup then killed the migration and blocked every later one. Treat a
missing owner as empty and leave the session alone.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@omarchybot omarchybot added the bug Something isn't working label Oct 3, 2026
A user who disabled or masked omarchy-fcitx5.service and runs fcitx5 their own way also has a bus owner that is not the unit's MainPID. The migration took that for the activation loop and called omarchy-restart-xcompose, which killed their fcitx5; with the unit masked, the start that follows fails and the migration aborts the queue. Only hand the name back when the unit is enabled, which is the only state the loop happens in.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Codex Medium <[email protected]>
@greptile-apps

greptile-apps Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 4/5

[Medium risk] Adds D-Bus service activation file and migration for fcitx5.

The PR appears safe to merge, with a non-blocking gap in the migration test.

Findings

  1. P2 Reload failures go unnoticed ▶

Summary

Routes D-Bus requests for org.fcitx.Fcitx5 through omarchy-fcitx5.service instead of starting a second process.

  • Adds a migration that reloads the bus configuration and repairs sessions with a foreign bus owner.
  • Adds package-path checks and tests for restart decisions.
  • The new test should also check the required reload call.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Client requests org.fcitx.Fcitx5] --> B[D-Bus activation file]
  B --> C[omarchy-fcitx5.service]
  C --> D[fcitx5 owns the bus name]
  E[Migration reloads bus configuration] --> B
  E --> F{Foreign bus owner?}
  F -->|Yes, graphical session and unit enabled| G[Restart through existing helper]
  G --> C
  F -->|No| H[Leave running process alone]
Loading

Reviews (1) · Last reviewed commit: "Leave a disabled or masked fcitx5 unit's..." · Reviewed by Greptile

cat >"$stub_bin/busctl" <<'SH'
#!/bin/bash
case "$2" in
call) exit 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 Reload failures go unnoticed

The busctl stub accepts any call, and the test never checks that ReloadConfig was requested. Removing or misspelling that call would leave every case passing, even though the current session would keep using the old activation file. Record the call arguments and require the expected reload before checking restart behavior.

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

Copy link
Copy Markdown
Collaborator

Reviewed and verified on a disposable worker built from the Omarchy ISO (fcitx5 5.1.22, dbus-broker 37, systemd 261.2), in a live Hyprland session. Reviewed by Claude Opus 5.5 and Codex Medium.

The bug is real and this fixes it. With the unit stopped, a D-Bus call to org.fcitx.Fcitx5 spawned a bare fcitx5, and once the unit was started it looped (NRestarts 8 → 13 in 10 seconds, MainPID 0). With the override installed at /usr/local/share/dbus-1/services/, the same sequence left one fcitx5 owned by the unit and no restarts. Removing the override brought the loop back. On a session that was already looping, the migration handed the name back to the unit, and running it again on a healthy unit left the same MainPID running.

Pushed d1ea3f5: the migration only hands the name back when omarchy-fcitx5.service is enabled. Before this, a user who had disabled or masked the unit and runs fcitx5 their own way also had a bus owner other than MainPID. On the worker, with the unit masked, the migration killed that fcitx5, failed to start the masked unit and exited 1, which stops omarchy-migrate and every migration after it. With the unit disabled, it replaced the user's fcitx5 with Omarchy's. Codex found this. The new fourth case in fcitx5-dbus-activation-migration-test.sh fails without the guard and passes with it.

Tests on the worker, at d1ea3f5: systemd-test.sh and the migration test pass. config-test.sh fails against omarchy-pkgs master and passes against omacom/omarchy-pkgs#704. The rest of ./test/shell and ./test/cli fail only where the base branch fails too.

Second opinion: Codex Medium reviewed it twice. The first round found the defect above. The second round, on d1ea3f5, found nothing more. It checked that the guard holds for each state the unit can be in, including the hand-made wants symlink that migration 1785167800 falls back to. It agreed that the override is the proportionate fix and that dbus-broker keeps the first activation file it finds for a name, with /usr/local/share searched before /usr/share.

Waiting on omacom/omarchy-pkgs#704, which installs the file, so this can't land before it. As it stands, #704 would also break the release build: omarchy-settings is pinned to v4.0.4 (c668141e), which has no default/dbus-1/, so its unconditional install fails package(). That install needs the same if [[ -f … ]] guard the plocate drop-in uses. After that it is the maintainer's call.

@omarchybot

Copy link
Copy Markdown
Collaborator

Thank you for this. What it does is now on quattro, so I am closing it.

This is now on quattro through #14433: a per-user D-Bus activation file (default/input-methods/org.fcitx.Fcitx5.service) delegates org.fcitx.Fcitx5 to omarchy-fcitx5.service, and the bus is reloaded when it is installed, so standard activation starts the supervised unit.

This was checked against quattro by Claude, with Codex at medium effort verifying the claims above. If something here is still missing, say so and this can be reopened.

@omarchybot omarchybot closed this Oct 15, 2026
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.

3 participants