fix(server): pass the explicit user to loginctl enable-linger (fixes WSL2 service install)
What Changed
t3 service install now runs loginctl enable-linger <user> with the user resolved from the effective uid (os.userInfo(), exposed as a new HostProcessUserName reference), instead of the bare loginctl enable-linger.
Files: apps/server/src/cloud/bootService.ts, packages/shared/src/hostProcess.ts, plus tests.
Why
Closes #4894.
The bare loginctl enable-linger resolves the caller through their logind session. Under WSL2 a normal shell has no XDG_SESSION_ID, so logind cannot resolve a session and the step exits non-zero — install then rolls back and the service is never set up, even when lingering is already enabled for that user.
The existing comment justified the no-arg form by wanting to avoid a stale-or-unset $USER. Resolving the username from the effective uid keeps that intent (it is never $USER) while dropping the session dependency, so loginctl enable-linger <user> succeeds on WSL2 and on ordinary systemd Linux. This is the standard way to enable-linger for a specific user and does not depend on an active session.
Verified: bootService.test.ts passes, including a new test asserting the resolved user is forwarded verbatim; apps/server typecheck is clean.
Checklist
- [x] This PR is small and focused
- [x] I explained what changed and why
- [x] No UI changes
[!NOTE] Low Risk Narrow change to Linux boot-service install linger invocation and a shared host-process username ref; no auth, data, or API surface changes.
Overview Fixes
t3 service installfailing on WSL2 when the linger step runsloginctl enable-lingerwith no arguments. That form needs a logind session; WSL2 shells often lackXDG_SESSION_ID, so the step fails and install rolls back.Install now runs
loginctl enable-linger <user>, with the username from a newHostProcessUserNamereference in@t3tools/shared/hostProcess(defaultos.userInfo().usernamefrom the effective uid, not$USER).bootServicereads that ref and passes it into the linger command.Tests expect the explicit user in the install command list and add a case that the resolved name is forwarded verbatim (e.g.
caesar).Reviewed by Cursor Bugbot for commit f3e132e70799b187089ba5b707fbc95a3566d048. Bugbot is set up for automated code reviews on this repo. Configure here.
[!NOTE]
Fix
loginctl enable-lingerto pass an explicit username for WSL2 service install
- Adds
HostProcessUserNameto hostProcess.ts, aContext.Reference<string>that resolves the current user's account name from the system passwd database (viaos.userInfo().username) rather than the$USERenv var.- Updates
bootService.tsto pass the resolved username explicitly tologinctl enable-linger <user>, fixing a failure in WSL2 where the no-argument form fails without an active logind session.- Behavioral Change:
loginctl enable-lingeris now always called with an explicit username argument instead of relying on the session-derived default.Macroscope summarized f3e132e.
[!IMPORTANT]
Review skipped
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID:
bceca6e0-a94b-4227-a606-dcd33b185755You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
- [ ] 🔍 Trigger review
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands.
Approvability
Verdict: Needs human review
An unresolved review comment identifies a potential bug introduced by this fix: the eager os.userInfo() call could throw when the effective uid lacks a passwd entry, causing failures in operations like status and uninstall that don't need the username. This correctness concern warrants human review.
You can customize Macroscope's approvability policy. Learn more.
Confirming this on a second platform, and I think the polkit detail is worth recording since it is the reason the fix works.
openSUSE MicroOS 20260802, [email protected], headless (no display, no login session). t3 service install fails at enable-linger with Access denied ... requires interactive authentication.
logind picks its polkit action from the target uid: set-self-linger when it is the caller's
own, set-user-linger otherwise. Those are governed differently, and only the first is usable
with no authentication agent to prompt anyone:
$ pkcheck --action-id org.freedesktop.login1.set-self-linger --process $$; echo $?
0
$ pkcheck --action-id org.freedesktop.login1.set-user-linger --process $$; echo $?
polkit.result=auth_admin_keep
2
$ loginctl enable-linger "$(id -un)"; echo $? # named user, my own
0
$ loginctl enable-linger; echo $? # bare, as t3 calls it today
Could not enable linger: Access denied as the requested operation requires interactive
authentication. However, interactive authentication has not been enabled by the calling program.
1
Same host, same user, same moment. So naming the user is not only about resolving a session, it selects the action that needs no password, which is why this fixes headless hosts as well as WSL2.
Two limits on that: I did not build and run #5012 itself, only the call it makes, and lingering was already on for this user so the successful call was a no-op write. The polkit check runs before the write, so I would not expect a first-time write to differ.
Workaround until this lands, for anyone else who finds this issue. First confirm lingering is already on, because otherwise you would be skipping a step that genuinely needs to run and the service will not start at boot:
loginctl show-user "$(id -un)" --property=Linger # must print Linger=yes
If it does, shim out just that one call for the duration of the install:
mkdir -p /tmp/linger-shim
printf '#!/bin/sh\n[ "$1" = enable-linger ] && exit 0\nexec /usr/bin/loginctl "$@"\n' \
> /tmp/linger-shim/loginctl
chmod +x /tmp/linger-shim/loginctl
PATH=/tmp/linger-shim:$PATH t3 service install
rm -rf /tmp/linger-shim
The unit you end up with is identical to a normal install.
AI Disclosure: Prepared with the assistance of Claude Code (Claude Opus 5). Every command and output above was run and observed on my own machine. Reviewed by me before posting.
Ran this on Linux (Docker node:24) rather than a Windows host, since bootService.test.ts is Linux-only by design.
main: 7/7 pass- this branch: 17/17 pass
So no regression, and the 10 added tests all pass.
Two limits worth stating rather than implying a stronger result:
I could not run the new tests against main's source to show they fail without the fix. They depend on HostProcessUserName, which this PR adds to packages/shared/src/hostProcess.ts, so reverting the source makes the test file fail to load instead of failing an assertion.
Docker Linux is not WSL2, so the actual loginctl enable-linger behavior under WSL2 is still untested from here.
Separately, in case anyone tries to check this from Windows and thinks the PR is at fault: bootService.test.ts already fails 4/7 on a Windows host on main, because it asserts a systemd ExecStart built from the host path (ExecStart=/usr/local/bin/node C:\Users\...). Same non-hermetic class as #4507.
Closing as part of the open-PR backlog sweep (wave 1).
Reason: Equivalent linger fix is on main: enable-linger already passes the uid. Related: main bootService.ts enable-linger uid
Reopen if this is still wanted and you’re willing to rebase onto current main.