Skip to content

session-recovery: optional auto-sweep + spare-yourself in --all #10

@abizer

Description

@abizer

Follow-ups from the session-recovery work (PR coming separately). Neither is needed today, but they would round out nssh sweep.

1. Auto-sweep on connect

Today nssh sweep <host> is a manual op. Once you trust the threshold, you almost never want to run it explicitly — you want it to happen as a side effect of nssh hostA.

Proposal: optional config key in ~/.config/nssh/config.toml:

sweep_older = "168h"  # kill mosh-server processes older than this on connect

When set, every fresh nssh hostA (not a join) kicks off a background sweep matching the threshold after the interactive session starts, so the sweep doesn't block the user.

Open questions:

  • Should it report what it killed on the next prompt, or stay silent?
  • Skip the sweep if --join / --replace / --new was passed explicitly?
  • One global threshold or per-host?

2. Spare-yourself in --all

Today nssh sweep --all <host> would kill the mosh-server backing your current nssh session if you ran it from inside one. That's almost never what you want.

Proposal: capture the spawned mosh-server's remote PID at connect time, persist it in our local pidfile (~/.local/state/nssh/sessions/<pid>.json gets a new mosh_pid field), and --all excludes any PID we know is held by a live local nssh.

The fiddly part: mosh-client doesn't surface the remote mosh-server PID. Options:

  • Right after mosh hostA starts, do a side-channel ssh hostA pgrep -u \$USER -n mosh-server to find the youngest one. Race-prone but usually right.
  • Have the remote shim write a breadcrumb at first invocation that includes \$PPID (which is mosh-server). Reliable but happens lazily.

Either way, default behavior of nssh sweep (interactive) is unchanged — the user picks PIDs explicitly and knows which one is theirs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions