Skip to content

Commit 81431ea

Browse files
committed
fix(service): leave a relocated XDG_CONFIG_HOME uncredited for Linux desktop startup
auto-launch 0.5.0 writes the login entry under ~/.config/autostart. When XDG_CONFIG_HOME points elsewhere the session searches another autostart directory, so that entry proves registration but not login startup.
1 parent a1b7e47 commit 81431ea

5 files changed

Lines changed: 15 additions & 10 deletions

File tree

‎docs-site/src/content/docs/guides/desktop-app.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,9 @@ Startup safety reports **Desktop app** protection when OpenCodex's recorded owne
7777
**Start at Login** registration, and live supervision of its bundled proxy all match.
7878
On Linux, the pinned autostart backend writes the login entry to
7979
`~/.config/autostart/OpenCodex.desktop`, even when `$XDG_CONFIG_HOME` is set. Startup
80-
safety reads that HOME-based entry; the desktop install-id separately follows
81-
`$XDG_CONFIG_HOME` (or `~/.config` by default).
80+
safety reads that entry and the desktop install-id under `~/.config`. When
81+
`$XDG_CONFIG_HOME` points elsewhere, the login session searches a different autostart
82+
directory, so startup safety stays **At risk** instead of crediting the entry.
8283
The entry counts only while it is not marked `Hidden=true` or
8384
`X-GNOME-Autostart-enabled=false`, and has no `OnlyShowIn`, `NotShowIn`, or `TryExec`
8485
condition. Its `Exec` must be an unquoted absolute path to `opencodex-desktop`, without

