Skip to content

Linux: in-flight fs sandbox helper can be orphaned and block forever when the app-server exits or is killed #54877

Open

Description

@alexdima

What issue are you seeing?

codex 0.162.0 (@openai/codex), Linux x64 (Ubuntu runner); unchanged on main

When the app-server exits or is killed while a filesystem sandbox helper is starting, the helper's bubblewrap sandbox child can be left behind forever. It is reparented to PID 1, keeps its pre-exec bwrap argv and bubblewrap's process group, and holds open the workspace bind mounts and every file descriptor it inherited.

PID    PPID  PGID   AGE  COMMAND
33198  1     33194  174  bwrap --as-pid-1 --new-session --die-with-parent ... --argv0 codex-linux-sandbox -- .../codex --sandbox-policy-cwd <workspace> ... --apply-seccomp-then-exec -- .../codex --codex-run-as-fs-helper

We hit it in VS Code's Agent Host E2E tests: the leaked process kept the test tmpfs busy, so it could not be unmounted.

What steps can reproduce the bug?

  1. exec-server/src/fs_sandbox.rs spawns the helper with the default ProcessMode::Inherit and no parent-death signal. On Linux it just calls wait_with_output().
  2. linux-sandbox/src/linux_run_main.rs (run_bwrap_in_child_with_synthetic_mount_cleanup) forks bubblewrap into its own process group (setpgid(0, 0)), sets it to die with the launcher, and execs bwrap --die-with-parent.
  3. When the app-server is killed while a helper is starting, the launcher dies. (Dropping an in-flight helper future may have the same effect, since KillAndReap kills only the direct child; we have not reproduced that path.) The outer bwrap then dies through its parent-death signal.
  4. The sandbox child that bwrap has just clone()d blocks on an eventfd, waiting for the outer bwrap. An eventfd never reports the writer's death, and the child only sets its own PR_SET_PDEATHSIG after that wait. So it blocks forever. This is --die-with-parent fails to clean up due to a race condition if the parent bwrap process is killed soon after startup containers/bubblewrap#633, with a proposed fix in PR_SET_PDEATHSIG is racy unless there is a check for the parent having already died containers/bubblewrap#700.

Because bubblewrap runs in its own process group, a process-group kill of the app-server does not reach it.

What is the expected behavior?

Killing or stopping the app-server should not leave sandbox helpers behind.

Additional information

  • When a helper is cancelled or dropped, or the app-server shuts down, kill the bubblewrap process group (kill(-pgid, SIGKILL)), not only the direct child. The sandbox child stays in that group until it calls setsid, which is after the wait.
  • Consider giving fs helpers a parent-death signal, as other spawns using codex_utils_pty already can.

As a host-side workaround, VS Code now freezes the app-server with SIGSTOP and kills its process tree on Linux (microsoft/vscode#342277).

Activity

  1. added
    bug
    on Oct 17, 2026
  2. added
    app-server
    sandbox
    on Oct 17, 2026
  3. alexdima commented on Oct 17, 2026

    @alexdima
    Author

    Update: the orphan is created mid-session, not at app-server shutdown

    Since filing, we looked at every occurrence in VS Code CI: 13 failed PR runs between 2026-10-07 and 2026-10-17 (microsoft/vscode#342277). In every run with holder details, the holder is this fs helper with PPID 1. Two findings change the picture:

    1. Timing. The holder's age dates its clone() while the app-server was still running, several seconds before we shut it down. In one run the child was cloned at about 12:39:54 and the app-server was stopped at 12:40:04. In another, cloned at about 13:19:01 and stopped at 13:19:07. So the launcher wasn't killed by our teardown. Most likely Codex killed it itself mid-session, when an in-flight helper was dropped and KillAndReap killed the direct child (the codex-linux-sandbox launcher). That's step 3's "may have the same effect" path, and it looks like the main one.
    2. Host-side tree kills can't help. Once orphaned, the child belongs to PID 1, outside the app-server's tree. We tried freezing the app-server and killing its tree (SIGSTOP + tree kill), and that run still leaked. We've dropped that change. Our test harness now kills orphaned --codex-run-as-fs-helper holders before unmounting.

    So the fix has to be in Codex: when an fs helper is dropped or cancelled, kill the bubblewrap process group (kill(-pgid, SIGKILL)), not only the launcher. The stranded child is still in that group, because it hasn't called setsid yet.

    (The last line of the description is out of date: VS Code no longer kills the app-server tree. It reaps the orphan in its test harness.)

  4. donnielrt commented on Nov 22, 2026

    @donnielrt

    Another occurrence of this shape: codex-cli 0.171.0 on Linux, an interactive CLI session (not app-server or IDE), with system bubblewrap.

    On a desktop session, two orphaned sandbox children were found at logout. Each one:

    • had comm bwrap and kept the pre-exec argv bwrap --as-pid-1 --new-session --die-with-parent --ro-bind / / --dev /dev --perms 000 --tmpfs /tmp/codex-daemon-<uid> …
    • had PPID = the user's systemd manager (reparented), and no children
    • was state S and PID 1 of its own PID namespace
    • had been alive for about 4 h and about 25 min (started mid-session, long after the CLI process that launched it)

    The Codex sessions had been closed earlier; only the terminal window was still open.

    An extra consequence of this bug: the stranded child is the init of a PID namespace and has no signal handlers. Signals from outside the namespace other than SIGKILL are therefore dropped (pid_namespaces(7)), so the orphan ignores SIGTERM. On logout, systemd's SIGTERM does nothing, and the terminal's app unit waits the full DefaultTimeoutStopSec (90 s) before SIGKILL. On a multi-user machine that also delays the next user's login by about 90 s, because the incoming session waits for the outgoing user manager to finish stopping.

    Journal at logout:

    app-<terminal>@<id>.service: State 'stop-sigterm' timed out. Killing.
    app-<terminal>@<id>.service: Killing process <pid> (bwrap) with signal SIGKILL.
    app-<terminal>@<id>.service: Killing process <pid> (bwrap) with signal SIGKILL.
    

    So the fix proposed above (kill the bubblewrap process group with SIGKILL when a helper is dropped) would also remove the logout stall. The workaround we use for now is a per-user DefaultTimeoutStopSec=10s in ~/.config/systemd/user.conf.

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

    app-serverbugsandbox

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions