Skip to content

[Bug] Dashboard self-update loses worker under custom systemd system service #7967

Closed

Description

@RHODIZSECURITY

Client or integration

OpenCodex dashboard

Area

Service lifecycle

Summary

A Dashboard-triggered npm self-update can leave OpenCodex unavailable (HTTP 502 from the reverse proxy) on Linux when the running proxy belongs to a system-wide systemd service under an unprivileged UID, rather than the canonical systemd user service. An update worker may die when the original service's cgroup is stopped; moreover the updater may target a different, installed-but-inactive user unit. The Dashboard job file can remain running with a dead worker PID.

Expected: never stop an active proxy unless a worker can outlive the stop and can restart the actual owner. Unsupported custom system units should receive an actionable, fail-closed error before package mutation.

Reproduction

  1. Configure a custom root-owned systemd service with User=<unprivileged-user>, KillMode=control-group, OCX_SERVICE_MANAGED=1, and ExecStart=ocx start --port 10101. Keep an OpenCodex-managed systemctl --user service installed but inactive.
  2. With OpenCodex v2.89.0 running under the system unit, start a v2.93.0 npm update with restart:true from the Dashboard.
  3. During stop/restart, the original proxy disappears and the browser reports 502; the update job can remain running even though its recorded PID is dead.
  4. Non-destructive supporting reproduction under the same UID: systemd-run --user --scope --quiet --collect -- /usr/bin/true fails with Failed to connect to bus: No medium found when the system service has INVOCATION_ID but no XDG_RUNTIME_DIR. Supplying the verified private /run/user/<uid> makes the scope probe exit 0. A test process launched in that scope is shown under /user.slice/.../app.slice/run-*.scope, outside the system unit cgroup.
  5. Distinct installed supervisor state was reproduced: ocx service status --json reports the user unit installed/enabled but running:false, viable:false, while the independent system unit serves HTTP 200.

The full destructive update scenario has not been re-enacted after remediation; do not treat the non-destructive probes alone as a completed E2E certification.

Version

OpenCodex 2.89.0 → 2.93.0; source baseline v2.93.0 commit 88aaa754566d119b6b8fc898f8fb47602387d82e.

Operating system

Linux, systemd system service + lingered systemd user manager, Bun 1.4.4.

Provider and model

Not provider-specific.

Logs or error output

Failed to connect to bus: No medium found
OWNERSHIP_MUTATION_LEASE_BUSY: another process owns the runtime mutation lease
(recorded PID no longer alive; lease age below stale-reclaim grace period)
systemd: Main process exited, status=1/FAILURE
systemd: Failed to start OpenCodex proxy service

Screenshots and supporting files

The operator captured HTTP 502 Bad gateway during the Dashboard upgrade and a separate startup-safety warning. No screenshots containing private hostnames or identifiers are uploaded here.

Redacted configuration

{
  "systemService": {
    "type": "systemd system",
    "user": "<unprivileged uid>",
    "killMode": "control-group",
    "managed": true
  },
  "dashboardUpdate": {
    "installer": "npm",
    "restart": true
  },
  "userService": {
    "installed": true,
    "enabled": true,
    "running": false
  }
}

Checks

  • I searched existing issues and documentation.
  • I removed secrets, tokens, account details, request credentials, and personal data.

Suggested safety contract

  • Identify and attest the actual running supervisor before beginning update.
  • Spawn the updater in an independently managed scope with a verified UID-private user-bus socket. Refuse safely if that is impossible.
  • Do not target an unrelated user unit when a root-owned custom system unit owns the listener; such a migration needs operator-supervised authorization.
  • Record a terminal, actionable failed state when the updater PID died; avoid indefinite running status.
  • Test service stop, update, restart identity, health stability, rollback and cgroup survival.

A staging-only candidate adds these guards with synthetic tests; it is not deployed or certified.

