Skip to content

fix(computer): launch Linux apps in transient scope and surface launch errors (WHI-1047) - #779

Open
Kilyn544 wants to merge 1 commit into
mainfrom
fix/whi-1047-linux-snap-launch-and-error
Open

Kilyn544 wants to merge 1 commit into
mainfrom
fix/whi-1047-linux-snap-launch-and-error

Conversation

@Kilyn544

@Kilyn544 Kilyn544 commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes WHI-1047 (Linux launch() using a transient systemd .service that strips session env and swallows launch failures behind an 8-second generic timeout).

Root Cause

  1. local_linux.py:launch() wrapped xdg-open and open_application in systemd-run --user --service-type=exec --unit=linger-app-<uuid>, stripping caller env (missing XDG_RUNTIME_DIR and desktop vars) and returning exit code 0 on execve before xdg-open / snap-confine failed with status=4/NOPERMISSION.
  2. Go (linux.go) saw confirmed launch success and waited 8 seconds before returning generic errURLNotOpened with zero diagnostic context.

Changes

  • apps/computer/local-daemon/internal/linger/localtools/local_linux.py:
    • Switched launch() to systemd-run --user --scope --quiet --collect --slice=app.slice --unit=app-linger-<uuid>.scope with start_new_session=True, preserving full caller session env + XDG_RUNTIME_DIR/DBUS_SESSION_BUS_ADDRESS defaults.
    • Replaced stderr-prose fallback with structured pre-launch reachability _systemd_user_reachable(env) (systemd-run on PATH, $XDG_RUNTIME_DIR/systemd/private socket, and org.freedesktop.DBus.NameHasOwner("org.freedesktop.systemd1") over session D-Bus via Gio with NO_AUTO_START and 300ms timeout). When reachable, runs .scope directly and never retries on app stderr; when unreachable (containers or broken user buses), launches directly via detached Popen(..., start_new_session=True).
    • Uses native /run/systemd/journal/stdout stream sockets (with a one-time journalctl --user readback probe) as child stderr on systemd hosts—avoiding unbounded unlinked /tmp growth for long-lived GUI apps, avoiding SIGPIPE, and never leaking SIGPIPE=SIG_IGN to gnome-terminal—with clean fallback to unlinked tempfile.TemporaryFile() on non-systemd/container/Storage=none hosts.
    • Added exit-gated launch-error diagnostics ("" while proc.poll() is None) and pre-truncation filtering of benign ERROR: ld.so: object ... cannot be preloaded noise.
  • apps/computer/local-daemon/internal/linger/localtools/linux.go & linux_native.go:
    • Queries read-only launch-error when window_opened == false to enrich errURLNotOpened and surface post-settle crashes on open_application.
  • apps/computer/local-daemon/README.md & Makefile:
    • Updated README launch docs for transient .scope, reachability-gated fallback, and fast launch-error surfacing.
    • Wired python3 -m unittest discover -s apps/computer/local-daemon/internal/linger/localtools -p '*_test.py' into check-computer-go (make check-computer & CI).
  • local_linux_test.py & linux_launch_test.go: 15 Python unit tests and Go launch/embedded-driver tests.

Review Updates

  • Addressed P2-1 (structured org.freedesktop.systemd1 NameHasOwner + socket reachability, removed _SYSTEMD_UNAVAILABLE_MARKERS stderr-text matching), P2-2 (README updated), P2-3 (Makefile check-computer-go runs Python tests), P3-4 (trimmed verbosity, zero issue IDs in code comments; kept both journald stream and TemporaryFile fallback to satisfy zero /tmp growth on systemd hosts and portability on containers/macOS), and rebased onto latest main (29ad855e).

Verification

@linger-review linger-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Approve with nits (3 P2, 1 P3)

Scope: base main, merge base 53f7d21a; 1 commit, 5 files reviewed at a71a2707. Loaded coderbook, ponytail-review, karpathy-guidelines. Ran in a separate session.

Findings

P2

  1. Systemd fallback is decided by matching stderr prose — apps/computer/local-daemon/internal/linger/localtools/local_linux.py:662 (_SYSTEMD_UNAVAILABLE_MARKERS), used in launch().
    The repo rule forbids driving behavior from third-party error wording. It also misfires here. With systemd-run --scope, systemd-run execs the target in place, so the stderr read back and the exit code belong to the application, not only to systemd-run. Example: an app (or xdg-open/gio) prints the common D-Bus warning Failed to connect to bus: ... and exits non-zero within 0.8 s. _is_systemd_unavailable then matches, and the same app is launched a second time outside a scope. The error the user sees comes from the second attempt.
    Fix: decide before launching, with a check that doesn't depend on wording. For example, use the scope path only when the user manager is reachable ($XDG_RUNTIME_DIR/systemd/private exists, or systemctl --user is-system-running returns a status). On a scope failure, report the error and don't retry.

  2. Owning README still describes the old launch design — apps/computer/local-daemon/README.md:1051-1063.
    It still says the host needs a user systemd manager and that launches use systemd-run --user with KillMode=process. It also says open_url only fails after 8 s. After this PR, launches run in an app.slice scope, fall back to a detached Popen without systemd (and probe no longer requires systemd-run), and an immediate non-zero exit fails fast as a confirmed (not unknown-outcome) error, with launch-error diagnostics added to the timeout. AGENTS.md asks for the owning docs to change in the same PR.

  3. New Python unit tests are never run — apps/computer/local-daemon/internal/linger/localtools/local_linux_test.py.
    The only unittest invocation in the repo is Makefile:139 (apps/desktop/packaging). No make target, scripts/check-plan.mjs entry or workflow runs these 513 lines. The parsing, journald, settle and fallback logic they cover can regress without any check failing. Add them to make check-computer (or the existing unittest step) so check (computer-go) runs them.

P3

  1. Two parallel stderr sinks — local_linux.py:721-800 (_open_journal_stream, _query_journal_raw, _read_journal_stderr, _journal_sink_available, _open_stderr_sink).
    The hand-written sd_journal stream header, the readback probe with retries, the journalctl polling and the TemporaryFile fallback are two ways to do one job, about 150 lines plus a mock AF_UNIX server in tests. Consider whether one sink is enough. For example, keep only the unlinked temp file; the driver already closes it on the next launch or on exit. Or keep only journald and drop the file path.

Verified as fine

  • The driver still runs as python3 -u -c <program> (linux_native.go:42), so the new if __name__ == "__main__": block runs and the stdout dup/signal handlers are set up as before.
  • status: "failed" from LaunchError reaches Go as a plain error, not errOutcomeUnknown: linuxAction only wraps status == "unknown" and returns receipt.Error directly (linux_native.go:80-88). So the action journal is not blocked.
  • launch-error is added to the read-only set (linux_native.go:56), so a failed diagnostic read never turns into an unknown-outcome input.
  • launchFailure (linux.go:469) keeps the old open behavior (it always returns errURLNotOpened, now with detail). For run, it errors only when the driver reports a real detail, so a slow app still returns window_opened: false as before (linux.go:220-226, 244-250).
  • launch_error reads nothing while the process is still running (proc.poll() is None), so startup noise from a slow cold start can't fail a launch.
  • A failed first spawn closes its stderr file before the fallback spawn (_spawn_and_settle). The previous launch's file is closed on the next launch, on exit and on SIGTERM (_close_last_launch).
  • xdg-open presence is checked before input begins in open, since probe no longer requires it.
  • No CJK in added lines or in the commit message.

Process notes

  • The branch is 10 commits behind main, and main requires up-to-date branches, so it needs a rebase.
  • Commit a71a2707 is authored by engineer@simplexai.com, which isn't linked to a GitHub account.
  • No merge or fixup commits.

CI

All checks that ran pass (check (computer-go), check (computer-go-windows), check (desktop), repository-gate, CodeQL); the rest were skipped by path. CI doesn't run local_linux_test.py (see finding 3) and runs Go tests without -race. Locally: python3 -m unittest local_linux_test → 15/15 OK; go test -race -count=1 -run TestLinux ./internal/linger/localtools/ → ok.

