shell: report a truncated -c command line instead of hanging on it - #4
Merged
Conversation
A remote shell caps how long a single command line may be, and past that cap it truncates the line and says nothing at all: the command still runs, but what falls off the end is dwshell's RC sentinel, so -c waited out its whole --timeout — or, with no --timeout, forever — for a marker that could never arrive. This is not specific to Windows. cmd.exe cuts at 8190 characters, but a *nix remote truncates too, depending on the user's shell: bash and zsh read the prompt line in raw mode and take a megabyte, while sh, dash and ash read in canonical mode, where the tty line discipline cuts at 4094. Measured under dash on a live agent: 4094 passes, 4095 does not. Which shell the remote user has is not knowable in advance, and guessing it would be the wrong side of the trade — a wrong guess denies work the remote would have run. So detect instead of predict: type a short probe line after the command. A shell reads it only once it has read and run the command line, so its marker cannot come back before that command's RC sentinel unless the line was cut short. Verified under dash and on Windows: with the line truncated the RC never appears and the probe still does. Like the RC sentinel, the probe marker is assembled by the remote, so neither the PTY echoing the line back nor a command printing its own stdin can be taken for it. Cost is one 55-byte message per -c run. Detection cannot prevent the partial execution that already happened; it replaces a silent hang with a clear error, and the error names no character count, since every such figure belongs to one shell only. Verified live: on Windows 8190 still runs and 8191 reports in 2 s rather than timing out; exit codes, a 1 MB bash command and 60 KB byte-exact round-trips all unaffected, and a stdin-reading command does not false-positive. Fixes #3. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01MvidAFW9a2r4hTgHPW9ywG
ale-rinaldi
force-pushed
the
fix/windows-command-line-limit
branch
from
September 5, 2026 16:13
f12584d to
89b6610
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3 (residual finding from #1).
Root cause
A remote shell caps how long a single command line may be, and past that cap it truncates the line and says nothing at all. Instrumenting the raw terminal stream over an over-long line shows
__DWSH_BEGIN__arriving and the prompt returning, with no error text — the command runs truncated, and what falls off the end is exactly the__DWSH_RC_..._END__sentinel-cwaits for. So-cburned its whole--timeout, or hung forever with the default of none.It is not Windows-specific. cmd.exe cuts at 8190 characters, but a *nix remote truncates too, depending on the remote user's shell:
Measured under
dashon a live Linux agent: 4094 passes, 4095 does not.The report guessed cmd.exe would print
The input line is too long.and that it simply was not reaching the client. It prints nothing in this path — there is no remote error to surface, which is why the fix cannot be better output handling.Change
Which shell the remote user has is not knowable in advance, and guessing it would be the wrong side of the trade: a wrong guess denies work the remote would have run. So detect rather than predict.
A short probe line is typed after the command. A shell reads it only once it has read and run the command line, so its marker cannot come back before that command's RC sentinel — unless the line was cut short and took the sentinel with it. Verified under
dashand on Windows: with the line truncated the RC never appears and the probe still does.Like the RC sentinel, the probe marker is assembled by the remote (
$?/%errorlevel%), so neither the PTY echoing the typed line back nor a command printing its own stdin can be mistaken for it.An earlier revision of this branch also pre-checked the length against cmd.exe's 8190. That was dropped: it baked into the client an assumption about the remote — the current agent hardcodes
cmd.exe, with apowershell.exeline commented out right beneath it — and if that ever flips the check becomes a false rejection. The error message likewise names no character count, since every such figure belongs to one shell only.Honest limit: detection cannot prevent the partial execution that already happened. It replaces a silent hang with a clear error.
Verification
--timeoutdash, line past 4094-c "head -1"(reads stdin)gofmt,go vet,go test -race ./...green.🤖 Generated with Claude Code
https://claude.ai/code/session_01MvidAFW9a2r4hTgHPW9ywG