Skip to content

Let environment recovery pass on Linux machines with login sessions - #7854

Merged
ymichael merged 3 commits into
get-bb:mainfrom
lanjak:fix-7435-linux-cleanup-inspection
Nov 30, 2026
Merged

ymichael merged 3 commits into
get-bb:mainfrom
lanjak:fix-7435-linux-cleanup-inspection

Conversation

@lanjak

@lanjak lanjak commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Human comments

What was wrong

bb environment cleanup <id> --recover, and the storage plugin's automatic recovery, refuse while any same-user process cannot be inspected (environment-engine.ts#L1145-L1150). The Linux scan treats a process as same-user when any of its four UIDs matches. It also counts every cwd or maps read error as unreadable (workspace-processes.ts#L53-L98).

Every Linux login session has such processes. systemd --user, (sd-pam), sshd-session and gpg-agent are non-dumpable, so their cwd cannot be read without privileges. Setuid helpers such as fusermount3 match through their real UID. On this machine (Fedora, one SSH session) recovery is refused for 6 such processes with nothing in the workspace, so it can never pass (#7435).

A second gap in the same scan: a process in another mount namespace, such as a rootless container, reports its cwd and mapped files as paths inside that namespace. The scan compared them with the host workspace path, so a container that bind-mounts the workspace was not found.

What changed

apps/host-daemon/src/workspace-processes.ts, Linux only:

  • Another effective UID: an unreadable process running under another effective UID counts as another user's process, as on macOS since Support environment cleanup recovery on macOS #7520 (fusermount3, a sudo process).
  • Own mount namespace: an unreadable process in the daemon's own mount namespace is not a blocker. A process shares the namespace when the ID of its root mount equals the daemon's. Its mountinfo is readable even when its cwd is not.
  • Another mount namespace: the process is checked through its own mountinfo.
    • Paths are resolved to a filesystem device and a path within that filesystem, then compared with the workspace's location.
    • A readable process blocks when its cwd or a mapped file resolves into the workspace.
    • An unreadable process blocks when one of its mounts exposes the workspace, a directory inside it, or a parent directory.
  • Fallback: if the daemon's own namespace link or mountinfo cannot be read or parsed, the previous rules apply.
  • bb-guide-environments.md describes the Linux rules and the gap below.

No wire change: the result shape and its meaning ("processes that may be using the workspace" and "processes that could not be ruled out") are unchanged, so HOST_DAEMON_PROTOCOL_VERSION is not bumped. The server is unchanged.

Decision for review: the same-namespace exception. A non-dumpable program running inside the workspace in the daemon's own mount namespace is not detected. One example is ssh-agent -D started from a shell there; the shell that started it is still detected. This is the Linux counterpart of the sudo gap accepted for macOS in #7520. Without the exception, recovery cannot pass on any Linux machine with a login session.

Not changed: the issue's nested "Needs recovery: Needs recovery: ..." message. On current main I found no path that re-wraps a stored "Needs recovery" message. Every write that moves an exhausted environment out of failed needs states that do not occur together, or resets the retry budget first, as --recover does. The issue was seen on 0.48.1, before #7725 reworked the teardown retry schedule. Its 46,759-attempt count is also bounded since #7725.

How you verified

  • New real-process tests in apps/host-daemon/src/workspace-processes-linux.test.ts:
    • "does not refuse for a non-dumpable process in the daemon's own mount namespace" (prctl(PR_SET_DUMPABLE, 0) through python3). On main: the PID is in unreadablePids.
    • "finds a process in another mount namespace that works in the workspace through a bind mount" (unshare -Urm, mount --bind, cd into the bind target). On main: not found.
    • "ignores a process in another mount namespace that does not work in the workspace": passes on main and here.
    • The unshare cases skip where unprivileged user namespaces are blocked, which may include GitHub's Ubuntu runners.
  • New mocked cases in workspace-processes.test.ts, both failing on main:
    • unreadable processes with realistic mountinfo: same namespace, a container bind-mounting the workspace, one bind-mounting a parent, one that does not reach it, and an unreadable mountinfo;
    • an unreadable process under another effective UID.
  • The existing Linux tests are unchanged and pass. pnpm exec turbo run test --filter=@bb/host-daemon passes (890 tests). typecheck lint lint:type-aware pass for @bb/host-daemon, and @bb/templates tests pass.
  • Live on this machine (Fedora 44, xfs, SELinux enforcing, one SSH session), calling the real inspectWorkspaceProcesses on a real bb worktree:
Situation main This branch
Nothing in the workspace unreadablePids with 6 PIDs: systemd, sd-pam, sshd-session, gpg-agent and 2 rootful container processes { pids: [], unreadablePids: [] }
A process with its cwd in the workspace found found
Rootless podman container with -v <workspace>:/app -w /app pids: [] (missed) container PID in pids
Container without that mount ignored ignored
  • Not run: the full tests/qa/scripts/environment-recovery.py flow, which needs the host-care plugin.

Fixes #7435
Fixes #8328

AGENT GENERATED

bb environment cleanup --recover refused whenever any same-user process
could not be inspected. Every Linux login session has such processes:
systemd --user, (sd-pam), sshd-session and gpg-agent are non-dumpable, so
their cwd cannot be read without privileges, and setuid helpers such as
fusermount3 count as same-user through their real UID. Recovery could
never pass on a desktop or SSH machine (get-bb#7435).

The Linux scan now decides from what /proc does expose:
- An unreadable process under another effective UID is another user's
  process, as on macOS (get-bb#7520).
- An unreadable process in the daemon's own mount namespace is not a
  blocker. A non-dumpable program running inside the workspace is
  therefore not detected; that is the accepted cost, like the sudo case
  on macOS.
- A process in another mount namespace, such as a container, is checked
  through its own mount table. A readable one blocks when its cwd or a
  mapped file resolves into the workspace; an unreadable one blocks when
  one of its mounts exposes the workspace or a parent directory. Before,
  a container's namespace-relative cwd was compared with the host path,
  so a container that bind-mounted the workspace was missed.

If the daemon's own mount table cannot be read, the previous rules apply.
The process-identity guard rejected the negated PID assertions in
workspace-processes-linux.test.ts. A check that a PID is not in the
result also passes when the child exited before the inspection.

The test now keeps each ChildProcess, checks that it still runs at
inspection time, and compares one record of how the inspection reported it.
@ymichael
ymichael merged commit 7aac33d into get-bb:main Nov 30, 2026
94 of 95 checks passed
scowalt pushed a commit to scowalt/bb that referenced this pull request Dec 1, 2026
…et-bb#7854)

## Human comments

## What was wrong

`bb environment cleanup <id> --recover`, and the storage plugin's
automatic recovery, refuse while any same-user process cannot be
inspected
([environment-engine.ts#L1145-L1150](https://github.com/get-bb/bb/blob/c113593252d5bdd55b39718a1cadaa6fa09aaac3/apps/server/src/services/environments/environment-engine.ts#L1145-L1150)).
The Linux scan treats a process as same-user when any of its four UIDs
matches. It also counts every `cwd` or `maps` read error as unreadable
([workspace-processes.ts#L53-L98](https://github.com/get-bb/bb/blob/c113593252d5bdd55b39718a1cadaa6fa09aaac3/apps/host-daemon/src/workspace-processes.ts#L53-L98)).

Every Linux login session has such processes. `systemd --user`,
`(sd-pam)`, `sshd-session` and `gpg-agent` are non-dumpable, so their
`cwd` cannot be read without privileges. Setuid helpers such as
`fusermount3` match through their real UID. On this machine (Fedora, one
SSH session) recovery is refused for 6 such processes with nothing in
the workspace, so it can never pass (get-bb#7435).

A second gap in the same scan: a process in another mount namespace,
such as a rootless container, reports its `cwd` and mapped files as
paths inside that namespace. The scan compared them with the host
workspace path, so a container that bind-mounts the workspace was not
found.

## What changed

`apps/host-daemon/src/workspace-processes.ts`, Linux only:
- **Another effective UID:** an unreadable process running under another
effective UID counts as another user's process, as on macOS since get-bb#7520
(`fusermount3`, a `sudo` process).
- **Own mount namespace:** an unreadable process in the daemon's own
mount namespace is not a blocker. A process shares the namespace when
the ID of its root mount equals the daemon's. Its `mountinfo` is
readable even when its `cwd` is not.
- **Another mount namespace:** the process is checked through its own
`mountinfo`.
- Paths are resolved to a filesystem device and a path within that
filesystem, then compared with the workspace's location.
- A readable process blocks when its `cwd` or a mapped file resolves
into the workspace.
- An unreadable process blocks when one of its mounts exposes the
workspace, a directory inside it, or a parent directory.
- **Fallback:** if the daemon's own namespace link or `mountinfo` cannot
be read or parsed, the previous rules apply.
- `bb-guide-environments.md` describes the Linux rules and the gap
below.

No wire change: the result shape and its meaning ("processes that may be
using the workspace" and "processes that could not be ruled out") are
unchanged, so `HOST_DAEMON_PROTOCOL_VERSION` is not bumped. The server
is unchanged.

**Decision for review: the same-namespace exception.** A non-dumpable
program running inside the workspace in the daemon's own mount namespace
is not detected. One example is `ssh-agent -D` started from a shell
there; the shell that started it is still detected. This is the Linux
counterpart of the `sudo` gap accepted for macOS in get-bb#7520. Without the
exception, recovery cannot pass on any Linux machine with a login
session.

Not changed: the issue's nested "Needs recovery: Needs recovery: ..."
message. On current main I found no path that re-wraps a stored "Needs
recovery" message. Every write that moves an exhausted environment out
of `failed` needs states that do not occur together, or resets the retry
budget first, as `--recover` does. The issue was seen on 0.48.1, before
get-bb#7725 reworked the teardown retry schedule. Its 46,759-attempt count is
also bounded since get-bb#7725.

## How you verified

- New real-process tests in
`apps/host-daemon/src/workspace-processes-linux.test.ts`:
- "does not refuse for a non-dumpable process in the daemon's own mount
namespace" (`prctl(PR_SET_DUMPABLE, 0)` through python3). **On main:**
the PID is in `unreadablePids`.
- "finds a process in another mount namespace that works in the
workspace through a bind mount" (`unshare -Urm`, `mount --bind`, `cd`
into the bind target). **On main:** not found.
- "ignores a process in another mount namespace that does not work in
the workspace": passes on main and here.
- The `unshare` cases skip where unprivileged user namespaces are
blocked, which may include GitHub's Ubuntu runners.
- New mocked cases in `workspace-processes.test.ts`, both failing on
main:
- unreadable processes with realistic `mountinfo`: same namespace, a
container bind-mounting the workspace, one bind-mounting a parent, one
that does not reach it, and an unreadable `mountinfo`;
  - an unreadable process under another effective UID.
- The existing Linux tests are unchanged and pass. `pnpm exec turbo run
test --filter=@bb/host-daemon` passes (890 tests). `typecheck lint
lint:type-aware` pass for `@bb/host-daemon`, and `@bb/templates` tests
pass.
- Live on this machine (Fedora 44, xfs, SELinux enforcing, one SSH
session), calling the real `inspectWorkspaceProcesses` on a real bb
worktree:

| Situation | main | This branch |
|---|---|---|
| Nothing in the workspace | `unreadablePids` with 6 PIDs: systemd,
sd-pam, sshd-session, gpg-agent and 2 rootful container processes | `{
pids: [], unreadablePids: [] }` |
| A process with its cwd in the workspace | found | found |
| Rootless podman container with `-v <workspace>:/app -w /app` | `pids:
[]` (missed) | container PID in `pids` |
| Container without that mount | ignored | ignored |

- Not run: the full `tests/qa/scripts/environment-recovery.py` flow,
which needs the host-care plugin.

Fixes get-bb#7435
Fixes get-bb#8328

> AGENT GENERATED

---------

Co-authored-by: Michael Yong <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants