base64 -w0 "$script" | ssh "$host" "f=\$(mktemp); base64 -d > \"\$f\" && bash \"\$f\" $args"
Both documented snippets run exactly as written. Solution complete.
Diagnosis. MAX_ARG_STRLEN = 131072 bytes caps a single argv word; with the NUL terminator the largest usable argument is 131071 bytes. A generated script (especially base64, which inflates 4/3) placed inside one ssh command word makes the local execve("ssh", …) fail with E2BIG (bash reports Argument list too long, exit 126) before any network I/O. getconf ARG_MAX (2 MiB total) hides this per-word cap, which is why it looks like it should work.
Exact crossover (verified): plain 98 301 B → base64 131 068 B → OK; plain 98 302 B → base64 131 072 B → E2BIG. The context's "~97 KB" is this boundary.
Fix. Never put the script into an argument — stream it on stdin:
ssh "$host" "f=\$(mktemp); cat > \"\$f\" && bash \"\$f\" $args" < "$script"
# or keep base64, decoded remotely from stdin:
base64 -w0 "$script" | ssh "$host" "f=\$(mktemp); base64 -d > \"\$f\" && bash \"\$f\" $args"
This is size-unbounded and quoting-safe. A reusable run_remote.sh helper (quotes only the small positional args, frees stdin, propagates exit status) is included in the doc.
Verification performed on this host:
- Boundary: 131071 OK, 131072 → E2BIG (errno probe).
- 345,929 B quoting-hostile script: old form → Argument list too long; new form → exit 0.
- Byte-for-byte integrity via stdin (sha256sum match).
- 5 MB script streams successfully; exit status 3 propagates.
- Both documented one-liners executed verbatim and pass.
Full write-up: ~/ssh-e2big-argument-list-too-long.md
# Evidence - Problem class: ssh-e2big-argument-list-too-long - Model: openrouter/deepseek/deepseek-v4.1-flash - Solved: 2026-10-05T04:24:08.075Z - Verification: solution produced by pi in sandbox; see signatures.json
{"description": "", "environment": "", "language": "", "model": "openrouter/deepseek/deepseek-v4.1-flash", "problem_class": "ssh-e2big-argument-list-too-long", "provider": "openrouter", "solved_at": "2026-10-05T04:24:08.075Z", "version": ""}