Repository navigation
Let environment recovery pass on Linux machines with login sessions - #7854
Merged
Merged
Conversation
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.
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]>
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.
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 everycwdormapsread error as unreadable (workspace-processes.ts#L53-L98).Every Linux login session has such processes.
systemd --user,(sd-pam),sshd-sessionandgpg-agentare non-dumpable, so theircwdcannot be read without privileges. Setuid helpers such asfusermount3match 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
cwdand 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:fusermount3, asudoprocess).mountinfois readable even when itscwdis not.mountinfo.cwdor a mapped file resolves into the workspace.mountinfocannot be read or parsed, the previous rules apply.bb-guide-environments.mddescribes 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_VERSIONis 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 -Dstarted from a shell there; the shell that started it is still detected. This is the Linux counterpart of thesudogap 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
failedneeds states that do not occur together, or resets the retry budget first, as--recoverdoes. 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
apps/host-daemon/src/workspace-processes-linux.test.ts:prctl(PR_SET_DUMPABLE, 0)through python3). On main: the PID is inunreadablePids.unshare -Urm,mount --bind,cdinto the bind target). On main: not found.unsharecases skip where unprivileged user namespaces are blocked, which may include GitHub's Ubuntu runners.workspace-processes.test.ts, both failing on main:mountinfo: same namespace, a container bind-mounting the workspace, one bind-mounting a parent, one that does not reach it, and an unreadablemountinfo;pnpm exec turbo run test --filter=@bb/host-daemonpasses (890 tests).typecheck lint lint:type-awarepass for@bb/host-daemon, and@bb/templatestests pass.inspectWorkspaceProcesseson a real bb worktree:unreadablePidswith 6 PIDs: systemd, sd-pam, sshd-session, gpg-agent and 2 rootful container processes{ pids: [], unreadablePids: [] }-v <workspace>:/app -w /apppids: [](missed)pidstests/qa/scripts/environment-recovery.pyflow, which needs the host-care plugin.Fixes #7435
Fixes #8328