Skip to content

3.0.1: keep the user manager bus when the updater relaunches itself - #71

Merged
promptclickrun merged 2 commits into
promptclickrun:mainfrom
atostivint:fix/launcher-user-bus
Sep 29, 2026
Merged

promptclickrun merged 2 commits into
promptclickrun:mainfrom
atostivint:fix/launcher-user-bus

Conversation

@atostivint

Copy link
Copy Markdown

Problem

The plugin's detached updater (_launch_detached_worker → systemd-run --user …) builds a deliberately stripped launcher environment of PATH/HOME/LANG. That also strips the locator a client needs to reach the per-user service manager, so on a host where the launcher runs without an inherited XDG_RUNTIME_DIR the job is rejected and the update stops with:

The service manager rejected the updater job

Reproduced on the affected host (Hermes Agent, Debian/LXC, loginctl show-user → Linger=yes, State=active, /run/user/0/bus present):

env -i PATH=… HOME=/root LANG=C.UTF-8 systemd-run --user --unit=probe-a --collect --no-block --service-type=exec -- /bin/true
→ exit 1: Failed to connect to user scope bus … $DBUS_SESSION_BUS_ADDRESS and $XDG_RUNTIME_DIR not defined

same command with XDG_RUNTIME_DIR=/run/user/0
→ exit 0: Running as unit: probe-b.service

The host is healthy — only the launcher environment lacked the bus locator, while the failure text points at the host ("This host cannot launch a restart-safe updater").

Change

_launcher_env() now:

  • keeps XDG_RUNTIME_DIR when the environment provides one and the directory exists,
  • otherwise derives /run/user/<uid> when that directory exists,
  • carries DBUS_SESSION_BUS_ADDRESS when it is set,
  • emits nothing for a path that does not exist.

PATH, HOME and LANG are unchanged, so a host that worked before behaves identically.

Tests

tests/test_update_launcher_env.py (unittest, 6 tests): existing runtime directory is carried, /run/user/<uid> fallback, DBUS_SESSION_BUS_ADDRESS pass-through, base keys unchanged, no fallback when /run/user/<uid> is missing, and a non-existent XDG_RUNTIME_DIR is dropped.

All 6 pass. Against current main the three locator tests fail (AssertionError: None != '/run/user/0'), so the regression is pinned.

Version bumped to 3.0.1 (plugin.yaml, PLUGIN_VERSION in loopdy_plugin/link_contracts.py).

The systemd-run --user launcher runs with a deliberately stripped environment,
which also stripped the locator the client needs to reach the per-user service
manager. On a host where that launcher runs without an inherited
XDG_RUNTIME_DIR, the updater job is rejected and the update stops with
"The service manager rejected the updater job".

Keep a valid XDG_RUNTIME_DIR when the environment provides one, derive
/run/user/<uid> when it exists, and carry DBUS_SESSION_BUS_ADDRESS when it is
set. Nothing else about the launcher environment changes.
promptclickrun
promptclickrun previously approved these changes Sep 29, 2026

@promptclickrun promptclickrun left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks for this, and for the clear write-up with the systemd-run repro. It made the problem easy to confirm.

Approved. We'll merge it today.

What we checked:

  • The change only affects the environment handed to systemd-run --user / launchctl. The updater itself still starts with a clean environment through env -i, so the bus locator doesn't leak into it.
  • PATH, HOME and LANG are unchanged, and on macOS nothing changes, since /run/user/<uid> doesn't exist there.
  • The new tests pass, and the locator tests fail on main without the fix. The existing updater tests behave the same with and without this PR.

Two optional thoughts. Neither is needed for this PR, and we're happy to handle them later ourselves:

  1. If XDG_RUNTIME_DIR is set but points at a missing directory, it's dropped without trying the /run/user/<uid> fallback. That's rare, and it's no worse than today.
  2. test_falls_back_to_existing_per_user_runtime_directory is skipped wherever /run/user/<uid> doesn't exist, which likely includes CI. Patching os.path.isdir, as the neighbouring test does, would let it run everywhere.

Plugin releases are batched now (promptclickrun#73): the release PR bumps the version.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@promptclickrun

Copy link
Copy Markdown
Owner

Small heads-up: I pushed one commit that takes the version bump out of this PR. We've just moved to batched plugin releases (#73): pull requests leave the version alone, and a separate release PR bumps it and ships the batch. Your fix goes out in the next plugin release, and you'll be credited in its notes. Nothing else in your change was touched.

@promptclickrun
promptclickrun merged commit 9adebc8 into promptclickrun:main Sep 29, 2026
2 checks passed
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.

3 participants