fix(@scripts): 🐛 revert systemd-run scope fallback to plain tmux

Co-Authored-By: Lilith Autocommit <noreply@atlilith.com>
This commit is contained in:
Natalie 2026-05-20 17:57:39 -07:00
parent 6eda3851a9
commit 0ed5118953

View file

@ -1662,25 +1662,17 @@ inner=$(build_inner "$dir")
# detached branch above; used by supervisor processes (e.g. clare web)
# that bring up a remote Claude pane without attaching the calling tty.
#
# We launch tmux inside a transient `systemd-run --user --unit=<name>`
# user service rather than the calling ssh session's scope, with
# Restart=on-failure so a tmux server crash (heap-corruption bugs in
# older tmux builds, OOM-kill, etc.) is automatically recovered by
# systemd rather than waiting on Clare's 60s supervisor heartbeat.
#
# `--scope` was the old approach but a scope dies with its process — no
# restart. Falls back to a plain detached `tmux new-session -d` if the
# remote host has no systemd-run (e.g. macOS).
# Plain `ssh ... tmux new-session -d` — mirrors the attached remote path
# below (just `-d` instead of `-A`). A tmux server already survives ssh
# disconnect by design (that is what tmux is for); no cgroup gymnastics
# are needed. An earlier `systemd-run --user --scope --collect` wrapper
# here was a regression — `--collect` reaped the scope (and the tmux
# server inside its cgroup) the instant the spawning client exited, so
# the session never materialized. Verified 2026-05-20: plain ssh+tmux
# detached spawn survives; the systemd-run variant did not.
# Mosh is interactive-only — always go through ssh for detached spawn.
if [ -n "${RCLAUDE_DETACHED:-}" ]; then
# Run tmux inside a transient user scope so the tmux daemon escapes
# the calling ssh login session's cgroup (which systemd-logind would
# otherwise reap on disconnect, even with linger enabled). `--scope`
# exits as soon as the tmux daemon detaches; recovery from later
# tmux crashes is handled by Clare's supervisor heartbeat in
# `clare web` (re-runs ensure_running every 60s).
_remote_cmd="systemd-run --user --scope --collect --quiet tmux new-session -d -s '${session}' \"${inner}\" 2>/dev/null || tmux new-session -d -s '${session}' \"${inner}\""
ssh $_SSH_LIVE_OPTS "$host" "$_remote_cmd"
ssh $_SSH_LIVE_OPTS "$host" "tmux new-session -d -s '${session}' \"${inner}\""
printf '%s\n' "$session"
exit 0
fi