feat(cli): add exec --stream for non-PTY bidirectional streaming exec#922
Open
dijdzv wants to merge 7 commits into
Open
feat(cli): add exec --stream for non-PTY bidirectional streaming exec#922dijdzv wants to merge 7 commits into
exec --stream for non-PTY bidirectional streaming exec#922dijdzv wants to merge 7 commits into
Conversation
…g exec orbit drives a long-lived guest agent process (claude --input-format stream-json) turn by turn: it must read each turn's output before sending the next request. The default `exec` path can't do this — it reads stdin to EOF upfront and buffers all guest output until the process exits (collect()). `ssh connect` streams stdout but doesn't forward piped stdin. `--stream` uses the existing streaming primitives (exec_stream_with + ExecHandle::recv + ExecSink) to forward host stdin incrementally and flush guest stdout/stderr per chunk, without allocating a PTY (so the byte stream is not echoed or CRLF-translated — safe for JSON lines). The default path is untouched, so existing buffered exec callers are unaffected. agentd/protocol unchanged (CLI-only patch). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
`_ => {}` would silently drop a newly added ExecEvent variant. Matching
`Started`/`StdinError` by name (as the SDK's own `collect()` does) turns a
future variant into a compile error instead of a swallowed event.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…event The recv loop seeded exit_code to 0 and fell through to Ok(()), so a session that ended without an Exited event (agent/VM dropped mid-run) was reported as success. The buffered `exec_with`/`collect()` path errors here. Track the code as Option and bail on None so a dead session can't masquerade as exit 0. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The `--stream` flag had no test. The SDK primitives it wraps are covered by `tests/stdin.rs`, but the CLI wiring — forward stdin incrementally, flush output per chunk — wasn't. Add a `#[msb_test]` e2e that drives a guest awk loop turn by turn over the streamed channel, sending each line only after reading the previous reply. The buffered `exec` path reads stdin to EOF before emitting output, so it deadlocks here; completing within the timeout is the assertion (confirmed: dropping `--stream` makes it time out). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
What
Adds a
--streamflag tomsb exec. It streams stdin/stdout bidirectionallywithout buffering or a PTY, built on the existing streaming primitives
(
Sandbox::exec_stream_with+ExecHandle::recv+ExecSink).Diff is one file (
crates/cli/lib/commands/exec.rs); the defaultexecpath,agentd, and the protocol are untouched.Why
msb execcan't drive a long-lived guest process turn by turn (read turn N'soutput, then send turn N+1's request):
the process exits (
collect()), so output never comes back mid-run;-t/--ttyallocates a PTY, which echoes input and translates CRLF —unsafe for line protocols like JSON lines.
--streamforwards host stdin incrementally and flushes guest stdout/stderr perchunk, with no PTY. This lets a host driver run e.g. an agent CLI in stream-json
mode and read each turn before sending the next.
How
--streambool; skips the upfrontread_to_endof stdin.exec_stream_with(... .stdin_pipe()).closes the guest's stdin.
ExecEvents, writing + flushingStdout/Stderrper chunk, exits withthe child's code, and fails if the session ends without an
Exitedevent(matching the buffered
collect()path).Notes
Builds on the streaming SDK API already present (added in feat(microsandbox): add exec, attach, and streaming execution (#387) #387).
Adds a CLI e2e test (
crates/cli/tests/exec_stream.rs) that drives a guestturn by turn over the stream; it deadlocks under the buffered
execpath, soit fails closed if streaming ever regresses. Gated behind
#[msb_test]likethe other KVM integration tests: