Index of every page on this site: llms.txt
All skills
mcfrank avatar

/remote-vm-gotchas

@d1c0494
Run it yourself

Common footguns when running long jobs on remote VMs over SSH (GCP, AWS, Sherlock, any cloud). Use as a sanity check before kill/relaunch operations, before scp'ing into a running script, or when an SSH session keeps dropping unexpectedly.

  • 1 file
  • 5.2 KB
  • Updated 4 weeks ago
  • GitHub
Use this Skill: https://skilld.dev/gh/mcfrank/claude-skills/remote-vm-gotchas

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

SKILL.md

≈65 tokens for metadata: the name and description. ≈1.3k when used: this file.

Description uses 3.2% of example budget

Before choosing a Skill, your Agent reads its name and description. All available Skills share that space.

  • A shorter description leaves more room for other Skills. This entry exceeds our 1% size suggestion.

In our Claude Code example, all Skill names and descriptions share 8,000 characters. This Skill uses ≈259 characters, or 3.2%.

The 1% threshold is a size suggestion. Longer descriptions can still fit.

Your model, settings, and other Skills decide how much text your Agent can read.

Example settings and source

The example uses a 200k-token context and default Claude Code settings. The count includes the name, description, separators, and when_to_use when present. Codex also counts local file paths.

Skit's source and limits: Codex 0.160.1, Claude Code 2.1.292.

Remote VM workflow gotchas

Bite-sized rules from running long jobs over ssh and gcloud compute ssh.

Don't scp a script that's currently executing

gcloud compute scp run_thing.sh vm:path/run_thing.sh while a run_thing.sh process is mid-execution will corrupt the running shell. bash re-reads its source at line boundaries; if the file changed (even just byte length), the next read can land mid-token and throw "unexpected EOF" or "syntax error".

This will crash a long-running launcher right between phases (e.g., between sampling and post-processing).

Workarounds:

  • Wait for the current invocation to finish before patching
  • Patch into a new filename (run_thing_v2.sh) and switch the caller
  • Make the change only in the next launch's environment

pkill -9 of session ancestors kills the SSH session

If you gcloud compute ssh ... --command="pkill -9 -f some_pattern" and the SSH session itself is somewhere in the process tree being walked, ssh dies. You'll see:

ERROR: (gcloud.compute.ssh) [/usr/bin/ssh] exited with return code [255].

This is harmless — the pkill ran, just before SSH could send a clean exit. Reconnect to verify the kill worked:

gcloud compute ssh <vm> --command="ps -eo cmd | grep <pattern> | grep -v grep || echo clean"

Detached background launches

The robust pattern for "fire and forget" on a remote VM:

gcloud compute ssh <vm> --command="cd ~/path && \
  ENV_VAR=val nohup bash run_thing.sh > thing.log 2>&1 < /dev/null & disown"

All four pieces matter:

Piece Why
nohup survives SIGHUP when ssh disconnects
> log 2>&1 captures all output (else SSH waits on stdout/stderr drain)
< /dev/null closes stdin (else SSH waits on stdin)
& disown backgrounds AND removes from bash's job table

Without < /dev/null and & disown, the SSH session can still hang waiting for IO, or the process can die when ssh closes — depending on shell version.

Background tasks vs. harness notifications

If your runner harness has a "background task" feature (like Claude Code's Bash(..., run_in_background: true)), use it for commands that return useful output. For pure "fire on remote and forget" launches, use the inline nohup ... & disown pattern above — the wrapper exits in <1s anyway, so backgrounding the wrapper itself is pointless.

For "watch this thing until done" patterns where the thing takes hours, prefer scheduled wakeups (ScheduleWakeup or similar) over background-bash-polling. You get fresh process/log state each time.

scp --recurse with multiple sources flattens

gcloud compute scp file1.sh file2.sh file3.R vm:dest/ --recurse

flattens all sources into dest/, losing the local path hierarchy. To preserve gcp/run_fit.sh → vm:standard_model_2/gcp/run_fit.sh, do one scp per file with the explicit destination path. Annoying but reliable.

Symlinks vs mkdir -p order

Code that does:

mkdir -p $X/sub
[ -L $X/sub ] || ln -sfn $TARGET $X/sub

will never create the symlink — mkdir -p always creates $X/sub as a real directory first, so the [ -L ] check is always false (it's a directory, not a symlink) and ln -sfn then refuses to clobber a non-empty dir.

Robust version (bash):

mkdir -p "$X" "$TARGET"
if [ -e "$X/sub" ] && [ ! -L "$X/sub" ]; then
  # Move contents into $TARGET without overwriting anything (dotfiles too)
  (shopt -s dotglob nullglob; mv -n "$X/sub"/* "$TARGET"/) || true
  # Remove the old dir only if it is now empty. Never rm -rf here: anything
  # left is a name collision with $TARGET and needs a human decision.
  if ! rmdir "$X/sub"; then
    echo "$X/sub still has entries that collide with $TARGET; resolve by hand" >&2
    exit 1
  fi
fi
ln -sfn "$TARGET" "$X/sub"

This idiom catches the case where a previous run created a real dir: it moves the contents over, refuses to delete anything that didn't move (mv -n skips names already in $TARGET, and an rm -rf fallback would silently destroy those), then sets up the symlink.

Disk space silently fills /tmp

Many tools write intermediate output to /tmp (in GB) without warning. Stan, R, Python's tempfile, etc. /tmp is often on the boot disk, which is small by default.

Before launching long jobs: df -h /tmp /. If the boot disk is < 100 GB and you're about to write log_lik or similar per-obs data: stop and provision more disk. Online-resize is supported on most cloud disks:

# GCP
gcloud compute disks resize <name> --size=250GB --zone=<zone>
# Then on the VM
sudo growpart /dev/sda 1 && sudo resize2fs /dev/sda1

Mac binaries leak to Linux VMs via rsync

If you rsync a project directory from a Mac to a Linux VM, compiled binaries (Stan models, native extensions) get copied and will segfault on Linux x86_64 because they were built for Mac arm64.

Always exclude .o, .so, model-binary files in your rsync, or recompile after sync. Better: rsync only source files and let the remote rebuild.

Source: SKILL.md on GitHub

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No third-party reports yet.

Signed by skilld at d1c0494. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 3 days ago.

Activeupdated 4 weeks ago

README badge

README badge for mcfrank/claude-skills/remote-vm-gotchas