‎src/service/desktop-startup.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,9 @@ export function diagnoseLinuxDesktopStartup(deps: DesktopStartupDeps = {}): Desk
144144
const home = deps.home ?? homedir();
145145
const configured = env.XDG_CONFIG_HOME;
146146
const config = configured && isAbsolute(configured) ? configured : join(home, ".config");
147-
// auto-launch 0.5.0 uses HOME for autostart; Tauri app_config_dir uses XDG for install-id.
147+
// auto-launch 0.5.0 writes autostart under HOME; Tauri app_config_dir uses XDG for install-id.
148+
// A relocated XDG_CONFIG_HOME puts that entry outside the session's autostart search path.
149+
if (config !== join(home, ".config")) return deriveDesktopStartup(facts);
148150
const capture = () => {
149151
const id = readFileSync(join(config, "com.opencodex.desktop", "install-id"), "utf8");
150152
if (id.trim() !== owner.ownership.installId) return null;

‎structure/ops/service-and-sidecars.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,6 @@ src/update/async-check.ts uses the existing owner-bound registry target with a b
509509

510510
The desktop badge snapshot in src/update/desktop-badge.ts is process-local display state keyed by a Tauri session id. A 60-second shell heartbeat renews receipt time; entries expire after 180 seconds and the store retains at most 32 sessions. It is separate from the package version cache and from the updater job/ownership transaction. A proxy restart reports unknown until a bound desktop shell republishes; no update installation can be authorized by this snapshot.
511511

512-
Desktop startup diagnostics use `src/service/desktop-startup.ts` to read the ownership record, the login registration (macOS: launchd; Linux: the `$XDG_CONFIG_HOME/autostart/OpenCodex.desktop` entry, which must launch an absolute `opencodex-desktop` with `--autostart` and not be hidden or disabled) and exact parent/child executable paths (Linux: `/proc/<pid>/exe` and the parent pid from `/proc/<pid>/stat`) without mutating them. A durable desktop claim survives a failed identity or supervision check; only fresh matching identity, enabled login registration, and live supervision grant protection. Ownership and PID are re-read before crediting the result. The startup-health subprocess uses `selfLaunchArgv` to support both source and compiled entrypoints.
512+
Desktop startup diagnostics use `src/service/desktop-startup.ts` to read the ownership record, the login registration (macOS: launchd; Linux: the `~/.config/autostart/OpenCodex.desktop` entry that auto-launch writes, credited only when `XDG_CONFIG_HOME` is unset or `~/.config`; it must launch an unquoted absolute `opencodex-desktop` with exactly `--autostart`, without conditional keys, and not be hidden or disabled) and exact parent/child executable paths (Linux: `/proc/<pid>/exe` and the parent pid from `/proc/<pid>/stat`) without mutating them. A durable desktop claim survives a failed identity or supervision check; only fresh matching identity, enabled login registration, and live supervision grant protection. On macOS, ownership and PID are re-read before crediting the result; on Linux, the complete evidence chain is read twice and both reads must agree. The startup-health subprocess uses `selfLaunchArgv` to support both source and compiled entrypoints.
513513

514514
On Linux, a dashboard update worker started from the systemd user service is launched through an executable regular file at a trusted absolute path — `/usr/bin/systemd-run`, `/bin/systemd-run`, `/usr/local/bin/systemd-run` (local installs), or `/run/current-system/sw/bin/systemd-run` (the NixOS layout) — with `--user --scope --quiet --collect` (`src/update/worker-launch.ts`), so it leaves the service cgroup before the updater stops `opencodex-proxy.service`; the default `KillMode=control-group` otherwise kills it with the proxy (#5750). The inherited `PATH` is never searched, and each candidate's resolved target — plus every ancestor directory able to substitute it — must be root-owned and not group/world-writable: a trusted-path symlink into a user-replaceable directory is skipped, as is a group-writable `/usr/local/bin`, rather than exec'd under the service account. Candidates are tried in order and a path whose no-op scope probe fails falls through to the next trusted path; the probe applies only when `INVOCATION_ID` is set, and every other case keeps the plain detached spawn. The management route resolves the launcher with `resolveSystemdRunAsync` before spawning, so first-request probing overlaps other work instead of blocking the event loop for up to twenty seconds. `--scope` moves `systemd-run` itself into the scope and then execs the worker, so the recorded PID is the worker's (`tests/update/update-worker-launch.test.ts`).

‎structure/runtime.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ Codex compaction uses a request-local model override for the configured triggers
543543
state, beside the install provenance. The claim carries an `owner` (`cli` or `desktop`), an
544544
opaque `installId` naming the owning installation rather than the user or the machine, and a
545545
`consentGeneration`. An absent claim means the CLI install that registered the service owns
546-
the runtime, which is what every record written before the field existed says. `src/service/desktop-startup.ts` separates the durable macOS and Linux desktop claim from startup viability. The bounded probe verifies matching install identity, loaded and enabled login registration, and exact app-to-bundled-proxy process paths. On Linux, install-id follows XDG_CONFIG_HOME while auto-launch 0.5.0 writes the login entry under HOME/.config/autostart. Conditional entries and ambiguous Exec syntax are uncredited; the resolved desktop basename must match and its resolved ocx stays in the same directory. Both complete evidence reads must agree on ownership, install-id, entry contents, executable targets, PID and parent relationship; changes fail closed. AppImage registrations are uncredited because they name the outer image rather than the mounted executable. `src/server/startup-health-cache.ts` launches source and compiled probes with `selfLaunchArgv`, revokes stale protection, and preserves desktop recovery guidance.
546+
the runtime, which is what every record written before the field existed says. `src/service/desktop-startup.ts` separates the durable macOS and Linux desktop claim from startup viability. The bounded probe verifies matching install identity, loaded and enabled login registration, and exact app-to-bundled-proxy process paths. On Linux, auto-launch 0.5.0 writes the login entry under HOME/.config/autostart, so a relocated XDG_CONFIG_HOME (outside that search path) is uncredited. Conditional entries and ambiguous Exec syntax are uncredited; the resolved desktop basename must match and its resolved ocx stays in the same directory. Both complete evidence reads must agree on ownership, install-id, entry contents, executable targets, PID and parent relationship; changes fail closed. AppImage registrations are uncredited because they name the outer image rather than the mounted executable. `src/server/startup-health-cache.ts` launches source and compiled probes with `selfLaunchArgv`, revokes stale protection, and preserves desktop recovery guidance.
547547

548548
Every write goes through `swapServiceInstallState`. With a custom home, the default-home
549549
record is the authority every writer can derive and the active-home record is a compatibility

‎tests/service/service-desktop-startup-linux.test.ts‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,19 @@ test("matching install, XDG login entry and the app supervising its sidecar gran
6363
expect(startupHealthSummary(health)).toBe("protected by desktop app at login and its proxy supervisor");
6464
});
6565

66-
test("XDG_CONFIG_HOME relocates only the install id; autostart remains under HOME", () => {
66+
test("a relocated XDG_CONFIG_HOME is not credited: the HOME-based entry is outside its autostart path", () => {
6767
const f = fixture();
6868
const moved = join(f.home, "xdg");
6969
mkdirSync(join(moved, "com.opencodex.desktop"), { recursive: true });
7070
writeFileSync(join(moved, "com.opencodex.desktop", "install-id"), "installation-a");
71-
writeFileSync(f.idPath, "stale-default-install");
72-
expect(diagnoseLinuxDesktopStartup({ ...f.deps, env: { XDG_CONFIG_HOME: moved } })).toMatchObject({ viable: true });
71+
expect(diagnoseLinuxDesktopStartup({ ...f.deps, env: { XDG_CONFIG_HOME: moved } })).toMatchObject({ viable: false });
7372
mkdirSync(join(moved, "autostart"), { recursive: true });
74-
writeFileSync(join(moved, "autostart", "OpenCodex.desktop"), `[Desktop Entry]\nType=Application\nExec=${f.app} --autostart\n`);
75-
rmSync(f.entryPath);
73+
writeFileSync(join(moved, "autostart", "OpenCodex.desktop"), `[Desktop Entry]
74+
Type=Application
75+
Exec=${f.app} --autostart
76+
`);
7677
expect(diagnoseLinuxDesktopStartup({ ...f.deps, env: { XDG_CONFIG_HOME: moved } })).toMatchObject({ viable: false });
78+
expect(diagnoseLinuxDesktopStartup({ ...f.deps, env: { XDG_CONFIG_HOME: join(f.home, ".config") } })).toMatchObject({ viable: true });
7779
});
7880

7981
for (const field of ["OnlyShowIn=GNOME;", "NotShowIn=GNOME;", "TryExec=/missing", "OnlyShowIn=", "NotShowIn=", "TryExec="]) {

0 commit comments

Comments
 (0)