Automated review by Claude Code


Automated review of a71a270 by Claude Code.

@linger-review linger-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Approve (0 findings)

Scope: follow-up review of 1b50d9c against main (merge base 19cdc336), 1 commit, 7 files. The previous review was on a71a270; the branch has been rebased since then, so I compared the two merge-base diffs and also re-read the whole PR. Helper skills loaded: coderbook. ponytail-review and karpathy-guidelines were not loaded; I applied their checklists from the review instructions. This review ran in a separate session.

Previous findings (follow-up on a71a270)

  • P2: systemd unavailability was detected by matching stderr prose. Resolved. _SYSTEMD_UNAVAILABLE_MARKERS is gone. launch() now chooses the scope or a direct launch once, up front, through _systemd_user_reachable (local_linux.py:804): systemd-run on PATH, $XDG_RUNTIME_DIR/systemd/private is a socket, and NameHasOwner("org.freedesktop.systemd1") with NO_AUTO_START. A non-zero exit is never retried (local_linux.py:940-945). test_launch_skips_systemd_when_user_manager_unreachable_and_never_retries_on_stderr_prose (local_linux_test.py:247) asserts that an app printing "Failed to connect to bus" runs exactly once.
  • P2: README described the old .service launch. Resolved. apps/computer/local-daemon/README.md:1063-1083 now describes the scope under app.slice, the detached fallback, and the fast launch-error surfacing. systemd-run is no longer listed as a hard dependency, which matches the probe that no longer requires it (local_linux.py, native_action("probe")).
  • P2: the new Python tests did not run anywhere. Resolved. Makefile:149 adds python3 -m unittest discover to check-computer-go. The check (computer-go) job log shows Ran 15 tests ... OK.
  • P3: two stderr collection paths. Partially resolved. The code is trimmed (single-expression helpers, with for the probe socket), but both the journald stream and the TemporaryFile fallback remain. The reason (no /tmp growth on systemd hosts, portability elsewhere) is now documented in the _open_stderr_sink docstring (local_linux.py:871). This is acceptable as a deliberate trade-off.

Findings

None.

Verified as fine

  • The embedded driver still runs its server loop. Go starts it with python3 -u -c <program> (linux_native.go:43), so __name__ == "__main__" and the moved fd and signal setup run as before (local_linux.py:1116-1121). Importing the module in tests no longer hijacks stdout or the signal handlers.
  • A confirmed launch failure is not recorded as an unknown input outcome. LaunchError replies with status: "failed" (local_linux.py:1105). In linuxAction, a non-empty Error with a status other than unknown returns a plain error, not errOutcomeUnknown (linux_native.go:85-91), so the action journal is not blocked.
  • launch-error is classed as read-only in linuxAction (linux_native.go:56), so querying it never turns a failure into an unknown outcome.
  • launchFailure (linux.go:469) keeps the old open behaviour: it still returns errURLNotOpened and drops window_opened, now with any detail appended. run (open_application) fails only when the exited process left a non-zero status or stderr. launch_error returns "" while the process is still running (local_linux.py:956-975), so a slow cold start keeps window_opened: false without an error (TestLinuxOpenApplicationSlowRunningAppPreservesWindowOpenedFalse).
  • In runActions, a run step with no window and no launch error still continues as before, and an open step still stops with errURLNotOpened (linux.go:220-226).
  • Child processes are not left as zombies: a still-running child is reaped by a daemon thread calling proc.wait (local_linux.py:927-931). The journald socket is closed in the parent right after spawn. The temp-file sink is closed on the next launch and on driver exit (_close_last_launch in exit_driver and stop_driver).
  • If gi is missing, _systemd_user_bus_has_owner returns False (local_linux.py:784). That host already fails check_permissions on the missing AT-SPI import (local_linux.py:492-497), so the direct-launch fallback there changes nothing reachable.
  • The isLocalLinux test seam is restored in t.Cleanup, and no test in linux_launch_test.go uses t.Parallel, so the shared package variable is not raced.
  • No CJK in added lines or in the commit message. No stale KillMode or linger-app-*.service references remain outside test fixtures that reproduce the old error text.

