Fix command cleanup and first-use races in `BubblewrapWorkspace`
Why we make these changes
Foreground descendants can survive timeout or cancellation, and concurrent first calls can race during login-path setup. Remove --new-session so the backend's process-group cleanup reaches the command's children, and make the login-path setup script accept a path another workspace created between its check and its creation (each run of BubblewrapSandbox builds its own workspace, so a per-instance lock alone cannot serialize them; the lock stays as an optimisation within one workspace). Without --new-session, the wrapped workspace must run commands without a controlling terminal; the class docstring, README, and docs page now state this requirement and the TIOCSTI risk it avoids. The docs also say which backends stop a command's descendants.
- Closes #10743
This PR now contains everything from #10763 and #10778, so those two are redundant.
New public surface
none
User-visible behavior
- Before:
sleep 3600 & waitcan leave its child running after timeout or cancellation. After: withLocalWorkspaceBackendorSSHWorkspaceBackend, foreground descendants are stopped; E2B and Modal stop only the leader when the image lackssetsid. Deliberately detached jobs still survive. - Before: concurrent first calls, on one workspace or on separate runs against the same home, can fail with
WorkspaceUnavailableErrorwhile creating missing login files. After: both proceed; a path that turns out to be a symlink after a failed creation is still refused.
Verification
- Login paths created by another workspace meanwhile and a parent symlinked meanwhile: both fail with the script change reverted (
cannot overwrite existing fileorFile exists); files are created withprintfbecause dash exits on a failed:redirection, which CI caught; the second also fails without the post-creation symlink check. - Concurrent first calls on one workspace run setup once.
--new-sessionremoval is guarded in CI by the fake-bwrapargv tests, including an explicit'--new-session' not inassertion intest_commands_run_in_bwrap_on_the_wrapped_host.- The real process-group test,
TestRealBubblewrap::test_stopping_a_command_kills_its_descendants, is skipped in CI because CI hosts have nobwrap. For commit 1cbe7b3 it was run on a Linux host withbwrap(passes; fails with--new-sessionrestored), and timeouts were checked over real SSH there; it was not rerun for the later commits, which do not touch the launcher. - Locally (macOS):
tests/harness/bubblewrap_sandbox100 passed, 51 skipped; Ruff and Pyright clean; docs parity 8 passed.
What changes for existing users
Foreground commands respect backend timeout/cancellation cleanup, and concurrent first calls no longer race to create login files. Custom wrapped backends must not attach a controlling terminal.
Checklist
- No breaking changes in accordance with the version policy.
- Any permitted compatibility impact has a label, warning, migration, release note, and exact API-check waiver. N/A: no public API or supported compatibility change.
- PR title is fit for the release changelog.