The sandbox launcher kept only (env, pid) and later ran kill -TERM on that number: after a Chromium
crash a persistent sandbox or ssh host can reuse the pid, and stale-session eviction or idle cleanup
would stop an unrelated job. The launch exec now also reads the browser's start time inside the
sandbox (/proc/<pid>/stat field 22), and the stop is one exec that re-checks the start time and the
exact --user-data-dir argv token before signalling. A pid whose identity no longer matches, or
whose start time could not be read at launch, is left alone and logged.
_wait_for_port treats a docker/ssh exec that times out as one more not-ready answer (the launch
deadline decides readiness), and stop_sandbox_browser swallows TimeoutExpired like any other exec
failure, so a slow sandbox cannot crash the teardown.
create_sandbox_session holds a per-container lock across the liveness check, the launch and the
ownership claim (and stop_sandbox_browser across the stop), so two sessions first using one container
no longer both see no browser and both launch Chromium.
create_sandbox_session now owns the detached Chromium under its shared key the moment it is spawned
and stops it when the port wait, the forward or an interrupt (BaseException) fails, so a timeout no
longer leaves an unowned browser running that stop_sandbox_browser cannot reach.
The confirmed-alive cache now expires after _CONFIRMED_TTL_S (30 s) and the port forward counts an
HTTP 404 on /devtools/browser/<id> as a forward failure, so a session cached on a relaunched sandbox
Chromium is rebuilt instead of kept. Healthy calls inside the TTL still spend no exec.
N2 (re-review of #143146). The shared sandbox Chromium's launcher key was
`sandbox:<profile home>:<profile dir>`, but the Chromium belongs to the container:
- profiles sharing one container (terminal.docker_shared_container_key) got different keys
for the same browser, so one profile's teardown killed the browser the other still used;
- with one container per session (container_persistent: false) every container's browser
got the same key, `_launched` kept only the last, and the first container's Chromium was
never stopped.
The key is now the container's env object (its port forwards keep it alive, so the id is
never reused while a session names it) plus the profile dir: profiles in one container
share one refcount, and a per-session container's browser stops with that session.
N1 (re-review of #143146). sandbox_browser_alive read any non-zero exec exit (a docker/ssh
transport error) as "Chromium dead": the session was rebuilt and, as the last user, its
teardown SIGTERMed a browser that was still running. A probe timeout raised TimeoutExpired
out of get_session_info, so browser_exec failed. Every browser call also paid one exec in
the sandbox.
- The probe script exits 3 only when the sandbox itself answers "not running" (no
DevToolsActivePort, or nothing listens on its port). Any other failure, including a
timeout, is "unknown" and keeps the session.
- Creating a session refuses to launch on an unknown answer instead of wiping a live
browser's DevToolsActivePort and losing to its singleton.
- A confirmed endpoint is cached. The port forward now counts connections that never
reached the target, and the session is re-probed only after that count changes (or the
sandbox was replaced), so a healthy call spends no exec.
Sessions placed in the terminal sandbox all attach to one in-sandbox Chromium, but teardown of the
session that launched it SIGTERMed it under the others. Sandbox sessions now share a per-profile
launcher key (same in-use check as host profiles; the launch pid + env are kept per key), and
_backend_dead rebuilds once that Chromium is gone, relaunched or behind a new port forward.
main gave the root/Docker/AppArmor sandbox bypass only to the Chromium agent-browser launched (packaged,
pinned, Bot Desktop) and never to the real-profile Chrome/Edge/Brave; launch_chromium now threads an
explicit sandbox_bypass flag that the real-profile launch turns off.