openclaw/src/daemon
Aftab 700efe6d16
fix(daemon): skip machine-scope fallback on permission-denied bus errors (#62337)
* fix(daemon): skip machine-scope fallback on permission-denied bus errors; fall back to --user when sudo machine scope fails

When systemctl --user fails with "Failed to connect to bus: Permission
denied", the machine-scope fallback is now skipped. A Permission denied
error means the bus socket exists but the process cannot connect to it,
so --machine user@ would hit the same wall.

Additionally, the sudo path in execSystemctlUser now tries machine scope
first but falls through to a direct --user attempt if it fails, instead
of returning the error immediately.

Fixes #61959

* fix(daemon): guard against double machine-scope call when sudo path already tried it

When SUDO_USER is set and machine scope fails with a non-permission-denied
bus error, execution falls through to the direct --user attempt. If that
also fails with a bus-unavailable message, shouldFallbackToMachineUserScope
returns true and machine scope is tried a second time -- a redundant exec
that was never reachable before this PR opened the fallthrough path.

Add machineScopeAlreadyTried flag and include it in the bottom-fallback
guard condition so the second call is skipped when machine scope was
already attempted in the sudo branch.

Add regression test asserting exactly 2 execFile calls in this scenario.

* fix: keep sudo systemctl scoped

---------

Co-authored-by: Peter Steinberger <steipete@gmail.com>
2026-04-08 01:22:31 +01:00
..
test-helpers
arg-split.ts
cmd-argv.test.ts
cmd-argv.ts
cmd-set.ts
constants.test.ts
constants.ts refactor: dedupe daemon lowercase helpers 2026-04-07 13:44:42 +01:00
container-context.ts refactor: dedupe cli daemon readers 2026-04-07 06:42:34 +01:00
diagnostics.ts
exec-file.ts
inspect.test.ts
inspect.ts refactor: dedupe daemon lowercase helpers 2026-04-07 13:44:42 +01:00
launchd-plist.ts
launchd-restart-handoff.test.ts test: trim core partial mocks 2026-04-03 19:28:19 +01:00
launchd-restart-handoff.ts refactor: dedupe cli daemon readers 2026-04-07 06:42:34 +01:00
launchd.integration.e2e.test.ts
launchd.test.ts fix: recover launchd restart and restore prompt-cache gate 2026-04-05 17:47:07 +09:00
launchd.ts refactor: dedupe core lowercase helpers 2026-04-07 20:58:01 +01:00
node-service.ts
output.ts
paths.ts refactor: dedupe cli daemon readers 2026-04-07 06:42:34 +01:00
program-args.test.ts test: trim test partial mocks 2026-04-03 19:10:56 +01:00
program-args.ts
runtime-binary.test.ts
runtime-binary.ts refactor: dedupe core lowercase helpers 2026-04-07 20:58:01 +01:00
runtime-format.ts
runtime-hints.test.ts
runtime-hints.ts
runtime-hints.windows-paths.test.ts
runtime-parse.ts refactor: dedupe daemon lowercase helpers 2026-04-07 13:44:42 +01:00
runtime-paths.test.ts test: trim core partial mocks 2026-04-03 19:28:19 +01:00
runtime-paths.ts refactor: dedupe core lowercase helpers 2026-04-07 20:58:01 +01:00
schtasks-exec.test.ts
schtasks-exec.ts
schtasks.install.test.ts fix: preserve Windows scheduled task restart/install behavior (#59335) (thanks @tmimmanuel) 2026-04-04 08:46:00 +05:30
schtasks.startup-fallback.test.ts fix: preserve Windows scheduled task restart/install behavior (#59335) (thanks @tmimmanuel) 2026-04-04 08:46:00 +05:30
schtasks.stop.test.ts fix: preserve Windows scheduled task restart/install behavior (#59335) (thanks @tmimmanuel) 2026-04-04 08:46:00 +05:30
schtasks.test.ts
schtasks.ts refactor: dedupe daemon lowercase helpers 2026-04-07 13:44:42 +01:00
service-audit.test.ts
service-audit.ts refactor: dedupe core lowercase helpers 2026-04-07 20:58:01 +01:00
service-env.test.ts Tests: fix boundary and late-run drift 2026-04-07 19:59:51 +08:00
service-env.ts refactor: dedupe setup token readers 2026-04-07 06:07:13 +01:00
service-runtime.ts
service-types.ts
service.test-helpers.ts
service.test.ts
service.ts refactor: dedupe normalization lowercase helpers 2026-04-07 22:57:52 +01:00
systemd-hints.test.ts
systemd-hints.ts
systemd-linger.ts refactor: dedupe reply lowercase helpers 2026-04-07 10:37:39 +01:00
systemd-unavailable.test.ts
systemd-unavailable.ts refactor: dedupe core lowercase helpers 2026-04-07 15:12:32 +01:00
systemd-unit.test.ts
systemd-unit.ts
systemd.test.ts fix(daemon): skip machine-scope fallback on permission-denied bus errors (#62337) 2026-04-08 01:22:31 +01:00
systemd.ts fix(daemon): skip machine-scope fallback on permission-denied bus errors (#62337) 2026-04-08 01:22:31 +01:00