Process notes

  • The branch is one commit behind main (4ef3f8f7, which only touches apps/computer/local-daemon/README.md in a different section). main requires up-to-date branches, so rebase before merging.
  • The commit author Linger Engineer <engineer@simplexai.com> is not linked to a GitHub account.

CI
All checks pass, including check (computer-go), which ran the 15 new Python tests, and check (computer-go-windows). CI runs the Go tests without -race. This PR adds no goroutine concurrency in Go, so I did not run any tests locally.

Automated review by Claude Code


Automated review of 1b50d9c by Claude Code.

…h errors (WHI-1047)

Switch local_linux.py launch() from systemd-run --service-type=exec
(transient .service unit with stripped environment) to a transient
.scope unit under app.slice (app-linger-<uuid>.scope) when the user
systemd manager is reachable, preserving the session environment and
populating XDG_RUNTIME_DIR/DBUS_SESSION_BUS_ADDRESS defaults so Snap
apps (such as Ubuntu's Snap Firefox) can create their own tracking
scope without .service cgroup rejections.

Probe user systemd reachability before launching via structured signals
(systemd-run in PATH, runtime_dir/systemd/private socket, and D-Bus
NameHasOwner for org.freedesktop.systemd1 with NO_AUTO_START and a
300 ms timeout) instead of matching stderr prose. Fall back cleanly to
direct detached Popen(start_new_session=True) when unreachable, and
fail directly without retrying when a systemd-scoped launch exits
non-zero.

Route launched process stderr to systemd-journald's native stdout
stream socket (/run/systemd/journal/stdout) once journalctl --user
readback is verified (avoiding unbounded unlinked /tmp growth on
long-lived GUI apps without SIGPIPE, SIG_IGN leaks, or relay
processes), falling back to an unlinked TemporaryFile when journald is
unavailable or unreadable. Monitor startup during a bounded settle
window so immediate non-zero exits surface as confirmed failures
without blocking the action journal or waiting 8 s for errURLNotOpened,
filter benign ld.so.preload noise before truncation, and only inspect
post-settle stderr in launch-error once the process has exited.

Update local-daemon README to document the new Linux launch behavior
and wire local_linux_test.py into Makefile check-computer-go so both
local check-computer and CI run it.
@Kilyn544
Kilyn544 force-pushed the fix/whi-1047-linux-snap-launch-and-error branch from 1b50d9c to d928a3f Compare November 26, 2026 19:49

@linger-review linger-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Approve (0 findings)

Follow-up on 1b50d9c. Merge base 6a511c15; 1 commit and 7 files reviewed. git range-diff shows the only change since the previous review is a rebase onto main. The only line that differs is the Makefile context line, which now includes ./cmd/linger-teamhub-launcher from main. I still re-checked the full merge-base diff.

Verified as fine

  • A LaunchError makes the driver reply status: "failed" (local_linux.py:1104-1108). linuxAction returns receipt.Error as a plain error before it reaches the unknown-outcome path (linux_native.go:91-92). A confirmed launch failure therefore doesn't block the action journal. launch-error is in the read-only list (linux_native.go:55).
  • The __main__ guard still runs the server under python3 -u -c (linux_native.go:42), because -c sets __name__ to "__main__". Gio/GLib come from the guarded import at local_linux.py:492, and _systemd_user_bus_has_owner returns False when they are missing (local_linux.py:784).
  • open still always fails when no window opens: launchFailure returns errURLNotOpened with or without detail (linux.go:472-479). run fails only when the driver reports exit detail, so the earlier no-window run behavior is unchanged (linux.go:480-486).

Process notes

  • The commit author Linger Engineer <engineer@simplexai.com> is not linked to a GitHub account.

CI: Analyze, changes and repository-gate are still pending. I ran these locally and both passed:

  • python3 -m unittest discover ... -p '*_test.py': 15 tests OK.
  • go test -race -count=1 -run 'Launch|Linux' ./internal/linger/localtools.

Automated review by Claude Code


Automated review of d928a3f by Claude Code.

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.

1 participant