Activity

  1. added
    gui
    on Oct 29, 2026
  2. github-actions commented on Oct 29, 2026

    @github-actions
    Contributor

    Issue reopened

    The report now contains the information required by the automated check. Thanks for updating it.

  3. changed the title [-]Dashboard update can kill its worker under custom systemd system unit; missing XDG_RUNTIME_DIR and wrong supervisor[/-] [+][Bug] Dashboard self-update loses worker under custom systemd system service[/+] on Oct 29, 2026
  4. added
    bug
    proxy
    service
    on Oct 29, 2026
  5. RHODIZSECURITY commented on Oct 29, 2026

    @RHODIZSECURITY
    ContributorAuthor

    Follow-up: reproducible on the latest v2.94.0 tree (29 Oct 2026)

    The affected system has two simultaneously enabled systemd definitions: a root-owned system unit currently serving OpenCodex and an OpenCodex-generated user unit inactive. The active process is UID 1001 inside /system.slice/opencodex-rhodiz.service, has INVOCATION_ID, but no XDG_RUNTIME_DIR nor DBUS_SESSION_BUS_ADDRESS. These service definitions also use different API-token files/values, so blindly switching service ownership risks client failures.

    Non-destructive, root-authorized probes on the affected VM:

    • systemd-run --user --scope --quiet --collect -- /usr/bin/true under UID 1001 with XDG_RUNTIME_DIR absent: exit 1 (Failed to connect to bus: No medium found).
    • The same command with the UID-owned private runtime /run/user/1001: exit 0.
    • A harmless scoped cat /proc/self/cgroup confirms /user.slice/user-1001.slice/[email protected]/app.slice/run-<...>.scope, independent of the proxy's root-owned service cgroup.
    • The Dashboard's old update-job.json was left as running with a dead PID after the original upgrade and systemd recorded OWNERSHIP_MUTATION_LEASE_BUSY during restart.

    I checked official tag v2.94.0 (commit d844ff4af67c98271be1c1451e7583d36c323527): the Dashboard still resolves systemd-run --user from the service environment, with plain detached-spawn fallback; a root-owned system unit isn't rejected as an unsupported supervisor. This scenario remains open in that tag.

    A defensive patch is being rebased and certified in a private RHODIZ branch. It (a) validates UID/cgroup ownership and rejects update before stopping a root-owned system unit, (b) validates the user-runtime path and socket for scope discovery, (c) prevents fallback to an unsafe in-cgroup update worker, and (d) displays a failed status for a dead updater instead of an endless spinner. It is not deployed or production-certified yet. We will provide an upstream PR and test evidence once the complete gated suite passes.

  6. RHODIZSECURITY commented on Oct 30, 2026

    @RHODIZSECURITY
    ContributorAuthor

    The v2.94.0-based mitigation for the root-owned systemd service Dashboard crash is now in RHODIZ draft PR #7, tree f33483ec6435dfff636b642ef20e83a15f76ae5e. It refuses a GUI update before it stops a listener owned by a system-wide unit, validates the lingered user bus, refuses unsafe in-cgroup fallback, and exposes a dead/stale update worker as failed with a PID-starttime fence. The affected VM has a separate user unit; switching ownership while preserving the external API token and security controls is a controlled deployment step, not something this PR silently performs. The old root system service remains healthy in production. Full suite/CI and an actual user-supervised Dashboard update are required before we can assert the failure is fully fixed.

  7. lidge-jun commented on Oct 30, 2026

    @lidge-jun
    Owner

    Partly fixed by #7996, merged into dev as 261131d3726d95b4ad3335cf416254a868963e08. These are the fail-closed parts of the safety contract:

    • A dashboard update, with or without restart, is now refused before any package mutation when the proxy runs inside a systemd service that is not OpenCodex's own opencodex-proxy.service user unit. The reported custom system unit with User= and an inactive user unit installed is one such case. The same refusal applies when the worker cannot be moved into its own systemd-run --user --scope. The response is 409 update_restart_unsupervised, and it tells the operator to stop the service with its own manager, update from a shell, and start it again. This keeps the updater from killing its own worker with the cgroup and from aiming its restart at the unrelated user unit.
    • GET /api/update/status now reports an active job whose worker PID is gone as failed with the reason, instead of running forever. The next run's existing stale recovery settles the persisted record.

    Still open here: identifying and attesting a custom system unit as the supervisor so the dashboard can update it, and any operator-authorized migration to or restart of such a unit. A real systemd system-unit update has not been re-enacted. Verification is source review plus deterministic tests with injected cgroup and liveness inputs.

  8. lidge-jun commented on Nov 3, 2026

    @lidge-jun
    Owner

    Closing as fixed by #7996 (261131d, released in 2.95.0), which implements the fail-closed contract this report asks for. When the proxy runs inside a systemd unit other than OpenCodex's own opencodex-proxy.service user unit, or the worker cannot move into its own systemd-run --user --scope, a dashboard update is refused with 409 update_restart_unsupervised before any package mutation, with instructions to stop the service with its own manager, update from a shell and start it again (src/server/management/config-routes.ts). GET /api/update/status reports a job whose worker PID is gone as failed. tests/server/update-async-routes.test.ts ("dashboard update restart supervision (#7967)") covers both. Letting the dashboard update and restart a custom system unit it can attest as the supervisor would be a new capability; please open a feature proposal for it.

  9. github-actions commented on Nov 3, 2026

    @github-actions
    Contributor

    Automated translation bookkeeping — detected language: English.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugguiproxyservice

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions